Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/kaber/nf-2.6
[linux-2.6] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
33 #include "hda_beep.h"
34
35 #define ALC880_FRONT_EVENT              0x01
36 #define ALC880_DCVOL_EVENT              0x02
37 #define ALC880_HP_EVENT                 0x04
38 #define ALC880_MIC_EVENT                0x08
39
40 /* ALC880 board config type */
41 enum {
42         ALC880_3ST,
43         ALC880_3ST_DIG,
44         ALC880_5ST,
45         ALC880_5ST_DIG,
46         ALC880_W810,
47         ALC880_Z71V,
48         ALC880_6ST,
49         ALC880_6ST_DIG,
50         ALC880_F1734,
51         ALC880_ASUS,
52         ALC880_ASUS_DIG,
53         ALC880_ASUS_W1V,
54         ALC880_ASUS_DIG2,
55         ALC880_FUJITSU,
56         ALC880_UNIWILL_DIG,
57         ALC880_UNIWILL,
58         ALC880_UNIWILL_P53,
59         ALC880_CLEVO,
60         ALC880_TCL_S700,
61         ALC880_LG,
62         ALC880_LG_LW,
63         ALC880_MEDION_RIM,
64 #ifdef CONFIG_SND_DEBUG
65         ALC880_TEST,
66 #endif
67         ALC880_AUTO,
68         ALC880_MODEL_LAST /* last tag */
69 };
70
71 /* ALC260 models */
72 enum {
73         ALC260_BASIC,
74         ALC260_HP,
75         ALC260_HP_DC7600,
76         ALC260_HP_3013,
77         ALC260_FUJITSU_S702X,
78         ALC260_ACER,
79         ALC260_WILL,
80         ALC260_REPLACER_672V,
81         ALC260_FAVORIT100,
82 #ifdef CONFIG_SND_DEBUG
83         ALC260_TEST,
84 #endif
85         ALC260_AUTO,
86         ALC260_MODEL_LAST /* last tag */
87 };
88
89 /* ALC262 models */
90 enum {
91         ALC262_BASIC,
92         ALC262_HIPPO,
93         ALC262_HIPPO_1,
94         ALC262_FUJITSU,
95         ALC262_HP_BPC,
96         ALC262_HP_BPC_D7000_WL,
97         ALC262_HP_BPC_D7000_WF,
98         ALC262_HP_TC_T5735,
99         ALC262_HP_RP5700,
100         ALC262_BENQ_ED8,
101         ALC262_SONY_ASSAMD,
102         ALC262_BENQ_T31,
103         ALC262_ULTRA,
104         ALC262_LENOVO_3000,
105         ALC262_NEC,
106         ALC262_TOSHIBA_S06,
107         ALC262_TOSHIBA_RX1,
108         ALC262_TYAN,
109         ALC262_AUTO,
110         ALC262_MODEL_LAST /* last tag */
111 };
112
113 /* ALC268 models */
114 enum {
115         ALC267_QUANTA_IL1,
116         ALC268_3ST,
117         ALC268_TOSHIBA,
118         ALC268_ACER,
119         ALC268_ACER_DMIC,
120         ALC268_ACER_ASPIRE_ONE,
121         ALC268_DELL,
122         ALC268_ZEPTO,
123 #ifdef CONFIG_SND_DEBUG
124         ALC268_TEST,
125 #endif
126         ALC268_AUTO,
127         ALC268_MODEL_LAST /* last tag */
128 };
129
130 /* ALC269 models */
131 enum {
132         ALC269_BASIC,
133         ALC269_QUANTA_FL1,
134         ALC269_ASUS_EEEPC_P703,
135         ALC269_ASUS_EEEPC_P901,
136         ALC269_FUJITSU,
137         ALC269_LIFEBOOK,
138         ALC269_AUTO,
139         ALC269_MODEL_LAST /* last tag */
140 };
141
142 /* ALC861 models */
143 enum {
144         ALC861_3ST,
145         ALC660_3ST,
146         ALC861_3ST_DIG,
147         ALC861_6ST_DIG,
148         ALC861_UNIWILL_M31,
149         ALC861_TOSHIBA,
150         ALC861_ASUS,
151         ALC861_ASUS_LAPTOP,
152         ALC861_AUTO,
153         ALC861_MODEL_LAST,
154 };
155
156 /* ALC861-VD models */
157 enum {
158         ALC660VD_3ST,
159         ALC660VD_3ST_DIG,
160         ALC660VD_ASUS_V1S,
161         ALC861VD_3ST,
162         ALC861VD_3ST_DIG,
163         ALC861VD_6ST_DIG,
164         ALC861VD_LENOVO,
165         ALC861VD_DALLAS,
166         ALC861VD_HP,
167         ALC861VD_AUTO,
168         ALC861VD_MODEL_LAST,
169 };
170
171 /* ALC662 models */
172 enum {
173         ALC662_3ST_2ch_DIG,
174         ALC662_3ST_6ch_DIG,
175         ALC662_3ST_6ch,
176         ALC662_5ST_DIG,
177         ALC662_LENOVO_101E,
178         ALC662_ASUS_EEEPC_P701,
179         ALC662_ASUS_EEEPC_EP20,
180         ALC663_ASUS_M51VA,
181         ALC663_ASUS_G71V,
182         ALC663_ASUS_H13,
183         ALC663_ASUS_G50V,
184         ALC662_ECS,
185         ALC663_ASUS_MODE1,
186         ALC662_ASUS_MODE2,
187         ALC663_ASUS_MODE3,
188         ALC663_ASUS_MODE4,
189         ALC663_ASUS_MODE5,
190         ALC663_ASUS_MODE6,
191         ALC272_DELL,
192         ALC272_DELL_ZM1,
193         ALC662_AUTO,
194         ALC662_MODEL_LAST,
195 };
196
197 /* ALC882 models */
198 enum {
199         ALC882_3ST_DIG,
200         ALC882_6ST_DIG,
201         ALC882_ARIMA,
202         ALC882_W2JC,
203         ALC882_TARGA,
204         ALC882_ASUS_A7J,
205         ALC882_ASUS_A7M,
206         ALC885_MACPRO,
207         ALC885_MBP3,
208         ALC885_IMAC24,
209         ALC882_AUTO,
210         ALC882_MODEL_LAST,
211 };
212
213 /* ALC883 models */
214 enum {
215         ALC883_3ST_2ch_DIG,
216         ALC883_3ST_6ch_DIG,
217         ALC883_3ST_6ch,
218         ALC883_6ST_DIG,
219         ALC883_TARGA_DIG,
220         ALC883_TARGA_2ch_DIG,
221         ALC883_ACER,
222         ALC883_ACER_ASPIRE,
223         ALC888_ACER_ASPIRE_4930G,
224         ALC883_MEDION,
225         ALC883_MEDION_MD2,
226         ALC883_LAPTOP_EAPD,
227         ALC883_LENOVO_101E_2ch,
228         ALC883_LENOVO_NB0763,
229         ALC888_LENOVO_MS7195_DIG,
230         ALC888_LENOVO_SKY,
231         ALC883_HAIER_W66,
232         ALC888_3ST_HP,
233         ALC888_6ST_DELL,
234         ALC883_MITAC,
235         ALC883_CLEVO_M720,
236         ALC883_FUJITSU_PI2515,
237         ALC888_FUJITSU_XA3530,
238         ALC883_3ST_6ch_INTEL,
239         ALC888_ASUS_M90V,
240         ALC888_ASUS_EEE1601,
241         ALC1200_ASUS_P5Q,
242         ALC883_AUTO,
243         ALC883_MODEL_LAST,
244 };
245
246 /* styles of capture selection */
247 enum {
248         CAPT_MUX = 0,   /* only mux based */
249         CAPT_MIX,       /* only mixer based */
250         CAPT_1MUX_MIX,  /* first mux and other mixers */
251 };
252
253 /* for GPIO Poll */
254 #define GPIO_MASK       0x03
255
256 struct alc_spec {
257         /* codec parameterization */
258         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
259         unsigned int num_mixers;
260         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
261         unsigned int beep_amp;  /* beep amp value, set via set_beep_amp() */
262
263         const struct hda_verb *init_verbs[5];   /* initialization verbs
264                                                  * don't forget NULL
265                                                  * termination!
266                                                  */
267         unsigned int num_init_verbs;
268
269         char *stream_name_analog;       /* analog PCM stream */
270         struct hda_pcm_stream *stream_analog_playback;
271         struct hda_pcm_stream *stream_analog_capture;
272         struct hda_pcm_stream *stream_analog_alt_playback;
273         struct hda_pcm_stream *stream_analog_alt_capture;
274
275         char *stream_name_digital;      /* digital PCM stream */
276         struct hda_pcm_stream *stream_digital_playback;
277         struct hda_pcm_stream *stream_digital_capture;
278
279         /* playback */
280         struct hda_multi_out multiout;  /* playback set-up
281                                          * max_channels, dacs must be set
282                                          * dig_out_nid and hp_nid are optional
283                                          */
284         hda_nid_t alt_dac_nid;
285         hda_nid_t slave_dig_outs[3];    /* optional - for auto-parsing */
286         int dig_out_type;
287
288         /* capture */
289         unsigned int num_adc_nids;
290         hda_nid_t *adc_nids;
291         hda_nid_t *capsrc_nids;
292         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
293         int capture_style;              /* capture style (CAPT_*) */
294
295         /* capture source */
296         unsigned int num_mux_defs;
297         const struct hda_input_mux *input_mux;
298         unsigned int cur_mux[3];
299
300         /* channel model */
301         const struct hda_channel_mode *channel_mode;
302         int num_channel_mode;
303         int need_dac_fix;
304
305         /* PCM information */
306         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
307
308         /* dynamic controls, init_verbs and input_mux */
309         struct auto_pin_cfg autocfg;
310         struct snd_array kctls;
311         struct hda_input_mux private_imux[3];
312         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
313
314         /* hooks */
315         void (*init_hook)(struct hda_codec *codec);
316         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
317
318         /* for pin sensing */
319         unsigned int sense_updated: 1;
320         unsigned int jack_present: 1;
321         unsigned int master_sw: 1;
322
323         /* other flags */
324         unsigned int no_analog :1; /* digital I/O only */
325
326         /* for virtual master */
327         hda_nid_t vmaster_nid;
328 #ifdef CONFIG_SND_HDA_POWER_SAVE
329         struct hda_loopback_check loopback;
330 #endif
331
332         /* for PLL fix */
333         hda_nid_t pll_nid;
334         unsigned int pll_coef_idx, pll_coef_bit;
335 };
336
337 /*
338  * configuration template - to be copied to the spec instance
339  */
340 struct alc_config_preset {
341         struct snd_kcontrol_new *mixers[5]; /* should be identical size
342                                              * with spec
343                                              */
344         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
345         const struct hda_verb *init_verbs[5];
346         unsigned int num_dacs;
347         hda_nid_t *dac_nids;
348         hda_nid_t dig_out_nid;          /* optional */
349         hda_nid_t hp_nid;               /* optional */
350         hda_nid_t *slave_dig_outs;
351         unsigned int num_adc_nids;
352         hda_nid_t *adc_nids;
353         hda_nid_t *capsrc_nids;
354         hda_nid_t dig_in_nid;
355         unsigned int num_channel_mode;
356         const struct hda_channel_mode *channel_mode;
357         int need_dac_fix;
358         unsigned int num_mux_defs;
359         const struct hda_input_mux *input_mux;
360         void (*unsol_event)(struct hda_codec *, unsigned int);
361         void (*init_hook)(struct hda_codec *);
362 #ifdef CONFIG_SND_HDA_POWER_SAVE
363         struct hda_amp_list *loopbacks;
364 #endif
365 };
366
367
368 /*
369  * input MUX handling
370  */
371 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
372                              struct snd_ctl_elem_info *uinfo)
373 {
374         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
375         struct alc_spec *spec = codec->spec;
376         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
377         if (mux_idx >= spec->num_mux_defs)
378                 mux_idx = 0;
379         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
380 }
381
382 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
383                             struct snd_ctl_elem_value *ucontrol)
384 {
385         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
386         struct alc_spec *spec = codec->spec;
387         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
388
389         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
390         return 0;
391 }
392
393 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
394                             struct snd_ctl_elem_value *ucontrol)
395 {
396         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
397         struct alc_spec *spec = codec->spec;
398         const struct hda_input_mux *imux;
399         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
400         unsigned int mux_idx;
401         hda_nid_t nid = spec->capsrc_nids ?
402                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
403
404         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
405         imux = &spec->input_mux[mux_idx];
406
407         if (spec->capture_style &&
408             !(spec->capture_style == CAPT_1MUX_MIX && !adc_idx)) {
409                 /* Matrix-mixer style (e.g. ALC882) */
410                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
411                 unsigned int i, idx;
412
413                 idx = ucontrol->value.enumerated.item[0];
414                 if (idx >= imux->num_items)
415                         idx = imux->num_items - 1;
416                 if (*cur_val == idx)
417                         return 0;
418                 for (i = 0; i < imux->num_items; i++) {
419                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
420                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
421                                                  imux->items[i].index,
422                                                  HDA_AMP_MUTE, v);
423                 }
424                 *cur_val = idx;
425                 return 1;
426         } else {
427                 /* MUX style (e.g. ALC880) */
428                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
429                                              &spec->cur_mux[adc_idx]);
430         }
431 }
432
433 /*
434  * channel mode setting
435  */
436 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
437                             struct snd_ctl_elem_info *uinfo)
438 {
439         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
440         struct alc_spec *spec = codec->spec;
441         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
442                                     spec->num_channel_mode);
443 }
444
445 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
446                            struct snd_ctl_elem_value *ucontrol)
447 {
448         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
449         struct alc_spec *spec = codec->spec;
450         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
451                                    spec->num_channel_mode,
452                                    spec->multiout.max_channels);
453 }
454
455 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
456                            struct snd_ctl_elem_value *ucontrol)
457 {
458         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
459         struct alc_spec *spec = codec->spec;
460         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
461                                       spec->num_channel_mode,
462                                       &spec->multiout.max_channels);
463         if (err >= 0 && spec->need_dac_fix)
464                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
465         return err;
466 }
467
468 /*
469  * Control the mode of pin widget settings via the mixer.  "pc" is used
470  * instead of "%" to avoid consequences of accidently treating the % as
471  * being part of a format specifier.  Maximum allowed length of a value is
472  * 63 characters plus NULL terminator.
473  *
474  * Note: some retasking pin complexes seem to ignore requests for input
475  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
476  * are requested.  Therefore order this list so that this behaviour will not
477  * cause problems when mixer clients move through the enum sequentially.
478  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
479  * March 2006.
480  */
481 static char *alc_pin_mode_names[] = {
482         "Mic 50pc bias", "Mic 80pc bias",
483         "Line in", "Line out", "Headphone out",
484 };
485 static unsigned char alc_pin_mode_values[] = {
486         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
487 };
488 /* The control can present all 5 options, or it can limit the options based
489  * in the pin being assumed to be exclusively an input or an output pin.  In
490  * addition, "input" pins may or may not process the mic bias option
491  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
492  * accept requests for bias as of chip versions up to March 2006) and/or
493  * wiring in the computer.
494  */
495 #define ALC_PIN_DIR_IN              0x00
496 #define ALC_PIN_DIR_OUT             0x01
497 #define ALC_PIN_DIR_INOUT           0x02
498 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
499 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
500
501 /* Info about the pin modes supported by the different pin direction modes.
502  * For each direction the minimum and maximum values are given.
503  */
504 static signed char alc_pin_mode_dir_info[5][2] = {
505         { 0, 2 },    /* ALC_PIN_DIR_IN */
506         { 3, 4 },    /* ALC_PIN_DIR_OUT */
507         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
508         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
509         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
510 };
511 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
512 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
513 #define alc_pin_mode_n_items(_dir) \
514         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
515
516 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
517                              struct snd_ctl_elem_info *uinfo)
518 {
519         unsigned int item_num = uinfo->value.enumerated.item;
520         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
521
522         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
523         uinfo->count = 1;
524         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
525
526         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
527                 item_num = alc_pin_mode_min(dir);
528         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
529         return 0;
530 }
531
532 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
533                             struct snd_ctl_elem_value *ucontrol)
534 {
535         unsigned int i;
536         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
537         hda_nid_t nid = kcontrol->private_value & 0xffff;
538         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
539         long *valp = ucontrol->value.integer.value;
540         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
541                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
542                                                  0x00);
543
544         /* Find enumerated value for current pinctl setting */
545         i = alc_pin_mode_min(dir);
546         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
547                 i++;
548         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
549         return 0;
550 }
551
552 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
553                             struct snd_ctl_elem_value *ucontrol)
554 {
555         signed int change;
556         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
557         hda_nid_t nid = kcontrol->private_value & 0xffff;
558         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
559         long val = *ucontrol->value.integer.value;
560         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
561                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
562                                                  0x00);
563
564         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
565                 val = alc_pin_mode_min(dir);
566
567         change = pinctl != alc_pin_mode_values[val];
568         if (change) {
569                 /* Set pin mode to that requested */
570                 snd_hda_codec_write_cache(codec, nid, 0,
571                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
572                                           alc_pin_mode_values[val]);
573
574                 /* Also enable the retasking pin's input/output as required
575                  * for the requested pin mode.  Enum values of 2 or less are
576                  * input modes.
577                  *
578                  * Dynamically switching the input/output buffers probably
579                  * reduces noise slightly (particularly on input) so we'll
580                  * do it.  However, having both input and output buffers
581                  * enabled simultaneously doesn't seem to be problematic if
582                  * this turns out to be necessary in the future.
583                  */
584                 if (val <= 2) {
585                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
586                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
587                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
588                                                  HDA_AMP_MUTE, 0);
589                 } else {
590                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
591                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
592                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
593                                                  HDA_AMP_MUTE, 0);
594                 }
595         }
596         return change;
597 }
598
599 #define ALC_PIN_MODE(xname, nid, dir) \
600         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
601           .info = alc_pin_mode_info, \
602           .get = alc_pin_mode_get, \
603           .put = alc_pin_mode_put, \
604           .private_value = nid | (dir<<16) }
605
606 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
607  * together using a mask with more than one bit set.  This control is
608  * currently used only by the ALC260 test model.  At this stage they are not
609  * needed for any "production" models.
610  */
611 #ifdef CONFIG_SND_DEBUG
612 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
613
614 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
615                              struct snd_ctl_elem_value *ucontrol)
616 {
617         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
618         hda_nid_t nid = kcontrol->private_value & 0xffff;
619         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
620         long *valp = ucontrol->value.integer.value;
621         unsigned int val = snd_hda_codec_read(codec, nid, 0,
622                                               AC_VERB_GET_GPIO_DATA, 0x00);
623
624         *valp = (val & mask) != 0;
625         return 0;
626 }
627 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
628                              struct snd_ctl_elem_value *ucontrol)
629 {
630         signed int change;
631         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
632         hda_nid_t nid = kcontrol->private_value & 0xffff;
633         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
634         long val = *ucontrol->value.integer.value;
635         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
636                                                     AC_VERB_GET_GPIO_DATA,
637                                                     0x00);
638
639         /* Set/unset the masked GPIO bit(s) as needed */
640         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
641         if (val == 0)
642                 gpio_data &= ~mask;
643         else
644                 gpio_data |= mask;
645         snd_hda_codec_write_cache(codec, nid, 0,
646                                   AC_VERB_SET_GPIO_DATA, gpio_data);
647
648         return change;
649 }
650 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
651         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
652           .info = alc_gpio_data_info, \
653           .get = alc_gpio_data_get, \
654           .put = alc_gpio_data_put, \
655           .private_value = nid | (mask<<16) }
656 #endif   /* CONFIG_SND_DEBUG */
657
658 /* A switch control to allow the enabling of the digital IO pins on the
659  * ALC260.  This is incredibly simplistic; the intention of this control is
660  * to provide something in the test model allowing digital outputs to be
661  * identified if present.  If models are found which can utilise these
662  * outputs a more complete mixer control can be devised for those models if
663  * necessary.
664  */
665 #ifdef CONFIG_SND_DEBUG
666 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
667
668 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
669                               struct snd_ctl_elem_value *ucontrol)
670 {
671         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
672         hda_nid_t nid = kcontrol->private_value & 0xffff;
673         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
674         long *valp = ucontrol->value.integer.value;
675         unsigned int val = snd_hda_codec_read(codec, nid, 0,
676                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
677
678         *valp = (val & mask) != 0;
679         return 0;
680 }
681 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
682                               struct snd_ctl_elem_value *ucontrol)
683 {
684         signed int change;
685         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
686         hda_nid_t nid = kcontrol->private_value & 0xffff;
687         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
688         long val = *ucontrol->value.integer.value;
689         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
690                                                     AC_VERB_GET_DIGI_CONVERT_1,
691                                                     0x00);
692
693         /* Set/unset the masked control bit(s) as needed */
694         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
695         if (val==0)
696                 ctrl_data &= ~mask;
697         else
698                 ctrl_data |= mask;
699         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
700                                   ctrl_data);
701
702         return change;
703 }
704 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
705         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
706           .info = alc_spdif_ctrl_info, \
707           .get = alc_spdif_ctrl_get, \
708           .put = alc_spdif_ctrl_put, \
709           .private_value = nid | (mask<<16) }
710 #endif   /* CONFIG_SND_DEBUG */
711
712 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
713  * Again, this is only used in the ALC26x test models to help identify when
714  * the EAPD line must be asserted for features to work.
715  */
716 #ifdef CONFIG_SND_DEBUG
717 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
718
719 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
720                               struct snd_ctl_elem_value *ucontrol)
721 {
722         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
723         hda_nid_t nid = kcontrol->private_value & 0xffff;
724         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
725         long *valp = ucontrol->value.integer.value;
726         unsigned int val = snd_hda_codec_read(codec, nid, 0,
727                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
728
729         *valp = (val & mask) != 0;
730         return 0;
731 }
732
733 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
734                               struct snd_ctl_elem_value *ucontrol)
735 {
736         int change;
737         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
738         hda_nid_t nid = kcontrol->private_value & 0xffff;
739         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
740         long val = *ucontrol->value.integer.value;
741         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
742                                                     AC_VERB_GET_EAPD_BTLENABLE,
743                                                     0x00);
744
745         /* Set/unset the masked control bit(s) as needed */
746         change = (!val ? 0 : mask) != (ctrl_data & mask);
747         if (!val)
748                 ctrl_data &= ~mask;
749         else
750                 ctrl_data |= mask;
751         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
752                                   ctrl_data);
753
754         return change;
755 }
756
757 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
758         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
759           .info = alc_eapd_ctrl_info, \
760           .get = alc_eapd_ctrl_get, \
761           .put = alc_eapd_ctrl_put, \
762           .private_value = nid | (mask<<16) }
763 #endif   /* CONFIG_SND_DEBUG */
764
765 /*
766  * set up the input pin config (depending on the given auto-pin type)
767  */
768 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
769                               int auto_pin_type)
770 {
771         unsigned int val = PIN_IN;
772
773         if (auto_pin_type <= AUTO_PIN_FRONT_MIC) {
774                 unsigned int pincap;
775                 pincap = snd_hda_query_pin_caps(codec, nid);
776                 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
777                 if (pincap & AC_PINCAP_VREF_80)
778                         val = PIN_VREF80;
779         }
780         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
781 }
782
783 /*
784  */
785 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
786 {
787         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
788                 return;
789         spec->mixers[spec->num_mixers++] = mix;
790 }
791
792 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
793 {
794         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
795                 return;
796         spec->init_verbs[spec->num_init_verbs++] = verb;
797 }
798
799 #ifdef CONFIG_PROC_FS
800 /*
801  * hook for proc
802  */
803 static void print_realtek_coef(struct snd_info_buffer *buffer,
804                                struct hda_codec *codec, hda_nid_t nid)
805 {
806         int coeff;
807
808         if (nid != 0x20)
809                 return;
810         coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
811         snd_iprintf(buffer, "  Processing Coefficient: 0x%02x\n", coeff);
812         coeff = snd_hda_codec_read(codec, nid, 0,
813                                    AC_VERB_GET_COEF_INDEX, 0);
814         snd_iprintf(buffer, "  Coefficient Index: 0x%02x\n", coeff);
815 }
816 #else
817 #define print_realtek_coef      NULL
818 #endif
819
820 /*
821  * set up from the preset table
822  */
823 static void setup_preset(struct alc_spec *spec,
824                          const struct alc_config_preset *preset)
825 {
826         int i;
827
828         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
829                 add_mixer(spec, preset->mixers[i]);
830         spec->cap_mixer = preset->cap_mixer;
831         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
832              i++)
833                 add_verb(spec, preset->init_verbs[i]);
834
835         spec->channel_mode = preset->channel_mode;
836         spec->num_channel_mode = preset->num_channel_mode;
837         spec->need_dac_fix = preset->need_dac_fix;
838
839         spec->multiout.max_channels = spec->channel_mode[0].channels;
840
841         spec->multiout.num_dacs = preset->num_dacs;
842         spec->multiout.dac_nids = preset->dac_nids;
843         spec->multiout.dig_out_nid = preset->dig_out_nid;
844         spec->multiout.slave_dig_outs = preset->slave_dig_outs;
845         spec->multiout.hp_nid = preset->hp_nid;
846
847         spec->num_mux_defs = preset->num_mux_defs;
848         if (!spec->num_mux_defs)
849                 spec->num_mux_defs = 1;
850         spec->input_mux = preset->input_mux;
851
852         spec->num_adc_nids = preset->num_adc_nids;
853         spec->adc_nids = preset->adc_nids;
854         spec->capsrc_nids = preset->capsrc_nids;
855         spec->dig_in_nid = preset->dig_in_nid;
856
857         spec->unsol_event = preset->unsol_event;
858         spec->init_hook = preset->init_hook;
859 #ifdef CONFIG_SND_HDA_POWER_SAVE
860         spec->loopback.amplist = preset->loopbacks;
861 #endif
862 }
863
864 /* Enable GPIO mask and set output */
865 static struct hda_verb alc_gpio1_init_verbs[] = {
866         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
867         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
868         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
869         { }
870 };
871
872 static struct hda_verb alc_gpio2_init_verbs[] = {
873         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
874         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
875         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
876         { }
877 };
878
879 static struct hda_verb alc_gpio3_init_verbs[] = {
880         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
881         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
882         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
883         { }
884 };
885
886 /*
887  * Fix hardware PLL issue
888  * On some codecs, the analog PLL gating control must be off while
889  * the default value is 1.
890  */
891 static void alc_fix_pll(struct hda_codec *codec)
892 {
893         struct alc_spec *spec = codec->spec;
894         unsigned int val;
895
896         if (!spec->pll_nid)
897                 return;
898         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
899                             spec->pll_coef_idx);
900         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
901                                  AC_VERB_GET_PROC_COEF, 0);
902         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
903                             spec->pll_coef_idx);
904         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
905                             val & ~(1 << spec->pll_coef_bit));
906 }
907
908 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
909                              unsigned int coef_idx, unsigned int coef_bit)
910 {
911         struct alc_spec *spec = codec->spec;
912         spec->pll_nid = nid;
913         spec->pll_coef_idx = coef_idx;
914         spec->pll_coef_bit = coef_bit;
915         alc_fix_pll(codec);
916 }
917
918 static void alc_sku_automute(struct hda_codec *codec)
919 {
920         struct alc_spec *spec = codec->spec;
921         unsigned int present;
922         unsigned int hp_nid = spec->autocfg.hp_pins[0];
923         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
924
925         /* need to execute and sync at first */
926         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
927         present = snd_hda_codec_read(codec, hp_nid, 0,
928                                      AC_VERB_GET_PIN_SENSE, 0);
929         spec->jack_present = (present & 0x80000000) != 0;
930         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
931                             spec->jack_present ? 0 : PIN_OUT);
932 }
933
934 #if 0 /* it's broken in some acses -- temporarily disabled */
935 static void alc_mic_automute(struct hda_codec *codec)
936 {
937         struct alc_spec *spec = codec->spec;
938         unsigned int present;
939         unsigned int mic_nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
940         unsigned int fmic_nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
941         unsigned int mix_nid = spec->capsrc_nids[0];
942         unsigned int capsrc_idx_mic, capsrc_idx_fmic;
943
944         capsrc_idx_mic = mic_nid - 0x18;
945         capsrc_idx_fmic = fmic_nid - 0x18;
946         present = snd_hda_codec_read(codec, mic_nid, 0,
947                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
948         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
949                     0x7000 | (capsrc_idx_mic << 8) | (present ? 0 : 0x80));
950         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
951                     0x7000 | (capsrc_idx_fmic << 8) | (present ? 0x80 : 0));
952         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, capsrc_idx_fmic,
953                          HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
954 }
955 #else
956 #define alc_mic_automute(codec) do {} while(0) /* NOP */
957 #endif /* disabled */
958
959 /* unsolicited event for HP jack sensing */
960 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
961 {
962         if (codec->vendor_id == 0x10ec0880)
963                 res >>= 28;
964         else
965                 res >>= 26;
966         if (res == ALC880_HP_EVENT)
967                 alc_sku_automute(codec);
968
969         if (res == ALC880_MIC_EVENT)
970                 alc_mic_automute(codec);
971 }
972
973 static void alc_inithook(struct hda_codec *codec)
974 {
975         alc_sku_automute(codec);
976         alc_mic_automute(codec);
977 }
978
979 /* additional initialization for ALC888 variants */
980 static void alc888_coef_init(struct hda_codec *codec)
981 {
982         unsigned int tmp;
983
984         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
985         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
986         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
987         if ((tmp & 0xf0) == 0x20)
988                 /* alc888S-VC */
989                 snd_hda_codec_read(codec, 0x20, 0,
990                                    AC_VERB_SET_PROC_COEF, 0x830);
991          else
992                  /* alc888-VB */
993                  snd_hda_codec_read(codec, 0x20, 0,
994                                     AC_VERB_SET_PROC_COEF, 0x3030);
995 }
996
997 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
998  *      31 ~ 16 :       Manufacture ID
999  *      15 ~ 8  :       SKU ID
1000  *      7  ~ 0  :       Assembly ID
1001  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1002  */
1003 static void alc_subsystem_id(struct hda_codec *codec,
1004                              unsigned int porta, unsigned int porte,
1005                              unsigned int portd)
1006 {
1007         unsigned int ass, tmp, i;
1008         unsigned nid;
1009         struct alc_spec *spec = codec->spec;
1010
1011         ass = codec->subsystem_id & 0xffff;
1012         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1013                 goto do_sku;
1014
1015         /*
1016          * 31~30        : port conetcivity
1017          * 29~21        : reserve
1018          * 20           : PCBEEP input
1019          * 19~16        : Check sum (15:1)
1020          * 15~1         : Custom
1021          * 0            : override
1022         */
1023         nid = 0x1d;
1024         if (codec->vendor_id == 0x10ec0260)
1025                 nid = 0x17;
1026         ass = snd_hda_codec_get_pincfg(codec, nid);
1027         if (!(ass & 1) && !(ass & 0x100000))
1028                 return;
1029         if ((ass >> 30) != 1)   /* no physical connection */
1030                 return;
1031
1032         /* check sum */
1033         tmp = 0;
1034         for (i = 1; i < 16; i++) {
1035                 if ((ass >> i) & 1)
1036                         tmp++;
1037         }
1038         if (((ass >> 16) & 0xf) != tmp)
1039                 return;
1040 do_sku:
1041         /*
1042          * 0 : override
1043          * 1 :  Swap Jack
1044          * 2 : 0 --> Desktop, 1 --> Laptop
1045          * 3~5 : External Amplifier control
1046          * 7~6 : Reserved
1047         */
1048         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1049         switch (tmp) {
1050         case 1:
1051                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1052                 break;
1053         case 3:
1054                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1055                 break;
1056         case 7:
1057                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1058                 break;
1059         case 5: /* set EAPD output high */
1060                 switch (codec->vendor_id) {
1061                 case 0x10ec0260:
1062                         snd_hda_codec_write(codec, 0x0f, 0,
1063                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1064                         snd_hda_codec_write(codec, 0x10, 0,
1065                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1066                         break;
1067                 case 0x10ec0262:
1068                 case 0x10ec0267:
1069                 case 0x10ec0268:
1070                 case 0x10ec0269:
1071                 case 0x10ec0272:
1072                 case 0x10ec0660:
1073                 case 0x10ec0662:
1074                 case 0x10ec0663:
1075                 case 0x10ec0862:
1076                 case 0x10ec0889:
1077                         snd_hda_codec_write(codec, 0x14, 0,
1078                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1079                         snd_hda_codec_write(codec, 0x15, 0,
1080                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1081                         break;
1082                 }
1083                 switch (codec->vendor_id) {
1084                 case 0x10ec0260:
1085                         snd_hda_codec_write(codec, 0x1a, 0,
1086                                             AC_VERB_SET_COEF_INDEX, 7);
1087                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1088                                                  AC_VERB_GET_PROC_COEF, 0);
1089                         snd_hda_codec_write(codec, 0x1a, 0,
1090                                             AC_VERB_SET_COEF_INDEX, 7);
1091                         snd_hda_codec_write(codec, 0x1a, 0,
1092                                             AC_VERB_SET_PROC_COEF,
1093                                             tmp | 0x2010);
1094                         break;
1095                 case 0x10ec0262:
1096                 case 0x10ec0880:
1097                 case 0x10ec0882:
1098                 case 0x10ec0883:
1099                 case 0x10ec0885:
1100                 case 0x10ec0887:
1101                 case 0x10ec0889:
1102                         snd_hda_codec_write(codec, 0x20, 0,
1103                                             AC_VERB_SET_COEF_INDEX, 7);
1104                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1105                                                  AC_VERB_GET_PROC_COEF, 0);
1106                         snd_hda_codec_write(codec, 0x20, 0,
1107                                             AC_VERB_SET_COEF_INDEX, 7);
1108                         snd_hda_codec_write(codec, 0x20, 0,
1109                                             AC_VERB_SET_PROC_COEF,
1110                                             tmp | 0x2010);
1111                         break;
1112                 case 0x10ec0888:
1113                         /*alc888_coef_init(codec);*/ /* called in alc_init() */
1114                         break;
1115                 case 0x10ec0267:
1116                 case 0x10ec0268:
1117                         snd_hda_codec_write(codec, 0x20, 0,
1118                                             AC_VERB_SET_COEF_INDEX, 7);
1119                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1120                                                  AC_VERB_GET_PROC_COEF, 0);
1121                         snd_hda_codec_write(codec, 0x20, 0,
1122                                             AC_VERB_SET_COEF_INDEX, 7);
1123                         snd_hda_codec_write(codec, 0x20, 0,
1124                                             AC_VERB_SET_PROC_COEF,
1125                                             tmp | 0x3000);
1126                         break;
1127                 }
1128         default:
1129                 break;
1130         }
1131
1132         /* is laptop or Desktop and enable the function "Mute internal speaker
1133          * when the external headphone out jack is plugged"
1134          */
1135         if (!(ass & 0x8000))
1136                 return;
1137         /*
1138          * 10~8 : Jack location
1139          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1140          * 14~13: Resvered
1141          * 15   : 1 --> enable the function "Mute internal speaker
1142          *              when the external headphone out jack is plugged"
1143          */
1144         if (!spec->autocfg.speaker_pins[0]) {
1145                 if (spec->autocfg.line_out_pins[0])
1146                         spec->autocfg.speaker_pins[0] =
1147                                 spec->autocfg.line_out_pins[0];
1148                 else
1149                         return;
1150         }
1151
1152         if (!spec->autocfg.hp_pins[0]) {
1153                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1154                 if (tmp == 0)
1155                         spec->autocfg.hp_pins[0] = porta;
1156                 else if (tmp == 1)
1157                         spec->autocfg.hp_pins[0] = porte;
1158                 else if (tmp == 2)
1159                         spec->autocfg.hp_pins[0] = portd;
1160                 else
1161                         return;
1162         }
1163         if (spec->autocfg.hp_pins[0])
1164                 snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1165                         AC_VERB_SET_UNSOLICITED_ENABLE,
1166                         AC_USRSP_EN | ALC880_HP_EVENT);
1167
1168 #if 0 /* it's broken in some acses -- temporarily disabled */
1169         if (spec->autocfg.input_pins[AUTO_PIN_MIC] &&
1170                 spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC])
1171                 snd_hda_codec_write(codec,
1172                         spec->autocfg.input_pins[AUTO_PIN_MIC], 0,
1173                         AC_VERB_SET_UNSOLICITED_ENABLE,
1174                         AC_USRSP_EN | ALC880_MIC_EVENT);
1175 #endif /* disabled */
1176
1177         spec->unsol_event = alc_sku_unsol_event;
1178 }
1179
1180 /*
1181  * Fix-up pin default configurations
1182  */
1183
1184 struct alc_pincfg {
1185         hda_nid_t nid;
1186         u32 val;
1187 };
1188
1189 static void alc_fix_pincfg(struct hda_codec *codec,
1190                            const struct snd_pci_quirk *quirk,
1191                            const struct alc_pincfg **pinfix)
1192 {
1193         const struct alc_pincfg *cfg;
1194
1195         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1196         if (!quirk)
1197                 return;
1198
1199         cfg = pinfix[quirk->value];
1200         for (; cfg->nid; cfg++)
1201                 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1202 }
1203
1204 /*
1205  * ALC888
1206  */
1207
1208 /*
1209  * 2ch mode
1210  */
1211 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1212 /* Mic-in jack as mic in */
1213         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1214         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1215 /* Line-in jack as Line in */
1216         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1217         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1218 /* Line-Out as Front */
1219         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1220         { } /* end */
1221 };
1222
1223 /*
1224  * 4ch mode
1225  */
1226 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1227 /* Mic-in jack as mic in */
1228         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1229         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1230 /* Line-in jack as Surround */
1231         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1232         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1233 /* Line-Out as Front */
1234         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1235         { } /* end */
1236 };
1237
1238 /*
1239  * 6ch mode
1240  */
1241 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1242 /* Mic-in jack as CLFE */
1243         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1244         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1245 /* Line-in jack as Surround */
1246         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1247         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1248 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1249         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1250         { } /* end */
1251 };
1252
1253 /*
1254  * 8ch mode
1255  */
1256 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1257 /* Mic-in jack as CLFE */
1258         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1259         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1260 /* Line-in jack as Surround */
1261         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1262         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1263 /* Line-Out as Side */
1264         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1265         { } /* end */
1266 };
1267
1268 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1269         { 2, alc888_4ST_ch2_intel_init },
1270         { 4, alc888_4ST_ch4_intel_init },
1271         { 6, alc888_4ST_ch6_intel_init },
1272         { 8, alc888_4ST_ch8_intel_init },
1273 };
1274
1275 /*
1276  * ALC888 Fujitsu Siemens Amillo xa3530
1277  */
1278
1279 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1280 /* Front Mic: set to PIN_IN (empty by default) */
1281         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1282 /* Connect Internal HP to Front */
1283         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1284         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1285         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1286 /* Connect Bass HP to Front */
1287         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1288         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1289         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1290 /* Connect Line-Out side jack (SPDIF) to Side */
1291         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1292         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1293         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1294 /* Connect Mic jack to CLFE */
1295         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1296         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1297         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1298 /* Connect Line-in jack to Surround */
1299         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1300         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1301         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1302 /* Connect HP out jack to Front */
1303         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1304         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1305         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1306 /* Enable unsolicited event for HP jack and Line-out jack */
1307         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1308         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1309         {}
1310 };
1311
1312 static void alc888_fujitsu_xa3530_automute(struct hda_codec *codec)
1313 {
1314         unsigned int present;
1315         unsigned int bits;
1316         /* Line out presence */
1317         present = snd_hda_codec_read(codec, 0x17, 0,
1318                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1319         /* HP out presence */
1320         present = present || snd_hda_codec_read(codec, 0x1b, 0,
1321                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1322         bits = present ? HDA_AMP_MUTE : 0;
1323         /* Toggle internal speakers muting */
1324         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1325                                  HDA_AMP_MUTE, bits);
1326         /* Toggle internal bass muting */
1327         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1328                                  HDA_AMP_MUTE, bits);
1329 }
1330
1331 static void alc888_fujitsu_xa3530_unsol_event(struct hda_codec *codec,
1332                 unsigned int res)
1333 {
1334         if (res >> 26 == ALC880_HP_EVENT)
1335                 alc888_fujitsu_xa3530_automute(codec);
1336 }
1337
1338
1339 /*
1340  * ALC888 Acer Aspire 4930G model
1341  */
1342
1343 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1344 /* Front Mic: set to PIN_IN (empty by default) */
1345         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1346 /* Unselect Front Mic by default in input mixer 3 */
1347         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1348 /* Enable unsolicited event for HP jack */
1349         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1350 /* Connect Internal HP to front */
1351         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1352         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1353         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1354 /* Connect HP out to front */
1355         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1356         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1357         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1358         { }
1359 };
1360
1361 static struct hda_input_mux alc888_2_capture_sources[2] = {
1362         /* Front mic only available on one ADC */
1363         {
1364                 .num_items = 4,
1365                 .items = {
1366                         { "Mic", 0x0 },
1367                         { "Line", 0x2 },
1368                         { "CD", 0x4 },
1369                         { "Front Mic", 0xb },
1370                 },
1371         },
1372         {
1373                 .num_items = 3,
1374                 .items = {
1375                         { "Mic", 0x0 },
1376                         { "Line", 0x2 },
1377                         { "CD", 0x4 },
1378                 },
1379         }
1380 };
1381
1382 static struct snd_kcontrol_new alc888_base_mixer[] = {
1383         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1384         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1385         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1386         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1387         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1388                 HDA_OUTPUT),
1389         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1390         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1391         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1392         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1393         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1394         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1395         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1396         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1397         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1398         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1399         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1400         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1401         { } /* end */
1402 };
1403
1404 static void alc888_acer_aspire_4930g_automute(struct hda_codec *codec)
1405 {
1406         unsigned int present;
1407         unsigned int bits;
1408         present = snd_hda_codec_read(codec, 0x15, 0,
1409                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1410         bits = present ? HDA_AMP_MUTE : 0;
1411         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1412                                  HDA_AMP_MUTE, bits);
1413 }
1414
1415 static void alc888_acer_aspire_4930g_unsol_event(struct hda_codec *codec,
1416                 unsigned int res)
1417 {
1418         if (res >> 26 == ALC880_HP_EVENT)
1419                 alc888_acer_aspire_4930g_automute(codec);
1420 }
1421
1422 /*
1423  * ALC880 3-stack model
1424  *
1425  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1426  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1427  *                 F-Mic = 0x1b, HP = 0x19
1428  */
1429
1430 static hda_nid_t alc880_dac_nids[4] = {
1431         /* front, rear, clfe, rear_surr */
1432         0x02, 0x05, 0x04, 0x03
1433 };
1434
1435 static hda_nid_t alc880_adc_nids[3] = {
1436         /* ADC0-2 */
1437         0x07, 0x08, 0x09,
1438 };
1439
1440 /* The datasheet says the node 0x07 is connected from inputs,
1441  * but it shows zero connection in the real implementation on some devices.
1442  * Note: this is a 915GAV bug, fixed on 915GLV
1443  */
1444 static hda_nid_t alc880_adc_nids_alt[2] = {
1445         /* ADC1-2 */
1446         0x08, 0x09,
1447 };
1448
1449 #define ALC880_DIGOUT_NID       0x06
1450 #define ALC880_DIGIN_NID        0x0a
1451
1452 static struct hda_input_mux alc880_capture_source = {
1453         .num_items = 4,
1454         .items = {
1455                 { "Mic", 0x0 },
1456                 { "Front Mic", 0x3 },
1457                 { "Line", 0x2 },
1458                 { "CD", 0x4 },
1459         },
1460 };
1461
1462 /* channel source setting (2/6 channel selection for 3-stack) */
1463 /* 2ch mode */
1464 static struct hda_verb alc880_threestack_ch2_init[] = {
1465         /* set line-in to input, mute it */
1466         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1467         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1468         /* set mic-in to input vref 80%, mute it */
1469         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1470         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1471         { } /* end */
1472 };
1473
1474 /* 6ch mode */
1475 static struct hda_verb alc880_threestack_ch6_init[] = {
1476         /* set line-in to output, unmute it */
1477         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1478         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1479         /* set mic-in to output, unmute it */
1480         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1481         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1482         { } /* end */
1483 };
1484
1485 static struct hda_channel_mode alc880_threestack_modes[2] = {
1486         { 2, alc880_threestack_ch2_init },
1487         { 6, alc880_threestack_ch6_init },
1488 };
1489
1490 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1491         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1492         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1493         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1494         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1495         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1496         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1497         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1498         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1499         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1500         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1501         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1502         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1503         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1504         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1505         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1506         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1507         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1508         {
1509                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1510                 .name = "Channel Mode",
1511                 .info = alc_ch_mode_info,
1512                 .get = alc_ch_mode_get,
1513                 .put = alc_ch_mode_put,
1514         },
1515         { } /* end */
1516 };
1517
1518 /* capture mixer elements */
1519 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1520                             struct snd_ctl_elem_info *uinfo)
1521 {
1522         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1523         struct alc_spec *spec = codec->spec;
1524         int err;
1525
1526         mutex_lock(&codec->control_mutex);
1527         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1528                                                       HDA_INPUT);
1529         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1530         mutex_unlock(&codec->control_mutex);
1531         return err;
1532 }
1533
1534 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1535                            unsigned int size, unsigned int __user *tlv)
1536 {
1537         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1538         struct alc_spec *spec = codec->spec;
1539         int err;
1540
1541         mutex_lock(&codec->control_mutex);
1542         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1543                                                       HDA_INPUT);
1544         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1545         mutex_unlock(&codec->control_mutex);
1546         return err;
1547 }
1548
1549 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1550                              struct snd_ctl_elem_value *ucontrol);
1551
1552 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1553                                  struct snd_ctl_elem_value *ucontrol,
1554                                  getput_call_t func)
1555 {
1556         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1557         struct alc_spec *spec = codec->spec;
1558         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1559         int err;
1560
1561         mutex_lock(&codec->control_mutex);
1562         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1563                                                       3, 0, HDA_INPUT);
1564         err = func(kcontrol, ucontrol);
1565         mutex_unlock(&codec->control_mutex);
1566         return err;
1567 }
1568
1569 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1570                            struct snd_ctl_elem_value *ucontrol)
1571 {
1572         return alc_cap_getput_caller(kcontrol, ucontrol,
1573                                      snd_hda_mixer_amp_volume_get);
1574 }
1575
1576 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1577                            struct snd_ctl_elem_value *ucontrol)
1578 {
1579         return alc_cap_getput_caller(kcontrol, ucontrol,
1580                                      snd_hda_mixer_amp_volume_put);
1581 }
1582
1583 /* capture mixer elements */
1584 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1585
1586 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1587                           struct snd_ctl_elem_value *ucontrol)
1588 {
1589         return alc_cap_getput_caller(kcontrol, ucontrol,
1590                                      snd_hda_mixer_amp_switch_get);
1591 }
1592
1593 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1594                           struct snd_ctl_elem_value *ucontrol)
1595 {
1596         return alc_cap_getput_caller(kcontrol, ucontrol,
1597                                      snd_hda_mixer_amp_switch_put);
1598 }
1599
1600 #define _DEFINE_CAPMIX(num) \
1601         { \
1602                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1603                 .name = "Capture Switch", \
1604                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1605                 .count = num, \
1606                 .info = alc_cap_sw_info, \
1607                 .get = alc_cap_sw_get, \
1608                 .put = alc_cap_sw_put, \
1609         }, \
1610         { \
1611                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1612                 .name = "Capture Volume", \
1613                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1614                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1615                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1616                 .count = num, \
1617                 .info = alc_cap_vol_info, \
1618                 .get = alc_cap_vol_get, \
1619                 .put = alc_cap_vol_put, \
1620                 .tlv = { .c = alc_cap_vol_tlv }, \
1621         }
1622
1623 #define _DEFINE_CAPSRC(num) \
1624         { \
1625                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1626                 /* .name = "Capture Source", */ \
1627                 .name = "Input Source", \
1628                 .count = num, \
1629                 .info = alc_mux_enum_info, \
1630                 .get = alc_mux_enum_get, \
1631                 .put = alc_mux_enum_put, \
1632         }
1633
1634 #define DEFINE_CAPMIX(num) \
1635 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1636         _DEFINE_CAPMIX(num),                                  \
1637         _DEFINE_CAPSRC(num),                                  \
1638         { } /* end */                                         \
1639 }
1640
1641 #define DEFINE_CAPMIX_NOSRC(num) \
1642 static struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1643         _DEFINE_CAPMIX(num),                                        \
1644         { } /* end */                                               \
1645 }
1646
1647 /* up to three ADCs */
1648 DEFINE_CAPMIX(1);
1649 DEFINE_CAPMIX(2);
1650 DEFINE_CAPMIX(3);
1651 DEFINE_CAPMIX_NOSRC(1);
1652 DEFINE_CAPMIX_NOSRC(2);
1653 DEFINE_CAPMIX_NOSRC(3);
1654
1655 /*
1656  * ALC880 5-stack model
1657  *
1658  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1659  *      Side = 0x02 (0xd)
1660  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1661  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1662  */
1663
1664 /* additional mixers to alc880_three_stack_mixer */
1665 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1666         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1667         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1668         { } /* end */
1669 };
1670
1671 /* channel source setting (6/8 channel selection for 5-stack) */
1672 /* 6ch mode */
1673 static struct hda_verb alc880_fivestack_ch6_init[] = {
1674         /* set line-in to input, mute it */
1675         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1676         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1677         { } /* end */
1678 };
1679
1680 /* 8ch mode */
1681 static struct hda_verb alc880_fivestack_ch8_init[] = {
1682         /* set line-in to output, unmute it */
1683         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1684         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1685         { } /* end */
1686 };
1687
1688 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1689         { 6, alc880_fivestack_ch6_init },
1690         { 8, alc880_fivestack_ch8_init },
1691 };
1692
1693
1694 /*
1695  * ALC880 6-stack model
1696  *
1697  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1698  *      Side = 0x05 (0x0f)
1699  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1700  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1701  */
1702
1703 static hda_nid_t alc880_6st_dac_nids[4] = {
1704         /* front, rear, clfe, rear_surr */
1705         0x02, 0x03, 0x04, 0x05
1706 };
1707
1708 static struct hda_input_mux alc880_6stack_capture_source = {
1709         .num_items = 4,
1710         .items = {
1711                 { "Mic", 0x0 },
1712                 { "Front Mic", 0x1 },
1713                 { "Line", 0x2 },
1714                 { "CD", 0x4 },
1715         },
1716 };
1717
1718 /* fixed 8-channels */
1719 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1720         { 8, NULL },
1721 };
1722
1723 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1724         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1725         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1726         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1727         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1728         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1729         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1730         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1731         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1732         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1733         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1734         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1735         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1736         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1737         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1738         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1739         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1740         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1741         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1742         {
1743                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1744                 .name = "Channel Mode",
1745                 .info = alc_ch_mode_info,
1746                 .get = alc_ch_mode_get,
1747                 .put = alc_ch_mode_put,
1748         },
1749         { } /* end */
1750 };
1751
1752
1753 /*
1754  * ALC880 W810 model
1755  *
1756  * W810 has rear IO for:
1757  * Front (DAC 02)
1758  * Surround (DAC 03)
1759  * Center/LFE (DAC 04)
1760  * Digital out (06)
1761  *
1762  * The system also has a pair of internal speakers, and a headphone jack.
1763  * These are both connected to Line2 on the codec, hence to DAC 02.
1764  *
1765  * There is a variable resistor to control the speaker or headphone
1766  * volume. This is a hardware-only device without a software API.
1767  *
1768  * Plugging headphones in will disable the internal speakers. This is
1769  * implemented in hardware, not via the driver using jack sense. In
1770  * a similar fashion, plugging into the rear socket marked "front" will
1771  * disable both the speakers and headphones.
1772  *
1773  * For input, there's a microphone jack, and an "audio in" jack.
1774  * These may not do anything useful with this driver yet, because I
1775  * haven't setup any initialization verbs for these yet...
1776  */
1777
1778 static hda_nid_t alc880_w810_dac_nids[3] = {
1779         /* front, rear/surround, clfe */
1780         0x02, 0x03, 0x04
1781 };
1782
1783 /* fixed 6 channels */
1784 static struct hda_channel_mode alc880_w810_modes[1] = {
1785         { 6, NULL }
1786 };
1787
1788 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1789 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1790         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1791         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1792         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1793         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1794         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1795         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1796         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1797         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1798         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1799         { } /* end */
1800 };
1801
1802
1803 /*
1804  * Z710V model
1805  *
1806  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1807  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1808  *                 Line = 0x1a
1809  */
1810
1811 static hda_nid_t alc880_z71v_dac_nids[1] = {
1812         0x02
1813 };
1814 #define ALC880_Z71V_HP_DAC      0x03
1815
1816 /* fixed 2 channels */
1817 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1818         { 2, NULL }
1819 };
1820
1821 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1822         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1823         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1824         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1825         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1826         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1827         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1828         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1829         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1830         { } /* end */
1831 };
1832
1833
1834 /*
1835  * ALC880 F1734 model
1836  *
1837  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1838  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1839  */
1840
1841 static hda_nid_t alc880_f1734_dac_nids[1] = {
1842         0x03
1843 };
1844 #define ALC880_F1734_HP_DAC     0x02
1845
1846 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1847         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1848         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1849         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1850         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1851         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1852         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1853         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1854         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1855         { } /* end */
1856 };
1857
1858 static struct hda_input_mux alc880_f1734_capture_source = {
1859         .num_items = 2,
1860         .items = {
1861                 { "Mic", 0x1 },
1862                 { "CD", 0x4 },
1863         },
1864 };
1865
1866
1867 /*
1868  * ALC880 ASUS model
1869  *
1870  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1871  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1872  *  Mic = 0x18, Line = 0x1a
1873  */
1874
1875 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1876 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1877
1878 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1879         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1880         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1881         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1882         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1883         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1884         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1885         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1886         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1887         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1888         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1889         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1890         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1891         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1892         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1893         {
1894                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1895                 .name = "Channel Mode",
1896                 .info = alc_ch_mode_info,
1897                 .get = alc_ch_mode_get,
1898                 .put = alc_ch_mode_put,
1899         },
1900         { } /* end */
1901 };
1902
1903 /*
1904  * ALC880 ASUS W1V model
1905  *
1906  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1907  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1908  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1909  */
1910
1911 /* additional mixers to alc880_asus_mixer */
1912 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1913         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1914         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1915         { } /* end */
1916 };
1917
1918 /* TCL S700 */
1919 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1920         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1921         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1922         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1923         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1924         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1925         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1926         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1927         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1928         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1929         { } /* end */
1930 };
1931
1932 /* Uniwill */
1933 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1934         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1935         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1936         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1937         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1938         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1939         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1940         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1941         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1942         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1943         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1944         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1945         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1946         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1947         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1948         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1949         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1950         {
1951                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1952                 .name = "Channel Mode",
1953                 .info = alc_ch_mode_info,
1954                 .get = alc_ch_mode_get,
1955                 .put = alc_ch_mode_put,
1956         },
1957         { } /* end */
1958 };
1959
1960 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1961         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1962         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1963         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1964         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1965         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1966         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1967         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1968         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1969         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1970         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1971         { } /* end */
1972 };
1973
1974 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1975         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1976         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1977         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1978         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1979         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1980         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1981         { } /* end */
1982 };
1983
1984 /*
1985  * virtual master controls
1986  */
1987
1988 /*
1989  * slave controls for virtual master
1990  */
1991 static const char *alc_slave_vols[] = {
1992         "Front Playback Volume",
1993         "Surround Playback Volume",
1994         "Center Playback Volume",
1995         "LFE Playback Volume",
1996         "Side Playback Volume",
1997         "Headphone Playback Volume",
1998         "Speaker Playback Volume",
1999         "Mono Playback Volume",
2000         "Line-Out Playback Volume",
2001         "PCM Playback Volume",
2002         NULL,
2003 };
2004
2005 static const char *alc_slave_sws[] = {
2006         "Front Playback Switch",
2007         "Surround Playback Switch",
2008         "Center Playback Switch",
2009         "LFE Playback Switch",
2010         "Side Playback Switch",
2011         "Headphone Playback Switch",
2012         "Speaker Playback Switch",
2013         "Mono Playback Switch",
2014         "IEC958 Playback Switch",
2015         NULL,
2016 };
2017
2018 /*
2019  * build control elements
2020  */
2021
2022 static void alc_free_kctls(struct hda_codec *codec);
2023
2024 /* additional beep mixers; the actual parameters are overwritten at build */
2025 static struct snd_kcontrol_new alc_beep_mixer[] = {
2026         HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
2027         HDA_CODEC_MUTE("Beep Playback Switch", 0, 0, HDA_INPUT),
2028         { } /* end */
2029 };
2030
2031 static int alc_build_controls(struct hda_codec *codec)
2032 {
2033         struct alc_spec *spec = codec->spec;
2034         int err;
2035         int i;
2036
2037         for (i = 0; i < spec->num_mixers; i++) {
2038                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2039                 if (err < 0)
2040                         return err;
2041         }
2042         if (spec->cap_mixer) {
2043                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2044                 if (err < 0)
2045                         return err;
2046         }
2047         if (spec->multiout.dig_out_nid) {
2048                 err = snd_hda_create_spdif_out_ctls(codec,
2049                                                     spec->multiout.dig_out_nid);
2050                 if (err < 0)
2051                         return err;
2052                 if (!spec->no_analog) {
2053                         err = snd_hda_create_spdif_share_sw(codec,
2054                                                             &spec->multiout);
2055                         if (err < 0)
2056                                 return err;
2057                         spec->multiout.share_spdif = 1;
2058                 }
2059         }
2060         if (spec->dig_in_nid) {
2061                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2062                 if (err < 0)
2063                         return err;
2064         }
2065
2066         /* create beep controls if needed */
2067         if (spec->beep_amp) {
2068                 struct snd_kcontrol_new *knew;
2069                 for (knew = alc_beep_mixer; knew->name; knew++) {
2070                         struct snd_kcontrol *kctl;
2071                         kctl = snd_ctl_new1(knew, codec);
2072                         if (!kctl)
2073                                 return -ENOMEM;
2074                         kctl->private_value = spec->beep_amp;
2075                         err = snd_hda_ctl_add(codec, kctl);
2076                         if (err < 0)
2077                                 return err;
2078                 }
2079         }
2080
2081         /* if we have no master control, let's create it */
2082         if (!spec->no_analog &&
2083             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2084                 unsigned int vmaster_tlv[4];
2085                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2086                                         HDA_OUTPUT, vmaster_tlv);
2087                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2088                                           vmaster_tlv, alc_slave_vols);
2089                 if (err < 0)
2090                         return err;
2091         }
2092         if (!spec->no_analog &&
2093             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2094                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2095                                           NULL, alc_slave_sws);
2096                 if (err < 0)
2097                         return err;
2098         }
2099
2100         alc_free_kctls(codec); /* no longer needed */
2101         return 0;
2102 }
2103
2104
2105 /*
2106  * initialize the codec volumes, etc
2107  */
2108
2109 /*
2110  * generic initialization of ADC, input mixers and output mixers
2111  */
2112 static struct hda_verb alc880_volume_init_verbs[] = {
2113         /*
2114          * Unmute ADC0-2 and set the default input to mic-in
2115          */
2116         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2117         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2118         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2119         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2120         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2121         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2122
2123         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2124          * mixer widget
2125          * Note: PASD motherboards uses the Line In 2 as the input for front
2126          * panel mic (mic 2)
2127          */
2128         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2129         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2130         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2131         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2132         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2133         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2134         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2135         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2136
2137         /*
2138          * Set up output mixers (0x0c - 0x0f)
2139          */
2140         /* set vol=0 to output mixers */
2141         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2142         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2143         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2144         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2145         /* set up input amps for analog loopback */
2146         /* Amp Indices: DAC = 0, mixer = 1 */
2147         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2148         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2149         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2150         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2151         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2152         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2153         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2154         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2155
2156         { }
2157 };
2158
2159 /*
2160  * 3-stack pin configuration:
2161  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2162  */
2163 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2164         /*
2165          * preset connection lists of input pins
2166          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2167          */
2168         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2169         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2170         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2171
2172         /*
2173          * Set pin mode and muting
2174          */
2175         /* set front pin widgets 0x14 for output */
2176         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2177         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2178         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2179         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2180         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2181         /* Mic2 (as headphone out) for HP output */
2182         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2183         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2184         /* Line In pin widget for input */
2185         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2186         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2187         /* Line2 (as front mic) pin widget for input and vref at 80% */
2188         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2189         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2190         /* CD pin widget for input */
2191         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2192
2193         { }
2194 };
2195
2196 /*
2197  * 5-stack pin configuration:
2198  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2199  * line-in/side = 0x1a, f-mic = 0x1b
2200  */
2201 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2202         /*
2203          * preset connection lists of input pins
2204          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2205          */
2206         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2207         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2208
2209         /*
2210          * Set pin mode and muting
2211          */
2212         /* set pin widgets 0x14-0x17 for output */
2213         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2214         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2215         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2216         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2217         /* unmute pins for output (no gain on this amp) */
2218         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2219         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2220         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2221         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2222
2223         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2224         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2225         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2226         /* Mic2 (as headphone out) for HP output */
2227         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2228         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2229         /* Line In pin widget for input */
2230         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2231         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2232         /* Line2 (as front mic) pin widget for input and vref at 80% */
2233         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2234         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2235         /* CD pin widget for input */
2236         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2237
2238         { }
2239 };
2240
2241 /*
2242  * W810 pin configuration:
2243  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2244  */
2245 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2246         /* hphone/speaker input selector: front DAC */
2247         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2248
2249         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2250         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2251         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2252         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2253         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2254         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2255
2256         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2257         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2258
2259         { }
2260 };
2261
2262 /*
2263  * Z71V pin configuration:
2264  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2265  */
2266 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2267         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2268         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2269         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2270         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2271
2272         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2273         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2274         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2275         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2276
2277         { }
2278 };
2279
2280 /*
2281  * 6-stack pin configuration:
2282  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2283  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2284  */
2285 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2286         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2287
2288         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2289         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2290         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2291         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2292         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2293         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2294         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2295         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2296
2297         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2298         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2299         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2300         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2301         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2302         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2303         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2304         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2305         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2306
2307         { }
2308 };
2309
2310 /*
2311  * Uniwill pin configuration:
2312  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2313  * line = 0x1a
2314  */
2315 static struct hda_verb alc880_uniwill_init_verbs[] = {
2316         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2317
2318         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2319         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2320         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2321         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2322         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2323         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2324         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2325         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2326         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2327         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2328         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2329         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2330         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2331         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2332
2333         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2334         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2335         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2336         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2337         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2338         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2339         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2340         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2341         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2342
2343         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2344         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2345
2346         { }
2347 };
2348
2349 /*
2350 * Uniwill P53
2351 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2352  */
2353 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2354         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2355
2356         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2357         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2358         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2359         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2360         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2361         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2362         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2363         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2364         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2365         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2366         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2367         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2368
2369         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2370         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2371         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2372         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2373         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2374         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2375
2376         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2377         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2378
2379         { }
2380 };
2381
2382 static struct hda_verb alc880_beep_init_verbs[] = {
2383         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2384         { }
2385 };
2386
2387 /* toggle speaker-output according to the hp-jack state */
2388 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
2389 {
2390         unsigned int present;
2391         unsigned char bits;
2392
2393         present = snd_hda_codec_read(codec, 0x14, 0,
2394                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2395         bits = present ? HDA_AMP_MUTE : 0;
2396         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
2397                                  HDA_AMP_MUTE, bits);
2398         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
2399                                  HDA_AMP_MUTE, bits);
2400 }
2401
2402 /* auto-toggle front mic */
2403 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2404 {
2405         unsigned int present;
2406         unsigned char bits;
2407
2408         present = snd_hda_codec_read(codec, 0x18, 0,
2409                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2410         bits = present ? HDA_AMP_MUTE : 0;
2411         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2412 }
2413
2414 static void alc880_uniwill_automute(struct hda_codec *codec)
2415 {
2416         alc880_uniwill_hp_automute(codec);
2417         alc880_uniwill_mic_automute(codec);
2418 }
2419
2420 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2421                                        unsigned int res)
2422 {
2423         /* Looks like the unsol event is incompatible with the standard
2424          * definition.  4bit tag is placed at 28 bit!
2425          */
2426         switch (res >> 28) {
2427         case ALC880_HP_EVENT:
2428                 alc880_uniwill_hp_automute(codec);
2429                 break;
2430         case ALC880_MIC_EVENT:
2431                 alc880_uniwill_mic_automute(codec);
2432                 break;
2433         }
2434 }
2435
2436 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
2437 {
2438         unsigned int present;
2439         unsigned char bits;
2440
2441         present = snd_hda_codec_read(codec, 0x14, 0,
2442                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2443         bits = present ? HDA_AMP_MUTE : 0;
2444         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
2445 }
2446
2447 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2448 {
2449         unsigned int present;
2450
2451         present = snd_hda_codec_read(codec, 0x21, 0,
2452                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2453         present &= HDA_AMP_VOLMASK;
2454         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2455                                  HDA_AMP_VOLMASK, present);
2456         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2457                                  HDA_AMP_VOLMASK, present);
2458 }
2459
2460 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2461                                            unsigned int res)
2462 {
2463         /* Looks like the unsol event is incompatible with the standard
2464          * definition.  4bit tag is placed at 28 bit!
2465          */
2466         if ((res >> 28) == ALC880_HP_EVENT)
2467                 alc880_uniwill_p53_hp_automute(codec);
2468         if ((res >> 28) == ALC880_DCVOL_EVENT)
2469                 alc880_uniwill_p53_dcvol_automute(codec);
2470 }
2471
2472 /*
2473  * F1734 pin configuration:
2474  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2475  */
2476 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2477         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2478         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2479         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2480         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2481         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2482
2483         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2484         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2485         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2486         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2487
2488         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2489         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2490         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2491         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2492         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2493         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2494         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2495         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2496         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2497
2498         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2499         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2500
2501         { }
2502 };
2503
2504 /*
2505  * ASUS pin configuration:
2506  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2507  */
2508 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2509         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2510         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2511         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2512         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2513
2514         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2515         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2516         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2517         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2518         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2519         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2520         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2521         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2522
2523         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2524         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2525         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2526         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2527         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2528         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2529         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2530         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2531         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2532
2533         { }
2534 };
2535
2536 /* Enable GPIO mask and set output */
2537 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2538 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2539
2540 /* Clevo m520g init */
2541 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2542         /* headphone output */
2543         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2544         /* line-out */
2545         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2546         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2547         /* Line-in */
2548         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2549         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2550         /* CD */
2551         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2552         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2553         /* Mic1 (rear panel) */
2554         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2555         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2556         /* Mic2 (front panel) */
2557         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2558         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2559         /* headphone */
2560         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2561         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2562         /* change to EAPD mode */
2563         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2564         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2565
2566         { }
2567 };
2568
2569 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2570         /* change to EAPD mode */
2571         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2572         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2573
2574         /* Headphone output */
2575         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2576         /* Front output*/
2577         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2578         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2579
2580         /* Line In pin widget for input */
2581         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2582         /* CD pin widget for input */
2583         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2584         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2585         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2586
2587         /* change to EAPD mode */
2588         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2589         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2590
2591         { }
2592 };
2593
2594 /*
2595  * LG m1 express dual
2596  *
2597  * Pin assignment:
2598  *   Rear Line-In/Out (blue): 0x14
2599  *   Build-in Mic-In: 0x15
2600  *   Speaker-out: 0x17
2601  *   HP-Out (green): 0x1b
2602  *   Mic-In/Out (red): 0x19
2603  *   SPDIF-Out: 0x1e
2604  */
2605
2606 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2607 static hda_nid_t alc880_lg_dac_nids[3] = {
2608         0x05, 0x02, 0x03
2609 };
2610
2611 /* seems analog CD is not working */
2612 static struct hda_input_mux alc880_lg_capture_source = {
2613         .num_items = 3,
2614         .items = {
2615                 { "Mic", 0x1 },
2616                 { "Line", 0x5 },
2617                 { "Internal Mic", 0x6 },
2618         },
2619 };
2620
2621 /* 2,4,6 channel modes */
2622 static struct hda_verb alc880_lg_ch2_init[] = {
2623         /* set line-in and mic-in to input */
2624         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2625         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2626         { }
2627 };
2628
2629 static struct hda_verb alc880_lg_ch4_init[] = {
2630         /* set line-in to out and mic-in to input */
2631         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2632         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2633         { }
2634 };
2635
2636 static struct hda_verb alc880_lg_ch6_init[] = {
2637         /* set line-in and mic-in to output */
2638         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2639         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2640         { }
2641 };
2642
2643 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2644         { 2, alc880_lg_ch2_init },
2645         { 4, alc880_lg_ch4_init },
2646         { 6, alc880_lg_ch6_init },
2647 };
2648
2649 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2650         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2651         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2652         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2653         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2654         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2655         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2656         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2657         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2658         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2659         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2660         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2661         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2662         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2663         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2664         {
2665                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2666                 .name = "Channel Mode",
2667                 .info = alc_ch_mode_info,
2668                 .get = alc_ch_mode_get,
2669                 .put = alc_ch_mode_put,
2670         },
2671         { } /* end */
2672 };
2673
2674 static struct hda_verb alc880_lg_init_verbs[] = {
2675         /* set capture source to mic-in */
2676         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2677         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2678         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2679         /* mute all amp mixer inputs */
2680         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2681         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2682         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2683         /* line-in to input */
2684         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2685         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2686         /* built-in mic */
2687         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2688         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2689         /* speaker-out */
2690         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2691         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2692         /* mic-in to input */
2693         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2694         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2695         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2696         /* HP-out */
2697         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2698         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2699         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2700         /* jack sense */
2701         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2702         { }
2703 };
2704
2705 /* toggle speaker-output according to the hp-jack state */
2706 static void alc880_lg_automute(struct hda_codec *codec)
2707 {
2708         unsigned int present;
2709         unsigned char bits;
2710
2711         present = snd_hda_codec_read(codec, 0x1b, 0,
2712                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2713         bits = present ? HDA_AMP_MUTE : 0;
2714         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2715                                  HDA_AMP_MUTE, bits);
2716 }
2717
2718 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2719 {
2720         /* Looks like the unsol event is incompatible with the standard
2721          * definition.  4bit tag is placed at 28 bit!
2722          */
2723         if ((res >> 28) == 0x01)
2724                 alc880_lg_automute(codec);
2725 }
2726
2727 /*
2728  * LG LW20
2729  *
2730  * Pin assignment:
2731  *   Speaker-out: 0x14
2732  *   Mic-In: 0x18
2733  *   Built-in Mic-In: 0x19
2734  *   Line-In: 0x1b
2735  *   HP-Out: 0x1a
2736  *   SPDIF-Out: 0x1e
2737  */
2738
2739 static struct hda_input_mux alc880_lg_lw_capture_source = {
2740         .num_items = 3,
2741         .items = {
2742                 { "Mic", 0x0 },
2743                 { "Internal Mic", 0x1 },
2744                 { "Line In", 0x2 },
2745         },
2746 };
2747
2748 #define alc880_lg_lw_modes alc880_threestack_modes
2749
2750 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2751         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2752         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2753         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2754         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2755         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2756         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2757         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2758         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2759         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2760         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2761         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2762         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2763         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2764         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2765         {
2766                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2767                 .name = "Channel Mode",
2768                 .info = alc_ch_mode_info,
2769                 .get = alc_ch_mode_get,
2770                 .put = alc_ch_mode_put,
2771         },
2772         { } /* end */
2773 };
2774
2775 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2776         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2777         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2778         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2779
2780         /* set capture source to mic-in */
2781         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2782         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2783         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2784         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2785         /* speaker-out */
2786         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2787         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2788         /* HP-out */
2789         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2790         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2791         /* mic-in to input */
2792         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2793         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2794         /* built-in mic */
2795         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2796         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2797         /* jack sense */
2798         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2799         { }
2800 };
2801
2802 /* toggle speaker-output according to the hp-jack state */
2803 static void alc880_lg_lw_automute(struct hda_codec *codec)
2804 {
2805         unsigned int present;
2806         unsigned char bits;
2807
2808         present = snd_hda_codec_read(codec, 0x1b, 0,
2809                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2810         bits = present ? HDA_AMP_MUTE : 0;
2811         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2812                                  HDA_AMP_MUTE, bits);
2813 }
2814
2815 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2816 {
2817         /* Looks like the unsol event is incompatible with the standard
2818          * definition.  4bit tag is placed at 28 bit!
2819          */
2820         if ((res >> 28) == 0x01)
2821                 alc880_lg_lw_automute(codec);
2822 }
2823
2824 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2825         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2826         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2827         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2828         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2829         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2830         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2831         { } /* end */
2832 };
2833
2834 static struct hda_input_mux alc880_medion_rim_capture_source = {
2835         .num_items = 2,
2836         .items = {
2837                 { "Mic", 0x0 },
2838                 { "Internal Mic", 0x1 },
2839         },
2840 };
2841
2842 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2843         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2844
2845         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2846         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2847
2848         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2849         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2850         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2851         /* Mic2 (as headphone out) for HP output */
2852         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2853         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2854         /* Internal Speaker */
2855         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2856         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2857
2858         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2859         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2860
2861         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2862         { }
2863 };
2864
2865 /* toggle speaker-output according to the hp-jack state */
2866 static void alc880_medion_rim_automute(struct hda_codec *codec)
2867 {
2868         unsigned int present;
2869         unsigned char bits;
2870
2871         present = snd_hda_codec_read(codec, 0x14, 0,
2872                                      AC_VERB_GET_PIN_SENSE, 0)
2873                 & AC_PINSENSE_PRESENCE;
2874         bits = present ? HDA_AMP_MUTE : 0;
2875         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2876                                  HDA_AMP_MUTE, bits);
2877         if (present)
2878                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2879         else
2880                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2881 }
2882
2883 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2884                                           unsigned int res)
2885 {
2886         /* Looks like the unsol event is incompatible with the standard
2887          * definition.  4bit tag is placed at 28 bit!
2888          */
2889         if ((res >> 28) == ALC880_HP_EVENT)
2890                 alc880_medion_rim_automute(codec);
2891 }
2892
2893 #ifdef CONFIG_SND_HDA_POWER_SAVE
2894 static struct hda_amp_list alc880_loopbacks[] = {
2895         { 0x0b, HDA_INPUT, 0 },
2896         { 0x0b, HDA_INPUT, 1 },
2897         { 0x0b, HDA_INPUT, 2 },
2898         { 0x0b, HDA_INPUT, 3 },
2899         { 0x0b, HDA_INPUT, 4 },
2900         { } /* end */
2901 };
2902
2903 static struct hda_amp_list alc880_lg_loopbacks[] = {
2904         { 0x0b, HDA_INPUT, 1 },
2905         { 0x0b, HDA_INPUT, 6 },
2906         { 0x0b, HDA_INPUT, 7 },
2907         { } /* end */
2908 };
2909 #endif
2910
2911 /*
2912  * Common callbacks
2913  */
2914
2915 static int alc_init(struct hda_codec *codec)
2916 {
2917         struct alc_spec *spec = codec->spec;
2918         unsigned int i;
2919
2920         alc_fix_pll(codec);
2921         if (codec->vendor_id == 0x10ec0888)
2922                 alc888_coef_init(codec);
2923
2924         for (i = 0; i < spec->num_init_verbs; i++)
2925                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2926
2927         if (spec->init_hook)
2928                 spec->init_hook(codec);
2929
2930         return 0;
2931 }
2932
2933 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2934 {
2935         struct alc_spec *spec = codec->spec;
2936
2937         if (spec->unsol_event)
2938                 spec->unsol_event(codec, res);
2939 }
2940
2941 #ifdef CONFIG_SND_HDA_POWER_SAVE
2942 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2943 {
2944         struct alc_spec *spec = codec->spec;
2945         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2946 }
2947 #endif
2948
2949 /*
2950  * Analog playback callbacks
2951  */
2952 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2953                                     struct hda_codec *codec,
2954                                     struct snd_pcm_substream *substream)
2955 {
2956         struct alc_spec *spec = codec->spec;
2957         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2958                                              hinfo);
2959 }
2960
2961 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2962                                        struct hda_codec *codec,
2963                                        unsigned int stream_tag,
2964                                        unsigned int format,
2965                                        struct snd_pcm_substream *substream)
2966 {
2967         struct alc_spec *spec = codec->spec;
2968         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2969                                                 stream_tag, format, substream);
2970 }
2971
2972 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2973                                        struct hda_codec *codec,
2974                                        struct snd_pcm_substream *substream)
2975 {
2976         struct alc_spec *spec = codec->spec;
2977         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2978 }
2979
2980 /*
2981  * Digital out
2982  */
2983 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2984                                         struct hda_codec *codec,
2985                                         struct snd_pcm_substream *substream)
2986 {
2987         struct alc_spec *spec = codec->spec;
2988         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2989 }
2990
2991 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2992                                            struct hda_codec *codec,
2993                                            unsigned int stream_tag,
2994                                            unsigned int format,
2995                                            struct snd_pcm_substream *substream)
2996 {
2997         struct alc_spec *spec = codec->spec;
2998         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2999                                              stream_tag, format, substream);
3000 }
3001
3002 static int alc880_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3003                                            struct hda_codec *codec,
3004                                            struct snd_pcm_substream *substream)
3005 {
3006         struct alc_spec *spec = codec->spec;
3007         return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3008 }
3009
3010 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3011                                          struct hda_codec *codec,
3012                                          struct snd_pcm_substream *substream)
3013 {
3014         struct alc_spec *spec = codec->spec;
3015         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3016 }
3017
3018 /*
3019  * Analog capture
3020  */
3021 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3022                                       struct hda_codec *codec,
3023                                       unsigned int stream_tag,
3024                                       unsigned int format,
3025                                       struct snd_pcm_substream *substream)
3026 {
3027         struct alc_spec *spec = codec->spec;
3028
3029         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
3030                                    stream_tag, 0, format);
3031         return 0;
3032 }
3033
3034 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3035                                       struct hda_codec *codec,
3036                                       struct snd_pcm_substream *substream)
3037 {
3038         struct alc_spec *spec = codec->spec;
3039
3040         snd_hda_codec_cleanup_stream(codec,
3041                                      spec->adc_nids[substream->number + 1]);
3042         return 0;
3043 }
3044
3045
3046 /*
3047  */
3048 static struct hda_pcm_stream alc880_pcm_analog_playback = {
3049         .substreams = 1,
3050         .channels_min = 2,
3051         .channels_max = 8,
3052         /* NID is set in alc_build_pcms */
3053         .ops = {
3054                 .open = alc880_playback_pcm_open,
3055                 .prepare = alc880_playback_pcm_prepare,
3056                 .cleanup = alc880_playback_pcm_cleanup
3057         },
3058 };
3059
3060 static struct hda_pcm_stream alc880_pcm_analog_capture = {
3061         .substreams = 1,
3062         .channels_min = 2,
3063         .channels_max = 2,
3064         /* NID is set in alc_build_pcms */
3065 };
3066
3067 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
3068         .substreams = 1,
3069         .channels_min = 2,
3070         .channels_max = 2,
3071         /* NID is set in alc_build_pcms */
3072 };
3073
3074 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
3075         .substreams = 2, /* can be overridden */
3076         .channels_min = 2,
3077         .channels_max = 2,
3078         /* NID is set in alc_build_pcms */
3079         .ops = {
3080                 .prepare = alc880_alt_capture_pcm_prepare,
3081                 .cleanup = alc880_alt_capture_pcm_cleanup
3082         },
3083 };
3084
3085 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3086         .substreams = 1,
3087         .channels_min = 2,
3088         .channels_max = 2,
3089         /* NID is set in alc_build_pcms */
3090         .ops = {
3091                 .open = alc880_dig_playback_pcm_open,
3092                 .close = alc880_dig_playback_pcm_close,
3093                 .prepare = alc880_dig_playback_pcm_prepare,
3094                 .cleanup = alc880_dig_playback_pcm_cleanup
3095         },
3096 };
3097
3098 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3099         .substreams = 1,
3100         .channels_min = 2,
3101         .channels_max = 2,
3102         /* NID is set in alc_build_pcms */
3103 };
3104
3105 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3106 static struct hda_pcm_stream alc_pcm_null_stream = {
3107         .substreams = 0,
3108         .channels_min = 0,
3109         .channels_max = 0,
3110 };
3111
3112 static int alc_build_pcms(struct hda_codec *codec)
3113 {
3114         struct alc_spec *spec = codec->spec;
3115         struct hda_pcm *info = spec->pcm_rec;
3116         int i;
3117
3118         codec->num_pcms = 1;
3119         codec->pcm_info = info;
3120
3121         if (spec->no_analog)
3122                 goto skip_analog;
3123
3124         info->name = spec->stream_name_analog;
3125         if (spec->stream_analog_playback) {
3126                 if (snd_BUG_ON(!spec->multiout.dac_nids))
3127                         return -EINVAL;
3128                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
3129                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
3130         }
3131         if (spec->stream_analog_capture) {
3132                 if (snd_BUG_ON(!spec->adc_nids))
3133                         return -EINVAL;
3134                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
3135                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
3136         }
3137
3138         if (spec->channel_mode) {
3139                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
3140                 for (i = 0; i < spec->num_channel_mode; i++) {
3141                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
3142                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
3143                         }
3144                 }
3145         }
3146
3147  skip_analog:
3148         /* SPDIF for stream index #1 */
3149         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3150                 codec->num_pcms = 2;
3151                 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
3152                 info = spec->pcm_rec + 1;
3153                 info->name = spec->stream_name_digital;
3154                 if (spec->dig_out_type)
3155                         info->pcm_type = spec->dig_out_type;
3156                 else
3157                         info->pcm_type = HDA_PCM_TYPE_SPDIF;
3158                 if (spec->multiout.dig_out_nid &&
3159                     spec->stream_digital_playback) {
3160                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
3161                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
3162                 }
3163                 if (spec->dig_in_nid &&
3164                     spec->stream_digital_capture) {
3165                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
3166                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
3167                 }
3168                 /* FIXME: do we need this for all Realtek codec models? */
3169                 codec->spdif_status_reset = 1;
3170         }
3171
3172         if (spec->no_analog)
3173                 return 0;
3174
3175         /* If the use of more than one ADC is requested for the current
3176          * model, configure a second analog capture-only PCM.
3177          */
3178         /* Additional Analaog capture for index #2 */
3179         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
3180             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3181                 codec->num_pcms = 3;
3182                 info = spec->pcm_rec + 2;
3183                 info->name = spec->stream_name_analog;
3184                 if (spec->alt_dac_nid) {
3185                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3186                                 *spec->stream_analog_alt_playback;
3187                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
3188                                 spec->alt_dac_nid;
3189                 } else {
3190                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3191                                 alc_pcm_null_stream;
3192                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
3193                 }
3194                 if (spec->num_adc_nids > 1) {
3195                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3196                                 *spec->stream_analog_alt_capture;
3197                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
3198                                 spec->adc_nids[1];
3199                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3200                                 spec->num_adc_nids - 1;
3201                 } else {
3202                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3203                                 alc_pcm_null_stream;
3204                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3205                 }
3206         }
3207
3208         return 0;
3209 }
3210
3211 static void alc_free_kctls(struct hda_codec *codec)
3212 {
3213         struct alc_spec *spec = codec->spec;
3214
3215         if (spec->kctls.list) {
3216                 struct snd_kcontrol_new *kctl = spec->kctls.list;
3217                 int i;
3218                 for (i = 0; i < spec->kctls.used; i++)
3219                         kfree(kctl[i].name);
3220         }
3221         snd_array_free(&spec->kctls);
3222 }
3223
3224 static void alc_free(struct hda_codec *codec)
3225 {
3226         struct alc_spec *spec = codec->spec;
3227
3228         if (!spec)
3229                 return;
3230
3231         alc_free_kctls(codec);
3232         kfree(spec);
3233         snd_hda_detach_beep_device(codec);
3234 }
3235
3236 #ifdef SND_HDA_NEEDS_RESUME
3237 static int alc_resume(struct hda_codec *codec)
3238 {
3239         codec->patch_ops.init(codec);
3240         snd_hda_codec_resume_amp(codec);
3241         snd_hda_codec_resume_cache(codec);
3242         return 0;
3243 }
3244 #endif
3245
3246 /*
3247  */
3248 static struct hda_codec_ops alc_patch_ops = {
3249         .build_controls = alc_build_controls,
3250         .build_pcms = alc_build_pcms,
3251         .init = alc_init,
3252         .free = alc_free,
3253         .unsol_event = alc_unsol_event,
3254 #ifdef SND_HDA_NEEDS_RESUME
3255         .resume = alc_resume,
3256 #endif
3257 #ifdef CONFIG_SND_HDA_POWER_SAVE
3258         .check_power_status = alc_check_power_status,
3259 #endif
3260 };
3261
3262
3263 /*
3264  * Test configuration for debugging
3265  *
3266  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3267  * enum controls.
3268  */
3269 #ifdef CONFIG_SND_DEBUG
3270 static hda_nid_t alc880_test_dac_nids[4] = {
3271         0x02, 0x03, 0x04, 0x05
3272 };
3273
3274 static struct hda_input_mux alc880_test_capture_source = {
3275         .num_items = 7,
3276         .items = {
3277                 { "In-1", 0x0 },
3278                 { "In-2", 0x1 },
3279                 { "In-3", 0x2 },
3280                 { "In-4", 0x3 },
3281                 { "CD", 0x4 },
3282                 { "Front", 0x5 },
3283                 { "Surround", 0x6 },
3284         },
3285 };
3286
3287 static struct hda_channel_mode alc880_test_modes[4] = {
3288         { 2, NULL },
3289         { 4, NULL },
3290         { 6, NULL },
3291         { 8, NULL },
3292 };
3293
3294 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3295                                  struct snd_ctl_elem_info *uinfo)
3296 {
3297         static char *texts[] = {
3298                 "N/A", "Line Out", "HP Out",
3299                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3300         };
3301         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3302         uinfo->count = 1;
3303         uinfo->value.enumerated.items = 8;
3304         if (uinfo->value.enumerated.item >= 8)
3305                 uinfo->value.enumerated.item = 7;
3306         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3307         return 0;
3308 }
3309
3310 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3311                                 struct snd_ctl_elem_value *ucontrol)
3312 {
3313         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3314         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3315         unsigned int pin_ctl, item = 0;
3316
3317         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3318                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3319         if (pin_ctl & AC_PINCTL_OUT_EN) {
3320                 if (pin_ctl & AC_PINCTL_HP_EN)
3321                         item = 2;
3322                 else
3323                         item = 1;
3324         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3325                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3326                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3327                 case AC_PINCTL_VREF_50:  item = 4; break;
3328                 case AC_PINCTL_VREF_GRD: item = 5; break;
3329                 case AC_PINCTL_VREF_80:  item = 6; break;
3330                 case AC_PINCTL_VREF_100: item = 7; break;
3331                 }
3332         }
3333         ucontrol->value.enumerated.item[0] = item;
3334         return 0;
3335 }
3336
3337 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3338                                 struct snd_ctl_elem_value *ucontrol)
3339 {
3340         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3341         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3342         static unsigned int ctls[] = {
3343                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3344                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3345                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3346                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3347                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3348                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3349         };
3350         unsigned int old_ctl, new_ctl;
3351
3352         old_ctl = snd_hda_codec_read(codec, nid, 0,
3353                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3354         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3355         if (old_ctl != new_ctl) {
3356                 int val;
3357                 snd_hda_codec_write_cache(codec, nid, 0,
3358                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3359                                           new_ctl);
3360                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3361                         HDA_AMP_MUTE : 0;
3362                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3363                                          HDA_AMP_MUTE, val);
3364                 return 1;
3365         }
3366         return 0;
3367 }
3368
3369 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3370                                  struct snd_ctl_elem_info *uinfo)
3371 {
3372         static char *texts[] = {
3373                 "Front", "Surround", "CLFE", "Side"
3374         };
3375         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3376         uinfo->count = 1;
3377         uinfo->value.enumerated.items = 4;
3378         if (uinfo->value.enumerated.item >= 4)
3379                 uinfo->value.enumerated.item = 3;
3380         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3381         return 0;
3382 }
3383
3384 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3385                                 struct snd_ctl_elem_value *ucontrol)
3386 {
3387         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3388         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3389         unsigned int sel;
3390
3391         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3392         ucontrol->value.enumerated.item[0] = sel & 3;
3393         return 0;
3394 }
3395
3396 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3397                                 struct snd_ctl_elem_value *ucontrol)
3398 {
3399         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3400         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3401         unsigned int sel;
3402
3403         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3404         if (ucontrol->value.enumerated.item[0] != sel) {
3405                 sel = ucontrol->value.enumerated.item[0] & 3;
3406                 snd_hda_codec_write_cache(codec, nid, 0,
3407                                           AC_VERB_SET_CONNECT_SEL, sel);
3408                 return 1;
3409         }
3410         return 0;
3411 }
3412
3413 #define PIN_CTL_TEST(xname,nid) {                       \
3414                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3415                         .name = xname,                 \
3416                         .info = alc_test_pin_ctl_info, \
3417                         .get = alc_test_pin_ctl_get,   \
3418                         .put = alc_test_pin_ctl_put,   \
3419                         .private_value = nid           \
3420                         }
3421
3422 #define PIN_SRC_TEST(xname,nid) {                       \
3423                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3424                         .name = xname,                 \
3425                         .info = alc_test_pin_src_info, \
3426                         .get = alc_test_pin_src_get,   \
3427                         .put = alc_test_pin_src_put,   \
3428                         .private_value = nid           \
3429                         }
3430
3431 static struct snd_kcontrol_new alc880_test_mixer[] = {
3432         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3433         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3434         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3435         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3436         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3437         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3438         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3439         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3440         PIN_CTL_TEST("Front Pin Mode", 0x14),
3441         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3442         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3443         PIN_CTL_TEST("Side Pin Mode", 0x17),
3444         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3445         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3446         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3447         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3448         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3449         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3450         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3451         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3452         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3453         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3454         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3455         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3456         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3457         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3458         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3459         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3460         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3461         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3462         {
3463                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3464                 .name = "Channel Mode",
3465                 .info = alc_ch_mode_info,
3466                 .get = alc_ch_mode_get,
3467                 .put = alc_ch_mode_put,
3468         },
3469         { } /* end */
3470 };
3471
3472 static struct hda_verb alc880_test_init_verbs[] = {
3473         /* Unmute inputs of 0x0c - 0x0f */
3474         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3475         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3476         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3477         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3478         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3479         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3480         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3481         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3482         /* Vol output for 0x0c-0x0f */
3483         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3484         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3485         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3486         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3487         /* Set output pins 0x14-0x17 */
3488         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3489         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3490         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3491         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3492         /* Unmute output pins 0x14-0x17 */
3493         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3494         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3495         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3496         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3497         /* Set input pins 0x18-0x1c */
3498         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3499         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3500         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3501         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3502         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3503         /* Mute input pins 0x18-0x1b */
3504         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3505         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3506         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3507         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3508         /* ADC set up */
3509         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3510         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3511         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3512         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3513         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3514         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3515         /* Analog input/passthru */
3516         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3517         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3518         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3519         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3520         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3521         { }
3522 };
3523 #endif
3524
3525 /*
3526  */
3527
3528 static const char *alc880_models[ALC880_MODEL_LAST] = {
3529         [ALC880_3ST]            = "3stack",
3530         [ALC880_TCL_S700]       = "tcl",
3531         [ALC880_3ST_DIG]        = "3stack-digout",
3532         [ALC880_CLEVO]          = "clevo",
3533         [ALC880_5ST]            = "5stack",
3534         [ALC880_5ST_DIG]        = "5stack-digout",
3535         [ALC880_W810]           = "w810",
3536         [ALC880_Z71V]           = "z71v",
3537         [ALC880_6ST]            = "6stack",
3538         [ALC880_6ST_DIG]        = "6stack-digout",
3539         [ALC880_ASUS]           = "asus",
3540         [ALC880_ASUS_W1V]       = "asus-w1v",
3541         [ALC880_ASUS_DIG]       = "asus-dig",
3542         [ALC880_ASUS_DIG2]      = "asus-dig2",
3543         [ALC880_UNIWILL_DIG]    = "uniwill",
3544         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3545         [ALC880_FUJITSU]        = "fujitsu",
3546         [ALC880_F1734]          = "F1734",
3547         [ALC880_LG]             = "lg",
3548         [ALC880_LG_LW]          = "lg-lw",
3549         [ALC880_MEDION_RIM]     = "medion",
3550 #ifdef CONFIG_SND_DEBUG
3551         [ALC880_TEST]           = "test",
3552 #endif
3553         [ALC880_AUTO]           = "auto",
3554 };
3555
3556 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3557         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3558         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3559         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3560         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3561         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3562         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3563         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3564         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3565         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3566         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3567         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3568         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3569         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3570         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3571         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3572         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3573         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3574         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3575         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3576         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3577         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3578         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3579         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3580         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3581         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3582         SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_ASUS), /* default ASUS */
3583         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3584         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3585         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3586         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3587         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3588         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3589         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3590         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3591         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3592         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3593         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3594         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3595         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3596         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3597         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3598         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3599         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3600         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3601         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3602         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3603         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3604         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3605         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3606         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3607         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3608         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3609         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3610         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3611         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3612         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3613         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3614         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3615         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3616         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3617         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3618         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3619         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3620         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3621         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3622         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3623         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3624         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3625         /* default Intel */
3626         SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_3ST),
3627         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3628         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3629         {}
3630 };
3631
3632 /*
3633  * ALC880 codec presets
3634  */
3635 static struct alc_config_preset alc880_presets[] = {
3636         [ALC880_3ST] = {
3637                 .mixers = { alc880_three_stack_mixer },
3638                 .init_verbs = { alc880_volume_init_verbs,
3639                                 alc880_pin_3stack_init_verbs },
3640                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3641                 .dac_nids = alc880_dac_nids,
3642                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3643                 .channel_mode = alc880_threestack_modes,
3644                 .need_dac_fix = 1,
3645                 .input_mux = &alc880_capture_source,
3646         },
3647         [ALC880_3ST_DIG] = {
3648                 .mixers = { alc880_three_stack_mixer },
3649                 .init_verbs = { alc880_volume_init_verbs,
3650                                 alc880_pin_3stack_init_verbs },
3651                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3652                 .dac_nids = alc880_dac_nids,
3653                 .dig_out_nid = ALC880_DIGOUT_NID,
3654                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3655                 .channel_mode = alc880_threestack_modes,
3656                 .need_dac_fix = 1,
3657                 .input_mux = &alc880_capture_source,
3658         },
3659         [ALC880_TCL_S700] = {
3660                 .mixers = { alc880_tcl_s700_mixer },
3661                 .init_verbs = { alc880_volume_init_verbs,
3662                                 alc880_pin_tcl_S700_init_verbs,
3663                                 alc880_gpio2_init_verbs },
3664                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3665                 .dac_nids = alc880_dac_nids,
3666                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
3667                 .num_adc_nids = 1, /* single ADC */
3668                 .hp_nid = 0x03,
3669                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3670                 .channel_mode = alc880_2_jack_modes,
3671                 .input_mux = &alc880_capture_source,
3672         },
3673         [ALC880_5ST] = {
3674                 .mixers = { alc880_three_stack_mixer,
3675                             alc880_five_stack_mixer},
3676                 .init_verbs = { alc880_volume_init_verbs,
3677                                 alc880_pin_5stack_init_verbs },
3678                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3679                 .dac_nids = alc880_dac_nids,
3680                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3681                 .channel_mode = alc880_fivestack_modes,
3682                 .input_mux = &alc880_capture_source,
3683         },
3684         [ALC880_5ST_DIG] = {
3685                 .mixers = { alc880_three_stack_mixer,
3686                             alc880_five_stack_mixer },
3687                 .init_verbs = { alc880_volume_init_verbs,
3688                                 alc880_pin_5stack_init_verbs },
3689                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3690                 .dac_nids = alc880_dac_nids,
3691                 .dig_out_nid = ALC880_DIGOUT_NID,
3692                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3693                 .channel_mode = alc880_fivestack_modes,
3694                 .input_mux = &alc880_capture_source,
3695         },
3696         [ALC880_6ST] = {
3697                 .mixers = { alc880_six_stack_mixer },
3698                 .init_verbs = { alc880_volume_init_verbs,
3699                                 alc880_pin_6stack_init_verbs },
3700                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3701                 .dac_nids = alc880_6st_dac_nids,
3702                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3703                 .channel_mode = alc880_sixstack_modes,
3704                 .input_mux = &alc880_6stack_capture_source,
3705         },
3706         [ALC880_6ST_DIG] = {
3707                 .mixers = { alc880_six_stack_mixer },
3708                 .init_verbs = { alc880_volume_init_verbs,
3709                                 alc880_pin_6stack_init_verbs },
3710                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3711                 .dac_nids = alc880_6st_dac_nids,
3712                 .dig_out_nid = ALC880_DIGOUT_NID,
3713                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3714                 .channel_mode = alc880_sixstack_modes,
3715                 .input_mux = &alc880_6stack_capture_source,
3716         },
3717         [ALC880_W810] = {
3718                 .mixers = { alc880_w810_base_mixer },
3719                 .init_verbs = { alc880_volume_init_verbs,
3720                                 alc880_pin_w810_init_verbs,
3721                                 alc880_gpio2_init_verbs },
3722                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3723                 .dac_nids = alc880_w810_dac_nids,
3724                 .dig_out_nid = ALC880_DIGOUT_NID,
3725                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3726                 .channel_mode = alc880_w810_modes,
3727                 .input_mux = &alc880_capture_source,
3728         },
3729         [ALC880_Z71V] = {
3730                 .mixers = { alc880_z71v_mixer },
3731                 .init_verbs = { alc880_volume_init_verbs,
3732                                 alc880_pin_z71v_init_verbs },
3733                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3734                 .dac_nids = alc880_z71v_dac_nids,
3735                 .dig_out_nid = ALC880_DIGOUT_NID,
3736                 .hp_nid = 0x03,
3737                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3738                 .channel_mode = alc880_2_jack_modes,
3739                 .input_mux = &alc880_capture_source,
3740         },
3741         [ALC880_F1734] = {
3742                 .mixers = { alc880_f1734_mixer },
3743                 .init_verbs = { alc880_volume_init_verbs,
3744                                 alc880_pin_f1734_init_verbs },
3745                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3746                 .dac_nids = alc880_f1734_dac_nids,
3747                 .hp_nid = 0x02,
3748                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3749                 .channel_mode = alc880_2_jack_modes,
3750                 .input_mux = &alc880_f1734_capture_source,
3751                 .unsol_event = alc880_uniwill_p53_unsol_event,
3752                 .init_hook = alc880_uniwill_p53_hp_automute,
3753         },
3754         [ALC880_ASUS] = {
3755                 .mixers = { alc880_asus_mixer },
3756                 .init_verbs = { alc880_volume_init_verbs,
3757                                 alc880_pin_asus_init_verbs,
3758                                 alc880_gpio1_init_verbs },
3759                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3760                 .dac_nids = alc880_asus_dac_nids,
3761                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3762                 .channel_mode = alc880_asus_modes,
3763                 .need_dac_fix = 1,
3764                 .input_mux = &alc880_capture_source,
3765         },
3766         [ALC880_ASUS_DIG] = {
3767                 .mixers = { alc880_asus_mixer },
3768                 .init_verbs = { alc880_volume_init_verbs,
3769                                 alc880_pin_asus_init_verbs,
3770                                 alc880_gpio1_init_verbs },
3771                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3772                 .dac_nids = alc880_asus_dac_nids,
3773                 .dig_out_nid = ALC880_DIGOUT_NID,
3774                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3775                 .channel_mode = alc880_asus_modes,
3776                 .need_dac_fix = 1,
3777                 .input_mux = &alc880_capture_source,
3778         },
3779         [ALC880_ASUS_DIG2] = {
3780                 .mixers = { alc880_asus_mixer },
3781                 .init_verbs = { alc880_volume_init_verbs,
3782                                 alc880_pin_asus_init_verbs,
3783                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3784                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3785                 .dac_nids = alc880_asus_dac_nids,
3786                 .dig_out_nid = ALC880_DIGOUT_NID,
3787                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3788                 .channel_mode = alc880_asus_modes,
3789                 .need_dac_fix = 1,
3790                 .input_mux = &alc880_capture_source,
3791         },
3792         [ALC880_ASUS_W1V] = {
3793                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3794                 .init_verbs = { alc880_volume_init_verbs,
3795                                 alc880_pin_asus_init_verbs,
3796                                 alc880_gpio1_init_verbs },
3797                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3798                 .dac_nids = alc880_asus_dac_nids,
3799                 .dig_out_nid = ALC880_DIGOUT_NID,
3800                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3801                 .channel_mode = alc880_asus_modes,
3802                 .need_dac_fix = 1,
3803                 .input_mux = &alc880_capture_source,
3804         },
3805         [ALC880_UNIWILL_DIG] = {
3806                 .mixers = { alc880_asus_mixer },
3807                 .init_verbs = { alc880_volume_init_verbs,
3808                                 alc880_pin_asus_init_verbs },
3809                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3810                 .dac_nids = alc880_asus_dac_nids,
3811                 .dig_out_nid = ALC880_DIGOUT_NID,
3812                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3813                 .channel_mode = alc880_asus_modes,
3814                 .need_dac_fix = 1,
3815                 .input_mux = &alc880_capture_source,
3816         },
3817         [ALC880_UNIWILL] = {
3818                 .mixers = { alc880_uniwill_mixer },
3819                 .init_verbs = { alc880_volume_init_verbs,
3820                                 alc880_uniwill_init_verbs },
3821                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3822                 .dac_nids = alc880_asus_dac_nids,
3823                 .dig_out_nid = ALC880_DIGOUT_NID,
3824                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3825                 .channel_mode = alc880_threestack_modes,
3826                 .need_dac_fix = 1,
3827                 .input_mux = &alc880_capture_source,
3828                 .unsol_event = alc880_uniwill_unsol_event,
3829                 .init_hook = alc880_uniwill_automute,
3830         },
3831         [ALC880_UNIWILL_P53] = {
3832                 .mixers = { alc880_uniwill_p53_mixer },
3833                 .init_verbs = { alc880_volume_init_verbs,
3834                                 alc880_uniwill_p53_init_verbs },
3835                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3836                 .dac_nids = alc880_asus_dac_nids,
3837                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3838                 .channel_mode = alc880_threestack_modes,
3839                 .input_mux = &alc880_capture_source,
3840                 .unsol_event = alc880_uniwill_p53_unsol_event,
3841                 .init_hook = alc880_uniwill_p53_hp_automute,
3842         },
3843         [ALC880_FUJITSU] = {
3844                 .mixers = { alc880_fujitsu_mixer },
3845                 .init_verbs = { alc880_volume_init_verbs,
3846                                 alc880_uniwill_p53_init_verbs,
3847                                 alc880_beep_init_verbs },
3848                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3849                 .dac_nids = alc880_dac_nids,
3850                 .dig_out_nid = ALC880_DIGOUT_NID,
3851                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3852                 .channel_mode = alc880_2_jack_modes,
3853                 .input_mux = &alc880_capture_source,
3854                 .unsol_event = alc880_uniwill_p53_unsol_event,
3855                 .init_hook = alc880_uniwill_p53_hp_automute,
3856         },
3857         [ALC880_CLEVO] = {
3858                 .mixers = { alc880_three_stack_mixer },
3859                 .init_verbs = { alc880_volume_init_verbs,
3860                                 alc880_pin_clevo_init_verbs },
3861                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3862                 .dac_nids = alc880_dac_nids,
3863                 .hp_nid = 0x03,
3864                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3865                 .channel_mode = alc880_threestack_modes,
3866                 .need_dac_fix = 1,
3867                 .input_mux = &alc880_capture_source,
3868         },
3869         [ALC880_LG] = {
3870                 .mixers = { alc880_lg_mixer },
3871                 .init_verbs = { alc880_volume_init_verbs,
3872                                 alc880_lg_init_verbs },
3873                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3874                 .dac_nids = alc880_lg_dac_nids,
3875                 .dig_out_nid = ALC880_DIGOUT_NID,
3876                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3877                 .channel_mode = alc880_lg_ch_modes,
3878                 .need_dac_fix = 1,
3879                 .input_mux = &alc880_lg_capture_source,
3880                 .unsol_event = alc880_lg_unsol_event,
3881                 .init_hook = alc880_lg_automute,
3882 #ifdef CONFIG_SND_HDA_POWER_SAVE
3883                 .loopbacks = alc880_lg_loopbacks,
3884 #endif
3885         },
3886         [ALC880_LG_LW] = {
3887                 .mixers = { alc880_lg_lw_mixer },
3888                 .init_verbs = { alc880_volume_init_verbs,
3889                                 alc880_lg_lw_init_verbs },
3890                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3891                 .dac_nids = alc880_dac_nids,
3892                 .dig_out_nid = ALC880_DIGOUT_NID,
3893                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3894                 .channel_mode = alc880_lg_lw_modes,
3895                 .input_mux = &alc880_lg_lw_capture_source,
3896                 .unsol_event = alc880_lg_lw_unsol_event,
3897                 .init_hook = alc880_lg_lw_automute,
3898         },
3899         [ALC880_MEDION_RIM] = {
3900                 .mixers = { alc880_medion_rim_mixer },
3901                 .init_verbs = { alc880_volume_init_verbs,
3902                                 alc880_medion_rim_init_verbs,
3903                                 alc_gpio2_init_verbs },
3904                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3905                 .dac_nids = alc880_dac_nids,
3906                 .dig_out_nid = ALC880_DIGOUT_NID,
3907                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3908                 .channel_mode = alc880_2_jack_modes,
3909                 .input_mux = &alc880_medion_rim_capture_source,
3910                 .unsol_event = alc880_medion_rim_unsol_event,
3911                 .init_hook = alc880_medion_rim_automute,
3912         },
3913 #ifdef CONFIG_SND_DEBUG
3914         [ALC880_TEST] = {
3915                 .mixers = { alc880_test_mixer },
3916                 .init_verbs = { alc880_test_init_verbs },
3917                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3918                 .dac_nids = alc880_test_dac_nids,
3919                 .dig_out_nid = ALC880_DIGOUT_NID,
3920                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3921                 .channel_mode = alc880_test_modes,
3922                 .input_mux = &alc880_test_capture_source,
3923         },
3924 #endif
3925 };
3926
3927 /*
3928  * Automatic parse of I/O pins from the BIOS configuration
3929  */
3930
3931 enum {
3932         ALC_CTL_WIDGET_VOL,
3933         ALC_CTL_WIDGET_MUTE,
3934         ALC_CTL_BIND_MUTE,
3935 };
3936 static struct snd_kcontrol_new alc880_control_templates[] = {
3937         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3938         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3939         HDA_BIND_MUTE(NULL, 0, 0, 0),
3940 };
3941
3942 /* add dynamic controls */
3943 static int add_control(struct alc_spec *spec, int type, const char *name,
3944                        unsigned long val)
3945 {
3946         struct snd_kcontrol_new *knew;
3947
3948         snd_array_init(&spec->kctls, sizeof(*knew), 32);
3949         knew = snd_array_new(&spec->kctls);
3950         if (!knew)
3951                 return -ENOMEM;
3952         *knew = alc880_control_templates[type];
3953         knew->name = kstrdup(name, GFP_KERNEL);
3954         if (!knew->name)
3955                 return -ENOMEM;
3956         knew->private_value = val;
3957         return 0;
3958 }
3959
3960 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3961 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3962 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3963 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3964 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3965 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3966 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3967 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3968 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3969 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3970 #define ALC880_PIN_CD_NID               0x1c
3971
3972 /* fill in the dac_nids table from the parsed pin configuration */
3973 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3974                                      const struct auto_pin_cfg *cfg)
3975 {
3976         hda_nid_t nid;
3977         int assigned[4];
3978         int i, j;
3979
3980         memset(assigned, 0, sizeof(assigned));
3981         spec->multiout.dac_nids = spec->private_dac_nids;
3982
3983         /* check the pins hardwired to audio widget */
3984         for (i = 0; i < cfg->line_outs; i++) {
3985                 nid = cfg->line_out_pins[i];
3986                 if (alc880_is_fixed_pin(nid)) {
3987                         int idx = alc880_fixed_pin_idx(nid);
3988                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3989                         assigned[idx] = 1;
3990                 }
3991         }
3992         /* left pins can be connect to any audio widget */
3993         for (i = 0; i < cfg->line_outs; i++) {
3994                 nid = cfg->line_out_pins[i];
3995                 if (alc880_is_fixed_pin(nid))
3996                         continue;
3997                 /* search for an empty channel */
3998                 for (j = 0; j < cfg->line_outs; j++) {
3999                         if (!assigned[j]) {
4000                                 spec->multiout.dac_nids[i] =
4001                                         alc880_idx_to_dac(j);
4002                                 assigned[j] = 1;
4003                                 break;
4004                         }
4005                 }
4006         }
4007         spec->multiout.num_dacs = cfg->line_outs;
4008         return 0;
4009 }
4010
4011 /* add playback controls from the parsed DAC table */
4012 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4013                                              const struct auto_pin_cfg *cfg)
4014 {
4015         char name[32];
4016         static const char *chname[4] = {
4017                 "Front", "Surround", NULL /*CLFE*/, "Side"
4018         };
4019         hda_nid_t nid;
4020         int i, err;
4021
4022         for (i = 0; i < cfg->line_outs; i++) {
4023                 if (!spec->multiout.dac_nids[i])
4024                         continue;
4025                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
4026                 if (i == 2) {
4027                         /* Center/LFE */
4028                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4029                                           "Center Playback Volume",
4030                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
4031                                                               HDA_OUTPUT));
4032                         if (err < 0)
4033                                 return err;
4034                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4035                                           "LFE Playback Volume",
4036                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
4037                                                               HDA_OUTPUT));
4038                         if (err < 0)
4039                                 return err;
4040                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4041                                           "Center Playback Switch",
4042                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4043                                                               HDA_INPUT));
4044                         if (err < 0)
4045                                 return err;
4046                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4047                                           "LFE Playback Switch",
4048                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4049                                                               HDA_INPUT));
4050                         if (err < 0)
4051                                 return err;
4052                 } else {
4053                         sprintf(name, "%s Playback Volume", chname[i]);
4054                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4055                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4056                                                               HDA_OUTPUT));
4057                         if (err < 0)
4058                                 return err;
4059                         sprintf(name, "%s Playback Switch", chname[i]);
4060                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4061                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4062                                                               HDA_INPUT));
4063                         if (err < 0)
4064                                 return err;
4065                 }
4066         }
4067         return 0;
4068 }
4069
4070 /* add playback controls for speaker and HP outputs */
4071 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4072                                         const char *pfx)
4073 {
4074         hda_nid_t nid;
4075         int err;
4076         char name[32];
4077
4078         if (!pin)
4079                 return 0;
4080
4081         if (alc880_is_fixed_pin(pin)) {
4082                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
4083                 /* specify the DAC as the extra output */
4084                 if (!spec->multiout.hp_nid)
4085                         spec->multiout.hp_nid = nid;
4086                 else
4087                         spec->multiout.extra_out_nid[0] = nid;
4088                 /* control HP volume/switch on the output mixer amp */
4089                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4090                 sprintf(name, "%s Playback Volume", pfx);
4091                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4092                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4093                 if (err < 0)
4094                         return err;
4095                 sprintf(name, "%s Playback Switch", pfx);
4096                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4097                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4098                 if (err < 0)
4099                         return err;
4100         } else if (alc880_is_multi_pin(pin)) {
4101                 /* set manual connection */
4102                 /* we have only a switch on HP-out PIN */
4103                 sprintf(name, "%s Playback Switch", pfx);
4104                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4105                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4106                 if (err < 0)
4107                         return err;
4108         }
4109         return 0;
4110 }
4111
4112 /* create input playback/capture controls for the given pin */
4113 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4114                             const char *ctlname,
4115                             int idx, hda_nid_t mix_nid)
4116 {
4117         char name[32];
4118         int err;
4119
4120         sprintf(name, "%s Playback Volume", ctlname);
4121         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4122                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4123         if (err < 0)
4124                 return err;
4125         sprintf(name, "%s Playback Switch", ctlname);
4126         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4127                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4128         if (err < 0)
4129                 return err;
4130         return 0;
4131 }
4132
4133 /* create playback/capture controls for input pins */
4134 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
4135                                                 const struct auto_pin_cfg *cfg)
4136 {
4137         struct hda_input_mux *imux = &spec->private_imux[0];
4138         int i, err, idx;
4139
4140         for (i = 0; i < AUTO_PIN_LAST; i++) {
4141                 if (alc880_is_input_pin(cfg->input_pins[i])) {
4142                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
4143                         err = new_analog_input(spec, cfg->input_pins[i],
4144                                                auto_pin_cfg_labels[i],
4145                                                idx, 0x0b);
4146                         if (err < 0)
4147                                 return err;
4148                         imux->items[imux->num_items].label =
4149                                 auto_pin_cfg_labels[i];
4150                         imux->items[imux->num_items].index =
4151                                 alc880_input_pin_idx(cfg->input_pins[i]);
4152                         imux->num_items++;
4153                 }
4154         }
4155         return 0;
4156 }
4157
4158 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
4159                                unsigned int pin_type)
4160 {
4161         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4162                             pin_type);
4163         /* unmute pin */
4164         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4165                             AMP_OUT_UNMUTE);
4166 }
4167
4168 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
4169                                               hda_nid_t nid, int pin_type,
4170                                               int dac_idx)
4171 {
4172         alc_set_pin_output(codec, nid, pin_type);
4173         /* need the manual connection? */
4174         if (alc880_is_multi_pin(nid)) {
4175                 struct alc_spec *spec = codec->spec;
4176                 int idx = alc880_multi_pin_idx(nid);
4177                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
4178                                     AC_VERB_SET_CONNECT_SEL,
4179                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
4180         }
4181 }
4182
4183 static int get_pin_type(int line_out_type)
4184 {
4185         if (line_out_type == AUTO_PIN_HP_OUT)
4186                 return PIN_HP;
4187         else
4188                 return PIN_OUT;
4189 }
4190
4191 static void alc880_auto_init_multi_out(struct hda_codec *codec)
4192 {
4193         struct alc_spec *spec = codec->spec;
4194         int i;
4195
4196         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
4197         for (i = 0; i < spec->autocfg.line_outs; i++) {
4198                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4199                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4200                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
4201         }
4202 }
4203
4204 static void alc880_auto_init_extra_out(struct hda_codec *codec)
4205 {
4206         struct alc_spec *spec = codec->spec;
4207         hda_nid_t pin;
4208
4209         pin = spec->autocfg.speaker_pins[0];
4210         if (pin) /* connect to front */
4211                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
4212         pin = spec->autocfg.hp_pins[0];
4213         if (pin) /* connect to front */
4214                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
4215 }
4216
4217 static void alc880_auto_init_analog_input(struct hda_codec *codec)
4218 {
4219         struct alc_spec *spec = codec->spec;
4220         int i;
4221
4222         for (i = 0; i < AUTO_PIN_LAST; i++) {
4223                 hda_nid_t nid = spec->autocfg.input_pins[i];
4224                 if (alc880_is_input_pin(nid)) {
4225                         alc_set_input_pin(codec, nid, i);
4226                         if (nid != ALC880_PIN_CD_NID &&
4227                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
4228                                 snd_hda_codec_write(codec, nid, 0,
4229                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4230                                                     AMP_OUT_MUTE);
4231                 }
4232         }
4233 }
4234
4235 /* parse the BIOS configuration and set up the alc_spec */
4236 /* return 1 if successful, 0 if the proper config is not found,
4237  * or a negative error code
4238  */
4239 static int alc880_parse_auto_config(struct hda_codec *codec)
4240 {
4241         struct alc_spec *spec = codec->spec;
4242         int i, err;
4243         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4244
4245         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4246                                            alc880_ignore);
4247         if (err < 0)
4248                 return err;
4249         if (!spec->autocfg.line_outs)
4250                 return 0; /* can't find valid BIOS pin config */
4251
4252         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
4253         if (err < 0)
4254                 return err;
4255         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
4256         if (err < 0)
4257                 return err;
4258         err = alc880_auto_create_extra_out(spec,
4259                                            spec->autocfg.speaker_pins[0],
4260                                            "Speaker");
4261         if (err < 0)
4262                 return err;
4263         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
4264                                            "Headphone");
4265         if (err < 0)
4266                 return err;
4267         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
4268         if (err < 0)
4269                 return err;
4270
4271         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4272
4273         /* check multiple SPDIF-out (for recent codecs) */
4274         for (i = 0; i < spec->autocfg.dig_outs; i++) {
4275                 hda_nid_t dig_nid;
4276                 err = snd_hda_get_connections(codec,
4277                                               spec->autocfg.dig_out_pins[i],
4278                                               &dig_nid, 1);
4279                 if (err < 0)
4280                         continue;
4281                 if (!i)
4282                         spec->multiout.dig_out_nid = dig_nid;
4283                 else {
4284                         spec->multiout.slave_dig_outs = spec->slave_dig_outs;
4285                         spec->slave_dig_outs[i - 1] = dig_nid;
4286                         if (i == ARRAY_SIZE(spec->slave_dig_outs) - 1)
4287                                 break;
4288                 }
4289         }
4290         if (spec->autocfg.dig_in_pin)
4291                 spec->dig_in_nid = ALC880_DIGIN_NID;
4292
4293         if (spec->kctls.list)
4294                 add_mixer(spec, spec->kctls.list);
4295
4296         add_verb(spec, alc880_volume_init_verbs);
4297
4298         spec->num_mux_defs = 1;
4299         spec->input_mux = &spec->private_imux[0];
4300
4301         return 1;
4302 }
4303
4304 /* additional initialization for auto-configuration model */
4305 static void alc880_auto_init(struct hda_codec *codec)
4306 {
4307         struct alc_spec *spec = codec->spec;
4308         alc880_auto_init_multi_out(codec);
4309         alc880_auto_init_extra_out(codec);
4310         alc880_auto_init_analog_input(codec);
4311         if (spec->unsol_event)
4312                 alc_inithook(codec);
4313 }
4314
4315 static void set_capture_mixer(struct alc_spec *spec)
4316 {
4317         static struct snd_kcontrol_new *caps[2][3] = {
4318                 { alc_capture_mixer_nosrc1,
4319                   alc_capture_mixer_nosrc2,
4320                   alc_capture_mixer_nosrc3 },
4321                 { alc_capture_mixer1,
4322                   alc_capture_mixer2,
4323                   alc_capture_mixer3 },
4324         };
4325         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) {
4326                 int mux;
4327                 if (spec->input_mux && spec->input_mux->num_items > 1)
4328                         mux = 1;
4329                 else
4330                         mux = 0;
4331                 spec->cap_mixer = caps[mux][spec->num_adc_nids - 1];
4332         }
4333 }
4334
4335 #define set_beep_amp(spec, nid, idx, dir) \
4336         ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4337
4338 /*
4339  * OK, here we have finally the patch for ALC880
4340  */
4341
4342 static int patch_alc880(struct hda_codec *codec)
4343 {
4344         struct alc_spec *spec;
4345         int board_config;
4346         int err;
4347
4348         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4349         if (spec == NULL)
4350                 return -ENOMEM;
4351
4352         codec->spec = spec;
4353
4354         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4355                                                   alc880_models,
4356                                                   alc880_cfg_tbl);
4357         if (board_config < 0) {
4358                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
4359                        "trying auto-probe from BIOS...\n");
4360                 board_config = ALC880_AUTO;
4361         }
4362
4363         if (board_config == ALC880_AUTO) {
4364                 /* automatic parse from the BIOS config */
4365                 err = alc880_parse_auto_config(codec);
4366                 if (err < 0) {
4367                         alc_free(codec);
4368                         return err;
4369                 } else if (!err) {
4370                         printk(KERN_INFO
4371                                "hda_codec: Cannot set up configuration "
4372                                "from BIOS.  Using 3-stack mode...\n");
4373                         board_config = ALC880_3ST;
4374                 }
4375         }
4376
4377         err = snd_hda_attach_beep_device(codec, 0x1);
4378         if (err < 0) {
4379                 alc_free(codec);
4380                 return err;
4381         }
4382
4383         if (board_config != ALC880_AUTO)
4384                 setup_preset(spec, &alc880_presets[board_config]);
4385
4386         spec->stream_name_analog = "ALC880 Analog";
4387         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4388         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4389         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4390
4391         spec->stream_name_digital = "ALC880 Digital";
4392         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4393         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4394
4395         if (!spec->adc_nids && spec->input_mux) {
4396                 /* check whether NID 0x07 is valid */
4397                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4398                 /* get type */
4399                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
4400                 if (wcap != AC_WID_AUD_IN) {
4401                         spec->adc_nids = alc880_adc_nids_alt;
4402                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4403                 } else {
4404                         spec->adc_nids = alc880_adc_nids;
4405                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4406                 }
4407         }
4408         set_capture_mixer(spec);
4409         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4410
4411         spec->vmaster_nid = 0x0c;
4412
4413         codec->patch_ops = alc_patch_ops;
4414         if (board_config == ALC880_AUTO)
4415                 spec->init_hook = alc880_auto_init;
4416 #ifdef CONFIG_SND_HDA_POWER_SAVE
4417         if (!spec->loopback.amplist)
4418                 spec->loopback.amplist = alc880_loopbacks;
4419 #endif
4420         codec->proc_widget_hook = print_realtek_coef;
4421
4422         return 0;
4423 }
4424
4425
4426 /*
4427  * ALC260 support
4428  */
4429
4430 static hda_nid_t alc260_dac_nids[1] = {
4431         /* front */
4432         0x02,
4433 };
4434
4435 static hda_nid_t alc260_adc_nids[1] = {
4436         /* ADC0 */
4437         0x04,
4438 };
4439
4440 static hda_nid_t alc260_adc_nids_alt[1] = {
4441         /* ADC1 */
4442         0x05,
4443 };
4444
4445 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4446  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4447  */
4448 static hda_nid_t alc260_dual_adc_nids[2] = {
4449         /* ADC0, ADC1 */
4450         0x04, 0x05
4451 };
4452
4453 #define ALC260_DIGOUT_NID       0x03
4454 #define ALC260_DIGIN_NID        0x06
4455
4456 static struct hda_input_mux alc260_capture_source = {
4457         .num_items = 4,
4458         .items = {
4459                 { "Mic", 0x0 },
4460                 { "Front Mic", 0x1 },
4461                 { "Line", 0x2 },
4462                 { "CD", 0x4 },
4463         },
4464 };
4465
4466 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4467  * headphone jack and the internal CD lines since these are the only pins at
4468  * which audio can appear.  For flexibility, also allow the option of
4469  * recording the mixer output on the second ADC (ADC0 doesn't have a
4470  * connection to the mixer output).
4471  */
4472 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4473         {
4474                 .num_items = 3,
4475                 .items = {
4476                         { "Mic/Line", 0x0 },
4477                         { "CD", 0x4 },
4478                         { "Headphone", 0x2 },
4479                 },
4480         },
4481         {
4482                 .num_items = 4,
4483                 .items = {
4484                         { "Mic/Line", 0x0 },
4485                         { "CD", 0x4 },
4486                         { "Headphone", 0x2 },
4487                         { "Mixer", 0x5 },
4488                 },
4489         },
4490
4491 };
4492
4493 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4494  * the Fujitsu S702x, but jacks are marked differently.
4495  */
4496 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4497         {
4498                 .num_items = 4,
4499                 .items = {
4500                         { "Mic", 0x0 },
4501                         { "Line", 0x2 },
4502                         { "CD", 0x4 },
4503                         { "Headphone", 0x5 },
4504                 },
4505         },
4506         {
4507                 .num_items = 5,
4508                 .items = {
4509                         { "Mic", 0x0 },
4510                         { "Line", 0x2 },
4511                         { "CD", 0x4 },
4512                         { "Headphone", 0x6 },
4513                         { "Mixer", 0x5 },
4514                 },
4515         },
4516 };
4517
4518 /* Maxdata Favorit 100XS */
4519 static struct hda_input_mux alc260_favorit100_capture_sources[2] = {
4520         {
4521                 .num_items = 2,
4522                 .items = {
4523                         { "Line/Mic", 0x0 },
4524                         { "CD", 0x4 },
4525                 },
4526         },
4527         {
4528                 .num_items = 3,
4529                 .items = {
4530                         { "Line/Mic", 0x0 },
4531                         { "CD", 0x4 },
4532                         { "Mixer", 0x5 },
4533                 },
4534         },
4535 };
4536
4537 /*
4538  * This is just place-holder, so there's something for alc_build_pcms to look
4539  * at when it calculates the maximum number of channels. ALC260 has no mixer
4540  * element which allows changing the channel mode, so the verb list is
4541  * never used.
4542  */
4543 static struct hda_channel_mode alc260_modes[1] = {
4544         { 2, NULL },
4545 };
4546
4547
4548 /* Mixer combinations
4549  *
4550  * basic: base_output + input + pc_beep + capture
4551  * HP: base_output + input + capture_alt
4552  * HP_3013: hp_3013 + input + capture
4553  * fujitsu: fujitsu + capture
4554  * acer: acer + capture
4555  */
4556
4557 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
4558         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4559         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4560         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4561         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4562         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4563         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4564         { } /* end */
4565 };
4566
4567 static struct snd_kcontrol_new alc260_input_mixer[] = {
4568         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4569         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4570         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4571         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4572         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4573         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4574         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4575         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4576         { } /* end */
4577 };
4578
4579 /* update HP, line and mono out pins according to the master switch */
4580 static void alc260_hp_master_update(struct hda_codec *codec,
4581                                     hda_nid_t hp, hda_nid_t line,
4582                                     hda_nid_t mono)
4583 {
4584         struct alc_spec *spec = codec->spec;
4585         unsigned int val = spec->master_sw ? PIN_HP : 0;
4586         /* change HP and line-out pins */
4587         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4588                             val);
4589         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4590                             val);
4591         /* mono (speaker) depending on the HP jack sense */
4592         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4593         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4594                             val);
4595 }
4596
4597 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4598                                    struct snd_ctl_elem_value *ucontrol)
4599 {
4600         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4601         struct alc_spec *spec = codec->spec;
4602         *ucontrol->value.integer.value = spec->master_sw;
4603         return 0;
4604 }
4605
4606 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4607                                    struct snd_ctl_elem_value *ucontrol)
4608 {
4609         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4610         struct alc_spec *spec = codec->spec;
4611         int val = !!*ucontrol->value.integer.value;
4612         hda_nid_t hp, line, mono;
4613
4614         if (val == spec->master_sw)
4615                 return 0;
4616         spec->master_sw = val;
4617         hp = (kcontrol->private_value >> 16) & 0xff;
4618         line = (kcontrol->private_value >> 8) & 0xff;
4619         mono = kcontrol->private_value & 0xff;
4620         alc260_hp_master_update(codec, hp, line, mono);
4621         return 1;
4622 }
4623
4624 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4625         {
4626                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4627                 .name = "Master Playback Switch",
4628                 .info = snd_ctl_boolean_mono_info,
4629                 .get = alc260_hp_master_sw_get,
4630                 .put = alc260_hp_master_sw_put,
4631                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4632         },
4633         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4634         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4635         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4636         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4637         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4638                               HDA_OUTPUT),
4639         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4640         { } /* end */
4641 };
4642
4643 static struct hda_verb alc260_hp_unsol_verbs[] = {
4644         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4645         {},
4646 };
4647
4648 static void alc260_hp_automute(struct hda_codec *codec)
4649 {
4650         struct alc_spec *spec = codec->spec;
4651         unsigned int present;
4652
4653         present = snd_hda_codec_read(codec, 0x10, 0,
4654                                      AC_VERB_GET_PIN_SENSE, 0);
4655         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4656         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4657 }
4658
4659 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4660 {
4661         if ((res >> 26) == ALC880_HP_EVENT)
4662                 alc260_hp_automute(codec);
4663 }
4664
4665 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4666         {
4667                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4668                 .name = "Master Playback Switch",
4669                 .info = snd_ctl_boolean_mono_info,
4670                 .get = alc260_hp_master_sw_get,
4671                 .put = alc260_hp_master_sw_put,
4672                 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
4673         },
4674         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4675         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4676         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4677         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4678         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4679         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4680         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4681         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4682         { } /* end */
4683 };
4684
4685 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
4686         .ops = &snd_hda_bind_vol,
4687         .values = {
4688                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
4689                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
4690                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
4691                 0
4692         },
4693 };
4694
4695 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
4696         .ops = &snd_hda_bind_sw,
4697         .values = {
4698                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
4699                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
4700                 0
4701         },
4702 };
4703
4704 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
4705         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
4706         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
4707         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
4708         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4709         { } /* end */
4710 };
4711
4712 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4713         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4714         {},
4715 };
4716
4717 static void alc260_hp_3013_automute(struct hda_codec *codec)
4718 {
4719         struct alc_spec *spec = codec->spec;
4720         unsigned int present;
4721
4722         present = snd_hda_codec_read(codec, 0x15, 0,
4723                                      AC_VERB_GET_PIN_SENSE, 0);
4724         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4725         alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
4726 }
4727
4728 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4729                                        unsigned int res)
4730 {
4731         if ((res >> 26) == ALC880_HP_EVENT)
4732                 alc260_hp_3013_automute(codec);
4733 }
4734
4735 static void alc260_hp_3012_automute(struct hda_codec *codec)
4736 {
4737         unsigned int present, bits;
4738
4739         present = snd_hda_codec_read(codec, 0x10, 0,
4740                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
4741
4742         bits = present ? 0 : PIN_OUT;
4743         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4744                             bits);
4745         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4746                             bits);
4747         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4748                             bits);
4749 }
4750
4751 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
4752                                        unsigned int res)
4753 {
4754         if ((res >> 26) == ALC880_HP_EVENT)
4755                 alc260_hp_3012_automute(codec);
4756 }
4757
4758 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
4759  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4760  */
4761 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4762         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4763         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4764         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4765         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4766         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4767         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4768         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4769         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4770         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4771         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4772         { } /* end */
4773 };
4774
4775 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4776  * versions of the ALC260 don't act on requests to enable mic bias from NID
4777  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4778  * datasheet doesn't mention this restriction.  At this stage it's not clear
4779  * whether this behaviour is intentional or is a hardware bug in chip
4780  * revisions available in early 2006.  Therefore for now allow the
4781  * "Headphone Jack Mode" control to span all choices, but if it turns out
4782  * that the lack of mic bias for this NID is intentional we could change the
4783  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4784  *
4785  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4786  * don't appear to make the mic bias available from the "line" jack, even
4787  * though the NID used for this jack (0x14) can supply it.  The theory is
4788  * that perhaps Acer have included blocking capacitors between the ALC260
4789  * and the output jack.  If this turns out to be the case for all such
4790  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4791  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4792  *
4793  * The C20x Tablet series have a mono internal speaker which is controlled
4794  * via the chip's Mono sum widget and pin complex, so include the necessary
4795  * controls for such models.  On models without a "mono speaker" the control
4796  * won't do anything.
4797  */
4798 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4799         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4800         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4801         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4802         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4803                               HDA_OUTPUT),
4804         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4805                            HDA_INPUT),
4806         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4807         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4808         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4809         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4810         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4811         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4812         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4813         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4814         { } /* end */
4815 };
4816
4817 /* Maxdata Favorit 100XS: one output and one input (0x12) jack
4818  */
4819 static struct snd_kcontrol_new alc260_favorit100_mixer[] = {
4820         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4821         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4822         ALC_PIN_MODE("Output Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4823         HDA_CODEC_VOLUME("Line/Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4824         HDA_CODEC_MUTE("Line/Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4825         ALC_PIN_MODE("Line/Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4826         { } /* end */
4827 };
4828
4829 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4830  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4831  */
4832 static struct snd_kcontrol_new alc260_will_mixer[] = {
4833         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4834         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4835         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4836         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4837         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4838         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4839         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4840         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4841         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4842         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4843         { } /* end */
4844 };
4845
4846 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4847  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4848  */
4849 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4850         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4851         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4852         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4853         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4854         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4855         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4856         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4857         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4858         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4859         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4860         { } /* end */
4861 };
4862
4863 /*
4864  * initialization verbs
4865  */
4866 static struct hda_verb alc260_init_verbs[] = {
4867         /* Line In pin widget for input */
4868         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4869         /* CD pin widget for input */
4870         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4871         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4872         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4873         /* Mic2 (front panel) pin widget for input and vref at 80% */
4874         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4875         /* LINE-2 is used for line-out in rear */
4876         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4877         /* select line-out */
4878         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4879         /* LINE-OUT pin */
4880         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4881         /* enable HP */
4882         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4883         /* enable Mono */
4884         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4885         /* mute capture amp left and right */
4886         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4887         /* set connection select to line in (default select for this ADC) */
4888         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4889         /* mute capture amp left and right */
4890         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4891         /* set connection select to line in (default select for this ADC) */
4892         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4893         /* set vol=0 Line-Out mixer amp left and right */
4894         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4895         /* unmute pin widget amp left and right (no gain on this amp) */
4896         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4897         /* set vol=0 HP mixer amp left and right */
4898         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4899         /* unmute pin widget amp left and right (no gain on this amp) */
4900         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4901         /* set vol=0 Mono mixer amp left and right */
4902         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4903         /* unmute pin widget amp left and right (no gain on this amp) */
4904         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4905         /* unmute LINE-2 out pin */
4906         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4907         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4908          * Line In 2 = 0x03
4909          */
4910         /* mute analog inputs */
4911         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4912         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4913         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4914         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4915         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4916         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4917         /* mute Front out path */
4918         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4919         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4920         /* mute Headphone out path */
4921         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4922         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4923         /* mute Mono out path */
4924         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4925         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4926         { }
4927 };
4928
4929 #if 0 /* should be identical with alc260_init_verbs? */
4930 static struct hda_verb alc260_hp_init_verbs[] = {
4931         /* Headphone and output */
4932         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4933         /* mono output */
4934         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4935         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4936         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4937         /* Mic2 (front panel) pin widget for input and vref at 80% */
4938         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4939         /* Line In pin widget for input */
4940         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4941         /* Line-2 pin widget for output */
4942         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4943         /* CD pin widget for input */
4944         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4945         /* unmute amp left and right */
4946         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4947         /* set connection select to line in (default select for this ADC) */
4948         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4949         /* unmute Line-Out mixer amp left and right (volume = 0) */
4950         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4951         /* mute pin widget amp left and right (no gain on this amp) */
4952         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4953         /* unmute HP mixer amp left and right (volume = 0) */
4954         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4955         /* mute pin widget amp left and right (no gain on this amp) */
4956         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4957         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4958          * Line In 2 = 0x03
4959          */
4960         /* mute analog inputs */
4961         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4962         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4963         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4964         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4965         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4966         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4967         /* Unmute Front out path */
4968         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4969         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4970         /* Unmute Headphone out path */
4971         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4972         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4973         /* Unmute Mono out path */
4974         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4975         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4976         { }
4977 };
4978 #endif
4979
4980 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4981         /* Line out and output */
4982         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4983         /* mono output */
4984         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4985         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4986         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4987         /* Mic2 (front panel) pin widget for input and vref at 80% */
4988         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4989         /* Line In pin widget for input */
4990         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4991         /* Headphone pin widget for output */
4992         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4993         /* CD pin widget for input */
4994         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4995         /* unmute amp left and right */
4996         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4997         /* set connection select to line in (default select for this ADC) */
4998         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4999         /* unmute Line-Out mixer amp left and right (volume = 0) */
5000         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5001         /* mute pin widget amp left and right (no gain on this amp) */
5002         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5003         /* unmute HP mixer amp left and right (volume = 0) */
5004         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5005         /* mute pin widget amp left and right (no gain on this amp) */
5006         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5007         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5008          * Line In 2 = 0x03
5009          */
5010         /* mute analog inputs */
5011         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5012         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5013         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5014         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5015         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5016         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5017         /* Unmute Front out path */
5018         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5019         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5020         /* Unmute Headphone out path */
5021         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5022         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5023         /* Unmute Mono out path */
5024         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5025         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5026         { }
5027 };
5028
5029 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
5030  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
5031  * audio = 0x16, internal speaker = 0x10.
5032  */
5033 static struct hda_verb alc260_fujitsu_init_verbs[] = {
5034         /* Disable all GPIOs */
5035         {0x01, AC_VERB_SET_GPIO_MASK, 0},
5036         /* Internal speaker is connected to headphone pin */
5037         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5038         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
5039         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5040         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
5041         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5042         /* Ensure all other unused pins are disabled and muted. */
5043         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5044         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5045         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5046         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5047         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5048         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5049         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5050         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5051
5052         /* Disable digital (SPDIF) pins */
5053         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5054         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5055
5056         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
5057          * when acting as an output.
5058          */
5059         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5060
5061         /* Start with output sum widgets muted and their output gains at min */
5062         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5063         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5064         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5065         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5066         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5067         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5068         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5069         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5070         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5071
5072         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
5073         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5074         /* Unmute Line1 pin widget output buffer since it starts as an output.
5075          * If the pin mode is changed by the user the pin mode control will
5076          * take care of enabling the pin's input/output buffers as needed.
5077          * Therefore there's no need to enable the input buffer at this
5078          * stage.
5079          */
5080         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5081         /* Unmute input buffer of pin widget used for Line-in (no equiv
5082          * mixer ctrl)
5083          */
5084         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5085
5086         /* Mute capture amp left and right */
5087         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5088         /* Set ADC connection select to match default mixer setting - line
5089          * in (on mic1 pin)
5090          */
5091         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5092
5093         /* Do the same for the second ADC: mute capture input amp and
5094          * set ADC connection to line in (on mic1 pin)
5095          */
5096         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5097         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5098
5099         /* Mute all inputs to mixer widget (even unconnected ones) */
5100         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5101         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5102         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5103         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5104         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5105         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5106         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5107         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5108
5109         { }
5110 };
5111
5112 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
5113  * similar laptops (adapted from Fujitsu init verbs).
5114  */
5115 static struct hda_verb alc260_acer_init_verbs[] = {
5116         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
5117          * the headphone jack.  Turn this on and rely on the standard mute
5118          * methods whenever the user wants to turn these outputs off.
5119          */
5120         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5121         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5122         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5123         /* Internal speaker/Headphone jack is connected to Line-out pin */
5124         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5125         /* Internal microphone/Mic jack is connected to Mic1 pin */
5126         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5127         /* Line In jack is connected to Line1 pin */
5128         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5129         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
5130         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5131         /* Ensure all other unused pins are disabled and muted. */
5132         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5133         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5134         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5135         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5136         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5137         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5138         /* Disable digital (SPDIF) pins */
5139         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5140         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5141
5142         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5143          * bus when acting as outputs.
5144          */
5145         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5146         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5147
5148         /* Start with output sum widgets muted and their output gains at min */
5149         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5150         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5151         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5152         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5153         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5154         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5155         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5156         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5157         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5158
5159         /* Unmute Line-out pin widget amp left and right
5160          * (no equiv mixer ctrl)
5161          */
5162         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5163         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
5164         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5165         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5166          * inputs. If the pin mode is changed by the user the pin mode control
5167          * will take care of enabling the pin's input/output buffers as needed.
5168          * Therefore there's no need to enable the input buffer at this
5169          * stage.
5170          */
5171         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5172         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5173
5174         /* Mute capture amp left and right */
5175         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5176         /* Set ADC connection select to match default mixer setting - mic
5177          * (on mic1 pin)
5178          */
5179         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5180
5181         /* Do similar with the second ADC: mute capture input amp and
5182          * set ADC connection to mic to match ALSA's default state.
5183          */
5184         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5185         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5186
5187         /* Mute all inputs to mixer widget (even unconnected ones) */
5188         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5189         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5190         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5191         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5192         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5193         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5194         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5195         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5196
5197         { }
5198 };
5199
5200 /* Initialisation sequence for Maxdata Favorit 100XS
5201  * (adapted from Acer init verbs).
5202  */
5203 static struct hda_verb alc260_favorit100_init_verbs[] = {
5204         /* GPIO 0 enables the output jack.
5205          * Turn this on and rely on the standard mute
5206          * methods whenever the user wants to turn these outputs off.
5207          */
5208         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5209         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5210         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5211         /* Line/Mic input jack is connected to Mic1 pin */
5212         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5213         /* Ensure all other unused pins are disabled and muted. */
5214         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5215         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5216         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5217         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5218         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5219         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5220         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5221         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5222         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5223         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5224         /* Disable digital (SPDIF) pins */
5225         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5226         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5227
5228         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5229          * bus when acting as outputs.
5230          */
5231         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5232         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5233
5234         /* Start with output sum widgets muted and their output gains at min */
5235         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5236         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5237         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5238         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5239         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5240         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5241         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5242         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5243         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5244
5245         /* Unmute Line-out pin widget amp left and right
5246          * (no equiv mixer ctrl)
5247          */
5248         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5249         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5250          * inputs. If the pin mode is changed by the user the pin mode control
5251          * will take care of enabling the pin's input/output buffers as needed.
5252          * Therefore there's no need to enable the input buffer at this
5253          * stage.
5254          */
5255         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5256
5257         /* Mute capture amp left and right */
5258         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5259         /* Set ADC connection select to match default mixer setting - mic
5260          * (on mic1 pin)
5261          */
5262         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5263
5264         /* Do similar with the second ADC: mute capture input amp and
5265          * set ADC connection to mic to match ALSA's default state.
5266          */
5267         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5268         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5269
5270         /* Mute all inputs to mixer widget (even unconnected ones) */
5271         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5272         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5273         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5274         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5275         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5276         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5277         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5278         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5279
5280         { }
5281 };
5282
5283 static struct hda_verb alc260_will_verbs[] = {
5284         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5285         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
5286         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
5287         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5288         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5289         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
5290         {}
5291 };
5292
5293 static struct hda_verb alc260_replacer_672v_verbs[] = {
5294         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5295         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5296         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
5297
5298         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5299         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5300         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5301
5302         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5303         {}
5304 };
5305
5306 /* toggle speaker-output according to the hp-jack state */
5307 static void alc260_replacer_672v_automute(struct hda_codec *codec)
5308 {
5309         unsigned int present;
5310
5311         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5312         present = snd_hda_codec_read(codec, 0x0f, 0,
5313                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5314         if (present) {
5315                 snd_hda_codec_write_cache(codec, 0x01, 0,
5316                                           AC_VERB_SET_GPIO_DATA, 1);
5317                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5318                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5319                                           PIN_HP);
5320         } else {
5321                 snd_hda_codec_write_cache(codec, 0x01, 0,
5322                                           AC_VERB_SET_GPIO_DATA, 0);
5323                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5324                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5325                                           PIN_OUT);
5326         }
5327 }
5328
5329 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
5330                                        unsigned int res)
5331 {
5332         if ((res >> 26) == ALC880_HP_EVENT)
5333                 alc260_replacer_672v_automute(codec);
5334 }
5335
5336 static struct hda_verb alc260_hp_dc7600_verbs[] = {
5337         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
5338         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5339         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5340         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5341         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5342         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5343         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5344         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5345         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5346         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5347         {}
5348 };
5349
5350 /* Test configuration for debugging, modelled after the ALC880 test
5351  * configuration.
5352  */
5353 #ifdef CONFIG_SND_DEBUG
5354 static hda_nid_t alc260_test_dac_nids[1] = {
5355         0x02,
5356 };
5357 static hda_nid_t alc260_test_adc_nids[2] = {
5358         0x04, 0x05,
5359 };
5360 /* For testing the ALC260, each input MUX needs its own definition since
5361  * the signal assignments are different.  This assumes that the first ADC
5362  * is NID 0x04.
5363  */
5364 static struct hda_input_mux alc260_test_capture_sources[2] = {
5365         {
5366                 .num_items = 7,
5367                 .items = {
5368                         { "MIC1 pin", 0x0 },
5369                         { "MIC2 pin", 0x1 },
5370                         { "LINE1 pin", 0x2 },
5371                         { "LINE2 pin", 0x3 },
5372                         { "CD pin", 0x4 },
5373                         { "LINE-OUT pin", 0x5 },
5374                         { "HP-OUT pin", 0x6 },
5375                 },
5376         },
5377         {
5378                 .num_items = 8,
5379                 .items = {
5380                         { "MIC1 pin", 0x0 },
5381                         { "MIC2 pin", 0x1 },
5382                         { "LINE1 pin", 0x2 },
5383                         { "LINE2 pin", 0x3 },
5384                         { "CD pin", 0x4 },
5385                         { "Mixer", 0x5 },
5386                         { "LINE-OUT pin", 0x6 },
5387                         { "HP-OUT pin", 0x7 },
5388                 },
5389         },
5390 };
5391 static struct snd_kcontrol_new alc260_test_mixer[] = {
5392         /* Output driver widgets */
5393         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5394         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5395         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5396         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
5397         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5398         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
5399
5400         /* Modes for retasking pin widgets
5401          * Note: the ALC260 doesn't seem to act on requests to enable mic
5402          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
5403          * mention this restriction.  At this stage it's not clear whether
5404          * this behaviour is intentional or is a hardware bug in chip
5405          * revisions available at least up until early 2006.  Therefore for
5406          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
5407          * choices, but if it turns out that the lack of mic bias for these
5408          * NIDs is intentional we could change their modes from
5409          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5410          */
5411         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
5412         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
5413         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
5414         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5415         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5416         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5417
5418         /* Loopback mixer controls */
5419         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5420         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5421         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5422         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5423         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5424         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5425         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5426         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5427         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5428         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5429         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5430         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5431         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5432         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5433
5434         /* Controls for GPIO pins, assuming they are configured as outputs */
5435         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5436         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5437         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5438         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5439
5440         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5441          * is ambigious as to which NID is which; testing on laptops which
5442          * make this output available should provide clarification.
5443          */
5444         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5445         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5446
5447         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5448          * this output to turn on an external amplifier.
5449          */
5450         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5451         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5452
5453         { } /* end */
5454 };
5455 static struct hda_verb alc260_test_init_verbs[] = {
5456         /* Enable all GPIOs as outputs with an initial value of 0 */
5457         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5458         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5459         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5460
5461         /* Enable retasking pins as output, initially without power amp */
5462         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5463         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5464         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5465         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5466         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5467         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5468
5469         /* Disable digital (SPDIF) pins initially, but users can enable
5470          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5471          * payload also sets the generation to 0, output to be in "consumer"
5472          * PCM format, copyright asserted, no pre-emphasis and no validity
5473          * control.
5474          */
5475         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5476         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5477
5478         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5479          * OUT1 sum bus when acting as an output.
5480          */
5481         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5482         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5483         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5484         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5485
5486         /* Start with output sum widgets muted and their output gains at min */
5487         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5488         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5489         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5490         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5491         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5492         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5493         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5494         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5495         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5496
5497         /* Unmute retasking pin widget output buffers since the default
5498          * state appears to be output.  As the pin mode is changed by the
5499          * user the pin mode control will take care of enabling the pin's
5500          * input/output buffers as needed.
5501          */
5502         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5503         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5504         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5505         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5506         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5507         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5508         /* Also unmute the mono-out pin widget */
5509         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5510
5511         /* Mute capture amp left and right */
5512         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5513         /* Set ADC connection select to match default mixer setting (mic1
5514          * pin)
5515          */
5516         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5517
5518         /* Do the same for the second ADC: mute capture input amp and
5519          * set ADC connection to mic1 pin
5520          */
5521         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5522         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5523
5524         /* Mute all inputs to mixer widget (even unconnected ones) */
5525         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5526         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5527         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5528         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5529         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5530         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5531         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5532         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5533
5534         { }
5535 };
5536 #endif
5537
5538 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5539 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5540
5541 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5542 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5543
5544 /*
5545  * for BIOS auto-configuration
5546  */
5547
5548 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5549                                         const char *pfx, int *vol_bits)
5550 {
5551         hda_nid_t nid_vol;
5552         unsigned long vol_val, sw_val;
5553         char name[32];
5554         int err;
5555
5556         if (nid >= 0x0f && nid < 0x11) {
5557                 nid_vol = nid - 0x7;
5558                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5559                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5560         } else if (nid == 0x11) {
5561                 nid_vol = nid - 0x7;
5562                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
5563                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
5564         } else if (nid >= 0x12 && nid <= 0x15) {
5565                 nid_vol = 0x08;
5566                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5567                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5568         } else
5569                 return 0; /* N/A */
5570
5571         if (!(*vol_bits & (1 << nid_vol))) {
5572                 /* first control for the volume widget */
5573                 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
5574                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
5575                 if (err < 0)
5576                         return err;
5577                 *vol_bits |= (1 << nid_vol);
5578         }
5579         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
5580         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
5581         if (err < 0)
5582                 return err;
5583         return 1;
5584 }
5585
5586 /* add playback controls from the parsed DAC table */
5587 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5588                                              const struct auto_pin_cfg *cfg)
5589 {
5590         hda_nid_t nid;
5591         int err;
5592         int vols = 0;
5593
5594         spec->multiout.num_dacs = 1;
5595         spec->multiout.dac_nids = spec->private_dac_nids;
5596         spec->multiout.dac_nids[0] = 0x02;
5597
5598         nid = cfg->line_out_pins[0];
5599         if (nid) {
5600                 err = alc260_add_playback_controls(spec, nid, "Front", &vols);
5601                 if (err < 0)
5602                         return err;
5603         }
5604
5605         nid = cfg->speaker_pins[0];
5606         if (nid) {
5607                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
5608                 if (err < 0)
5609                         return err;
5610         }
5611
5612         nid = cfg->hp_pins[0];
5613         if (nid) {
5614                 err = alc260_add_playback_controls(spec, nid, "Headphone",
5615                                                    &vols);
5616                 if (err < 0)
5617                         return err;
5618         }
5619         return 0;
5620 }
5621
5622 /* create playback/capture controls for input pins */
5623 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
5624                                                 const struct auto_pin_cfg *cfg)
5625 {
5626         struct hda_input_mux *imux = &spec->private_imux[0];
5627         int i, err, idx;
5628
5629         for (i = 0; i < AUTO_PIN_LAST; i++) {
5630                 if (cfg->input_pins[i] >= 0x12) {
5631                         idx = cfg->input_pins[i] - 0x12;
5632                         err = new_analog_input(spec, cfg->input_pins[i],
5633                                                auto_pin_cfg_labels[i], idx,
5634                                                0x07);
5635                         if (err < 0)
5636                                 return err;
5637                         imux->items[imux->num_items].label =
5638                                 auto_pin_cfg_labels[i];
5639                         imux->items[imux->num_items].index = idx;
5640                         imux->num_items++;
5641                 }
5642                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
5643                         idx = cfg->input_pins[i] - 0x09;
5644                         err = new_analog_input(spec, cfg->input_pins[i],
5645                                                auto_pin_cfg_labels[i], idx,
5646                                                0x07);
5647                         if (err < 0)
5648                                 return err;
5649                         imux->items[imux->num_items].label =
5650                                 auto_pin_cfg_labels[i];
5651                         imux->items[imux->num_items].index = idx;
5652                         imux->num_items++;
5653                 }
5654         }
5655         return 0;
5656 }
5657
5658 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
5659                                               hda_nid_t nid, int pin_type,
5660                                               int sel_idx)
5661 {
5662         alc_set_pin_output(codec, nid, pin_type);
5663         /* need the manual connection? */
5664         if (nid >= 0x12) {
5665                 int idx = nid - 0x12;
5666                 snd_hda_codec_write(codec, idx + 0x0b, 0,
5667                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
5668         }
5669 }
5670
5671 static void alc260_auto_init_multi_out(struct hda_codec *codec)
5672 {
5673         struct alc_spec *spec = codec->spec;
5674         hda_nid_t nid;
5675
5676         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
5677         nid = spec->autocfg.line_out_pins[0];
5678         if (nid) {
5679                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5680                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5681         }
5682
5683         nid = spec->autocfg.speaker_pins[0];
5684         if (nid)
5685                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5686
5687         nid = spec->autocfg.hp_pins[0];
5688         if (nid)
5689                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5690 }
5691
5692 #define ALC260_PIN_CD_NID               0x16
5693 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5694 {
5695         struct alc_spec *spec = codec->spec;
5696         int i;
5697
5698         for (i = 0; i < AUTO_PIN_LAST; i++) {
5699                 hda_nid_t nid = spec->autocfg.input_pins[i];
5700                 if (nid >= 0x12) {
5701                         alc_set_input_pin(codec, nid, i);
5702                         if (nid != ALC260_PIN_CD_NID &&
5703                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
5704                                 snd_hda_codec_write(codec, nid, 0,
5705                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5706                                                     AMP_OUT_MUTE);
5707                 }
5708         }
5709 }
5710
5711 /*
5712  * generic initialization of ADC, input mixers and output mixers
5713  */
5714 static struct hda_verb alc260_volume_init_verbs[] = {
5715         /*
5716          * Unmute ADC0-1 and set the default input to mic-in
5717          */
5718         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5719         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5720         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5721         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5722
5723         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5724          * mixer widget
5725          * Note: PASD motherboards uses the Line In 2 as the input for
5726          * front panel mic (mic 2)
5727          */
5728         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5729         /* mute analog inputs */
5730         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5731         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5732         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5733         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5734         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5735
5736         /*
5737          * Set up output mixers (0x08 - 0x0a)
5738          */
5739         /* set vol=0 to output mixers */
5740         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5741         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5742         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5743         /* set up input amps for analog loopback */
5744         /* Amp Indices: DAC = 0, mixer = 1 */
5745         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5746         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5747         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5748         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5749         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5750         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5751
5752         { }
5753 };
5754
5755 static int alc260_parse_auto_config(struct hda_codec *codec)
5756 {
5757         struct alc_spec *spec = codec->spec;
5758         int err;
5759         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5760
5761         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5762                                            alc260_ignore);
5763         if (err < 0)
5764                 return err;
5765         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5766         if (err < 0)
5767                 return err;
5768         if (!spec->kctls.list)
5769                 return 0; /* can't find valid BIOS pin config */
5770         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5771         if (err < 0)
5772                 return err;
5773
5774         spec->multiout.max_channels = 2;
5775
5776         if (spec->autocfg.dig_outs)
5777                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5778         if (spec->kctls.list)
5779                 add_mixer(spec, spec->kctls.list);
5780
5781         add_verb(spec, alc260_volume_init_verbs);
5782
5783         spec->num_mux_defs = 1;
5784         spec->input_mux = &spec->private_imux[0];
5785
5786         return 1;
5787 }
5788
5789 /* additional initialization for auto-configuration model */
5790 static void alc260_auto_init(struct hda_codec *codec)
5791 {
5792         struct alc_spec *spec = codec->spec;
5793         alc260_auto_init_multi_out(codec);
5794         alc260_auto_init_analog_input(codec);
5795         if (spec->unsol_event)
5796                 alc_inithook(codec);
5797 }
5798
5799 #ifdef CONFIG_SND_HDA_POWER_SAVE
5800 static struct hda_amp_list alc260_loopbacks[] = {
5801         { 0x07, HDA_INPUT, 0 },
5802         { 0x07, HDA_INPUT, 1 },
5803         { 0x07, HDA_INPUT, 2 },
5804         { 0x07, HDA_INPUT, 3 },
5805         { 0x07, HDA_INPUT, 4 },
5806         { } /* end */
5807 };
5808 #endif
5809
5810 /*
5811  * ALC260 configurations
5812  */
5813 static const char *alc260_models[ALC260_MODEL_LAST] = {
5814         [ALC260_BASIC]          = "basic",
5815         [ALC260_HP]             = "hp",
5816         [ALC260_HP_3013]        = "hp-3013",
5817         [ALC260_HP_DC7600]      = "hp-dc7600",
5818         [ALC260_FUJITSU_S702X]  = "fujitsu",
5819         [ALC260_ACER]           = "acer",
5820         [ALC260_WILL]           = "will",
5821         [ALC260_REPLACER_672V]  = "replacer",
5822         [ALC260_FAVORIT100]     = "favorit100",
5823 #ifdef CONFIG_SND_DEBUG
5824         [ALC260_TEST]           = "test",
5825 #endif
5826         [ALC260_AUTO]           = "auto",
5827 };
5828
5829 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5830         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5831         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5832         SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FAVORIT100),
5833         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5834         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5835         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5836         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
5837         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
5838         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5839         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5840         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5841         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5842         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5843         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5844         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5845         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5846         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5847         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5848         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5849         {}
5850 };
5851
5852 static struct alc_config_preset alc260_presets[] = {
5853         [ALC260_BASIC] = {
5854                 .mixers = { alc260_base_output_mixer,
5855                             alc260_input_mixer },
5856                 .init_verbs = { alc260_init_verbs },
5857                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5858                 .dac_nids = alc260_dac_nids,
5859                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5860                 .adc_nids = alc260_adc_nids,
5861                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5862                 .channel_mode = alc260_modes,
5863                 .input_mux = &alc260_capture_source,
5864         },
5865         [ALC260_HP] = {
5866                 .mixers = { alc260_hp_output_mixer,
5867                             alc260_input_mixer },
5868                 .init_verbs = { alc260_init_verbs,
5869                                 alc260_hp_unsol_verbs },
5870                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5871                 .dac_nids = alc260_dac_nids,
5872                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5873                 .adc_nids = alc260_adc_nids_alt,
5874                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5875                 .channel_mode = alc260_modes,
5876                 .input_mux = &alc260_capture_source,
5877                 .unsol_event = alc260_hp_unsol_event,
5878                 .init_hook = alc260_hp_automute,
5879         },
5880         [ALC260_HP_DC7600] = {
5881                 .mixers = { alc260_hp_dc7600_mixer,
5882                             alc260_input_mixer },
5883                 .init_verbs = { alc260_init_verbs,
5884                                 alc260_hp_dc7600_verbs },
5885                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5886                 .dac_nids = alc260_dac_nids,
5887                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5888                 .adc_nids = alc260_adc_nids_alt,
5889                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5890                 .channel_mode = alc260_modes,
5891                 .input_mux = &alc260_capture_source,
5892                 .unsol_event = alc260_hp_3012_unsol_event,
5893                 .init_hook = alc260_hp_3012_automute,
5894         },
5895         [ALC260_HP_3013] = {
5896                 .mixers = { alc260_hp_3013_mixer,
5897                             alc260_input_mixer },
5898                 .init_verbs = { alc260_hp_3013_init_verbs,
5899                                 alc260_hp_3013_unsol_verbs },
5900                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5901                 .dac_nids = alc260_dac_nids,
5902                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5903                 .adc_nids = alc260_adc_nids_alt,
5904                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5905                 .channel_mode = alc260_modes,
5906                 .input_mux = &alc260_capture_source,
5907                 .unsol_event = alc260_hp_3013_unsol_event,
5908                 .init_hook = alc260_hp_3013_automute,
5909         },
5910         [ALC260_FUJITSU_S702X] = {
5911                 .mixers = { alc260_fujitsu_mixer },
5912                 .init_verbs = { alc260_fujitsu_init_verbs },
5913                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5914                 .dac_nids = alc260_dac_nids,
5915                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5916                 .adc_nids = alc260_dual_adc_nids,
5917                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5918                 .channel_mode = alc260_modes,
5919                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5920                 .input_mux = alc260_fujitsu_capture_sources,
5921         },
5922         [ALC260_ACER] = {
5923                 .mixers = { alc260_acer_mixer },
5924                 .init_verbs = { alc260_acer_init_verbs },
5925                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5926                 .dac_nids = alc260_dac_nids,
5927                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5928                 .adc_nids = alc260_dual_adc_nids,
5929                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5930                 .channel_mode = alc260_modes,
5931                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5932                 .input_mux = alc260_acer_capture_sources,
5933         },
5934         [ALC260_FAVORIT100] = {
5935                 .mixers = { alc260_favorit100_mixer },
5936                 .init_verbs = { alc260_favorit100_init_verbs },
5937                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5938                 .dac_nids = alc260_dac_nids,
5939                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5940                 .adc_nids = alc260_dual_adc_nids,
5941                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5942                 .channel_mode = alc260_modes,
5943                 .num_mux_defs = ARRAY_SIZE(alc260_favorit100_capture_sources),
5944                 .input_mux = alc260_favorit100_capture_sources,
5945         },
5946         [ALC260_WILL] = {
5947                 .mixers = { alc260_will_mixer },
5948                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5949                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5950                 .dac_nids = alc260_dac_nids,
5951                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5952                 .adc_nids = alc260_adc_nids,
5953                 .dig_out_nid = ALC260_DIGOUT_NID,
5954                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5955                 .channel_mode = alc260_modes,
5956                 .input_mux = &alc260_capture_source,
5957         },
5958         [ALC260_REPLACER_672V] = {
5959                 .mixers = { alc260_replacer_672v_mixer },
5960                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5961                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5962                 .dac_nids = alc260_dac_nids,
5963                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5964                 .adc_nids = alc260_adc_nids,
5965                 .dig_out_nid = ALC260_DIGOUT_NID,
5966                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5967                 .channel_mode = alc260_modes,
5968                 .input_mux = &alc260_capture_source,
5969                 .unsol_event = alc260_replacer_672v_unsol_event,
5970                 .init_hook = alc260_replacer_672v_automute,
5971         },
5972 #ifdef CONFIG_SND_DEBUG
5973         [ALC260_TEST] = {
5974                 .mixers = { alc260_test_mixer },
5975                 .init_verbs = { alc260_test_init_verbs },
5976                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5977                 .dac_nids = alc260_test_dac_nids,
5978                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5979                 .adc_nids = alc260_test_adc_nids,
5980                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5981                 .channel_mode = alc260_modes,
5982                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5983                 .input_mux = alc260_test_capture_sources,
5984         },
5985 #endif
5986 };
5987
5988 static int patch_alc260(struct hda_codec *codec)
5989 {
5990         struct alc_spec *spec;
5991         int err, board_config;
5992
5993         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5994         if (spec == NULL)
5995                 return -ENOMEM;
5996
5997         codec->spec = spec;
5998
5999         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
6000                                                   alc260_models,
6001                                                   alc260_cfg_tbl);
6002         if (board_config < 0) {
6003                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
6004                            "trying auto-probe from BIOS...\n");
6005                 board_config = ALC260_AUTO;
6006         }
6007
6008         if (board_config == ALC260_AUTO) {
6009                 /* automatic parse from the BIOS config */
6010                 err = alc260_parse_auto_config(codec);
6011                 if (err < 0) {
6012                         alc_free(codec);
6013                         return err;
6014                 } else if (!err) {
6015                         printk(KERN_INFO
6016                                "hda_codec: Cannot set up configuration "
6017                                "from BIOS.  Using base mode...\n");
6018                         board_config = ALC260_BASIC;
6019                 }
6020         }
6021
6022         err = snd_hda_attach_beep_device(codec, 0x1);
6023         if (err < 0) {
6024                 alc_free(codec);
6025                 return err;
6026         }
6027
6028         if (board_config != ALC260_AUTO)
6029                 setup_preset(spec, &alc260_presets[board_config]);
6030
6031         spec->stream_name_analog = "ALC260 Analog";
6032         spec->stream_analog_playback = &alc260_pcm_analog_playback;
6033         spec->stream_analog_capture = &alc260_pcm_analog_capture;
6034
6035         spec->stream_name_digital = "ALC260 Digital";
6036         spec->stream_digital_playback = &alc260_pcm_digital_playback;
6037         spec->stream_digital_capture = &alc260_pcm_digital_capture;
6038
6039         if (!spec->adc_nids && spec->input_mux) {
6040                 /* check whether NID 0x04 is valid */
6041                 unsigned int wcap = get_wcaps(codec, 0x04);
6042                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
6043                 /* get type */
6044                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
6045                         spec->adc_nids = alc260_adc_nids_alt;
6046                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
6047                 } else {
6048                         spec->adc_nids = alc260_adc_nids;
6049                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
6050                 }
6051         }
6052         set_capture_mixer(spec);
6053         set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
6054
6055         spec->vmaster_nid = 0x08;
6056
6057         codec->patch_ops = alc_patch_ops;
6058         if (board_config == ALC260_AUTO)
6059                 spec->init_hook = alc260_auto_init;
6060 #ifdef CONFIG_SND_HDA_POWER_SAVE
6061         if (!spec->loopback.amplist)
6062                 spec->loopback.amplist = alc260_loopbacks;
6063 #endif
6064         codec->proc_widget_hook = print_realtek_coef;
6065
6066         return 0;
6067 }
6068
6069
6070 /*
6071  * ALC882 support
6072  *
6073  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
6074  * configuration.  Each pin widget can choose any input DACs and a mixer.
6075  * Each ADC is connected from a mixer of all inputs.  This makes possible
6076  * 6-channel independent captures.
6077  *
6078  * In addition, an independent DAC for the multi-playback (not used in this
6079  * driver yet).
6080  */
6081 #define ALC882_DIGOUT_NID       0x06
6082 #define ALC882_DIGIN_NID        0x0a
6083
6084 static struct hda_channel_mode alc882_ch_modes[1] = {
6085         { 8, NULL }
6086 };
6087
6088 static hda_nid_t alc882_dac_nids[4] = {
6089         /* front, rear, clfe, rear_surr */
6090         0x02, 0x03, 0x04, 0x05
6091 };
6092
6093 /* identical with ALC880 */
6094 #define alc882_adc_nids         alc880_adc_nids
6095 #define alc882_adc_nids_alt     alc880_adc_nids_alt
6096
6097 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
6098 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
6099
6100 /* input MUX */
6101 /* FIXME: should be a matrix-type input source selection */
6102
6103 static struct hda_input_mux alc882_capture_source = {
6104         .num_items = 4,
6105         .items = {
6106                 { "Mic", 0x0 },
6107                 { "Front Mic", 0x1 },
6108                 { "Line", 0x2 },
6109                 { "CD", 0x4 },
6110         },
6111 };
6112 /*
6113  * 2ch mode
6114  */
6115 static struct hda_verb alc882_3ST_ch2_init[] = {
6116         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6117         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6118         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6119         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6120         { } /* end */
6121 };
6122
6123 /*
6124  * 6ch mode
6125  */
6126 static struct hda_verb alc882_3ST_ch6_init[] = {
6127         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6128         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6129         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6130         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6131         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6132         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6133         { } /* end */
6134 };
6135
6136 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
6137         { 2, alc882_3ST_ch2_init },
6138         { 6, alc882_3ST_ch6_init },
6139 };
6140
6141 /*
6142  * 6ch mode
6143  */
6144 static struct hda_verb alc882_sixstack_ch6_init[] = {
6145         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6146         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6147         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6148         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6149         { } /* end */
6150 };
6151
6152 /*
6153  * 8ch mode
6154  */
6155 static struct hda_verb alc882_sixstack_ch8_init[] = {
6156         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6157         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6158         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6159         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6160         { } /* end */
6161 };
6162
6163 static struct hda_channel_mode alc882_sixstack_modes[2] = {
6164         { 6, alc882_sixstack_ch6_init },
6165         { 8, alc882_sixstack_ch8_init },
6166 };
6167
6168 /*
6169  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
6170  */
6171
6172 /*
6173  * 2ch mode
6174  */
6175 static struct hda_verb alc885_mbp_ch2_init[] = {
6176         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6177         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6178         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6179         { } /* end */
6180 };
6181
6182 /*
6183  * 6ch mode
6184  */
6185 static struct hda_verb alc885_mbp_ch6_init[] = {
6186         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6187         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6188         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6189         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6190         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6191         { } /* end */
6192 };
6193
6194 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
6195         { 2, alc885_mbp_ch2_init },
6196         { 6, alc885_mbp_ch6_init },
6197 };
6198
6199
6200 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6201  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6202  */
6203 static struct snd_kcontrol_new alc882_base_mixer[] = {
6204         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6205         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6206         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6207         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6208         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6209         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6210         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6211         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6212         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6213         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6214         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6215         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6216         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6217         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6218         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6219         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6220         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6221         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6222         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6223         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6224         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6225         { } /* end */
6226 };
6227
6228 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
6229         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6230         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
6231         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
6232         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
6233         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6234         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6235         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
6236         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
6237         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
6238         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
6239         { } /* end */
6240 };
6241 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
6242         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6243         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6244         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6245         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6246         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6247         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6248         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6249         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6250         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6251         { } /* end */
6252 };
6253
6254 static struct snd_kcontrol_new alc882_targa_mixer[] = {
6255         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6256         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6257         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6258         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6259         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6260         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6261         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6262         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6263         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6264         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6265         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6266         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6267         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6268         { } /* end */
6269 };
6270
6271 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
6272  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
6273  */
6274 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
6275         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6276         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6277         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6278         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
6279         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6280         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6281         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6282         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6283         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
6284         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
6285         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6286         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6287         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6288         { } /* end */
6289 };
6290
6291 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
6292         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6293         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6294         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6295         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6296         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6297         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6298         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6299         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6300         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6301         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6302         { } /* end */
6303 };
6304
6305 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
6306         {
6307                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6308                 .name = "Channel Mode",
6309                 .info = alc_ch_mode_info,
6310                 .get = alc_ch_mode_get,
6311                 .put = alc_ch_mode_put,
6312         },
6313         { } /* end */
6314 };
6315
6316 static struct hda_verb alc882_init_verbs[] = {
6317         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6318         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6319         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6320         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6321         /* Rear mixer */
6322         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6323         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6324         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6325         /* CLFE mixer */
6326         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6327         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6328         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6329         /* Side mixer */
6330         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6331         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6332         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6333
6334         /* Front Pin: output 0 (0x0c) */
6335         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6336         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6337         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6338         /* Rear Pin: output 1 (0x0d) */
6339         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6340         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6341         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6342         /* CLFE Pin: output 2 (0x0e) */
6343         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6344         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6345         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
6346         /* Side Pin: output 3 (0x0f) */
6347         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6348         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6349         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
6350         /* Mic (rear) pin: input vref at 80% */
6351         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6352         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6353         /* Front Mic pin: input vref at 80% */
6354         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6355         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6356         /* Line In pin: input */
6357         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6358         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6359         /* Line-2 In: Headphone output (output 0 - 0x0c) */
6360         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6361         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6362         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6363         /* CD pin widget for input */
6364         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6365
6366         /* FIXME: use matrix-type input source selection */
6367         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6368         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6369         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6370         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6371         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6372         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6373         /* Input mixer2 */
6374         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6375         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6376         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6377         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6378         /* Input mixer3 */
6379         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6380         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6381         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6382         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6383         /* ADC1: mute amp left and right */
6384         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6385         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6386         /* ADC2: mute amp left and right */
6387         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6388         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6389         /* ADC3: mute amp left and right */
6390         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6391         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6392
6393         { }
6394 };
6395
6396 static struct hda_verb alc882_eapd_verbs[] = {
6397         /* change to EAPD mode */
6398         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6399         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
6400         { }
6401 };
6402
6403 /* Mac Pro test */
6404 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
6405         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6406         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6407         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
6408         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
6409         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
6410         /* FIXME: this looks suspicious...
6411         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
6412         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
6413         */
6414         { } /* end */
6415 };
6416
6417 static struct hda_verb alc882_macpro_init_verbs[] = {
6418         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6419         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6420         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6421         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6422         /* Front Pin: output 0 (0x0c) */
6423         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6424         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6425         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6426         /* Front Mic pin: input vref at 80% */
6427         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6428         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6429         /* Speaker:  output */
6430         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6431         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6432         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
6433         /* Headphone output (output 0 - 0x0c) */
6434         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6435         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6436         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6437
6438         /* FIXME: use matrix-type input source selection */
6439         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6440         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6441         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6442         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6443         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6444         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6445         /* Input mixer2 */
6446         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6447         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6448         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6449         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6450         /* Input mixer3 */
6451         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6452         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6453         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6454         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6455         /* ADC1: mute amp left and right */
6456         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6457         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6458         /* ADC2: mute amp left and right */
6459         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6460         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6461         /* ADC3: mute amp left and right */
6462         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6463         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6464
6465         { }
6466 };
6467
6468 /* Macbook Pro rev3 */
6469 static struct hda_verb alc885_mbp3_init_verbs[] = {
6470         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6471         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6472         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6473         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6474         /* Rear mixer */
6475         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6476         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6477         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6478         /* Front Pin: output 0 (0x0c) */
6479         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6480         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6481         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6482         /* HP Pin: output 0 (0x0d) */
6483         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
6484         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6485         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6486         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6487         /* Mic (rear) pin: input vref at 80% */
6488         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6489         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6490         /* Front Mic pin: input vref at 80% */
6491         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6492         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6493         /* Line In pin: use output 1 when in LineOut mode */
6494         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6495         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6496         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
6497
6498         /* FIXME: use matrix-type input source selection */
6499         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6500         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6501         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6502         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6503         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6504         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6505         /* Input mixer2 */
6506         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6507         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6508         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6509         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6510         /* Input mixer3 */
6511         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6512         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6513         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6514         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6515         /* ADC1: mute amp left and right */
6516         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6517         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6518         /* ADC2: mute amp left and right */
6519         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6520         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6521         /* ADC3: mute amp left and right */
6522         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6523         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6524
6525         { }
6526 };
6527
6528 /* iMac 24 mixer. */
6529 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
6530         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6531         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
6532         { } /* end */
6533 };
6534
6535 /* iMac 24 init verbs. */
6536 static struct hda_verb alc885_imac24_init_verbs[] = {
6537         /* Internal speakers: output 0 (0x0c) */
6538         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6539         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6540         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6541         /* Internal speakers: output 0 (0x0c) */
6542         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6543         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6544         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
6545         /* Headphone: output 0 (0x0c) */
6546         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6547         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6548         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6549         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6550         /* Front Mic: input vref at 80% */
6551         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6552         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6553         { }
6554 };
6555
6556 /* Toggle speaker-output according to the hp-jack state */
6557 static void alc885_imac24_automute(struct hda_codec *codec)
6558 {
6559         unsigned int present;
6560
6561         present = snd_hda_codec_read(codec, 0x14, 0,
6562                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6563         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
6564                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6565         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
6566                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6567 }
6568
6569 /* Processes unsolicited events. */
6570 static void alc885_imac24_unsol_event(struct hda_codec *codec,
6571                                       unsigned int res)
6572 {
6573         /* Headphone insertion or removal. */
6574         if ((res >> 26) == ALC880_HP_EVENT)
6575                 alc885_imac24_automute(codec);
6576 }
6577
6578 static void alc885_mbp3_automute(struct hda_codec *codec)
6579 {
6580         unsigned int present;
6581
6582         present = snd_hda_codec_read(codec, 0x15, 0,
6583                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6584         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
6585                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6586         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6587                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
6588
6589 }
6590 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
6591                                     unsigned int res)
6592 {
6593         /* Headphone insertion or removal. */
6594         if ((res >> 26) == ALC880_HP_EVENT)
6595                 alc885_mbp3_automute(codec);
6596 }
6597
6598
6599 static struct hda_verb alc882_targa_verbs[] = {
6600         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6601         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6602
6603         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6604         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6605
6606         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6607         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6608         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6609
6610         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6611         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6612         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6613         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6614         { } /* end */
6615 };
6616
6617 /* toggle speaker-output according to the hp-jack state */
6618 static void alc882_targa_automute(struct hda_codec *codec)
6619 {
6620         unsigned int present;
6621
6622         present = snd_hda_codec_read(codec, 0x14, 0,
6623                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6624         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
6625                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6626         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6627                                   present ? 1 : 3);
6628 }
6629
6630 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
6631 {
6632         /* Looks like the unsol event is incompatible with the standard
6633          * definition.  4bit tag is placed at 26 bit!
6634          */
6635         if (((res >> 26) == ALC880_HP_EVENT)) {
6636                 alc882_targa_automute(codec);
6637         }
6638 }
6639
6640 static struct hda_verb alc882_asus_a7j_verbs[] = {
6641         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6642         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6643
6644         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6645         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6646         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6647
6648         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6649         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6650         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6651
6652         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6653         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6654         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6655         { } /* end */
6656 };
6657
6658 static struct hda_verb alc882_asus_a7m_verbs[] = {
6659         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6660         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6661
6662         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6663         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6664         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6665
6666         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6667         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6668         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6669
6670         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6671         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6672         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6673         { } /* end */
6674 };
6675
6676 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6677 {
6678         unsigned int gpiostate, gpiomask, gpiodir;
6679
6680         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6681                                        AC_VERB_GET_GPIO_DATA, 0);
6682
6683         if (!muted)
6684                 gpiostate |= (1 << pin);
6685         else
6686                 gpiostate &= ~(1 << pin);
6687
6688         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
6689                                       AC_VERB_GET_GPIO_MASK, 0);
6690         gpiomask |= (1 << pin);
6691
6692         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
6693                                      AC_VERB_GET_GPIO_DIRECTION, 0);
6694         gpiodir |= (1 << pin);
6695
6696
6697         snd_hda_codec_write(codec, codec->afg, 0,
6698                             AC_VERB_SET_GPIO_MASK, gpiomask);
6699         snd_hda_codec_write(codec, codec->afg, 0,
6700                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
6701
6702         msleep(1);
6703
6704         snd_hda_codec_write(codec, codec->afg, 0,
6705                             AC_VERB_SET_GPIO_DATA, gpiostate);
6706 }
6707
6708 /* set up GPIO at initialization */
6709 static void alc885_macpro_init_hook(struct hda_codec *codec)
6710 {
6711         alc882_gpio_mute(codec, 0, 0);
6712         alc882_gpio_mute(codec, 1, 0);
6713 }
6714
6715 /* set up GPIO and update auto-muting at initialization */
6716 static void alc885_imac24_init_hook(struct hda_codec *codec)
6717 {
6718         alc885_macpro_init_hook(codec);
6719         alc885_imac24_automute(codec);
6720 }
6721
6722 /*
6723  * generic initialization of ADC, input mixers and output mixers
6724  */
6725 static struct hda_verb alc882_auto_init_verbs[] = {
6726         /*
6727          * Unmute ADC0-2 and set the default input to mic-in
6728          */
6729         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6730         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6731         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6732         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6733         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6734         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6735
6736         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6737          * mixer widget
6738          * Note: PASD motherboards uses the Line In 2 as the input for
6739          * front panel mic (mic 2)
6740          */
6741         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6742         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6743         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6744         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6745         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6746         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6747
6748         /*
6749          * Set up output mixers (0x0c - 0x0f)
6750          */
6751         /* set vol=0 to output mixers */
6752         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6753         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6754         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6755         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6756         /* set up input amps for analog loopback */
6757         /* Amp Indices: DAC = 0, mixer = 1 */
6758         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6759         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6760         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6761         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6762         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6763         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6764         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6765         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6766         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6767         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6768
6769         /* FIXME: use matrix-type input source selection */
6770         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6771         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6772         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6773         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6774         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6775         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6776         /* Input mixer2 */
6777         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6778         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6779         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6780         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6781         /* Input mixer3 */
6782         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6783         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6784         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6785         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6786
6787         { }
6788 };
6789
6790 #ifdef CONFIG_SND_HDA_POWER_SAVE
6791 #define alc882_loopbacks        alc880_loopbacks
6792 #endif
6793
6794 /* pcm configuration: identiacal with ALC880 */
6795 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6796 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6797 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6798 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6799
6800 /*
6801  * configuration and preset
6802  */
6803 static const char *alc882_models[ALC882_MODEL_LAST] = {
6804         [ALC882_3ST_DIG]        = "3stack-dig",
6805         [ALC882_6ST_DIG]        = "6stack-dig",
6806         [ALC882_ARIMA]          = "arima",
6807         [ALC882_W2JC]           = "w2jc",
6808         [ALC882_TARGA]          = "targa",
6809         [ALC882_ASUS_A7J]       = "asus-a7j",
6810         [ALC882_ASUS_A7M]       = "asus-a7m",
6811         [ALC885_MACPRO]         = "macpro",
6812         [ALC885_MBP3]           = "mbp3",
6813         [ALC885_IMAC24]         = "imac24",
6814         [ALC882_AUTO]           = "auto",
6815 };
6816
6817 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6818         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6819         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6820         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6821         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6822         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6823         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6824         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6825         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6826         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6827         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6828         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6829         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6830         {}
6831 };
6832
6833 static struct alc_config_preset alc882_presets[] = {
6834         [ALC882_3ST_DIG] = {
6835                 .mixers = { alc882_base_mixer },
6836                 .init_verbs = { alc882_init_verbs },
6837                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6838                 .dac_nids = alc882_dac_nids,
6839                 .dig_out_nid = ALC882_DIGOUT_NID,
6840                 .dig_in_nid = ALC882_DIGIN_NID,
6841                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6842                 .channel_mode = alc882_ch_modes,
6843                 .need_dac_fix = 1,
6844                 .input_mux = &alc882_capture_source,
6845         },
6846         [ALC882_6ST_DIG] = {
6847                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6848                 .init_verbs = { alc882_init_verbs },
6849                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6850                 .dac_nids = alc882_dac_nids,
6851                 .dig_out_nid = ALC882_DIGOUT_NID,
6852                 .dig_in_nid = ALC882_DIGIN_NID,
6853                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6854                 .channel_mode = alc882_sixstack_modes,
6855                 .input_mux = &alc882_capture_source,
6856         },
6857         [ALC882_ARIMA] = {
6858                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6859                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6860                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6861                 .dac_nids = alc882_dac_nids,
6862                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6863                 .channel_mode = alc882_sixstack_modes,
6864                 .input_mux = &alc882_capture_source,
6865         },
6866         [ALC882_W2JC] = {
6867                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6868                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6869                                 alc880_gpio1_init_verbs },
6870                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6871                 .dac_nids = alc882_dac_nids,
6872                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6873                 .channel_mode = alc880_threestack_modes,
6874                 .need_dac_fix = 1,
6875                 .input_mux = &alc882_capture_source,
6876                 .dig_out_nid = ALC882_DIGOUT_NID,
6877         },
6878         [ALC885_MBP3] = {
6879                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6880                 .init_verbs = { alc885_mbp3_init_verbs,
6881                                 alc880_gpio1_init_verbs },
6882                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6883                 .dac_nids = alc882_dac_nids,
6884                 .channel_mode = alc885_mbp_6ch_modes,
6885                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
6886                 .input_mux = &alc882_capture_source,
6887                 .dig_out_nid = ALC882_DIGOUT_NID,
6888                 .dig_in_nid = ALC882_DIGIN_NID,
6889                 .unsol_event = alc885_mbp3_unsol_event,
6890                 .init_hook = alc885_mbp3_automute,
6891         },
6892         [ALC885_MACPRO] = {
6893                 .mixers = { alc882_macpro_mixer },
6894                 .init_verbs = { alc882_macpro_init_verbs },
6895                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6896                 .dac_nids = alc882_dac_nids,
6897                 .dig_out_nid = ALC882_DIGOUT_NID,
6898                 .dig_in_nid = ALC882_DIGIN_NID,
6899                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6900                 .channel_mode = alc882_ch_modes,
6901                 .input_mux = &alc882_capture_source,
6902                 .init_hook = alc885_macpro_init_hook,
6903         },
6904         [ALC885_IMAC24] = {
6905                 .mixers = { alc885_imac24_mixer },
6906                 .init_verbs = { alc885_imac24_init_verbs },
6907                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6908                 .dac_nids = alc882_dac_nids,
6909                 .dig_out_nid = ALC882_DIGOUT_NID,
6910                 .dig_in_nid = ALC882_DIGIN_NID,
6911                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6912                 .channel_mode = alc882_ch_modes,
6913                 .input_mux = &alc882_capture_source,
6914                 .unsol_event = alc885_imac24_unsol_event,
6915                 .init_hook = alc885_imac24_init_hook,
6916         },
6917         [ALC882_TARGA] = {
6918                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
6919                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6920                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6921                 .dac_nids = alc882_dac_nids,
6922                 .dig_out_nid = ALC882_DIGOUT_NID,
6923                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6924                 .adc_nids = alc882_adc_nids,
6925                 .capsrc_nids = alc882_capsrc_nids,
6926                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6927                 .channel_mode = alc882_3ST_6ch_modes,
6928                 .need_dac_fix = 1,
6929                 .input_mux = &alc882_capture_source,
6930                 .unsol_event = alc882_targa_unsol_event,
6931                 .init_hook = alc882_targa_automute,
6932         },
6933         [ALC882_ASUS_A7J] = {
6934                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
6935                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6936                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6937                 .dac_nids = alc882_dac_nids,
6938                 .dig_out_nid = ALC882_DIGOUT_NID,
6939                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6940                 .adc_nids = alc882_adc_nids,
6941                 .capsrc_nids = alc882_capsrc_nids,
6942                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6943                 .channel_mode = alc882_3ST_6ch_modes,
6944                 .need_dac_fix = 1,
6945                 .input_mux = &alc882_capture_source,
6946         },
6947         [ALC882_ASUS_A7M] = {
6948                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6949                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6950                                 alc880_gpio1_init_verbs,
6951                                 alc882_asus_a7m_verbs },
6952                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6953                 .dac_nids = alc882_dac_nids,
6954                 .dig_out_nid = ALC882_DIGOUT_NID,
6955                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6956                 .channel_mode = alc880_threestack_modes,
6957                 .need_dac_fix = 1,
6958                 .input_mux = &alc882_capture_source,
6959         },
6960 };
6961
6962
6963 /*
6964  * Pin config fixes
6965  */
6966 enum {
6967         PINFIX_ABIT_AW9D_MAX
6968 };
6969
6970 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6971         { 0x15, 0x01080104 }, /* side */
6972         { 0x16, 0x01011012 }, /* rear */
6973         { 0x17, 0x01016011 }, /* clfe */
6974         { }
6975 };
6976
6977 static const struct alc_pincfg *alc882_pin_fixes[] = {
6978         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6979 };
6980
6981 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6982         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6983         {}
6984 };
6985
6986 /*
6987  * BIOS auto configuration
6988  */
6989 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6990                                               hda_nid_t nid, int pin_type,
6991                                               int dac_idx)
6992 {
6993         /* set as output */
6994         struct alc_spec *spec = codec->spec;
6995         int idx;
6996
6997         alc_set_pin_output(codec, nid, pin_type);
6998         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6999                 idx = 4;
7000         else
7001                 idx = spec->multiout.dac_nids[dac_idx] - 2;
7002         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
7003
7004 }
7005
7006 static void alc882_auto_init_multi_out(struct hda_codec *codec)
7007 {
7008         struct alc_spec *spec = codec->spec;
7009         int i;
7010
7011         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
7012         for (i = 0; i <= HDA_SIDE; i++) {
7013                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
7014                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
7015                 if (nid)
7016                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
7017                                                           i);
7018         }
7019 }
7020
7021 static void alc882_auto_init_hp_out(struct hda_codec *codec)
7022 {
7023         struct alc_spec *spec = codec->spec;
7024         hda_nid_t pin;
7025
7026         pin = spec->autocfg.hp_pins[0];
7027         if (pin) /* connect to front */
7028                 /* use dac 0 */
7029                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
7030         pin = spec->autocfg.speaker_pins[0];
7031         if (pin)
7032                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
7033 }
7034
7035 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
7036 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
7037
7038 static void alc882_auto_init_analog_input(struct hda_codec *codec)
7039 {
7040         struct alc_spec *spec = codec->spec;
7041         int i;
7042
7043         for (i = 0; i < AUTO_PIN_LAST; i++) {
7044                 hda_nid_t nid = spec->autocfg.input_pins[i];
7045                 if (!nid)
7046                         continue;
7047                 alc_set_input_pin(codec, nid, AUTO_PIN_FRONT_MIC /*i*/);
7048                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
7049                         snd_hda_codec_write(codec, nid, 0,
7050                                             AC_VERB_SET_AMP_GAIN_MUTE,
7051                                             AMP_OUT_MUTE);
7052         }
7053 }
7054
7055 static void alc882_auto_init_input_src(struct hda_codec *codec)
7056 {
7057         struct alc_spec *spec = codec->spec;
7058         int c;
7059
7060         for (c = 0; c < spec->num_adc_nids; c++) {
7061                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
7062                 hda_nid_t nid = spec->capsrc_nids[c];
7063                 unsigned int mux_idx;
7064                 const struct hda_input_mux *imux;
7065                 int conns, mute, idx, item;
7066
7067                 conns = snd_hda_get_connections(codec, nid, conn_list,
7068                                                 ARRAY_SIZE(conn_list));
7069                 if (conns < 0)
7070                         continue;
7071                 mux_idx = c >= spec->num_mux_defs ? 0 : c;
7072                 imux = &spec->input_mux[mux_idx];
7073                 for (idx = 0; idx < conns; idx++) {
7074                         /* if the current connection is the selected one,
7075                          * unmute it as default - otherwise mute it
7076                          */
7077                         mute = AMP_IN_MUTE(idx);
7078                         for (item = 0; item < imux->num_items; item++) {
7079                                 if (imux->items[item].index == idx) {
7080                                         if (spec->cur_mux[c] == item)
7081                                                 mute = AMP_IN_UNMUTE(idx);
7082                                         break;
7083                                 }
7084                         }
7085                         /* check if we have a selector or mixer
7086                          * we could check for the widget type instead, but
7087                          * just check for Amp-In presence (in case of mixer
7088                          * without amp-in there is something wrong, this
7089                          * function shouldn't be used or capsrc nid is wrong)
7090                          */
7091                         if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
7092                                 snd_hda_codec_write(codec, nid, 0,
7093                                                     AC_VERB_SET_AMP_GAIN_MUTE,
7094                                                     mute);
7095                         else if (mute != AMP_IN_MUTE(idx))
7096                                 snd_hda_codec_write(codec, nid, 0,
7097                                                     AC_VERB_SET_CONNECT_SEL,
7098                                                     idx);
7099                 }
7100         }
7101 }
7102
7103 /* add mic boosts if needed */
7104 static int alc_auto_add_mic_boost(struct hda_codec *codec)
7105 {
7106         struct alc_spec *spec = codec->spec;
7107         int err;
7108         hda_nid_t nid;
7109
7110         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
7111         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
7112                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
7113                                   "Mic Boost",
7114                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
7115                 if (err < 0)
7116                         return err;
7117         }
7118         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
7119         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
7120                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
7121                                   "Front Mic Boost",
7122                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
7123                 if (err < 0)
7124                         return err;
7125         }
7126         return 0;
7127 }
7128
7129 /* almost identical with ALC880 parser... */
7130 static int alc882_parse_auto_config(struct hda_codec *codec)
7131 {
7132         struct alc_spec *spec = codec->spec;
7133         int err = alc880_parse_auto_config(codec);
7134
7135         if (err < 0)
7136                 return err;
7137         else if (!err)
7138                 return 0; /* no config found */
7139
7140         err = alc_auto_add_mic_boost(codec);
7141         if (err < 0)
7142                 return err;
7143
7144         /* hack - override the init verbs */
7145         spec->init_verbs[0] = alc882_auto_init_verbs;
7146
7147         return 1; /* config found */
7148 }
7149
7150 /* additional initialization for auto-configuration model */
7151 static void alc882_auto_init(struct hda_codec *codec)
7152 {
7153         struct alc_spec *spec = codec->spec;
7154         alc882_auto_init_multi_out(codec);
7155         alc882_auto_init_hp_out(codec);
7156         alc882_auto_init_analog_input(codec);
7157         alc882_auto_init_input_src(codec);
7158         if (spec->unsol_event)
7159                 alc_inithook(codec);
7160 }
7161
7162 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
7163
7164 static int patch_alc882(struct hda_codec *codec)
7165 {
7166         struct alc_spec *spec;
7167         int err, board_config;
7168
7169         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7170         if (spec == NULL)
7171                 return -ENOMEM;
7172
7173         codec->spec = spec;
7174
7175         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
7176                                                   alc882_models,
7177                                                   alc882_cfg_tbl);
7178
7179         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
7180                 /* Pick up systems that don't supply PCI SSID */
7181                 switch (codec->subsystem_id) {
7182                 case 0x106b0c00: /* Mac Pro */
7183                         board_config = ALC885_MACPRO;
7184                         break;
7185                 case 0x106b1000: /* iMac 24 */
7186                 case 0x106b2800: /* AppleTV */
7187                 case 0x106b3e00: /* iMac 24 Aluminium */
7188                         board_config = ALC885_IMAC24;
7189                         break;
7190                 case 0x106b00a0: /* MacBookPro3,1 - Another revision */
7191                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
7192                 case 0x106b00a4: /* MacbookPro4,1 */
7193                 case 0x106b2c00: /* Macbook Pro rev3 */
7194                 case 0x106b3600: /* Macbook 3.1 */
7195                 case 0x106b3800: /* MacbookPro4,1 - latter revision */
7196                         board_config = ALC885_MBP3;
7197                         break;
7198                 default:
7199                         /* ALC889A is handled better as ALC888-compatible */
7200                         if (codec->revision_id == 0x100101 ||
7201                             codec->revision_id == 0x100103) {
7202                                 alc_free(codec);
7203                                 return patch_alc883(codec);
7204                         }
7205                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
7206                                          "trying auto-probe from BIOS...\n");
7207                         board_config = ALC882_AUTO;
7208                 }
7209         }
7210
7211         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
7212
7213         if (board_config == ALC882_AUTO) {
7214                 /* automatic parse from the BIOS config */
7215                 err = alc882_parse_auto_config(codec);
7216                 if (err < 0) {
7217                         alc_free(codec);
7218                         return err;
7219                 } else if (!err) {
7220                         printk(KERN_INFO
7221                                "hda_codec: Cannot set up configuration "
7222                                "from BIOS.  Using base mode...\n");
7223                         board_config = ALC882_3ST_DIG;
7224                 }
7225         }
7226
7227         err = snd_hda_attach_beep_device(codec, 0x1);
7228         if (err < 0) {
7229                 alc_free(codec);
7230                 return err;
7231         }
7232
7233         if (board_config != ALC882_AUTO)
7234                 setup_preset(spec, &alc882_presets[board_config]);
7235
7236         if (codec->vendor_id == 0x10ec0885) {
7237                 spec->stream_name_analog = "ALC885 Analog";
7238                 spec->stream_name_digital = "ALC885 Digital";
7239         } else {
7240                 spec->stream_name_analog = "ALC882 Analog";
7241                 spec->stream_name_digital = "ALC882 Digital";
7242         }
7243
7244         spec->stream_analog_playback = &alc882_pcm_analog_playback;
7245         spec->stream_analog_capture = &alc882_pcm_analog_capture;
7246         /* FIXME: setup DAC5 */
7247         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
7248         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
7249
7250         spec->stream_digital_playback = &alc882_pcm_digital_playback;
7251         spec->stream_digital_capture = &alc882_pcm_digital_capture;
7252
7253         spec->capture_style = CAPT_MIX; /* matrix-style capture */
7254         if (!spec->adc_nids && spec->input_mux) {
7255                 /* check whether NID 0x07 is valid */
7256                 unsigned int wcap = get_wcaps(codec, 0x07);
7257                 /* get type */
7258                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
7259                 if (wcap != AC_WID_AUD_IN) {
7260                         spec->adc_nids = alc882_adc_nids_alt;
7261                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
7262                         spec->capsrc_nids = alc882_capsrc_nids_alt;
7263                 } else {
7264                         spec->adc_nids = alc882_adc_nids;
7265                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
7266                         spec->capsrc_nids = alc882_capsrc_nids;
7267                 }
7268         }
7269         set_capture_mixer(spec);
7270         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7271
7272         spec->vmaster_nid = 0x0c;
7273
7274         codec->patch_ops = alc_patch_ops;
7275         if (board_config == ALC882_AUTO)
7276                 spec->init_hook = alc882_auto_init;
7277 #ifdef CONFIG_SND_HDA_POWER_SAVE
7278         if (!spec->loopback.amplist)
7279                 spec->loopback.amplist = alc882_loopbacks;
7280 #endif
7281         codec->proc_widget_hook = print_realtek_coef;
7282
7283         return 0;
7284 }
7285
7286 /*
7287  * ALC883 support
7288  *
7289  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
7290  * configuration.  Each pin widget can choose any input DACs and a mixer.
7291  * Each ADC is connected from a mixer of all inputs.  This makes possible
7292  * 6-channel independent captures.
7293  *
7294  * In addition, an independent DAC for the multi-playback (not used in this
7295  * driver yet).
7296  */
7297 #define ALC883_DIGOUT_NID       0x06
7298 #define ALC883_DIGIN_NID        0x0a
7299
7300 #define ALC1200_DIGOUT_NID      0x10
7301
7302 static hda_nid_t alc883_dac_nids[4] = {
7303         /* front, rear, clfe, rear_surr */
7304         0x02, 0x03, 0x04, 0x05
7305 };
7306
7307 static hda_nid_t alc883_adc_nids[2] = {
7308         /* ADC1-2 */
7309         0x08, 0x09,
7310 };
7311
7312 static hda_nid_t alc883_adc_nids_alt[1] = {
7313         /* ADC1 */
7314         0x08,
7315 };
7316
7317 static hda_nid_t alc883_adc_nids_rev[2] = {
7318         /* ADC2-1 */
7319         0x09, 0x08
7320 };
7321
7322 #define alc889_adc_nids         alc880_adc_nids
7323
7324 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
7325
7326 static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
7327
7328 #define alc889_capsrc_nids      alc882_capsrc_nids
7329
7330 /* input MUX */
7331 /* FIXME: should be a matrix-type input source selection */
7332
7333 static struct hda_input_mux alc883_capture_source = {
7334         .num_items = 4,
7335         .items = {
7336                 { "Mic", 0x0 },
7337                 { "Front Mic", 0x1 },
7338                 { "Line", 0x2 },
7339                 { "CD", 0x4 },
7340         },
7341 };
7342
7343 static struct hda_input_mux alc883_3stack_6ch_intel = {
7344         .num_items = 4,
7345         .items = {
7346                 { "Mic", 0x1 },
7347                 { "Front Mic", 0x0 },
7348                 { "Line", 0x2 },
7349                 { "CD", 0x4 },
7350         },
7351 };
7352
7353 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
7354         .num_items = 2,
7355         .items = {
7356                 { "Mic", 0x1 },
7357                 { "Line", 0x2 },
7358         },
7359 };
7360
7361 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
7362         .num_items = 4,
7363         .items = {
7364                 { "Mic", 0x0 },
7365                 { "iMic", 0x1 },
7366                 { "Line", 0x2 },
7367                 { "CD", 0x4 },
7368         },
7369 };
7370
7371 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
7372         .num_items = 2,
7373         .items = {
7374                 { "Mic", 0x0 },
7375                 { "Int Mic", 0x1 },
7376         },
7377 };
7378
7379 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
7380         .num_items = 3,
7381         .items = {
7382                 { "Mic", 0x0 },
7383                 { "Front Mic", 0x1 },
7384                 { "Line", 0x4 },
7385         },
7386 };
7387
7388 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
7389         .num_items = 2,
7390         .items = {
7391                 { "Mic", 0x0 },
7392                 { "Line", 0x2 },
7393         },
7394 };
7395
7396 /*
7397  * 2ch mode
7398  */
7399 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
7400         { 2, NULL }
7401 };
7402
7403 /*
7404  * 2ch mode
7405  */
7406 static struct hda_verb alc883_3ST_ch2_init[] = {
7407         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7408         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7409         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7410         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7411         { } /* end */
7412 };
7413
7414 /*
7415  * 4ch mode
7416  */
7417 static struct hda_verb alc883_3ST_ch4_init[] = {
7418         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7419         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7420         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7421         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7422         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7423         { } /* end */
7424 };
7425
7426 /*
7427  * 6ch mode
7428  */
7429 static struct hda_verb alc883_3ST_ch6_init[] = {
7430         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7431         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7432         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7433         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7434         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7435         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7436         { } /* end */
7437 };
7438
7439 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
7440         { 2, alc883_3ST_ch2_init },
7441         { 4, alc883_3ST_ch4_init },
7442         { 6, alc883_3ST_ch6_init },
7443 };
7444
7445 /*
7446  * 2ch mode
7447  */
7448 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
7449         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7450         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7451         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7452         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7453         { } /* end */
7454 };
7455
7456 /*
7457  * 4ch mode
7458  */
7459 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
7460         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7461         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7462         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7463         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7464         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7465         { } /* end */
7466 };
7467
7468 /*
7469  * 6ch mode
7470  */
7471 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
7472         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7473         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7474         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
7475         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7476         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7477         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7478         { } /* end */
7479 };
7480
7481 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
7482         { 2, alc883_3ST_ch2_intel_init },
7483         { 4, alc883_3ST_ch4_intel_init },
7484         { 6, alc883_3ST_ch6_intel_init },
7485 };
7486
7487 /*
7488  * 6ch mode
7489  */
7490 static struct hda_verb alc883_sixstack_ch6_init[] = {
7491         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7492         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7493         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7494         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7495         { } /* end */
7496 };
7497
7498 /*
7499  * 8ch mode
7500  */
7501 static struct hda_verb alc883_sixstack_ch8_init[] = {
7502         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7503         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7504         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7505         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7506         { } /* end */
7507 };
7508
7509 static struct hda_channel_mode alc883_sixstack_modes[2] = {
7510         { 6, alc883_sixstack_ch6_init },
7511         { 8, alc883_sixstack_ch8_init },
7512 };
7513
7514 static struct hda_verb alc883_medion_eapd_verbs[] = {
7515         /* eanable EAPD on medion laptop */
7516         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7517         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7518         { }
7519 };
7520
7521 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
7522  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
7523  */
7524
7525 static struct snd_kcontrol_new alc883_base_mixer[] = {
7526         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7527         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7528         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7529         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7530         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7531         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7532         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7533         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7534         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7535         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7536         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7537         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7538         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7539         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7540         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7541         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7542         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7543         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7544         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7545         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7546         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7547         { } /* end */
7548 };
7549
7550 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7551         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7552         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7553         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7554         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7555         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7556         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7557         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7558         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7559         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7560         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7561         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7562         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7563         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7564         { } /* end */
7565 };
7566
7567 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7568         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7569         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7570         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7571         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7572         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7573         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7574         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7575         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7576         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7577         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7578         { } /* end */
7579 };
7580
7581 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7582         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7583         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7584         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7585         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7586         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7587         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7588         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7589         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7590         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7591         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7592         { } /* end */
7593 };
7594
7595 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7596         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7597         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7598         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7599         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7600         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7601         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7602         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7603         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7604         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7605         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7606         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7607         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7608         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7609         { } /* end */
7610 };
7611
7612 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7613         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7614         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7615         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7616         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7617         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7618         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7619         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7620         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7621         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7622         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7623         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7624         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7625         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7626         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7627         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7628         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7629         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7630         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7631         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7632         { } /* end */
7633 };
7634
7635 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7636         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7637         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7638         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7639         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7640         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7641                               HDA_OUTPUT),
7642         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7643         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7644         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7645         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7646         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7647         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7648         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7649         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7650         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7651         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7652         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7653         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7654         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7655         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7656         { } /* end */
7657 };
7658
7659 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7660         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7661         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7662         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7663         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7664         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7665         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7666         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7667         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7668         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7669         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7670         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7671         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7672         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7673         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7674         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7675         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7676         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7677         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7678         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7679         { } /* end */
7680 };
7681
7682 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
7683         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7684         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7685         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7686         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7687         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7688         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7689         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7690         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7691         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7692         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7693         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7694         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7695         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7696         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7697         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7698         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7699         { } /* end */
7700 };
7701
7702 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
7703         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7704         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7705         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7706         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7707         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7708         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7709         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7710         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7711         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7712         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7713         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7714         { } /* end */
7715 };
7716
7717 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7718         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7719         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7720         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7721         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7722         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7723         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7724         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7725         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7726         { } /* end */
7727 };
7728
7729 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7730         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7731         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7732         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7733         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7734         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7735         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7736         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7737         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7738         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7739         { } /* end */
7740 };
7741
7742 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7743         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7744         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7745         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7746         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7747         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7748         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7749         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7750         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7751         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7752         { } /* end */
7753 };
7754
7755 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7756         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7757         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7758         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7759         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7760         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7761         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7762         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7763         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7764         { } /* end */
7765 };
7766
7767 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
7768         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7769         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7770         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
7771         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
7772         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
7773                                                 0x0d, 1, 0x0, HDA_OUTPUT),
7774         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
7775         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
7776         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
7777         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7778         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7779         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7780         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
7781         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7782         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7783         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7784         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7785         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7786         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7787         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7788         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7789         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7790         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7791         { } /* end */
7792 };
7793
7794 static struct hda_bind_ctls alc883_bind_cap_vol = {
7795         .ops = &snd_hda_bind_vol,
7796         .values = {
7797                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7798                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7799                 0
7800         },
7801 };
7802
7803 static struct hda_bind_ctls alc883_bind_cap_switch = {
7804         .ops = &snd_hda_bind_sw,
7805         .values = {
7806                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7807                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7808                 0
7809         },
7810 };
7811
7812 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
7813         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7814         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7815         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7816         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7817         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7818         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7819         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7820         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7821         { } /* end */
7822 };
7823
7824 static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
7825         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
7826         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
7827         {
7828                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7829                 /* .name = "Capture Source", */
7830                 .name = "Input Source",
7831                 .count = 1,
7832                 .info = alc_mux_enum_info,
7833                 .get = alc_mux_enum_get,
7834                 .put = alc_mux_enum_put,
7835         },
7836         { } /* end */
7837 };
7838
7839 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7840         {
7841                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7842                 .name = "Channel Mode",
7843                 .info = alc_ch_mode_info,
7844                 .get = alc_ch_mode_get,
7845                 .put = alc_ch_mode_put,
7846         },
7847         { } /* end */
7848 };
7849
7850 static struct hda_verb alc883_init_verbs[] = {
7851         /* ADC1: mute amp left and right */
7852         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7853         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7854         /* ADC2: mute amp left and right */
7855         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7856         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7857         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7858         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7859         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7860         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7861         /* Rear mixer */
7862         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7863         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7864         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7865         /* CLFE mixer */
7866         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7867         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7868         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7869         /* Side mixer */
7870         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7871         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7872         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7873
7874         /* mute analog input loopbacks */
7875         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7876         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7877         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7878         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7879         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7880
7881         /* Front Pin: output 0 (0x0c) */
7882         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7883         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7884         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7885         /* Rear Pin: output 1 (0x0d) */
7886         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7887         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7888         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7889         /* CLFE Pin: output 2 (0x0e) */
7890         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7891         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7892         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7893         /* Side Pin: output 3 (0x0f) */
7894         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7895         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7896         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7897         /* Mic (rear) pin: input vref at 80% */
7898         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7899         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7900         /* Front Mic pin: input vref at 80% */
7901         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7902         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7903         /* Line In pin: input */
7904         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7905         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7906         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7907         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7908         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7909         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7910         /* CD pin widget for input */
7911         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7912
7913         /* FIXME: use matrix-type input source selection */
7914         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7915         /* Input mixer2 */
7916         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7917         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7918         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7919         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7920         /* Input mixer3 */
7921         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7922         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7923         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7924         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7925         { }
7926 };
7927
7928 /* toggle speaker-output according to the hp-jack state */
7929 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7930 {
7931         unsigned int present;
7932
7933         present = snd_hda_codec_read(codec, 0x15, 0,
7934                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7935         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7936                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7937         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7938                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7939 }
7940
7941 /* auto-toggle front mic */
7942 /*
7943 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7944 {
7945         unsigned int present;
7946         unsigned char bits;
7947
7948         present = snd_hda_codec_read(codec, 0x18, 0,
7949                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7950         bits = present ? HDA_AMP_MUTE : 0;
7951         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7952 }
7953 */
7954
7955 static void alc883_mitac_automute(struct hda_codec *codec)
7956 {
7957         alc883_mitac_hp_automute(codec);
7958         /* alc883_mitac_mic_automute(codec); */
7959 }
7960
7961 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7962                                            unsigned int res)
7963 {
7964         switch (res >> 26) {
7965         case ALC880_HP_EVENT:
7966                 alc883_mitac_hp_automute(codec);
7967                 break;
7968         case ALC880_MIC_EVENT:
7969                 /* alc883_mitac_mic_automute(codec); */
7970                 break;
7971         }
7972 }
7973
7974 static struct hda_verb alc883_mitac_verbs[] = {
7975         /* HP */
7976         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7977         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7978         /* Subwoofer */
7979         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7980         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7981
7982         /* enable unsolicited event */
7983         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7984         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7985
7986         { } /* end */
7987 };
7988
7989 static struct hda_verb alc883_clevo_m720_verbs[] = {
7990         /* HP */
7991         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7992         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7993         /* Int speaker */
7994         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7995         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7996
7997         /* enable unsolicited event */
7998         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7999         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8000
8001         { } /* end */
8002 };
8003
8004 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
8005         /* HP */
8006         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8007         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8008         /* Subwoofer */
8009         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8010         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8011
8012         /* enable unsolicited event */
8013         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8014
8015         { } /* end */
8016 };
8017
8018 static struct hda_verb alc883_tagra_verbs[] = {
8019         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8020         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8021
8022         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8023         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8024
8025         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
8026         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
8027         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
8028
8029         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8030         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
8031         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
8032         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
8033
8034         { } /* end */
8035 };
8036
8037 static struct hda_verb alc883_lenovo_101e_verbs[] = {
8038         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8039         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
8040         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
8041         { } /* end */
8042 };
8043
8044 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
8045         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8046         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8047         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8048         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8049         { } /* end */
8050 };
8051
8052 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
8053         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8054         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8055         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8056         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
8057         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
8058         { } /* end */
8059 };
8060
8061 static struct hda_verb alc883_haier_w66_verbs[] = {
8062         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8063         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8064
8065         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8066
8067         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8068         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8069         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8070         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8071         { } /* end */
8072 };
8073
8074 static struct hda_verb alc888_lenovo_sky_verbs[] = {
8075         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8076         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8077         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8078         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8079         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8080         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8081         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
8082         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8083         { } /* end */
8084 };
8085
8086 static struct hda_verb alc888_6st_dell_verbs[] = {
8087         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8088         { }
8089 };
8090
8091 static void alc888_3st_hp_front_automute(struct hda_codec *codec)
8092 {
8093         unsigned int present, bits;
8094
8095         present = snd_hda_codec_read(codec, 0x1b, 0,
8096                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8097         bits = present ? HDA_AMP_MUTE : 0;
8098         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8099                                  HDA_AMP_MUTE, bits);
8100         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8101                                  HDA_AMP_MUTE, bits);
8102         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
8103                                  HDA_AMP_MUTE, bits);
8104 }
8105
8106 static void alc888_3st_hp_unsol_event(struct hda_codec *codec,
8107                                       unsigned int res)
8108 {
8109         switch (res >> 26) {
8110         case ALC880_HP_EVENT:
8111                 alc888_3st_hp_front_automute(codec);
8112                 break;
8113         }
8114 }
8115
8116 static struct hda_verb alc888_3st_hp_verbs[] = {
8117         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
8118         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
8119         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
8120         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8121         { } /* end */
8122 };
8123
8124 /*
8125  * 2ch mode
8126  */
8127 static struct hda_verb alc888_3st_hp_2ch_init[] = {
8128         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8129         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8130         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
8131         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8132         { } /* end */
8133 };
8134
8135 /*
8136  * 4ch mode
8137  */
8138 static struct hda_verb alc888_3st_hp_4ch_init[] = {
8139         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8140         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8141         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8142         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8143         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8144         { } /* end */
8145 };
8146
8147 /*
8148  * 6ch mode
8149  */
8150 static struct hda_verb alc888_3st_hp_6ch_init[] = {
8151         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8152         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8153         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
8154         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8155         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8156         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8157         { } /* end */
8158 };
8159
8160 static struct hda_channel_mode alc888_3st_hp_modes[3] = {
8161         { 2, alc888_3st_hp_2ch_init },
8162         { 4, alc888_3st_hp_4ch_init },
8163         { 6, alc888_3st_hp_6ch_init },
8164 };
8165
8166 /* toggle front-jack and RCA according to the hp-jack state */
8167 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
8168 {
8169         unsigned int present;
8170
8171         present = snd_hda_codec_read(codec, 0x1b, 0,
8172                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8173         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8174                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8175         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8176                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8177 }
8178
8179 /* toggle RCA according to the front-jack state */
8180 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
8181 {
8182         unsigned int present;
8183
8184         present = snd_hda_codec_read(codec, 0x14, 0,
8185                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8186         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8187                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8188 }
8189
8190 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
8191                                              unsigned int res)
8192 {
8193         if ((res >> 26) == ALC880_HP_EVENT)
8194                 alc888_lenovo_ms7195_front_automute(codec);
8195         if ((res >> 26) == ALC880_FRONT_EVENT)
8196                 alc888_lenovo_ms7195_rca_automute(codec);
8197 }
8198
8199 static struct hda_verb alc883_medion_md2_verbs[] = {
8200         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8201         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8202
8203         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8204
8205         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8206         { } /* end */
8207 };
8208
8209 /* toggle speaker-output according to the hp-jack state */
8210 static void alc883_medion_md2_automute(struct hda_codec *codec)
8211 {
8212         unsigned int present;
8213
8214         present = snd_hda_codec_read(codec, 0x14, 0,
8215                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8216         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8217                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8218 }
8219
8220 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
8221                                           unsigned int res)
8222 {
8223         if ((res >> 26) == ALC880_HP_EVENT)
8224                 alc883_medion_md2_automute(codec);
8225 }
8226
8227 /* toggle speaker-output according to the hp-jack state */
8228 static void alc883_tagra_automute(struct hda_codec *codec)
8229 {
8230         unsigned int present;
8231         unsigned char bits;
8232
8233         present = snd_hda_codec_read(codec, 0x14, 0,
8234                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8235         bits = present ? HDA_AMP_MUTE : 0;
8236         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
8237                                  HDA_AMP_MUTE, bits);
8238         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
8239                                   present ? 1 : 3);
8240 }
8241
8242 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
8243 {
8244         if ((res >> 26) == ALC880_HP_EVENT)
8245                 alc883_tagra_automute(codec);
8246 }
8247
8248 /* toggle speaker-output according to the hp-jack state */
8249 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
8250 {
8251         unsigned int present;
8252         unsigned char bits;
8253
8254         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
8255                 & AC_PINSENSE_PRESENCE;
8256         bits = present ? HDA_AMP_MUTE : 0;
8257         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8258                                  HDA_AMP_MUTE, bits);
8259 }
8260
8261 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8262 {
8263         unsigned int present;
8264
8265         present = snd_hda_codec_read(codec, 0x18, 0,
8266                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8267         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8268                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8269 }
8270
8271 static void alc883_clevo_m720_automute(struct hda_codec *codec)
8272 {
8273         alc883_clevo_m720_hp_automute(codec);
8274         alc883_clevo_m720_mic_automute(codec);
8275 }
8276
8277 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8278                                            unsigned int res)
8279 {
8280         switch (res >> 26) {
8281         case ALC880_HP_EVENT:
8282                 alc883_clevo_m720_hp_automute(codec);
8283                 break;
8284         case ALC880_MIC_EVENT:
8285                 alc883_clevo_m720_mic_automute(codec);
8286                 break;
8287         }
8288 }
8289
8290 /* toggle speaker-output according to the hp-jack state */
8291 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
8292 {
8293         unsigned int present;
8294         unsigned char bits;
8295
8296         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8297                 & AC_PINSENSE_PRESENCE;
8298         bits = present ? HDA_AMP_MUTE : 0;
8299         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8300                                  HDA_AMP_MUTE, bits);
8301 }
8302
8303 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
8304                                                   unsigned int res)
8305 {
8306         if ((res >> 26) == ALC880_HP_EVENT)
8307                 alc883_2ch_fujitsu_pi2515_automute(codec);
8308 }
8309
8310 static void alc883_haier_w66_automute(struct hda_codec *codec)
8311 {
8312         unsigned int present;
8313         unsigned char bits;
8314
8315         present = snd_hda_codec_read(codec, 0x1b, 0,
8316                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8317         bits = present ? 0x80 : 0;
8318         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8319                                  0x80, bits);
8320 }
8321
8322 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
8323                                          unsigned int res)
8324 {
8325         if ((res >> 26) == ALC880_HP_EVENT)
8326                 alc883_haier_w66_automute(codec);
8327 }
8328
8329 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8330 {
8331         unsigned int present;
8332         unsigned char bits;
8333
8334         present = snd_hda_codec_read(codec, 0x14, 0,
8335                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8336         bits = present ? HDA_AMP_MUTE : 0;
8337         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8338                                  HDA_AMP_MUTE, bits);
8339 }
8340
8341 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8342 {
8343         unsigned int present;
8344         unsigned char bits;
8345
8346         present = snd_hda_codec_read(codec, 0x1b, 0,
8347                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8348         bits = present ? HDA_AMP_MUTE : 0;
8349         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8350                                  HDA_AMP_MUTE, bits);
8351         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8352                                  HDA_AMP_MUTE, bits);
8353 }
8354
8355 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8356                                            unsigned int res)
8357 {
8358         if ((res >> 26) == ALC880_HP_EVENT)
8359                 alc883_lenovo_101e_all_automute(codec);
8360         if ((res >> 26) == ALC880_FRONT_EVENT)
8361                 alc883_lenovo_101e_ispeaker_automute(codec);
8362 }
8363
8364 /* toggle speaker-output according to the hp-jack state */
8365 static void alc883_acer_aspire_automute(struct hda_codec *codec)
8366 {
8367         unsigned int present;
8368
8369         present = snd_hda_codec_read(codec, 0x14, 0,
8370                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8371         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8372                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8373         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8374                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8375 }
8376
8377 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
8378                                            unsigned int res)
8379 {
8380         if ((res >> 26) == ALC880_HP_EVENT)
8381                 alc883_acer_aspire_automute(codec);
8382 }
8383
8384 static struct hda_verb alc883_acer_eapd_verbs[] = {
8385         /* HP Pin: output 0 (0x0c) */
8386         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8387         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8388         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8389         /* Front Pin: output 0 (0x0c) */
8390         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8391         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8392         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8393         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
8394         /* eanable EAPD on medion laptop */
8395         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8396         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8397         /* enable unsolicited event */
8398         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8399         { }
8400 };
8401
8402 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
8403 {
8404         unsigned int present;
8405
8406         present = snd_hda_codec_read(codec, 0x1b, 0,
8407                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8408         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8409                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8410         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8411                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8412         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8413                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8414         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8415                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8416 }
8417
8418 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
8419                                              unsigned int res)
8420 {
8421         switch (res >> 26) {
8422         case ALC880_HP_EVENT:
8423                 /* printk(KERN_DEBUG "hp_event\n"); */
8424                 alc888_6st_dell_front_automute(codec);
8425                 break;
8426         }
8427 }
8428
8429 static void alc888_lenovo_sky_front_automute(struct hda_codec *codec)
8430 {
8431         unsigned int mute;
8432         unsigned int present;
8433
8434         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8435         present = snd_hda_codec_read(codec, 0x1b, 0,
8436                                      AC_VERB_GET_PIN_SENSE, 0);
8437         present = (present & 0x80000000) != 0;
8438         if (present) {
8439                 /* mute internal speaker */
8440                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8441                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8442                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8443                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8444                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8445                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8446                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8447                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8448                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8449                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8450         } else {
8451                 /* unmute internal speaker if necessary */
8452                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8453                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8454                                          HDA_AMP_MUTE, mute);
8455                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8456                                          HDA_AMP_MUTE, mute);
8457                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8458                                          HDA_AMP_MUTE, mute);
8459                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8460                                          HDA_AMP_MUTE, mute);
8461                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8462                                          HDA_AMP_MUTE, mute);
8463         }
8464 }
8465
8466 static void alc883_lenovo_sky_unsol_event(struct hda_codec *codec,
8467                                              unsigned int res)
8468 {
8469         if ((res >> 26) == ALC880_HP_EVENT)
8470                 alc888_lenovo_sky_front_automute(codec);
8471 }
8472
8473 /*
8474  * generic initialization of ADC, input mixers and output mixers
8475  */
8476 static struct hda_verb alc883_auto_init_verbs[] = {
8477         /*
8478          * Unmute ADC0-2 and set the default input to mic-in
8479          */
8480         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8481         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8482         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8483         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8484
8485         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8486          * mixer widget
8487          * Note: PASD motherboards uses the Line In 2 as the input for
8488          * front panel mic (mic 2)
8489          */
8490         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8491         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8492         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8493         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8494         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8495         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8496
8497         /*
8498          * Set up output mixers (0x0c - 0x0f)
8499          */
8500         /* set vol=0 to output mixers */
8501         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8502         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8503         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8504         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8505         /* set up input amps for analog loopback */
8506         /* Amp Indices: DAC = 0, mixer = 1 */
8507         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8508         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8509         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8510         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8511         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8512         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8513         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8514         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8515         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8516         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8517
8518         /* FIXME: use matrix-type input source selection */
8519         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8520         /* Input mixer1 */
8521         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8522         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8523         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8524         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8525         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8526         /* Input mixer2 */
8527         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8528         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8529         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8530         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8531         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8532
8533         { }
8534 };
8535
8536 static struct hda_verb alc888_asus_m90v_verbs[] = {
8537         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8538         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8539         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8540         /* enable unsolicited event */
8541         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8542         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8543         { } /* end */
8544 };
8545
8546 static void alc883_nb_mic_automute(struct hda_codec *codec)
8547 {
8548         unsigned int present;
8549
8550         present = snd_hda_codec_read(codec, 0x18, 0,
8551                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8552         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8553                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
8554         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8555                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
8556 }
8557
8558 static void alc883_M90V_speaker_automute(struct hda_codec *codec)
8559 {
8560         unsigned int present;
8561         unsigned char bits;
8562
8563         present = snd_hda_codec_read(codec, 0x1b, 0,
8564                                      AC_VERB_GET_PIN_SENSE, 0)
8565                 & AC_PINSENSE_PRESENCE;
8566         bits = present ? 0 : PIN_OUT;
8567         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8568                             bits);
8569         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8570                             bits);
8571         snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8572                             bits);
8573 }
8574
8575 static void alc883_mode2_unsol_event(struct hda_codec *codec,
8576                                            unsigned int res)
8577 {
8578         switch (res >> 26) {
8579         case ALC880_HP_EVENT:
8580                 alc883_M90V_speaker_automute(codec);
8581                 break;
8582         case ALC880_MIC_EVENT:
8583                 alc883_nb_mic_automute(codec);
8584                 break;
8585         }
8586 }
8587
8588 static void alc883_mode2_inithook(struct hda_codec *codec)
8589 {
8590         alc883_M90V_speaker_automute(codec);
8591         alc883_nb_mic_automute(codec);
8592 }
8593
8594 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8595         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8596         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8597         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8598         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8599         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8600         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8601         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8602         /* enable unsolicited event */
8603         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8604         { } /* end */
8605 };
8606
8607 static void alc883_eee1601_speaker_automute(struct hda_codec *codec)
8608 {
8609         unsigned int present;
8610         unsigned char bits;
8611
8612         present = snd_hda_codec_read(codec, 0x14, 0,
8613                                      AC_VERB_GET_PIN_SENSE, 0)
8614                 & AC_PINSENSE_PRESENCE;
8615         bits = present ? 0 : PIN_OUT;
8616         snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8617                             bits);
8618 }
8619
8620 static void alc883_eee1601_unsol_event(struct hda_codec *codec,
8621                                            unsigned int res)
8622 {
8623         switch (res >> 26) {
8624         case ALC880_HP_EVENT:
8625                 alc883_eee1601_speaker_automute(codec);
8626                 break;
8627         }
8628 }
8629
8630 static void alc883_eee1601_inithook(struct hda_codec *codec)
8631 {
8632         alc883_eee1601_speaker_automute(codec);
8633 }
8634
8635 #ifdef CONFIG_SND_HDA_POWER_SAVE
8636 #define alc883_loopbacks        alc880_loopbacks
8637 #endif
8638
8639 /* pcm configuration: identiacal with ALC880 */
8640 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
8641 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
8642 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
8643 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
8644 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
8645
8646 /*
8647  * configuration and preset
8648  */
8649 static const char *alc883_models[ALC883_MODEL_LAST] = {
8650         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
8651         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8652         [ALC883_3ST_6ch]        = "3stack-6ch",
8653         [ALC883_6ST_DIG]        = "6stack-dig",
8654         [ALC883_TARGA_DIG]      = "targa-dig",
8655         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8656         [ALC883_ACER]           = "acer",
8657         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8658         [ALC888_ACER_ASPIRE_4930G]      = "acer-aspire-4930g",
8659         [ALC883_MEDION]         = "medion",
8660         [ALC883_MEDION_MD2]     = "medion-md2",
8661         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8662         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8663         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8664         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8665         [ALC888_LENOVO_SKY] = "lenovo-sky",
8666         [ALC883_HAIER_W66]      = "haier-w66",
8667         [ALC888_3ST_HP]         = "3stack-hp",
8668         [ALC888_6ST_DELL]       = "6stack-dell",
8669         [ALC883_MITAC]          = "mitac",
8670         [ALC883_CLEVO_M720]     = "clevo-m720",
8671         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8672         [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
8673         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8674         [ALC1200_ASUS_P5Q]      = "asus-p5q",
8675         [ALC883_AUTO]           = "auto",
8676 };
8677
8678 static struct snd_pci_quirk alc883_cfg_tbl[] = {
8679         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
8680         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8681         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
8682         SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_ACER_ASPIRE),
8683         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8684         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8685         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8686         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
8687                 ALC888_ACER_ASPIRE_4930G),
8688         SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
8689                 ALC888_ACER_ASPIRE_4930G),
8690         SND_PCI_QUIRK(0x1025, 0x0157, "Acer X3200", ALC883_AUTO),
8691         SND_PCI_QUIRK(0x1025, 0x0158, "Acer AX1700-U3700A", ALC883_AUTO),
8692         SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
8693                 ALC888_ACER_ASPIRE_4930G),
8694         SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
8695                 ALC888_ACER_ASPIRE_4930G),
8696         /* default Acer */
8697         SND_PCI_QUIRK_VENDOR(0x1025, "Acer laptop", ALC883_ACER),
8698         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8699         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8700         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8701         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8702         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8703         SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP),
8704         SND_PCI_QUIRK(0x103c, 0x2a72, "HP Educ.ar", ALC888_3ST_HP),
8705         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8706         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8707         SND_PCI_QUIRK(0x1043, 0x8284, "Asus Z37E", ALC883_6ST_DIG),
8708         SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
8709         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8710         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8711         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
8712         SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC),
8713         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8714         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8715         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
8716         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8717         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
8718         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8719         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8720         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8721         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8722         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8723         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8724         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8725         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8726         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8727         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8728         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8729         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8730         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8731         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8732         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8733         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8734         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8735         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8736         SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
8737         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8738         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8739         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8740         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8741         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8742         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8743         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8744         SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC883_LAPTOP_EAPD),
8745         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8746         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8747         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1100, "FSC AMILO Xi/Pi25xx",
8748                       ALC883_FUJITSU_PI2515),
8749         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1130, "Fujitsu AMILO Xa35xx",
8750                 ALC888_FUJITSU_XA3530),
8751         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8752         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8753         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8754         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8755         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
8756         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8757         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
8758         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8759         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8760         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8761         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8762         SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC),
8763         SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC883_3ST_6ch_INTEL),
8764         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8765         {}
8766 };
8767
8768 static hda_nid_t alc883_slave_dig_outs[] = {
8769         ALC1200_DIGOUT_NID, 0,
8770 };
8771
8772 static hda_nid_t alc1200_slave_dig_outs[] = {
8773         ALC883_DIGOUT_NID, 0,
8774 };
8775
8776 static struct alc_config_preset alc883_presets[] = {
8777         [ALC883_3ST_2ch_DIG] = {
8778                 .mixers = { alc883_3ST_2ch_mixer },
8779                 .init_verbs = { alc883_init_verbs },
8780                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8781                 .dac_nids = alc883_dac_nids,
8782                 .dig_out_nid = ALC883_DIGOUT_NID,
8783                 .dig_in_nid = ALC883_DIGIN_NID,
8784                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8785                 .channel_mode = alc883_3ST_2ch_modes,
8786                 .input_mux = &alc883_capture_source,
8787         },
8788         [ALC883_3ST_6ch_DIG] = {
8789                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8790                 .init_verbs = { alc883_init_verbs },
8791                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8792                 .dac_nids = alc883_dac_nids,
8793                 .dig_out_nid = ALC883_DIGOUT_NID,
8794                 .dig_in_nid = ALC883_DIGIN_NID,
8795                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8796                 .channel_mode = alc883_3ST_6ch_modes,
8797                 .need_dac_fix = 1,
8798                 .input_mux = &alc883_capture_source,
8799         },
8800         [ALC883_3ST_6ch] = {
8801                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8802                 .init_verbs = { alc883_init_verbs },
8803                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8804                 .dac_nids = alc883_dac_nids,
8805                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8806                 .channel_mode = alc883_3ST_6ch_modes,
8807                 .need_dac_fix = 1,
8808                 .input_mux = &alc883_capture_source,
8809         },
8810         [ALC883_3ST_6ch_INTEL] = {
8811                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
8812                 .init_verbs = { alc883_init_verbs },
8813                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8814                 .dac_nids = alc883_dac_nids,
8815                 .dig_out_nid = ALC883_DIGOUT_NID,
8816                 .dig_in_nid = ALC883_DIGIN_NID,
8817                 .slave_dig_outs = alc883_slave_dig_outs,
8818                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
8819                 .channel_mode = alc883_3ST_6ch_intel_modes,
8820                 .need_dac_fix = 1,
8821                 .input_mux = &alc883_3stack_6ch_intel,
8822         },
8823         [ALC883_6ST_DIG] = {
8824                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8825                 .init_verbs = { alc883_init_verbs },
8826                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8827                 .dac_nids = alc883_dac_nids,
8828                 .dig_out_nid = ALC883_DIGOUT_NID,
8829                 .dig_in_nid = ALC883_DIGIN_NID,
8830                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8831                 .channel_mode = alc883_sixstack_modes,
8832                 .input_mux = &alc883_capture_source,
8833         },
8834         [ALC883_TARGA_DIG] = {
8835                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
8836                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8837                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8838                 .dac_nids = alc883_dac_nids,
8839                 .dig_out_nid = ALC883_DIGOUT_NID,
8840                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8841                 .channel_mode = alc883_3ST_6ch_modes,
8842                 .need_dac_fix = 1,
8843                 .input_mux = &alc883_capture_source,
8844                 .unsol_event = alc883_tagra_unsol_event,
8845                 .init_hook = alc883_tagra_automute,
8846         },
8847         [ALC883_TARGA_2ch_DIG] = {
8848                 .mixers = { alc883_tagra_2ch_mixer},
8849                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8850                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8851                 .dac_nids = alc883_dac_nids,
8852                 .adc_nids = alc883_adc_nids_alt,
8853                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8854                 .dig_out_nid = ALC883_DIGOUT_NID,
8855                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8856                 .channel_mode = alc883_3ST_2ch_modes,
8857                 .input_mux = &alc883_capture_source,
8858                 .unsol_event = alc883_tagra_unsol_event,
8859                 .init_hook = alc883_tagra_automute,
8860         },
8861         [ALC883_ACER] = {
8862                 .mixers = { alc883_base_mixer },
8863                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
8864                  * and the headphone jack.  Turn this on and rely on the
8865                  * standard mute methods whenever the user wants to turn
8866                  * these outputs off.
8867                  */
8868                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
8869                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8870                 .dac_nids = alc883_dac_nids,
8871                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8872                 .channel_mode = alc883_3ST_2ch_modes,
8873                 .input_mux = &alc883_capture_source,
8874         },
8875         [ALC883_ACER_ASPIRE] = {
8876                 .mixers = { alc883_acer_aspire_mixer },
8877                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
8878                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8879                 .dac_nids = alc883_dac_nids,
8880                 .dig_out_nid = ALC883_DIGOUT_NID,
8881                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8882                 .channel_mode = alc883_3ST_2ch_modes,
8883                 .input_mux = &alc883_capture_source,
8884                 .unsol_event = alc883_acer_aspire_unsol_event,
8885                 .init_hook = alc883_acer_aspire_automute,
8886         },
8887         [ALC888_ACER_ASPIRE_4930G] = {
8888                 .mixers = { alc888_base_mixer,
8889                                 alc883_chmode_mixer },
8890                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
8891                                 alc888_acer_aspire_4930g_verbs },
8892                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8893                 .dac_nids = alc883_dac_nids,
8894                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
8895                 .adc_nids = alc883_adc_nids_rev,
8896                 .capsrc_nids = alc883_capsrc_nids_rev,
8897                 .dig_out_nid = ALC883_DIGOUT_NID,
8898                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8899                 .channel_mode = alc883_3ST_6ch_modes,
8900                 .need_dac_fix = 1,
8901                 .num_mux_defs =
8902                         ARRAY_SIZE(alc888_2_capture_sources),
8903                 .input_mux = alc888_2_capture_sources,
8904                 .unsol_event = alc888_acer_aspire_4930g_unsol_event,
8905                 .init_hook = alc888_acer_aspire_4930g_automute,
8906         },
8907         [ALC883_MEDION] = {
8908                 .mixers = { alc883_fivestack_mixer,
8909                             alc883_chmode_mixer },
8910                 .init_verbs = { alc883_init_verbs,
8911                                 alc883_medion_eapd_verbs },
8912                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8913                 .dac_nids = alc883_dac_nids,
8914                 .adc_nids = alc883_adc_nids_alt,
8915                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8916                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8917                 .channel_mode = alc883_sixstack_modes,
8918                 .input_mux = &alc883_capture_source,
8919         },
8920         [ALC883_MEDION_MD2] = {
8921                 .mixers = { alc883_medion_md2_mixer},
8922                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
8923                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8924                 .dac_nids = alc883_dac_nids,
8925                 .dig_out_nid = ALC883_DIGOUT_NID,
8926                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8927                 .channel_mode = alc883_3ST_2ch_modes,
8928                 .input_mux = &alc883_capture_source,
8929                 .unsol_event = alc883_medion_md2_unsol_event,
8930                 .init_hook = alc883_medion_md2_automute,
8931         },
8932         [ALC883_LAPTOP_EAPD] = {
8933                 .mixers = { alc883_base_mixer },
8934                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
8935                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8936                 .dac_nids = alc883_dac_nids,
8937                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8938                 .channel_mode = alc883_3ST_2ch_modes,
8939                 .input_mux = &alc883_capture_source,
8940         },
8941         [ALC883_CLEVO_M720] = {
8942                 .mixers = { alc883_clevo_m720_mixer },
8943                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
8944                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8945                 .dac_nids = alc883_dac_nids,
8946                 .dig_out_nid = ALC883_DIGOUT_NID,
8947                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8948                 .channel_mode = alc883_3ST_2ch_modes,
8949                 .input_mux = &alc883_capture_source,
8950                 .unsol_event = alc883_clevo_m720_unsol_event,
8951                 .init_hook = alc883_clevo_m720_automute,
8952         },
8953         [ALC883_LENOVO_101E_2ch] = {
8954                 .mixers = { alc883_lenovo_101e_2ch_mixer},
8955                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
8956                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8957                 .dac_nids = alc883_dac_nids,
8958                 .adc_nids = alc883_adc_nids_alt,
8959                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8960                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8961                 .channel_mode = alc883_3ST_2ch_modes,
8962                 .input_mux = &alc883_lenovo_101e_capture_source,
8963                 .unsol_event = alc883_lenovo_101e_unsol_event,
8964                 .init_hook = alc883_lenovo_101e_all_automute,
8965         },
8966         [ALC883_LENOVO_NB0763] = {
8967                 .mixers = { alc883_lenovo_nb0763_mixer },
8968                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
8969                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8970                 .dac_nids = alc883_dac_nids,
8971                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8972                 .channel_mode = alc883_3ST_2ch_modes,
8973                 .need_dac_fix = 1,
8974                 .input_mux = &alc883_lenovo_nb0763_capture_source,
8975                 .unsol_event = alc883_medion_md2_unsol_event,
8976                 .init_hook = alc883_medion_md2_automute,
8977         },
8978         [ALC888_LENOVO_MS7195_DIG] = {
8979                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8980                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
8981                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8982                 .dac_nids = alc883_dac_nids,
8983                 .dig_out_nid = ALC883_DIGOUT_NID,
8984                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8985                 .channel_mode = alc883_3ST_6ch_modes,
8986                 .need_dac_fix = 1,
8987                 .input_mux = &alc883_capture_source,
8988                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
8989                 .init_hook = alc888_lenovo_ms7195_front_automute,
8990         },
8991         [ALC883_HAIER_W66] = {
8992                 .mixers = { alc883_tagra_2ch_mixer},
8993                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
8994                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8995                 .dac_nids = alc883_dac_nids,
8996                 .dig_out_nid = ALC883_DIGOUT_NID,
8997                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8998                 .channel_mode = alc883_3ST_2ch_modes,
8999                 .input_mux = &alc883_capture_source,
9000                 .unsol_event = alc883_haier_w66_unsol_event,
9001                 .init_hook = alc883_haier_w66_automute,
9002         },
9003         [ALC888_3ST_HP] = {
9004                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9005                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
9006                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9007                 .dac_nids = alc883_dac_nids,
9008                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
9009                 .channel_mode = alc888_3st_hp_modes,
9010                 .need_dac_fix = 1,
9011                 .input_mux = &alc883_capture_source,
9012                 .unsol_event = alc888_3st_hp_unsol_event,
9013                 .init_hook = alc888_3st_hp_front_automute,
9014         },
9015         [ALC888_6ST_DELL] = {
9016                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9017                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
9018                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9019                 .dac_nids = alc883_dac_nids,
9020                 .dig_out_nid = ALC883_DIGOUT_NID,
9021                 .dig_in_nid = ALC883_DIGIN_NID,
9022                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9023                 .channel_mode = alc883_sixstack_modes,
9024                 .input_mux = &alc883_capture_source,
9025                 .unsol_event = alc888_6st_dell_unsol_event,
9026                 .init_hook = alc888_6st_dell_front_automute,
9027         },
9028         [ALC883_MITAC] = {
9029                 .mixers = { alc883_mitac_mixer },
9030                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
9031                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9032                 .dac_nids = alc883_dac_nids,
9033                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9034                 .channel_mode = alc883_3ST_2ch_modes,
9035                 .input_mux = &alc883_capture_source,
9036                 .unsol_event = alc883_mitac_unsol_event,
9037                 .init_hook = alc883_mitac_automute,
9038         },
9039         [ALC883_FUJITSU_PI2515] = {
9040                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
9041                 .init_verbs = { alc883_init_verbs,
9042                                 alc883_2ch_fujitsu_pi2515_verbs},
9043                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9044                 .dac_nids = alc883_dac_nids,
9045                 .dig_out_nid = ALC883_DIGOUT_NID,
9046                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9047                 .channel_mode = alc883_3ST_2ch_modes,
9048                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9049                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
9050                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
9051         },
9052         [ALC888_FUJITSU_XA3530] = {
9053                 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
9054                 .init_verbs = { alc883_init_verbs,
9055                         alc888_fujitsu_xa3530_verbs },
9056                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9057                 .dac_nids = alc883_dac_nids,
9058                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9059                 .adc_nids = alc883_adc_nids_rev,
9060                 .capsrc_nids = alc883_capsrc_nids_rev,
9061                 .dig_out_nid = ALC883_DIGOUT_NID,
9062                 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
9063                 .channel_mode = alc888_4ST_8ch_intel_modes,
9064                 .num_mux_defs =
9065                         ARRAY_SIZE(alc888_2_capture_sources),
9066                 .input_mux = alc888_2_capture_sources,
9067                 .unsol_event = alc888_fujitsu_xa3530_unsol_event,
9068                 .init_hook = alc888_fujitsu_xa3530_automute,
9069         },
9070         [ALC888_LENOVO_SKY] = {
9071                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
9072                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
9073                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9074                 .dac_nids = alc883_dac_nids,
9075                 .dig_out_nid = ALC883_DIGOUT_NID,
9076                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9077                 .channel_mode = alc883_sixstack_modes,
9078                 .need_dac_fix = 1,
9079                 .input_mux = &alc883_lenovo_sky_capture_source,
9080                 .unsol_event = alc883_lenovo_sky_unsol_event,
9081                 .init_hook = alc888_lenovo_sky_front_automute,
9082         },
9083         [ALC888_ASUS_M90V] = {
9084                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9085                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
9086                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9087                 .dac_nids = alc883_dac_nids,
9088                 .dig_out_nid = ALC883_DIGOUT_NID,
9089                 .dig_in_nid = ALC883_DIGIN_NID,
9090                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9091                 .channel_mode = alc883_3ST_6ch_modes,
9092                 .need_dac_fix = 1,
9093                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9094                 .unsol_event = alc883_mode2_unsol_event,
9095                 .init_hook = alc883_mode2_inithook,
9096         },
9097         [ALC888_ASUS_EEE1601] = {
9098                 .mixers = { alc883_asus_eee1601_mixer },
9099                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
9100                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
9101                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9102                 .dac_nids = alc883_dac_nids,
9103                 .dig_out_nid = ALC883_DIGOUT_NID,
9104                 .dig_in_nid = ALC883_DIGIN_NID,
9105                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9106                 .channel_mode = alc883_3ST_2ch_modes,
9107                 .need_dac_fix = 1,
9108                 .input_mux = &alc883_asus_eee1601_capture_source,
9109                 .unsol_event = alc883_eee1601_unsol_event,
9110                 .init_hook = alc883_eee1601_inithook,
9111         },
9112         [ALC1200_ASUS_P5Q] = {
9113                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9114                 .init_verbs = { alc883_init_verbs },
9115                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9116                 .dac_nids = alc883_dac_nids,
9117                 .dig_out_nid = ALC1200_DIGOUT_NID,
9118                 .dig_in_nid = ALC883_DIGIN_NID,
9119                 .slave_dig_outs = alc1200_slave_dig_outs,
9120                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9121                 .channel_mode = alc883_sixstack_modes,
9122                 .input_mux = &alc883_capture_source,
9123         },
9124 };
9125
9126
9127 /*
9128  * BIOS auto configuration
9129  */
9130 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
9131                                               hda_nid_t nid, int pin_type,
9132                                               int dac_idx)
9133 {
9134         /* set as output */
9135         struct alc_spec *spec = codec->spec;
9136         int idx;
9137
9138         alc_set_pin_output(codec, nid, pin_type);
9139         if (spec->multiout.dac_nids[dac_idx] == 0x25)
9140                 idx = 4;
9141         else
9142                 idx = spec->multiout.dac_nids[dac_idx] - 2;
9143         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
9144
9145 }
9146
9147 static void alc883_auto_init_multi_out(struct hda_codec *codec)
9148 {
9149         struct alc_spec *spec = codec->spec;
9150         int i;
9151
9152         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
9153         for (i = 0; i <= HDA_SIDE; i++) {
9154                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
9155                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
9156                 if (nid)
9157                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
9158                                                           i);
9159         }
9160 }
9161
9162 static void alc883_auto_init_hp_out(struct hda_codec *codec)
9163 {
9164         struct alc_spec *spec = codec->spec;
9165         hda_nid_t pin;
9166
9167         pin = spec->autocfg.hp_pins[0];
9168         if (pin) /* connect to front */
9169                 /* use dac 0 */
9170                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
9171         pin = spec->autocfg.speaker_pins[0];
9172         if (pin)
9173                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
9174 }
9175
9176 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
9177 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
9178
9179 static void alc883_auto_init_analog_input(struct hda_codec *codec)
9180 {
9181         struct alc_spec *spec = codec->spec;
9182         int i;
9183
9184         for (i = 0; i < AUTO_PIN_LAST; i++) {
9185                 hda_nid_t nid = spec->autocfg.input_pins[i];
9186                 if (alc883_is_input_pin(nid)) {
9187                         alc_set_input_pin(codec, nid, i);
9188                         if (nid != ALC883_PIN_CD_NID &&
9189                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
9190                                 snd_hda_codec_write(codec, nid, 0,
9191                                                     AC_VERB_SET_AMP_GAIN_MUTE,
9192                                                     AMP_OUT_MUTE);
9193                 }
9194         }
9195 }
9196
9197 #define alc883_auto_init_input_src      alc882_auto_init_input_src
9198
9199 /* almost identical with ALC880 parser... */
9200 static int alc883_parse_auto_config(struct hda_codec *codec)
9201 {
9202         struct alc_spec *spec = codec->spec;
9203         int err = alc880_parse_auto_config(codec);
9204         struct auto_pin_cfg *cfg = &spec->autocfg;
9205         int i;
9206
9207         if (err < 0)
9208                 return err;
9209         else if (!err)
9210                 return 0; /* no config found */
9211
9212         err = alc_auto_add_mic_boost(codec);
9213         if (err < 0)
9214                 return err;
9215
9216         /* hack - override the init verbs */
9217         spec->init_verbs[0] = alc883_auto_init_verbs;
9218
9219         /* setup input_mux for ALC889 */
9220         if (codec->vendor_id == 0x10ec0889) {
9221                 /* digital-mic input pin is excluded in alc880_auto_create..()
9222                  * because it's under 0x18
9223                  */
9224                 if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
9225                     cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
9226                         struct hda_input_mux *imux = &spec->private_imux[0];
9227                         for (i = 1; i < 3; i++)
9228                                 memcpy(&spec->private_imux[i],
9229                                        &spec->private_imux[0],
9230                                        sizeof(spec->private_imux[0]));
9231                         imux->items[imux->num_items].label = "Int DMic";
9232                         imux->items[imux->num_items].index = 0x0b;
9233                         imux->num_items++;
9234                         spec->num_mux_defs = 3;
9235                         spec->input_mux = spec->private_imux;
9236                 }
9237         }
9238
9239         return 1; /* config found */
9240 }
9241
9242 /* additional initialization for auto-configuration model */
9243 static void alc883_auto_init(struct hda_codec *codec)
9244 {
9245         struct alc_spec *spec = codec->spec;
9246         alc883_auto_init_multi_out(codec);
9247         alc883_auto_init_hp_out(codec);
9248         alc883_auto_init_analog_input(codec);
9249         alc883_auto_init_input_src(codec);
9250         if (spec->unsol_event)
9251                 alc_inithook(codec);
9252 }
9253
9254 static int patch_alc883(struct hda_codec *codec)
9255 {
9256         struct alc_spec *spec;
9257         int err, board_config;
9258
9259         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9260         if (spec == NULL)
9261                 return -ENOMEM;
9262
9263         codec->spec = spec;
9264
9265         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
9266
9267         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
9268                                                   alc883_models,
9269                                                   alc883_cfg_tbl);
9270         if (board_config < 0) {
9271                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
9272                        "trying auto-probe from BIOS...\n");
9273                 board_config = ALC883_AUTO;
9274         }
9275
9276         if (board_config == ALC883_AUTO) {
9277                 /* automatic parse from the BIOS config */
9278                 err = alc883_parse_auto_config(codec);
9279                 if (err < 0) {
9280                         alc_free(codec);
9281                         return err;
9282                 } else if (!err) {
9283                         printk(KERN_INFO
9284                                "hda_codec: Cannot set up configuration "
9285                                "from BIOS.  Using base mode...\n");
9286                         board_config = ALC883_3ST_2ch_DIG;
9287                 }
9288         }
9289
9290         err = snd_hda_attach_beep_device(codec, 0x1);
9291         if (err < 0) {
9292                 alc_free(codec);
9293                 return err;
9294         }
9295
9296         if (board_config != ALC883_AUTO)
9297                 setup_preset(spec, &alc883_presets[board_config]);
9298
9299         switch (codec->vendor_id) {
9300         case 0x10ec0888:
9301                 if (codec->revision_id == 0x100101) {
9302                         spec->stream_name_analog = "ALC1200 Analog";
9303                         spec->stream_name_digital = "ALC1200 Digital";
9304                 } else {
9305                         spec->stream_name_analog = "ALC888 Analog";
9306                         spec->stream_name_digital = "ALC888 Digital";
9307                 }
9308                 if (!spec->num_adc_nids) {
9309                         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9310                         spec->adc_nids = alc883_adc_nids;
9311                 }
9312                 if (!spec->capsrc_nids)
9313                         spec->capsrc_nids = alc883_capsrc_nids;
9314                 spec->capture_style = CAPT_MIX; /* matrix-style capture */
9315                 break;
9316         case 0x10ec0889:
9317                 spec->stream_name_analog = "ALC889 Analog";
9318                 spec->stream_name_digital = "ALC889 Digital";
9319                 if (!spec->num_adc_nids) {
9320                         spec->num_adc_nids = ARRAY_SIZE(alc889_adc_nids);
9321                         spec->adc_nids = alc889_adc_nids;
9322                 }
9323                 if (!spec->capsrc_nids)
9324                         spec->capsrc_nids = alc889_capsrc_nids;
9325                 spec->capture_style = CAPT_1MUX_MIX; /* 1mux/Nmix-style
9326                                                         capture */
9327                 break;
9328         default:
9329                 spec->stream_name_analog = "ALC883 Analog";
9330                 spec->stream_name_digital = "ALC883 Digital";
9331                 if (!spec->num_adc_nids) {
9332                         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9333                         spec->adc_nids = alc883_adc_nids;
9334                 }
9335                 if (!spec->capsrc_nids)
9336                         spec->capsrc_nids = alc883_capsrc_nids;
9337                 spec->capture_style = CAPT_MIX; /* matrix-style capture */
9338                 break;
9339         }
9340
9341         spec->stream_analog_playback = &alc883_pcm_analog_playback;
9342         spec->stream_analog_capture = &alc883_pcm_analog_capture;
9343         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
9344
9345         spec->stream_digital_playback = &alc883_pcm_digital_playback;
9346         spec->stream_digital_capture = &alc883_pcm_digital_capture;
9347
9348         if (!spec->cap_mixer)
9349                 set_capture_mixer(spec);
9350         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
9351
9352         spec->vmaster_nid = 0x0c;
9353
9354         codec->patch_ops = alc_patch_ops;
9355         if (board_config == ALC883_AUTO)
9356                 spec->init_hook = alc883_auto_init;
9357
9358 #ifdef CONFIG_SND_HDA_POWER_SAVE
9359         if (!spec->loopback.amplist)
9360                 spec->loopback.amplist = alc883_loopbacks;
9361 #endif
9362         codec->proc_widget_hook = print_realtek_coef;
9363
9364         return 0;
9365 }
9366
9367 /*
9368  * ALC262 support
9369  */
9370
9371 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
9372 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
9373
9374 #define alc262_dac_nids         alc260_dac_nids
9375 #define alc262_adc_nids         alc882_adc_nids
9376 #define alc262_adc_nids_alt     alc882_adc_nids_alt
9377 #define alc262_capsrc_nids      alc882_capsrc_nids
9378 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
9379
9380 #define alc262_modes            alc260_modes
9381 #define alc262_capture_source   alc882_capture_source
9382
9383 static hda_nid_t alc262_dmic_adc_nids[1] = {
9384         /* ADC0 */
9385         0x09
9386 };
9387
9388 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
9389
9390 static struct snd_kcontrol_new alc262_base_mixer[] = {
9391         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9392         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9393         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9394         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9395         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9396         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9397         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9398         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9399         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9400         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9401         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9402         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9403         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
9404         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9405         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9406         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
9407         { } /* end */
9408 };
9409
9410 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
9411         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9412         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9413         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9414         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9415         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9416         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9417         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9418         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9419         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9420         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9421         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9422         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9423         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
9424         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9425         { } /* end */
9426 };
9427
9428 /* update HP, line and mono-out pins according to the master switch */
9429 static void alc262_hp_master_update(struct hda_codec *codec)
9430 {
9431         struct alc_spec *spec = codec->spec;
9432         int val = spec->master_sw;
9433
9434         /* HP & line-out */
9435         snd_hda_codec_write_cache(codec, 0x1b, 0,
9436                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9437                                   val ? PIN_HP : 0);
9438         snd_hda_codec_write_cache(codec, 0x15, 0,
9439                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9440                                   val ? PIN_HP : 0);
9441         /* mono (speaker) depending on the HP jack sense */
9442         val = val && !spec->jack_present;
9443         snd_hda_codec_write_cache(codec, 0x16, 0,
9444                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9445                                   val ? PIN_OUT : 0);
9446 }
9447
9448 static void alc262_hp_bpc_automute(struct hda_codec *codec)
9449 {
9450         struct alc_spec *spec = codec->spec;
9451         unsigned int presence;
9452         presence = snd_hda_codec_read(codec, 0x1b, 0,
9453                                       AC_VERB_GET_PIN_SENSE, 0);
9454         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9455         alc262_hp_master_update(codec);
9456 }
9457
9458 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
9459 {
9460         if ((res >> 26) != ALC880_HP_EVENT)
9461                 return;
9462         alc262_hp_bpc_automute(codec);
9463 }
9464
9465 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
9466 {
9467         struct alc_spec *spec = codec->spec;
9468         unsigned int presence;
9469         presence = snd_hda_codec_read(codec, 0x15, 0,
9470                                       AC_VERB_GET_PIN_SENSE, 0);
9471         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9472         alc262_hp_master_update(codec);
9473 }
9474
9475 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
9476                                            unsigned int res)
9477 {
9478         if ((res >> 26) != ALC880_HP_EVENT)
9479                 return;
9480         alc262_hp_wildwest_automute(codec);
9481 }
9482
9483 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
9484                                    struct snd_ctl_elem_value *ucontrol)
9485 {
9486         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9487         struct alc_spec *spec = codec->spec;
9488         *ucontrol->value.integer.value = spec->master_sw;
9489         return 0;
9490 }
9491
9492 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
9493                                    struct snd_ctl_elem_value *ucontrol)
9494 {
9495         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9496         struct alc_spec *spec = codec->spec;
9497         int val = !!*ucontrol->value.integer.value;
9498
9499         if (val == spec->master_sw)
9500                 return 0;
9501         spec->master_sw = val;
9502         alc262_hp_master_update(codec);
9503         return 1;
9504 }
9505
9506 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
9507         {
9508                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9509                 .name = "Master Playback Switch",
9510                 .info = snd_ctl_boolean_mono_info,
9511                 .get = alc262_hp_master_sw_get,
9512                 .put = alc262_hp_master_sw_put,
9513         },
9514         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9515         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9516         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9517         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9518                               HDA_OUTPUT),
9519         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9520                             HDA_OUTPUT),
9521         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9522         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9523         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9524         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9525         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9526         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9527         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9528         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9529         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9530         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9531         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
9532         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
9533         { } /* end */
9534 };
9535
9536 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
9537         {
9538                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9539                 .name = "Master Playback Switch",
9540                 .info = snd_ctl_boolean_mono_info,
9541                 .get = alc262_hp_master_sw_get,
9542                 .put = alc262_hp_master_sw_put,
9543         },
9544         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9545         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9546         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9547         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9548         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9549                               HDA_OUTPUT),
9550         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9551                             HDA_OUTPUT),
9552         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
9553         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
9554         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
9555         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9556         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9557         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9558         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9559         { } /* end */
9560 };
9561
9562 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
9563         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9564         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9565         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
9566         { } /* end */
9567 };
9568
9569 /* mute/unmute internal speaker according to the hp jack and mute state */
9570 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
9571 {
9572         struct alc_spec *spec = codec->spec;
9573
9574         if (force || !spec->sense_updated) {
9575                 unsigned int present;
9576                 present = snd_hda_codec_read(codec, 0x15, 0,
9577                                              AC_VERB_GET_PIN_SENSE, 0);
9578                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9579                 spec->sense_updated = 1;
9580         }
9581         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
9582                                  spec->jack_present ? HDA_AMP_MUTE : 0);
9583 }
9584
9585 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
9586                                         unsigned int res)
9587 {
9588         if ((res >> 26) != ALC880_HP_EVENT)
9589                 return;
9590         alc262_hp_t5735_automute(codec, 1);
9591 }
9592
9593 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
9594 {
9595         alc262_hp_t5735_automute(codec, 1);
9596 }
9597
9598 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
9599         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9600         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9601         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9602         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9603         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9604         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9605         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9606         { } /* end */
9607 };
9608
9609 static struct hda_verb alc262_hp_t5735_verbs[] = {
9610         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9611         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9612
9613         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9614         { }
9615 };
9616
9617 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
9618         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9619         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9620         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
9621         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
9622         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9623         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9624         { } /* end */
9625 };
9626
9627 static struct hda_verb alc262_hp_rp5700_verbs[] = {
9628         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9629         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9630         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9631         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9632         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9633         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9634         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9635         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9636         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9637         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9638         {}
9639 };
9640
9641 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
9642         .num_items = 1,
9643         .items = {
9644                 { "Line", 0x1 },
9645         },
9646 };
9647
9648 /* bind hp and internal speaker mute (with plug check) */
9649 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
9650                                      struct snd_ctl_elem_value *ucontrol)
9651 {
9652         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9653         long *valp = ucontrol->value.integer.value;
9654         int change;
9655
9656         /* change hp mute */
9657         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
9658                                           HDA_AMP_MUTE,
9659                                           valp[0] ? 0 : HDA_AMP_MUTE);
9660         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
9661                                            HDA_AMP_MUTE,
9662                                            valp[1] ? 0 : HDA_AMP_MUTE);
9663         if (change) {
9664                 /* change speaker according to HP jack state */
9665                 struct alc_spec *spec = codec->spec;
9666                 unsigned int mute;
9667                 if (spec->jack_present)
9668                         mute = HDA_AMP_MUTE;
9669                 else
9670                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
9671                                                       HDA_OUTPUT, 0);
9672                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9673                                          HDA_AMP_MUTE, mute);
9674         }
9675         return change;
9676 }
9677
9678 static struct snd_kcontrol_new alc262_sony_mixer[] = {
9679         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9680         {
9681                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9682                 .name = "Master Playback Switch",
9683                 .info = snd_hda_mixer_amp_switch_info,
9684                 .get = snd_hda_mixer_amp_switch_get,
9685                 .put = alc262_sony_master_sw_put,
9686                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9687         },
9688         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9689         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9690         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9691         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9692         { } /* end */
9693 };
9694
9695 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
9696         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9697         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9698         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9699         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9700         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9701         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9702         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9703         { } /* end */
9704 };
9705
9706 static struct snd_kcontrol_new alc262_tyan_mixer[] = {
9707         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9708         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
9709         HDA_CODEC_VOLUME("Aux Playback Volume", 0x0b, 0x06, HDA_INPUT),
9710         HDA_CODEC_MUTE("Aux Playback Switch", 0x0b, 0x06, HDA_INPUT),
9711         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9712         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9713         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9714         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9715         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9716         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9717         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9718         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9719         { } /* end */
9720 };
9721
9722 static struct hda_verb alc262_tyan_verbs[] = {
9723         /* Headphone automute */
9724         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9725         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9726         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9727
9728         /* P11 AUX_IN, white 4-pin connector */
9729         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9730         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_1, 0xe1},
9731         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_2, 0x93},
9732         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, 0x19},
9733
9734         {}
9735 };
9736
9737 /* unsolicited event for HP jack sensing */
9738 static void alc262_tyan_automute(struct hda_codec *codec)
9739 {
9740         unsigned int mute;
9741         unsigned int present;
9742
9743         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9744         present = snd_hda_codec_read(codec, 0x1b, 0,
9745                                      AC_VERB_GET_PIN_SENSE, 0);
9746         present = (present & 0x80000000) != 0;
9747         if (present) {
9748                 /* mute line output on ATX panel */
9749                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9750                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9751         } else {
9752                 /* unmute line output if necessary */
9753                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9754                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9755                                          HDA_AMP_MUTE, mute);
9756         }
9757 }
9758
9759 static void alc262_tyan_unsol_event(struct hda_codec *codec,
9760                                        unsigned int res)
9761 {
9762         if ((res >> 26) != ALC880_HP_EVENT)
9763                 return;
9764         alc262_tyan_automute(codec);
9765 }
9766
9767 #define alc262_capture_mixer            alc882_capture_mixer
9768 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
9769
9770 /*
9771  * generic initialization of ADC, input mixers and output mixers
9772  */
9773 static struct hda_verb alc262_init_verbs[] = {
9774         /*
9775          * Unmute ADC0-2 and set the default input to mic-in
9776          */
9777         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9778         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9779         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9780         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9781         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9782         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9783
9784         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9785          * mixer widget
9786          * Note: PASD motherboards uses the Line In 2 as the input for
9787          * front panel mic (mic 2)
9788          */
9789         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9790         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9791         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9792         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9793         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9794         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9795
9796         /*
9797          * Set up output mixers (0x0c - 0x0e)
9798          */
9799         /* set vol=0 to output mixers */
9800         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9801         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9802         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9803         /* set up input amps for analog loopback */
9804         /* Amp Indices: DAC = 0, mixer = 1 */
9805         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9806         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9807         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9808         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9809         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9810         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9811
9812         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9813         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9814         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9815         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9816         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9817         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9818
9819         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9820         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9821         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9822         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9823         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9824
9825         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9826         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9827
9828         /* FIXME: use matrix-type input source selection */
9829         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9830         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9831         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9832         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9833         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9834         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9835         /* Input mixer2 */
9836         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9837         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9838         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9839         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9840         /* Input mixer3 */
9841         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9842         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9843         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9844         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9845
9846         { }
9847 };
9848
9849 static struct hda_verb alc262_eapd_verbs[] = {
9850         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9851         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9852         { }
9853 };
9854
9855 static struct hda_verb alc262_hippo_unsol_verbs[] = {
9856         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9857         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9858         {}
9859 };
9860
9861 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
9862         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9863         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9864         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9865
9866         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9867         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9868         {}
9869 };
9870
9871 static struct hda_verb alc262_sony_unsol_verbs[] = {
9872         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9873         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9874         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
9875
9876         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9877         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9878         {}
9879 };
9880
9881 static struct hda_input_mux alc262_dmic_capture_source = {
9882         .num_items = 2,
9883         .items = {
9884                 { "Int DMic", 0x9 },
9885                 { "Mic", 0x0 },
9886         },
9887 };
9888
9889 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
9890         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9891         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9892         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9893         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9894         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9895         { } /* end */
9896 };
9897
9898 static struct hda_verb alc262_toshiba_s06_verbs[] = {
9899         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9900         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9901         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9902         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9903         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
9904         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9905         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
9906         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9907         {}
9908 };
9909
9910 static void alc262_dmic_automute(struct hda_codec *codec)
9911 {
9912         unsigned int present;
9913
9914         present = snd_hda_codec_read(codec, 0x18, 0,
9915                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9916         snd_hda_codec_write(codec, 0x22, 0,
9917                                 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x09);
9918 }
9919
9920 /* toggle speaker-output according to the hp-jack state */
9921 static void alc262_toshiba_s06_speaker_automute(struct hda_codec *codec)
9922 {
9923         unsigned int present;
9924         unsigned char bits;
9925
9926         present = snd_hda_codec_read(codec, 0x15, 0,
9927                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9928         bits = present ? 0 : PIN_OUT;
9929         snd_hda_codec_write(codec, 0x14, 0,
9930                                         AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
9931 }
9932
9933
9934
9935 /* unsolicited event for HP jack sensing */
9936 static void alc262_toshiba_s06_unsol_event(struct hda_codec *codec,
9937                                        unsigned int res)
9938 {
9939         if ((res >> 26) == ALC880_HP_EVENT)
9940                 alc262_toshiba_s06_speaker_automute(codec);
9941         if ((res >> 26) == ALC880_MIC_EVENT)
9942                 alc262_dmic_automute(codec);
9943
9944 }
9945
9946 static void alc262_toshiba_s06_init_hook(struct hda_codec *codec)
9947 {
9948         alc262_toshiba_s06_speaker_automute(codec);
9949         alc262_dmic_automute(codec);
9950 }
9951
9952 /* mute/unmute internal speaker according to the hp jack and mute state */
9953 static void alc262_hippo_automute(struct hda_codec *codec)
9954 {
9955         struct alc_spec *spec = codec->spec;
9956         unsigned int mute;
9957         unsigned int present;
9958
9959         /* need to execute and sync at first */
9960         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9961         present = snd_hda_codec_read(codec, 0x15, 0,
9962                                      AC_VERB_GET_PIN_SENSE, 0);
9963         spec->jack_present = (present & 0x80000000) != 0;
9964         if (spec->jack_present) {
9965                 /* mute internal speaker */
9966                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9967                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9968         } else {
9969                 /* unmute internal speaker if necessary */
9970                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
9971                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9972                                          HDA_AMP_MUTE, mute);
9973         }
9974 }
9975
9976 /* unsolicited event for HP jack sensing */
9977 static void alc262_hippo_unsol_event(struct hda_codec *codec,
9978                                        unsigned int res)
9979 {
9980         if ((res >> 26) != ALC880_HP_EVENT)
9981                 return;
9982         alc262_hippo_automute(codec);
9983 }
9984
9985 static void alc262_hippo1_automute(struct hda_codec *codec)
9986 {
9987         unsigned int mute;
9988         unsigned int present;
9989
9990         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9991         present = snd_hda_codec_read(codec, 0x1b, 0,
9992                                      AC_VERB_GET_PIN_SENSE, 0);
9993         present = (present & 0x80000000) != 0;
9994         if (present) {
9995                 /* mute internal speaker */
9996                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9997                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9998         } else {
9999                 /* unmute internal speaker if necessary */
10000                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
10001                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10002                                          HDA_AMP_MUTE, mute);
10003         }
10004 }
10005
10006 /* unsolicited event for HP jack sensing */
10007 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
10008                                        unsigned int res)
10009 {
10010         if ((res >> 26) != ALC880_HP_EVENT)
10011                 return;
10012         alc262_hippo1_automute(codec);
10013 }
10014
10015 /*
10016  * nec model
10017  *  0x15 = headphone
10018  *  0x16 = internal speaker
10019  *  0x18 = external mic
10020  */
10021
10022 static struct snd_kcontrol_new alc262_nec_mixer[] = {
10023         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
10024         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
10025
10026         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10027         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10028         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10029
10030         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10031         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10032         { } /* end */
10033 };
10034
10035 static struct hda_verb alc262_nec_verbs[] = {
10036         /* Unmute Speaker */
10037         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10038
10039         /* Headphone */
10040         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10041         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10042
10043         /* External mic to headphone */
10044         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10045         /* External mic to speaker */
10046         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10047         {}
10048 };
10049
10050 /*
10051  * fujitsu model
10052  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
10053  *  0x1b = port replicator headphone out
10054  */
10055
10056 #define ALC_HP_EVENT    0x37
10057
10058 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
10059         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10060         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10061         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10062         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10063         {}
10064 };
10065
10066 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
10067         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10068         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10069         {}
10070 };
10071
10072 static struct hda_input_mux alc262_fujitsu_capture_source = {
10073         .num_items = 3,
10074         .items = {
10075                 { "Mic", 0x0 },
10076                 { "Int Mic", 0x1 },
10077                 { "CD", 0x4 },
10078         },
10079 };
10080
10081 static struct hda_input_mux alc262_HP_capture_source = {
10082         .num_items = 5,
10083         .items = {
10084                 { "Mic", 0x0 },
10085                 { "Front Mic", 0x1 },
10086                 { "Line", 0x2 },
10087                 { "CD", 0x4 },
10088                 { "AUX IN", 0x6 },
10089         },
10090 };
10091
10092 static struct hda_input_mux alc262_HP_D7000_capture_source = {
10093         .num_items = 4,
10094         .items = {
10095                 { "Mic", 0x0 },
10096                 { "Front Mic", 0x2 },
10097                 { "Line", 0x1 },
10098                 { "CD", 0x4 },
10099         },
10100 };
10101
10102 /* mute/unmute internal speaker according to the hp jacks and mute state */
10103 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
10104 {
10105         struct alc_spec *spec = codec->spec;
10106         unsigned int mute;
10107
10108         if (force || !spec->sense_updated) {
10109                 unsigned int present;
10110                 /* need to execute and sync at first */
10111                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
10112                 /* check laptop HP jack */
10113                 present = snd_hda_codec_read(codec, 0x14, 0,
10114                                              AC_VERB_GET_PIN_SENSE, 0);
10115                 /* need to execute and sync at first */
10116                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10117                 /* check docking HP jack */
10118                 present |= snd_hda_codec_read(codec, 0x1b, 0,
10119                                               AC_VERB_GET_PIN_SENSE, 0);
10120                 if (present & AC_PINSENSE_PRESENCE)
10121                         spec->jack_present = 1;
10122                 else
10123                         spec->jack_present = 0;
10124                 spec->sense_updated = 1;
10125         }
10126         /* unmute internal speaker only if both HPs are unplugged and
10127          * master switch is on
10128          */
10129         if (spec->jack_present)
10130                 mute = HDA_AMP_MUTE;
10131         else
10132                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10133         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10134                                  HDA_AMP_MUTE, mute);
10135 }
10136
10137 /* unsolicited event for HP jack sensing */
10138 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
10139                                        unsigned int res)
10140 {
10141         if ((res >> 26) != ALC_HP_EVENT)
10142                 return;
10143         alc262_fujitsu_automute(codec, 1);
10144 }
10145
10146 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
10147 {
10148         alc262_fujitsu_automute(codec, 1);
10149 }
10150
10151 /* bind volumes of both NID 0x0c and 0x0d */
10152 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
10153         .ops = &snd_hda_bind_vol,
10154         .values = {
10155                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
10156                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
10157                 0
10158         },
10159 };
10160
10161 /* mute/unmute internal speaker according to the hp jack and mute state */
10162 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
10163 {
10164         struct alc_spec *spec = codec->spec;
10165         unsigned int mute;
10166
10167         if (force || !spec->sense_updated) {
10168                 unsigned int present_int_hp;
10169                 /* need to execute and sync at first */
10170                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10171                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
10172                                         AC_VERB_GET_PIN_SENSE, 0);
10173                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
10174                 spec->sense_updated = 1;
10175         }
10176         if (spec->jack_present) {
10177                 /* mute internal speaker */
10178                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10179                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
10180                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
10181                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
10182         } else {
10183                 /* unmute internal speaker if necessary */
10184                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
10185                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10186                                          HDA_AMP_MUTE, mute);
10187                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
10188                                          HDA_AMP_MUTE, mute);
10189         }
10190 }
10191
10192 /* unsolicited event for HP jack sensing */
10193 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
10194                                        unsigned int res)
10195 {
10196         if ((res >> 26) != ALC_HP_EVENT)
10197                 return;
10198         alc262_lenovo_3000_automute(codec, 1);
10199 }
10200
10201 /* bind hp and internal speaker mute (with plug check) */
10202 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
10203                                          struct snd_ctl_elem_value *ucontrol)
10204 {
10205         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10206         long *valp = ucontrol->value.integer.value;
10207         int change;
10208
10209         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10210                                                  HDA_AMP_MUTE,
10211                                                  valp ? 0 : HDA_AMP_MUTE);
10212         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
10213                                                  HDA_AMP_MUTE,
10214                                                  valp ? 0 : HDA_AMP_MUTE);
10215
10216         if (change)
10217                 alc262_fujitsu_automute(codec, 0);
10218         return change;
10219 }
10220
10221 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
10222         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10223         {
10224                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10225                 .name = "Master Playback Switch",
10226                 .info = snd_hda_mixer_amp_switch_info,
10227                 .get = snd_hda_mixer_amp_switch_get,
10228                 .put = alc262_fujitsu_master_sw_put,
10229                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10230         },
10231         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10232         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10233         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10234         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10235         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10236         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10237         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10238         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10239         { } /* end */
10240 };
10241
10242 /* bind hp and internal speaker mute (with plug check) */
10243 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
10244                                          struct snd_ctl_elem_value *ucontrol)
10245 {
10246         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10247         long *valp = ucontrol->value.integer.value;
10248         int change;
10249
10250         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
10251                                                  HDA_AMP_MUTE,
10252                                                  valp ? 0 : HDA_AMP_MUTE);
10253
10254         if (change)
10255                 alc262_lenovo_3000_automute(codec, 0);
10256         return change;
10257 }
10258
10259 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
10260         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10261         {
10262                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10263                 .name = "Master Playback Switch",
10264                 .info = snd_hda_mixer_amp_switch_info,
10265                 .get = snd_hda_mixer_amp_switch_get,
10266                 .put = alc262_lenovo_3000_master_sw_put,
10267                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
10268         },
10269         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10270         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10271         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10272         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10273         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10274         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10275         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10276         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10277         { } /* end */
10278 };
10279
10280 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
10281         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10282         {
10283                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10284                 .name = "Master Playback Switch",
10285                 .info = snd_hda_mixer_amp_switch_info,
10286                 .get = snd_hda_mixer_amp_switch_get,
10287                 .put = alc262_sony_master_sw_put,
10288                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
10289         },
10290         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10291         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10292         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10293         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10294         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10295         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10296         { } /* end */
10297 };
10298
10299 /* additional init verbs for Benq laptops */
10300 static struct hda_verb alc262_EAPD_verbs[] = {
10301         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10302         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
10303         {}
10304 };
10305
10306 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
10307         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10308         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10309
10310         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10311         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
10312         {}
10313 };
10314
10315 /* Samsung Q1 Ultra Vista model setup */
10316 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
10317         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10318         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10319         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10320         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10321         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
10322         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
10323         { } /* end */
10324 };
10325
10326 static struct hda_verb alc262_ultra_verbs[] = {
10327         /* output mixer */
10328         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10329         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10330         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10331         /* speaker */
10332         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10333         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10334         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10335         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10336         /* HP */
10337         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10338         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10339         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10340         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10341         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10342         /* internal mic */
10343         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10344         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10345         /* ADC, choose mic */
10346         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10347         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10348         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10349         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10350         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10351         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10352         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10353         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10354         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10355         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
10356         {}
10357 };
10358
10359 /* mute/unmute internal speaker according to the hp jack and mute state */
10360 static void alc262_ultra_automute(struct hda_codec *codec)
10361 {
10362         struct alc_spec *spec = codec->spec;
10363         unsigned int mute;
10364
10365         mute = 0;
10366         /* auto-mute only when HP is used as HP */
10367         if (!spec->cur_mux[0]) {
10368                 unsigned int present;
10369                 /* need to execute and sync at first */
10370                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10371                 present = snd_hda_codec_read(codec, 0x15, 0,
10372                                              AC_VERB_GET_PIN_SENSE, 0);
10373                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10374                 if (spec->jack_present)
10375                         mute = HDA_AMP_MUTE;
10376         }
10377         /* mute/unmute internal speaker */
10378         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10379                                  HDA_AMP_MUTE, mute);
10380         /* mute/unmute HP */
10381         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10382                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
10383 }
10384
10385 /* unsolicited event for HP jack sensing */
10386 static void alc262_ultra_unsol_event(struct hda_codec *codec,
10387                                        unsigned int res)
10388 {
10389         if ((res >> 26) != ALC880_HP_EVENT)
10390                 return;
10391         alc262_ultra_automute(codec);
10392 }
10393
10394 static struct hda_input_mux alc262_ultra_capture_source = {
10395         .num_items = 2,
10396         .items = {
10397                 { "Mic", 0x1 },
10398                 { "Headphone", 0x7 },
10399         },
10400 };
10401
10402 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
10403                                      struct snd_ctl_elem_value *ucontrol)
10404 {
10405         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10406         struct alc_spec *spec = codec->spec;
10407         int ret;
10408
10409         ret = alc_mux_enum_put(kcontrol, ucontrol);
10410         if (!ret)
10411                 return 0;
10412         /* reprogram the HP pin as mic or HP according to the input source */
10413         snd_hda_codec_write_cache(codec, 0x15, 0,
10414                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10415                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
10416         alc262_ultra_automute(codec); /* mute/unmute HP */
10417         return ret;
10418 }
10419
10420 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10421         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10422         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10423         {
10424                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10425                 .name = "Capture Source",
10426                 .info = alc_mux_enum_info,
10427                 .get = alc_mux_enum_get,
10428                 .put = alc262_ultra_mux_enum_put,
10429         },
10430         { } /* end */
10431 };
10432
10433 /* add playback controls from the parsed DAC table */
10434 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
10435                                              const struct auto_pin_cfg *cfg)
10436 {
10437         hda_nid_t nid;
10438         int err;
10439
10440         spec->multiout.num_dacs = 1;    /* only use one dac */
10441         spec->multiout.dac_nids = spec->private_dac_nids;
10442         spec->multiout.dac_nids[0] = 2;
10443
10444         nid = cfg->line_out_pins[0];
10445         if (nid) {
10446                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10447                                   "Front Playback Volume",
10448                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
10449                 if (err < 0)
10450                         return err;
10451                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10452                                   "Front Playback Switch",
10453                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
10454                 if (err < 0)
10455                         return err;
10456         }
10457
10458         nid = cfg->speaker_pins[0];
10459         if (nid) {
10460                 if (nid == 0x16) {
10461                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10462                                           "Speaker Playback Volume",
10463                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10464                                                               HDA_OUTPUT));
10465                         if (err < 0)
10466                                 return err;
10467                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10468                                           "Speaker Playback Switch",
10469                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10470                                                               HDA_OUTPUT));
10471                         if (err < 0)
10472                                 return err;
10473                 } else {
10474                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10475                                           "Speaker Playback Switch",
10476                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10477                                                               HDA_OUTPUT));
10478                         if (err < 0)
10479                                 return err;
10480                 }
10481         }
10482         nid = cfg->hp_pins[0];
10483         if (nid) {
10484                 /* spec->multiout.hp_nid = 2; */
10485                 if (nid == 0x16) {
10486                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10487                                           "Headphone Playback Volume",
10488                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10489                                                               HDA_OUTPUT));
10490                         if (err < 0)
10491                                 return err;
10492                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10493                                           "Headphone Playback Switch",
10494                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10495                                                               HDA_OUTPUT));
10496                         if (err < 0)
10497                                 return err;
10498                 } else {
10499                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10500                                           "Headphone Playback Switch",
10501                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10502                                                               HDA_OUTPUT));
10503                         if (err < 0)
10504                                 return err;
10505                 }
10506         }
10507         return 0;
10508 }
10509
10510 /* identical with ALC880 */
10511 #define alc262_auto_create_analog_input_ctls \
10512         alc880_auto_create_analog_input_ctls
10513
10514 /*
10515  * generic initialization of ADC, input mixers and output mixers
10516  */
10517 static struct hda_verb alc262_volume_init_verbs[] = {
10518         /*
10519          * Unmute ADC0-2 and set the default input to mic-in
10520          */
10521         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10522         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10523         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10524         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10525         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10526         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10527
10528         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10529          * mixer widget
10530          * Note: PASD motherboards uses the Line In 2 as the input for
10531          * front panel mic (mic 2)
10532          */
10533         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10534         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10535         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10536         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10537         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10538         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10539
10540         /*
10541          * Set up output mixers (0x0c - 0x0f)
10542          */
10543         /* set vol=0 to output mixers */
10544         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10545         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10546         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10547
10548         /* set up input amps for analog loopback */
10549         /* Amp Indices: DAC = 0, mixer = 1 */
10550         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10551         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10552         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10553         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10554         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10555         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10556
10557         /* FIXME: use matrix-type input source selection */
10558         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10559         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10560         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10561         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10562         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10563         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10564         /* Input mixer2 */
10565         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10566         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10567         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10568         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10569         /* Input mixer3 */
10570         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10571         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10572         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10573         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10574
10575         { }
10576 };
10577
10578 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
10579         /*
10580          * Unmute ADC0-2 and set the default input to mic-in
10581          */
10582         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10583         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10584         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10585         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10586         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10587         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10588
10589         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10590          * mixer widget
10591          * Note: PASD motherboards uses the Line In 2 as the input for
10592          * front panel mic (mic 2)
10593          */
10594         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10595         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10596         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10597         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10598         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10599         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10600         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10601         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10602
10603         /*
10604          * Set up output mixers (0x0c - 0x0e)
10605          */
10606         /* set vol=0 to output mixers */
10607         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10608         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10609         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10610
10611         /* set up input amps for analog loopback */
10612         /* Amp Indices: DAC = 0, mixer = 1 */
10613         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10614         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10615         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10616         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10617         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10618         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10619
10620         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10621         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10622         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10623
10624         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10625         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10626
10627         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10628         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10629
10630         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10631         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10632         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10633         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10634         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10635
10636         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10637         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10638         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10639         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10640         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10641         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10642
10643
10644         /* FIXME: use matrix-type input source selection */
10645         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10646         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10647         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10648         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10649         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10650         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10651         /* Input mixer2 */
10652         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10653         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10654         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10655         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10656         /* Input mixer3 */
10657         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10658         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10659         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10660         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10661
10662         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10663
10664         { }
10665 };
10666
10667 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
10668         /*
10669          * Unmute ADC0-2 and set the default input to mic-in
10670          */
10671         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10672         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10673         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10674         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10675         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10676         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10677
10678         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10679          * mixer widget
10680          * Note: PASD motherboards uses the Line In 2 as the input for front
10681          * panel mic (mic 2)
10682          */
10683         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10684         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10685         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10686         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10687         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10688         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10689         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10690         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10691         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10692         /*
10693          * Set up output mixers (0x0c - 0x0e)
10694          */
10695         /* set vol=0 to output mixers */
10696         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10697         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10698         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10699
10700         /* set up input amps for analog loopback */
10701         /* Amp Indices: DAC = 0, mixer = 1 */
10702         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10703         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10704         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10705         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10706         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10707         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10708
10709
10710         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
10711         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
10712         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
10713         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
10714         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10715         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
10716         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
10717
10718         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10719         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10720
10721         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10722         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10723
10724         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
10725         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10726         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10727         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10728         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10729         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10730
10731         /* FIXME: use matrix-type input source selection */
10732         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10733         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10734         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
10735         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
10736         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
10737         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
10738         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
10739         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
10740         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
10741         /* Input mixer2 */
10742         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10743         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10744         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10745         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10746         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10747         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10748         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10749         /* Input mixer3 */
10750         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10751         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10752         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10753         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10754         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10755         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10756         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10757
10758         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10759
10760         { }
10761 };
10762
10763 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
10764
10765         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
10766         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10767         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
10768
10769         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
10770         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10771         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10772         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10773
10774         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
10775         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10776         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10777         {}
10778 };
10779
10780
10781 #ifdef CONFIG_SND_HDA_POWER_SAVE
10782 #define alc262_loopbacks        alc880_loopbacks
10783 #endif
10784
10785 /* pcm configuration: identiacal with ALC880 */
10786 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
10787 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
10788 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
10789 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
10790
10791 /*
10792  * BIOS auto configuration
10793  */
10794 static int alc262_parse_auto_config(struct hda_codec *codec)
10795 {
10796         struct alc_spec *spec = codec->spec;
10797         int err;
10798         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
10799
10800         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10801                                            alc262_ignore);
10802         if (err < 0)
10803                 return err;
10804         if (!spec->autocfg.line_outs) {
10805                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
10806                         spec->multiout.max_channels = 2;
10807                         spec->no_analog = 1;
10808                         goto dig_only;
10809                 }
10810                 return 0; /* can't find valid BIOS pin config */
10811         }
10812         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
10813         if (err < 0)
10814                 return err;
10815         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
10816         if (err < 0)
10817                 return err;
10818
10819         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10820
10821  dig_only:
10822         if (spec->autocfg.dig_outs) {
10823                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
10824                 spec->dig_out_type = spec->autocfg.dig_out_type[0];
10825         }
10826         if (spec->autocfg.dig_in_pin)
10827                 spec->dig_in_nid = ALC262_DIGIN_NID;
10828
10829         if (spec->kctls.list)
10830                 add_mixer(spec, spec->kctls.list);
10831
10832         add_verb(spec, alc262_volume_init_verbs);
10833         spec->num_mux_defs = 1;
10834         spec->input_mux = &spec->private_imux[0];
10835
10836         err = alc_auto_add_mic_boost(codec);
10837         if (err < 0)
10838                 return err;
10839
10840         return 1;
10841 }
10842
10843 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
10844 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
10845 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
10846 #define alc262_auto_init_input_src      alc882_auto_init_input_src
10847
10848
10849 /* init callback for auto-configuration model -- overriding the default init */
10850 static void alc262_auto_init(struct hda_codec *codec)
10851 {
10852         struct alc_spec *spec = codec->spec;
10853         alc262_auto_init_multi_out(codec);
10854         alc262_auto_init_hp_out(codec);
10855         alc262_auto_init_analog_input(codec);
10856         alc262_auto_init_input_src(codec);
10857         if (spec->unsol_event)
10858                 alc_inithook(codec);
10859 }
10860
10861 /*
10862  * configuration and preset
10863  */
10864 static const char *alc262_models[ALC262_MODEL_LAST] = {
10865         [ALC262_BASIC]          = "basic",
10866         [ALC262_HIPPO]          = "hippo",
10867         [ALC262_HIPPO_1]        = "hippo_1",
10868         [ALC262_FUJITSU]        = "fujitsu",
10869         [ALC262_HP_BPC]         = "hp-bpc",
10870         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
10871         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
10872         [ALC262_HP_RP5700]      = "hp-rp5700",
10873         [ALC262_BENQ_ED8]       = "benq",
10874         [ALC262_BENQ_T31]       = "benq-t31",
10875         [ALC262_SONY_ASSAMD]    = "sony-assamd",
10876         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
10877         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
10878         [ALC262_ULTRA]          = "ultra",
10879         [ALC262_LENOVO_3000]    = "lenovo-3000",
10880         [ALC262_NEC]            = "nec",
10881         [ALC262_TYAN]           = "tyan",
10882         [ALC262_AUTO]           = "auto",
10883 };
10884
10885 static struct snd_pci_quirk alc262_cfg_tbl[] = {
10886         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
10887         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
10888         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1200, "HP xw series",
10889                            ALC262_HP_BPC),
10890         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1300, "HP xw series",
10891                            ALC262_HP_BPC),
10892         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1700, "HP xw series",
10893                            ALC262_HP_BPC),
10894         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
10895         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
10896         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
10897         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
10898         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
10899         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
10900         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
10901         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
10902         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
10903         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
10904         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
10905         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
10906                       ALC262_HP_TC_T5735),
10907         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
10908         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10909         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
10910         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10911         SND_PCI_QUIRK(0x104d, 0x9016, "Sony VAIO", ALC262_AUTO), /* dig-only */
10912         SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO",
10913                            ALC262_SONY_ASSAMD),
10914         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
10915                       ALC262_TOSHIBA_RX1),
10916         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
10917         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
10918         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
10919         SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_TYAN),
10920         SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc032, "Samsung Q1",
10921                            ALC262_ULTRA),
10922         SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
10923         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
10924         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
10925         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
10926         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
10927         {}
10928 };
10929
10930 static struct alc_config_preset alc262_presets[] = {
10931         [ALC262_BASIC] = {
10932                 .mixers = { alc262_base_mixer },
10933                 .init_verbs = { alc262_init_verbs },
10934                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10935                 .dac_nids = alc262_dac_nids,
10936                 .hp_nid = 0x03,
10937                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10938                 .channel_mode = alc262_modes,
10939                 .input_mux = &alc262_capture_source,
10940         },
10941         [ALC262_HIPPO] = {
10942                 .mixers = { alc262_base_mixer },
10943                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
10944                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10945                 .dac_nids = alc262_dac_nids,
10946                 .hp_nid = 0x03,
10947                 .dig_out_nid = ALC262_DIGOUT_NID,
10948                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10949                 .channel_mode = alc262_modes,
10950                 .input_mux = &alc262_capture_source,
10951                 .unsol_event = alc262_hippo_unsol_event,
10952                 .init_hook = alc262_hippo_automute,
10953         },
10954         [ALC262_HIPPO_1] = {
10955                 .mixers = { alc262_hippo1_mixer },
10956                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
10957                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10958                 .dac_nids = alc262_dac_nids,
10959                 .hp_nid = 0x02,
10960                 .dig_out_nid = ALC262_DIGOUT_NID,
10961                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10962                 .channel_mode = alc262_modes,
10963                 .input_mux = &alc262_capture_source,
10964                 .unsol_event = alc262_hippo1_unsol_event,
10965                 .init_hook = alc262_hippo1_automute,
10966         },
10967         [ALC262_FUJITSU] = {
10968                 .mixers = { alc262_fujitsu_mixer },
10969                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10970                                 alc262_fujitsu_unsol_verbs },
10971                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10972                 .dac_nids = alc262_dac_nids,
10973                 .hp_nid = 0x03,
10974                 .dig_out_nid = ALC262_DIGOUT_NID,
10975                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10976                 .channel_mode = alc262_modes,
10977                 .input_mux = &alc262_fujitsu_capture_source,
10978                 .unsol_event = alc262_fujitsu_unsol_event,
10979                 .init_hook = alc262_fujitsu_init_hook,
10980         },
10981         [ALC262_HP_BPC] = {
10982                 .mixers = { alc262_HP_BPC_mixer },
10983                 .init_verbs = { alc262_HP_BPC_init_verbs },
10984                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10985                 .dac_nids = alc262_dac_nids,
10986                 .hp_nid = 0x03,
10987                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10988                 .channel_mode = alc262_modes,
10989                 .input_mux = &alc262_HP_capture_source,
10990                 .unsol_event = alc262_hp_bpc_unsol_event,
10991                 .init_hook = alc262_hp_bpc_automute,
10992         },
10993         [ALC262_HP_BPC_D7000_WF] = {
10994                 .mixers = { alc262_HP_BPC_WildWest_mixer },
10995                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10996                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10997                 .dac_nids = alc262_dac_nids,
10998                 .hp_nid = 0x03,
10999                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11000                 .channel_mode = alc262_modes,
11001                 .input_mux = &alc262_HP_D7000_capture_source,
11002                 .unsol_event = alc262_hp_wildwest_unsol_event,
11003                 .init_hook = alc262_hp_wildwest_automute,
11004         },
11005         [ALC262_HP_BPC_D7000_WL] = {
11006                 .mixers = { alc262_HP_BPC_WildWest_mixer,
11007                             alc262_HP_BPC_WildWest_option_mixer },
11008                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
11009                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11010                 .dac_nids = alc262_dac_nids,
11011                 .hp_nid = 0x03,
11012                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11013                 .channel_mode = alc262_modes,
11014                 .input_mux = &alc262_HP_D7000_capture_source,
11015                 .unsol_event = alc262_hp_wildwest_unsol_event,
11016                 .init_hook = alc262_hp_wildwest_automute,
11017         },
11018         [ALC262_HP_TC_T5735] = {
11019                 .mixers = { alc262_hp_t5735_mixer },
11020                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
11021                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11022                 .dac_nids = alc262_dac_nids,
11023                 .hp_nid = 0x03,
11024                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11025                 .channel_mode = alc262_modes,
11026                 .input_mux = &alc262_capture_source,
11027                 .unsol_event = alc262_hp_t5735_unsol_event,
11028                 .init_hook = alc262_hp_t5735_init_hook,
11029         },
11030         [ALC262_HP_RP5700] = {
11031                 .mixers = { alc262_hp_rp5700_mixer },
11032                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
11033                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11034                 .dac_nids = alc262_dac_nids,
11035                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11036                 .channel_mode = alc262_modes,
11037                 .input_mux = &alc262_hp_rp5700_capture_source,
11038         },
11039         [ALC262_BENQ_ED8] = {
11040                 .mixers = { alc262_base_mixer },
11041                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
11042                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11043                 .dac_nids = alc262_dac_nids,
11044                 .hp_nid = 0x03,
11045                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11046                 .channel_mode = alc262_modes,
11047                 .input_mux = &alc262_capture_source,
11048         },
11049         [ALC262_SONY_ASSAMD] = {
11050                 .mixers = { alc262_sony_mixer },
11051                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
11052                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11053                 .dac_nids = alc262_dac_nids,
11054                 .hp_nid = 0x02,
11055                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11056                 .channel_mode = alc262_modes,
11057                 .input_mux = &alc262_capture_source,
11058                 .unsol_event = alc262_hippo_unsol_event,
11059                 .init_hook = alc262_hippo_automute,
11060         },
11061         [ALC262_BENQ_T31] = {
11062                 .mixers = { alc262_benq_t31_mixer },
11063                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
11064                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11065                 .dac_nids = alc262_dac_nids,
11066                 .hp_nid = 0x03,
11067                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11068                 .channel_mode = alc262_modes,
11069                 .input_mux = &alc262_capture_source,
11070                 .unsol_event = alc262_hippo_unsol_event,
11071                 .init_hook = alc262_hippo_automute,
11072         },
11073         [ALC262_ULTRA] = {
11074                 .mixers = { alc262_ultra_mixer },
11075                 .cap_mixer = alc262_ultra_capture_mixer,
11076                 .init_verbs = { alc262_ultra_verbs },
11077                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11078                 .dac_nids = alc262_dac_nids,
11079                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11080                 .channel_mode = alc262_modes,
11081                 .input_mux = &alc262_ultra_capture_source,
11082                 .adc_nids = alc262_adc_nids, /* ADC0 */
11083                 .capsrc_nids = alc262_capsrc_nids,
11084                 .num_adc_nids = 1, /* single ADC */
11085                 .unsol_event = alc262_ultra_unsol_event,
11086                 .init_hook = alc262_ultra_automute,
11087         },
11088         [ALC262_LENOVO_3000] = {
11089                 .mixers = { alc262_lenovo_3000_mixer },
11090                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
11091                                 alc262_lenovo_3000_unsol_verbs },
11092                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11093                 .dac_nids = alc262_dac_nids,
11094                 .hp_nid = 0x03,
11095                 .dig_out_nid = ALC262_DIGOUT_NID,
11096                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11097                 .channel_mode = alc262_modes,
11098                 .input_mux = &alc262_fujitsu_capture_source,
11099                 .unsol_event = alc262_lenovo_3000_unsol_event,
11100         },
11101         [ALC262_NEC] = {
11102                 .mixers = { alc262_nec_mixer },
11103                 .init_verbs = { alc262_nec_verbs },
11104                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11105                 .dac_nids = alc262_dac_nids,
11106                 .hp_nid = 0x03,
11107                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11108                 .channel_mode = alc262_modes,
11109                 .input_mux = &alc262_capture_source,
11110         },
11111         [ALC262_TOSHIBA_S06] = {
11112                 .mixers = { alc262_toshiba_s06_mixer },
11113                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
11114                                                         alc262_eapd_verbs },
11115                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11116                 .capsrc_nids = alc262_dmic_capsrc_nids,
11117                 .dac_nids = alc262_dac_nids,
11118                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
11119                 .dig_out_nid = ALC262_DIGOUT_NID,
11120                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11121                 .channel_mode = alc262_modes,
11122                 .input_mux = &alc262_dmic_capture_source,
11123                 .unsol_event = alc262_toshiba_s06_unsol_event,
11124                 .init_hook = alc262_toshiba_s06_init_hook,
11125         },
11126         [ALC262_TOSHIBA_RX1] = {
11127                 .mixers = { alc262_toshiba_rx1_mixer },
11128                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
11129                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11130                 .dac_nids = alc262_dac_nids,
11131                 .hp_nid = 0x03,
11132                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11133                 .channel_mode = alc262_modes,
11134                 .input_mux = &alc262_capture_source,
11135                 .unsol_event = alc262_hippo_unsol_event,
11136                 .init_hook = alc262_hippo_automute,
11137         },
11138         [ALC262_TYAN] = {
11139                 .mixers = { alc262_tyan_mixer },
11140                 .init_verbs = { alc262_init_verbs, alc262_tyan_verbs},
11141                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11142                 .dac_nids = alc262_dac_nids,
11143                 .hp_nid = 0x02,
11144                 .dig_out_nid = ALC262_DIGOUT_NID,
11145                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11146                 .channel_mode = alc262_modes,
11147                 .input_mux = &alc262_capture_source,
11148                 .unsol_event = alc262_tyan_unsol_event,
11149                 .init_hook = alc262_tyan_automute,
11150         },
11151 };
11152
11153 static int patch_alc262(struct hda_codec *codec)
11154 {
11155         struct alc_spec *spec;
11156         int board_config;
11157         int err;
11158
11159         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11160         if (spec == NULL)
11161                 return -ENOMEM;
11162
11163         codec->spec = spec;
11164 #if 0
11165         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
11166          * under-run
11167          */
11168         {
11169         int tmp;
11170         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
11171         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
11172         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
11173         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
11174         }
11175 #endif
11176
11177         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
11178
11179         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
11180                                                   alc262_models,
11181                                                   alc262_cfg_tbl);
11182
11183         if (board_config < 0) {
11184                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
11185                        "trying auto-probe from BIOS...\n");
11186                 board_config = ALC262_AUTO;
11187         }
11188
11189         if (board_config == ALC262_AUTO) {
11190                 /* automatic parse from the BIOS config */
11191                 err = alc262_parse_auto_config(codec);
11192                 if (err < 0) {
11193                         alc_free(codec);
11194                         return err;
11195                 } else if (!err) {
11196                         printk(KERN_INFO
11197                                "hda_codec: Cannot set up configuration "
11198                                "from BIOS.  Using base mode...\n");
11199                         board_config = ALC262_BASIC;
11200                 }
11201         }
11202
11203         if (!spec->no_analog) {
11204                 err = snd_hda_attach_beep_device(codec, 0x1);
11205                 if (err < 0) {
11206                         alc_free(codec);
11207                         return err;
11208                 }
11209         }
11210
11211         if (board_config != ALC262_AUTO)
11212                 setup_preset(spec, &alc262_presets[board_config]);
11213
11214         spec->stream_name_analog = "ALC262 Analog";
11215         spec->stream_analog_playback = &alc262_pcm_analog_playback;
11216         spec->stream_analog_capture = &alc262_pcm_analog_capture;
11217
11218         spec->stream_name_digital = "ALC262 Digital";
11219         spec->stream_digital_playback = &alc262_pcm_digital_playback;
11220         spec->stream_digital_capture = &alc262_pcm_digital_capture;
11221
11222         spec->capture_style = CAPT_MIX;
11223         if (!spec->adc_nids && spec->input_mux) {
11224                 /* check whether NID 0x07 is valid */
11225                 unsigned int wcap = get_wcaps(codec, 0x07);
11226
11227                 /* get type */
11228                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
11229                 if (wcap != AC_WID_AUD_IN) {
11230                         spec->adc_nids = alc262_adc_nids_alt;
11231                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
11232                         spec->capsrc_nids = alc262_capsrc_nids_alt;
11233                 } else {
11234                         spec->adc_nids = alc262_adc_nids;
11235                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
11236                         spec->capsrc_nids = alc262_capsrc_nids;
11237                 }
11238         }
11239         if (!spec->cap_mixer && !spec->no_analog)
11240                 set_capture_mixer(spec);
11241         if (!spec->no_analog)
11242                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
11243
11244         spec->vmaster_nid = 0x0c;
11245
11246         codec->patch_ops = alc_patch_ops;
11247         if (board_config == ALC262_AUTO)
11248                 spec->init_hook = alc262_auto_init;
11249 #ifdef CONFIG_SND_HDA_POWER_SAVE
11250         if (!spec->loopback.amplist)
11251                 spec->loopback.amplist = alc262_loopbacks;
11252 #endif
11253         codec->proc_widget_hook = print_realtek_coef;
11254
11255         return 0;
11256 }
11257
11258 /*
11259  *  ALC268 channel source setting (2 channel)
11260  */
11261 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
11262 #define alc268_modes            alc260_modes
11263
11264 static hda_nid_t alc268_dac_nids[2] = {
11265         /* front, hp */
11266         0x02, 0x03
11267 };
11268
11269 static hda_nid_t alc268_adc_nids[2] = {
11270         /* ADC0-1 */
11271         0x08, 0x07
11272 };
11273
11274 static hda_nid_t alc268_adc_nids_alt[1] = {
11275         /* ADC0 */
11276         0x08
11277 };
11278
11279 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
11280
11281 static struct snd_kcontrol_new alc268_base_mixer[] = {
11282         /* output mixer control */
11283         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11284         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11285         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11286         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11287         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11288         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11289         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11290         { }
11291 };
11292
11293 /* bind Beep switches of both NID 0x0f and 0x10 */
11294 static struct hda_bind_ctls alc268_bind_beep_sw = {
11295         .ops = &snd_hda_bind_sw,
11296         .values = {
11297                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
11298                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
11299                 0
11300         },
11301 };
11302
11303 static struct snd_kcontrol_new alc268_beep_mixer[] = {
11304         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
11305         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
11306         { }
11307 };
11308
11309 static struct hda_verb alc268_eapd_verbs[] = {
11310         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11311         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
11312         { }
11313 };
11314
11315 /* Toshiba specific */
11316 #define alc268_toshiba_automute alc262_hippo_automute
11317
11318 static struct hda_verb alc268_toshiba_verbs[] = {
11319         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11320         { } /* end */
11321 };
11322
11323 static struct hda_input_mux alc268_acer_lc_capture_source = {
11324         .num_items = 2,
11325         .items = {
11326                 { "i-Mic", 0x6 },
11327                 { "E-Mic", 0x0 },
11328         },
11329 };
11330
11331 /* Acer specific */
11332 /* bind volumes of both NID 0x02 and 0x03 */
11333 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
11334         .ops = &snd_hda_bind_vol,
11335         .values = {
11336                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
11337                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
11338                 0
11339         },
11340 };
11341
11342 /* mute/unmute internal speaker according to the hp jack and mute state */
11343 static void alc268_acer_automute(struct hda_codec *codec, int force)
11344 {
11345         struct alc_spec *spec = codec->spec;
11346         unsigned int mute;
11347
11348         if (force || !spec->sense_updated) {
11349                 unsigned int present;
11350                 present = snd_hda_codec_read(codec, 0x14, 0,
11351                                          AC_VERB_GET_PIN_SENSE, 0);
11352                 spec->jack_present = (present & 0x80000000) != 0;
11353                 spec->sense_updated = 1;
11354         }
11355         if (spec->jack_present)
11356                 mute = HDA_AMP_MUTE; /* mute internal speaker */
11357         else /* unmute internal speaker if necessary */
11358                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
11359         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
11360                                  HDA_AMP_MUTE, mute);
11361 }
11362
11363
11364 /* bind hp and internal speaker mute (with plug check) */
11365 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
11366                                      struct snd_ctl_elem_value *ucontrol)
11367 {
11368         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11369         long *valp = ucontrol->value.integer.value;
11370         int change;
11371
11372         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
11373                                           HDA_AMP_MUTE,
11374                                           valp[0] ? 0 : HDA_AMP_MUTE);
11375         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
11376                                            HDA_AMP_MUTE,
11377                                            valp[1] ? 0 : HDA_AMP_MUTE);
11378         if (change)
11379                 alc268_acer_automute(codec, 0);
11380         return change;
11381 }
11382
11383 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
11384         /* output mixer control */
11385         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11386         {
11387                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11388                 .name = "Master Playback Switch",
11389                 .info = snd_hda_mixer_amp_switch_info,
11390                 .get = snd_hda_mixer_amp_switch_get,
11391                 .put = alc268_acer_master_sw_put,
11392                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11393         },
11394         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
11395         { }
11396 };
11397
11398 static struct snd_kcontrol_new alc268_acer_mixer[] = {
11399         /* output mixer control */
11400         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11401         {
11402                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11403                 .name = "Master Playback Switch",
11404                 .info = snd_hda_mixer_amp_switch_info,
11405                 .get = snd_hda_mixer_amp_switch_get,
11406                 .put = alc268_acer_master_sw_put,
11407                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11408         },
11409         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11410         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11411         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11412         { }
11413 };
11414
11415 static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
11416         /* output mixer control */
11417         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11418         {
11419                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11420                 .name = "Master Playback Switch",
11421                 .info = snd_hda_mixer_amp_switch_info,
11422                 .get = snd_hda_mixer_amp_switch_get,
11423                 .put = alc268_acer_master_sw_put,
11424                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11425         },
11426         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11427         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11428         { }
11429 };
11430
11431 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
11432         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11433         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11434         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11435         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11436         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
11437         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
11438         { }
11439 };
11440
11441 static struct hda_verb alc268_acer_verbs[] = {
11442         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
11443         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11444         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11445         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11446         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11447         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11448         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11449         { }
11450 };
11451
11452 /* unsolicited event for HP jack sensing */
11453 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
11454                                        unsigned int res)
11455 {
11456         if ((res >> 26) != ALC880_HP_EVENT)
11457                 return;
11458         alc268_toshiba_automute(codec);
11459 }
11460
11461 static void alc268_acer_unsol_event(struct hda_codec *codec,
11462                                        unsigned int res)
11463 {
11464         if ((res >> 26) != ALC880_HP_EVENT)
11465                 return;
11466         alc268_acer_automute(codec, 1);
11467 }
11468
11469 static void alc268_acer_init_hook(struct hda_codec *codec)
11470 {
11471         alc268_acer_automute(codec, 1);
11472 }
11473
11474 /* toggle speaker-output according to the hp-jack state */
11475 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
11476 {
11477         unsigned int present;
11478         unsigned char bits;
11479
11480         present = snd_hda_codec_read(codec, 0x15, 0,
11481                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11482         bits = present ? AMP_IN_MUTE(0) : 0;
11483         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
11484                                 AMP_IN_MUTE(0), bits);
11485         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
11486                                 AMP_IN_MUTE(0), bits);
11487 }
11488
11489
11490 static void alc268_acer_mic_automute(struct hda_codec *codec)
11491 {
11492         unsigned int present;
11493
11494         present = snd_hda_codec_read(codec, 0x18, 0,
11495                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11496         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
11497                             present ? 0x0 : 0x6);
11498 }
11499
11500 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
11501                                     unsigned int res)
11502 {
11503         if ((res >> 26) == ALC880_HP_EVENT)
11504                 alc268_aspire_one_speaker_automute(codec);
11505         if ((res >> 26) == ALC880_MIC_EVENT)
11506                 alc268_acer_mic_automute(codec);
11507 }
11508
11509 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
11510 {
11511         alc268_aspire_one_speaker_automute(codec);
11512         alc268_acer_mic_automute(codec);
11513 }
11514
11515 static struct snd_kcontrol_new alc268_dell_mixer[] = {
11516         /* output mixer control */
11517         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11518         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11519         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11520         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11521         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11522         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11523         { }
11524 };
11525
11526 static struct hda_verb alc268_dell_verbs[] = {
11527         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11528         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11529         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11530         { }
11531 };
11532
11533 /* mute/unmute internal speaker according to the hp jack and mute state */
11534 static void alc268_dell_automute(struct hda_codec *codec)
11535 {
11536         unsigned int present;
11537         unsigned int mute;
11538
11539         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
11540         if (present & 0x80000000)
11541                 mute = HDA_AMP_MUTE;
11542         else
11543                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
11544         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
11545                                  HDA_AMP_MUTE, mute);
11546 }
11547
11548 static void alc268_dell_unsol_event(struct hda_codec *codec,
11549                                     unsigned int res)
11550 {
11551         if ((res >> 26) != ALC880_HP_EVENT)
11552                 return;
11553         alc268_dell_automute(codec);
11554 }
11555
11556 #define alc268_dell_init_hook   alc268_dell_automute
11557
11558 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
11559         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11560         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11561         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11562         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11563         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11564         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
11565         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
11566         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
11567         { }
11568 };
11569
11570 static struct hda_verb alc267_quanta_il1_verbs[] = {
11571         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11572         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
11573         { }
11574 };
11575
11576 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
11577 {
11578         unsigned int present;
11579
11580         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
11581                 & AC_PINSENSE_PRESENCE;
11582         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
11583                             present ? 0 : PIN_OUT);
11584 }
11585
11586 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
11587 {
11588         unsigned int present;
11589
11590         present = snd_hda_codec_read(codec, 0x18, 0,
11591                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11592         snd_hda_codec_write(codec, 0x23, 0,
11593                             AC_VERB_SET_CONNECT_SEL,
11594                             present ? 0x00 : 0x01);
11595 }
11596
11597 static void alc267_quanta_il1_automute(struct hda_codec *codec)
11598 {
11599         alc267_quanta_il1_hp_automute(codec);
11600         alc267_quanta_il1_mic_automute(codec);
11601 }
11602
11603 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
11604                                            unsigned int res)
11605 {
11606         switch (res >> 26) {
11607         case ALC880_HP_EVENT:
11608                 alc267_quanta_il1_hp_automute(codec);
11609                 break;
11610         case ALC880_MIC_EVENT:
11611                 alc267_quanta_il1_mic_automute(codec);
11612                 break;
11613         }
11614 }
11615
11616 /*
11617  * generic initialization of ADC, input mixers and output mixers
11618  */
11619 static struct hda_verb alc268_base_init_verbs[] = {
11620         /* Unmute DAC0-1 and set vol = 0 */
11621         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11622         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11623
11624         /*
11625          * Set up output mixers (0x0c - 0x0e)
11626          */
11627         /* set vol=0 to output mixers */
11628         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11629         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
11630
11631         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11632         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11633
11634         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11635         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
11636         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11637         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11638         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11639         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11640         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11641         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11642
11643         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11644         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11645         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11646         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11647         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11648
11649         /* set PCBEEP vol = 0, mute connections */
11650         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11651         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11652         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11653
11654         /* Unmute Selector 23h,24h and set the default input to mic-in */
11655
11656         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
11657         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11658         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
11659         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11660
11661         { }
11662 };
11663
11664 /*
11665  * generic initialization of ADC, input mixers and output mixers
11666  */
11667 static struct hda_verb alc268_volume_init_verbs[] = {
11668         /* set output DAC */
11669         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11670         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11671
11672         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11673         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11674         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11675         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11676         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11677
11678         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11679         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11680         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11681
11682         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11683         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11684
11685         /* set PCBEEP vol = 0, mute connections */
11686         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11687         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11688         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11689
11690         { }
11691 };
11692
11693 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
11694         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11695         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11696         {
11697                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11698                 /* The multiple "Capture Source" controls confuse alsamixer
11699                  * So call somewhat different..
11700                  */
11701                 /* .name = "Capture Source", */
11702                 .name = "Input Source",
11703                 .count = 1,
11704                 .info = alc_mux_enum_info,
11705                 .get = alc_mux_enum_get,
11706                 .put = alc_mux_enum_put,
11707         },
11708         { } /* end */
11709 };
11710
11711 static struct snd_kcontrol_new alc268_capture_mixer[] = {
11712         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11713         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11714         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
11715         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
11716         {
11717                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11718                 /* The multiple "Capture Source" controls confuse alsamixer
11719                  * So call somewhat different..
11720                  */
11721                 /* .name = "Capture Source", */
11722                 .name = "Input Source",
11723                 .count = 2,
11724                 .info = alc_mux_enum_info,
11725                 .get = alc_mux_enum_get,
11726                 .put = alc_mux_enum_put,
11727         },
11728         { } /* end */
11729 };
11730
11731 static struct hda_input_mux alc268_capture_source = {
11732         .num_items = 4,
11733         .items = {
11734                 { "Mic", 0x0 },
11735                 { "Front Mic", 0x1 },
11736                 { "Line", 0x2 },
11737                 { "CD", 0x3 },
11738         },
11739 };
11740
11741 static struct hda_input_mux alc268_acer_capture_source = {
11742         .num_items = 3,
11743         .items = {
11744                 { "Mic", 0x0 },
11745                 { "Internal Mic", 0x1 },
11746                 { "Line", 0x2 },
11747         },
11748 };
11749
11750 static struct hda_input_mux alc268_acer_dmic_capture_source = {
11751         .num_items = 3,
11752         .items = {
11753                 { "Mic", 0x0 },
11754                 { "Internal Mic", 0x6 },
11755                 { "Line", 0x2 },
11756         },
11757 };
11758
11759 #ifdef CONFIG_SND_DEBUG
11760 static struct snd_kcontrol_new alc268_test_mixer[] = {
11761         /* Volume widgets */
11762         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11763         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11764         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
11765         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
11766         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
11767         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
11768         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
11769         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
11770         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
11771         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
11772         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
11773         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
11774         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
11775         /* The below appears problematic on some hardwares */
11776         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
11777         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11778         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
11779         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
11780         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
11781
11782         /* Modes for retasking pin widgets */
11783         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
11784         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
11785         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
11786         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
11787
11788         /* Controls for GPIO pins, assuming they are configured as outputs */
11789         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
11790         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
11791         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
11792         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
11793
11794         /* Switches to allow the digital SPDIF output pin to be enabled.
11795          * The ALC268 does not have an SPDIF input.
11796          */
11797         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
11798
11799         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
11800          * this output to turn on an external amplifier.
11801          */
11802         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
11803         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
11804
11805         { } /* end */
11806 };
11807 #endif
11808
11809 /* create input playback/capture controls for the given pin */
11810 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
11811                                     const char *ctlname, int idx)
11812 {
11813         char name[32];
11814         int err;
11815
11816         sprintf(name, "%s Playback Volume", ctlname);
11817         if (nid == 0x14) {
11818                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11819                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
11820                                                       HDA_OUTPUT));
11821                 if (err < 0)
11822                         return err;
11823         } else if (nid == 0x15) {
11824                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11825                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
11826                                                       HDA_OUTPUT));
11827                 if (err < 0)
11828                         return err;
11829         } else
11830                 return -1;
11831         sprintf(name, "%s Playback Switch", ctlname);
11832         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11833                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
11834         if (err < 0)
11835                 return err;
11836         return 0;
11837 }
11838
11839 /* add playback controls from the parsed DAC table */
11840 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
11841                                              const struct auto_pin_cfg *cfg)
11842 {
11843         hda_nid_t nid;
11844         int err;
11845
11846         spec->multiout.num_dacs = 2;    /* only use one dac */
11847         spec->multiout.dac_nids = spec->private_dac_nids;
11848         spec->multiout.dac_nids[0] = 2;
11849         spec->multiout.dac_nids[1] = 3;
11850
11851         nid = cfg->line_out_pins[0];
11852         if (nid)
11853                 alc268_new_analog_output(spec, nid, "Front", 0);
11854
11855         nid = cfg->speaker_pins[0];
11856         if (nid == 0x1d) {
11857                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
11858                                   "Speaker Playback Volume",
11859                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
11860                 if (err < 0)
11861                         return err;
11862         }
11863         nid = cfg->hp_pins[0];
11864         if (nid)
11865                 alc268_new_analog_output(spec, nid, "Headphone", 0);
11866
11867         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
11868         if (nid == 0x16) {
11869                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11870                                   "Mono Playback Switch",
11871                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
11872                 if (err < 0)
11873                         return err;
11874         }
11875         return 0;
11876 }
11877
11878 /* create playback/capture controls for input pins */
11879 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
11880                                                 const struct auto_pin_cfg *cfg)
11881 {
11882         struct hda_input_mux *imux = &spec->private_imux[0];
11883         int i, idx1;
11884
11885         for (i = 0; i < AUTO_PIN_LAST; i++) {
11886                 switch(cfg->input_pins[i]) {
11887                 case 0x18:
11888                         idx1 = 0;       /* Mic 1 */
11889                         break;
11890                 case 0x19:
11891                         idx1 = 1;       /* Mic 2 */
11892                         break;
11893                 case 0x1a:
11894                         idx1 = 2;       /* Line In */
11895                         break;
11896                 case 0x1c:
11897                         idx1 = 3;       /* CD */
11898                         break;
11899                 case 0x12:
11900                 case 0x13:
11901                         idx1 = 6;       /* digital mics */
11902                         break;
11903                 default:
11904                         continue;
11905                 }
11906                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
11907                 imux->items[imux->num_items].index = idx1;
11908                 imux->num_items++;
11909         }
11910         return 0;
11911 }
11912
11913 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
11914 {
11915         struct alc_spec *spec = codec->spec;
11916         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
11917         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
11918         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
11919         unsigned int    dac_vol1, dac_vol2;
11920
11921         if (speaker_nid) {
11922                 snd_hda_codec_write(codec, speaker_nid, 0,
11923                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
11924                 snd_hda_codec_write(codec, 0x0f, 0,
11925                                     AC_VERB_SET_AMP_GAIN_MUTE,
11926                                     AMP_IN_UNMUTE(1));
11927                 snd_hda_codec_write(codec, 0x10, 0,
11928                                     AC_VERB_SET_AMP_GAIN_MUTE,
11929                                     AMP_IN_UNMUTE(1));
11930         } else {
11931                 snd_hda_codec_write(codec, 0x0f, 0,
11932                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11933                 snd_hda_codec_write(codec, 0x10, 0,
11934                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11935         }
11936
11937         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
11938         if (line_nid == 0x14)
11939                 dac_vol2 = AMP_OUT_ZERO;
11940         else if (line_nid == 0x15)
11941                 dac_vol1 = AMP_OUT_ZERO;
11942         if (hp_nid == 0x14)
11943                 dac_vol2 = AMP_OUT_ZERO;
11944         else if (hp_nid == 0x15)
11945                 dac_vol1 = AMP_OUT_ZERO;
11946         if (line_nid != 0x16 || hp_nid != 0x16 ||
11947             spec->autocfg.line_out_pins[1] != 0x16 ||
11948             spec->autocfg.line_out_pins[2] != 0x16)
11949                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
11950
11951         snd_hda_codec_write(codec, 0x02, 0,
11952                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
11953         snd_hda_codec_write(codec, 0x03, 0,
11954                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
11955 }
11956
11957 /* pcm configuration: identiacal with ALC880 */
11958 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
11959 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
11960 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
11961 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
11962
11963 /*
11964  * BIOS auto configuration
11965  */
11966 static int alc268_parse_auto_config(struct hda_codec *codec)
11967 {
11968         struct alc_spec *spec = codec->spec;
11969         int err;
11970         static hda_nid_t alc268_ignore[] = { 0 };
11971
11972         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11973                                            alc268_ignore);
11974         if (err < 0)
11975                 return err;
11976         if (!spec->autocfg.line_outs) {
11977                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
11978                         spec->multiout.max_channels = 2;
11979                         spec->no_analog = 1;
11980                         goto dig_only;
11981                 }
11982                 return 0; /* can't find valid BIOS pin config */
11983         }
11984         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
11985         if (err < 0)
11986                 return err;
11987         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
11988         if (err < 0)
11989                 return err;
11990
11991         spec->multiout.max_channels = 2;
11992
11993  dig_only:
11994         /* digital only support output */
11995         if (spec->autocfg.dig_outs) {
11996                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
11997                 spec->dig_out_type = spec->autocfg.dig_out_type[0];
11998         }
11999         if (spec->kctls.list)
12000                 add_mixer(spec, spec->kctls.list);
12001
12002         if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d)
12003                 add_mixer(spec, alc268_beep_mixer);
12004
12005         add_verb(spec, alc268_volume_init_verbs);
12006         spec->num_mux_defs = 1;
12007         spec->input_mux = &spec->private_imux[0];
12008
12009         err = alc_auto_add_mic_boost(codec);
12010         if (err < 0)
12011                 return err;
12012
12013         return 1;
12014 }
12015
12016 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
12017 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
12018 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
12019
12020 /* init callback for auto-configuration model -- overriding the default init */
12021 static void alc268_auto_init(struct hda_codec *codec)
12022 {
12023         struct alc_spec *spec = codec->spec;
12024         alc268_auto_init_multi_out(codec);
12025         alc268_auto_init_hp_out(codec);
12026         alc268_auto_init_mono_speaker_out(codec);
12027         alc268_auto_init_analog_input(codec);
12028         if (spec->unsol_event)
12029                 alc_inithook(codec);
12030 }
12031
12032 /*
12033  * configuration and preset
12034  */
12035 static const char *alc268_models[ALC268_MODEL_LAST] = {
12036         [ALC267_QUANTA_IL1]     = "quanta-il1",
12037         [ALC268_3ST]            = "3stack",
12038         [ALC268_TOSHIBA]        = "toshiba",
12039         [ALC268_ACER]           = "acer",
12040         [ALC268_ACER_DMIC]      = "acer-dmic",
12041         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
12042         [ALC268_DELL]           = "dell",
12043         [ALC268_ZEPTO]          = "zepto",
12044 #ifdef CONFIG_SND_DEBUG
12045         [ALC268_TEST]           = "test",
12046 #endif
12047         [ALC268_AUTO]           = "auto",
12048 };
12049
12050 static struct snd_pci_quirk alc268_cfg_tbl[] = {
12051         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
12052         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
12053         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
12054         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
12055         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
12056         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
12057                                                 ALC268_ACER_ASPIRE_ONE),
12058         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
12059         SND_PCI_QUIRK(0x1028, 0x02b0, "Dell Inspiron Mini9", ALC268_DELL),
12060         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
12061         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
12062         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
12063         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
12064         SND_PCI_QUIRK(0x1179, 0xff64, "TOSHIBA L305", ALC268_TOSHIBA),
12065         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
12066         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
12067         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
12068         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
12069         {}
12070 };
12071
12072 static struct alc_config_preset alc268_presets[] = {
12073         [ALC267_QUANTA_IL1] = {
12074                 .mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer },
12075                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12076                                 alc267_quanta_il1_verbs },
12077                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12078                 .dac_nids = alc268_dac_nids,
12079                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12080                 .adc_nids = alc268_adc_nids_alt,
12081                 .hp_nid = 0x03,
12082                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12083                 .channel_mode = alc268_modes,
12084                 .input_mux = &alc268_capture_source,
12085                 .unsol_event = alc267_quanta_il1_unsol_event,
12086                 .init_hook = alc267_quanta_il1_automute,
12087         },
12088         [ALC268_3ST] = {
12089                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12090                             alc268_beep_mixer },
12091                 .init_verbs = { alc268_base_init_verbs },
12092                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12093                 .dac_nids = alc268_dac_nids,
12094                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12095                 .adc_nids = alc268_adc_nids_alt,
12096                 .capsrc_nids = alc268_capsrc_nids,
12097                 .hp_nid = 0x03,
12098                 .dig_out_nid = ALC268_DIGOUT_NID,
12099                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12100                 .channel_mode = alc268_modes,
12101                 .input_mux = &alc268_capture_source,
12102         },
12103         [ALC268_TOSHIBA] = {
12104                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12105                             alc268_beep_mixer },
12106                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12107                                 alc268_toshiba_verbs },
12108                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12109                 .dac_nids = alc268_dac_nids,
12110                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12111                 .adc_nids = alc268_adc_nids_alt,
12112                 .capsrc_nids = alc268_capsrc_nids,
12113                 .hp_nid = 0x03,
12114                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12115                 .channel_mode = alc268_modes,
12116                 .input_mux = &alc268_capture_source,
12117                 .unsol_event = alc268_toshiba_unsol_event,
12118                 .init_hook = alc268_toshiba_automute,
12119         },
12120         [ALC268_ACER] = {
12121                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
12122                             alc268_beep_mixer },
12123                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12124                                 alc268_acer_verbs },
12125                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12126                 .dac_nids = alc268_dac_nids,
12127                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12128                 .adc_nids = alc268_adc_nids_alt,
12129                 .capsrc_nids = alc268_capsrc_nids,
12130                 .hp_nid = 0x02,
12131                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12132                 .channel_mode = alc268_modes,
12133                 .input_mux = &alc268_acer_capture_source,
12134                 .unsol_event = alc268_acer_unsol_event,
12135                 .init_hook = alc268_acer_init_hook,
12136         },
12137         [ALC268_ACER_DMIC] = {
12138                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
12139                             alc268_beep_mixer },
12140                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12141                                 alc268_acer_verbs },
12142                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12143                 .dac_nids = alc268_dac_nids,
12144                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12145                 .adc_nids = alc268_adc_nids_alt,
12146                 .capsrc_nids = alc268_capsrc_nids,
12147                 .hp_nid = 0x02,
12148                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12149                 .channel_mode = alc268_modes,
12150                 .input_mux = &alc268_acer_dmic_capture_source,
12151                 .unsol_event = alc268_acer_unsol_event,
12152                 .init_hook = alc268_acer_init_hook,
12153         },
12154         [ALC268_ACER_ASPIRE_ONE] = {
12155                 .mixers = { alc268_acer_aspire_one_mixer,
12156                             alc268_beep_mixer,
12157                             alc268_capture_alt_mixer },
12158                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12159                                 alc268_acer_aspire_one_verbs },
12160                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12161                 .dac_nids = alc268_dac_nids,
12162                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12163                 .adc_nids = alc268_adc_nids_alt,
12164                 .capsrc_nids = alc268_capsrc_nids,
12165                 .hp_nid = 0x03,
12166                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12167                 .channel_mode = alc268_modes,
12168                 .input_mux = &alc268_acer_lc_capture_source,
12169                 .unsol_event = alc268_acer_lc_unsol_event,
12170                 .init_hook = alc268_acer_lc_init_hook,
12171         },
12172         [ALC268_DELL] = {
12173                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
12174                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12175                                 alc268_dell_verbs },
12176                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12177                 .dac_nids = alc268_dac_nids,
12178                 .hp_nid = 0x02,
12179                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12180                 .channel_mode = alc268_modes,
12181                 .unsol_event = alc268_dell_unsol_event,
12182                 .init_hook = alc268_dell_init_hook,
12183                 .input_mux = &alc268_capture_source,
12184         },
12185         [ALC268_ZEPTO] = {
12186                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12187                             alc268_beep_mixer },
12188                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12189                                 alc268_toshiba_verbs },
12190                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12191                 .dac_nids = alc268_dac_nids,
12192                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12193                 .adc_nids = alc268_adc_nids_alt,
12194                 .capsrc_nids = alc268_capsrc_nids,
12195                 .hp_nid = 0x03,
12196                 .dig_out_nid = ALC268_DIGOUT_NID,
12197                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12198                 .channel_mode = alc268_modes,
12199                 .input_mux = &alc268_capture_source,
12200                 .unsol_event = alc268_toshiba_unsol_event,
12201                 .init_hook = alc268_toshiba_automute
12202         },
12203 #ifdef CONFIG_SND_DEBUG
12204         [ALC268_TEST] = {
12205                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
12206                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12207                                 alc268_volume_init_verbs },
12208                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12209                 .dac_nids = alc268_dac_nids,
12210                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12211                 .adc_nids = alc268_adc_nids_alt,
12212                 .capsrc_nids = alc268_capsrc_nids,
12213                 .hp_nid = 0x03,
12214                 .dig_out_nid = ALC268_DIGOUT_NID,
12215                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12216                 .channel_mode = alc268_modes,
12217                 .input_mux = &alc268_capture_source,
12218         },
12219 #endif
12220 };
12221
12222 static int patch_alc268(struct hda_codec *codec)
12223 {
12224         struct alc_spec *spec;
12225         int board_config;
12226         int i, has_beep, err;
12227
12228         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
12229         if (spec == NULL)
12230                 return -ENOMEM;
12231
12232         codec->spec = spec;
12233
12234         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
12235                                                   alc268_models,
12236                                                   alc268_cfg_tbl);
12237
12238         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
12239                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
12240                        "trying auto-probe from BIOS...\n");
12241                 board_config = ALC268_AUTO;
12242         }
12243
12244         if (board_config == ALC268_AUTO) {
12245                 /* automatic parse from the BIOS config */
12246                 err = alc268_parse_auto_config(codec);
12247                 if (err < 0) {
12248                         alc_free(codec);
12249                         return err;
12250                 } else if (!err) {
12251                         printk(KERN_INFO
12252                                "hda_codec: Cannot set up configuration "
12253                                "from BIOS.  Using base mode...\n");
12254                         board_config = ALC268_3ST;
12255                 }
12256         }
12257
12258         if (board_config != ALC268_AUTO)
12259                 setup_preset(spec, &alc268_presets[board_config]);
12260
12261         if (codec->vendor_id == 0x10ec0267) {
12262                 spec->stream_name_analog = "ALC267 Analog";
12263                 spec->stream_name_digital = "ALC267 Digital";
12264         } else {
12265                 spec->stream_name_analog = "ALC268 Analog";
12266                 spec->stream_name_digital = "ALC268 Digital";
12267         }
12268
12269         spec->stream_analog_playback = &alc268_pcm_analog_playback;
12270         spec->stream_analog_capture = &alc268_pcm_analog_capture;
12271         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
12272
12273         spec->stream_digital_playback = &alc268_pcm_digital_playback;
12274
12275         has_beep = 0;
12276         for (i = 0; i < spec->num_mixers; i++) {
12277                 if (spec->mixers[i] == alc268_beep_mixer) {
12278                         has_beep = 1;
12279                         break;
12280                 }
12281         }
12282
12283         if (has_beep) {
12284                 err = snd_hda_attach_beep_device(codec, 0x1);
12285                 if (err < 0) {
12286                         alc_free(codec);
12287                         return err;
12288                 }
12289                 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
12290                         /* override the amp caps for beep generator */
12291                         snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
12292                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
12293                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
12294                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
12295                                           (0 << AC_AMPCAP_MUTE_SHIFT));
12296         }
12297
12298         if (!spec->no_analog && !spec->adc_nids && spec->input_mux) {
12299                 /* check whether NID 0x07 is valid */
12300                 unsigned int wcap = get_wcaps(codec, 0x07);
12301                 int i;
12302
12303                 /* get type */
12304                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
12305                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
12306                         spec->adc_nids = alc268_adc_nids_alt;
12307                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
12308                         add_mixer(spec, alc268_capture_alt_mixer);
12309                 } else {
12310                         spec->adc_nids = alc268_adc_nids;
12311                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
12312                         add_mixer(spec, alc268_capture_mixer);
12313                 }
12314                 spec->capsrc_nids = alc268_capsrc_nids;
12315                 /* set default input source */
12316                 for (i = 0; i < spec->num_adc_nids; i++)
12317                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
12318                                 0, AC_VERB_SET_CONNECT_SEL,
12319                                 spec->input_mux->items[0].index);
12320         }
12321
12322         spec->vmaster_nid = 0x02;
12323
12324         codec->patch_ops = alc_patch_ops;
12325         if (board_config == ALC268_AUTO)
12326                 spec->init_hook = alc268_auto_init;
12327
12328         codec->proc_widget_hook = print_realtek_coef;
12329
12330         return 0;
12331 }
12332
12333 /*
12334  *  ALC269 channel source setting (2 channel)
12335  */
12336 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
12337
12338 #define alc269_dac_nids         alc260_dac_nids
12339
12340 static hda_nid_t alc269_adc_nids[1] = {
12341         /* ADC1 */
12342         0x08,
12343 };
12344
12345 static hda_nid_t alc269_capsrc_nids[1] = {
12346         0x23,
12347 };
12348
12349 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
12350  *       not a mux!
12351  */
12352
12353 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
12354         .num_items = 2,
12355         .items = {
12356                 { "i-Mic", 0x5 },
12357                 { "e-Mic", 0x0 },
12358         },
12359 };
12360
12361 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
12362         .num_items = 2,
12363         .items = {
12364                 { "i-Mic", 0x1 },
12365                 { "e-Mic", 0x0 },
12366         },
12367 };
12368
12369 #define alc269_modes            alc260_modes
12370 #define alc269_capture_source   alc880_lg_lw_capture_source
12371
12372 static struct snd_kcontrol_new alc269_base_mixer[] = {
12373         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12374         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12375         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12376         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12377         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12378         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12379         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12380         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12381         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12382         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12383         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12384         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
12385         { } /* end */
12386 };
12387
12388 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
12389         /* output mixer control */
12390         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12391         {
12392                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12393                 .name = "Master Playback Switch",
12394                 .info = snd_hda_mixer_amp_switch_info,
12395                 .get = snd_hda_mixer_amp_switch_get,
12396                 .put = alc268_acer_master_sw_put,
12397                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12398         },
12399         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12400         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12401         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12402         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12403         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12404         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12405         { }
12406 };
12407
12408 static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12409         /* output mixer control */
12410         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12411         {
12412                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12413                 .name = "Master Playback Switch",
12414                 .info = snd_hda_mixer_amp_switch_info,
12415                 .get = snd_hda_mixer_amp_switch_get,
12416                 .put = alc268_acer_master_sw_put,
12417                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12418         },
12419         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12420         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12421         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12422         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12423         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12424         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12425         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
12426         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
12427         HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
12428         { }
12429 };
12430
12431 /* bind volumes of both NID 0x0c and 0x0d */
12432 static struct hda_bind_ctls alc269_epc_bind_vol = {
12433         .ops = &snd_hda_bind_vol,
12434         .values = {
12435                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
12436                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
12437                 0
12438         },
12439 };
12440
12441 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12442         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12443         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
12444         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12445         { } /* end */
12446 };
12447
12448 /* capture mixer elements */
12449 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
12450         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12451         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12452         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12453         { } /* end */
12454 };
12455
12456 /* FSC amilo */
12457 static struct snd_kcontrol_new alc269_fujitsu_mixer[] = {
12458         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12459         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12460         HDA_BIND_VOL("PCM Playback Volume", &alc269_epc_bind_vol),
12461         { } /* end */
12462 };
12463
12464 static struct hda_verb alc269_quanta_fl1_verbs[] = {
12465         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12466         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12467         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12468         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12469         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12470         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12471         { }
12472 };
12473
12474 static struct hda_verb alc269_lifebook_verbs[] = {
12475         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12476         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
12477         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12478         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12479         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12480         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12481         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12482         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12483         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12484         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12485         { }
12486 };
12487
12488 /* toggle speaker-output according to the hp-jack state */
12489 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
12490 {
12491         unsigned int present;
12492         unsigned char bits;
12493
12494         present = snd_hda_codec_read(codec, 0x15, 0,
12495                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12496         bits = present ? AMP_IN_MUTE(0) : 0;
12497         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12498                         AMP_IN_MUTE(0), bits);
12499         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12500                         AMP_IN_MUTE(0), bits);
12501
12502         snd_hda_codec_write(codec, 0x20, 0,
12503                         AC_VERB_SET_COEF_INDEX, 0x0c);
12504         snd_hda_codec_write(codec, 0x20, 0,
12505                         AC_VERB_SET_PROC_COEF, 0x680);
12506
12507         snd_hda_codec_write(codec, 0x20, 0,
12508                         AC_VERB_SET_COEF_INDEX, 0x0c);
12509         snd_hda_codec_write(codec, 0x20, 0,
12510                         AC_VERB_SET_PROC_COEF, 0x480);
12511 }
12512
12513 /* toggle speaker-output according to the hp-jacks state */
12514 static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
12515 {
12516         unsigned int present;
12517         unsigned char bits;
12518
12519         /* Check laptop headphone socket */
12520         present = snd_hda_codec_read(codec, 0x15, 0,
12521                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12522
12523         /* Check port replicator headphone socket */
12524         present |= snd_hda_codec_read(codec, 0x1a, 0,
12525                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12526
12527         bits = present ? AMP_IN_MUTE(0) : 0;
12528         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12529                         AMP_IN_MUTE(0), bits);
12530         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12531                         AMP_IN_MUTE(0), bits);
12532
12533         snd_hda_codec_write(codec, 0x20, 0,
12534                         AC_VERB_SET_COEF_INDEX, 0x0c);
12535         snd_hda_codec_write(codec, 0x20, 0,
12536                         AC_VERB_SET_PROC_COEF, 0x680);
12537
12538         snd_hda_codec_write(codec, 0x20, 0,
12539                         AC_VERB_SET_COEF_INDEX, 0x0c);
12540         snd_hda_codec_write(codec, 0x20, 0,
12541                         AC_VERB_SET_PROC_COEF, 0x480);
12542 }
12543
12544 static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
12545 {
12546         unsigned int present;
12547
12548         present = snd_hda_codec_read(codec, 0x18, 0,
12549                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12550         snd_hda_codec_write(codec, 0x23, 0,
12551                             AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
12552 }
12553
12554 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
12555 {
12556         unsigned int present_laptop;
12557         unsigned int present_dock;
12558
12559         present_laptop = snd_hda_codec_read(codec, 0x18, 0,
12560                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12561
12562         present_dock = snd_hda_codec_read(codec, 0x1b, 0,
12563                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12564
12565         /* Laptop mic port overrides dock mic port, design decision */
12566         if (present_dock)
12567                 snd_hda_codec_write(codec, 0x23, 0,
12568                                 AC_VERB_SET_CONNECT_SEL, 0x3);
12569         if (present_laptop)
12570                 snd_hda_codec_write(codec, 0x23, 0,
12571                                 AC_VERB_SET_CONNECT_SEL, 0x0);
12572         if (!present_dock && !present_laptop)
12573                 snd_hda_codec_write(codec, 0x23, 0,
12574                                 AC_VERB_SET_CONNECT_SEL, 0x1);
12575 }
12576
12577 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
12578                                     unsigned int res)
12579 {
12580         if ((res >> 26) == ALC880_HP_EVENT)
12581                 alc269_quanta_fl1_speaker_automute(codec);
12582         if ((res >> 26) == ALC880_MIC_EVENT)
12583                 alc269_quanta_fl1_mic_automute(codec);
12584 }
12585
12586 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
12587                                         unsigned int res)
12588 {
12589         if ((res >> 26) == ALC880_HP_EVENT)
12590                 alc269_lifebook_speaker_automute(codec);
12591         if ((res >> 26) == ALC880_MIC_EVENT)
12592                 alc269_lifebook_mic_autoswitch(codec);
12593 }
12594
12595 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
12596 {
12597         alc269_quanta_fl1_speaker_automute(codec);
12598         alc269_quanta_fl1_mic_automute(codec);
12599 }
12600
12601 static void alc269_lifebook_init_hook(struct hda_codec *codec)
12602 {
12603         alc269_lifebook_speaker_automute(codec);
12604         alc269_lifebook_mic_autoswitch(codec);
12605 }
12606
12607 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
12608         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12609         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
12610         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12611         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
12612         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12613         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12614         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12615         {}
12616 };
12617
12618 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
12619         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12620         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
12621         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12622         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
12623         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12624         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12625         {}
12626 };
12627
12628 /* toggle speaker-output according to the hp-jack state */
12629 static void alc269_speaker_automute(struct hda_codec *codec)
12630 {
12631         unsigned int present;
12632         unsigned char bits;
12633
12634         present = snd_hda_codec_read(codec, 0x15, 0,
12635                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12636         bits = present ? AMP_IN_MUTE(0) : 0;
12637         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12638                                 AMP_IN_MUTE(0), bits);
12639         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12640                                 AMP_IN_MUTE(0), bits);
12641 }
12642
12643 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
12644 {
12645         unsigned int present;
12646
12647         present = snd_hda_codec_read(codec, 0x18, 0,
12648                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12649         snd_hda_codec_write(codec, 0x23, 0,
12650                                 AC_VERB_SET_CONNECT_SEL,  (present ? 0 : 5));
12651 }
12652
12653 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
12654 {
12655         unsigned int present;
12656
12657         present = snd_hda_codec_read(codec, 0x18, 0,
12658                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12659         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12660                                 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
12661         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12662                                 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
12663 }
12664
12665 /* unsolicited event for HP jack sensing */
12666 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
12667                                      unsigned int res)
12668 {
12669         if ((res >> 26) == ALC880_HP_EVENT)
12670                 alc269_speaker_automute(codec);
12671
12672         if ((res >> 26) == ALC880_MIC_EVENT)
12673                 alc269_eeepc_dmic_automute(codec);
12674 }
12675
12676 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
12677 {
12678         alc269_speaker_automute(codec);
12679         alc269_eeepc_dmic_automute(codec);
12680 }
12681
12682 /* unsolicited event for HP jack sensing */
12683 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
12684                                      unsigned int res)
12685 {
12686         if ((res >> 26) == ALC880_HP_EVENT)
12687                 alc269_speaker_automute(codec);
12688
12689         if ((res >> 26) == ALC880_MIC_EVENT)
12690                 alc269_eeepc_amic_automute(codec);
12691 }
12692
12693 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
12694 {
12695         alc269_speaker_automute(codec);
12696         alc269_eeepc_amic_automute(codec);
12697 }
12698
12699 /*
12700  * generic initialization of ADC, input mixers and output mixers
12701  */
12702 static struct hda_verb alc269_init_verbs[] = {
12703         /*
12704          * Unmute ADC0 and set the default input to mic-in
12705          */
12706         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12707
12708         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
12709          * analog-loopback mixer widget
12710          * Note: PASD motherboards uses the Line In 2 as the input for
12711          * front panel mic (mic 2)
12712          */
12713         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12714         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12715         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12716         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12717         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12718         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12719
12720         /*
12721          * Set up output mixers (0x0c - 0x0e)
12722          */
12723         /* set vol=0 to output mixers */
12724         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12725         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12726
12727         /* set up input amps for analog loopback */
12728         /* Amp Indices: DAC = 0, mixer = 1 */
12729         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12730         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12731         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12732         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12733         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12734         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12735
12736         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12737         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12738         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12739         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12740         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12741         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12742         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12743
12744         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12745         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12746         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12747         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12748         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12749         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12750         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12751
12752         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12753         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12754
12755         /* FIXME: use matrix-type input source selection */
12756         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
12757         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
12758         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12759         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12760         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12761         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12762
12763         /* set EAPD */
12764         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
12765         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
12766         { }
12767 };
12768
12769 /* add playback controls from the parsed DAC table */
12770 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
12771                                              const struct auto_pin_cfg *cfg)
12772 {
12773         hda_nid_t nid;
12774         int err;
12775
12776         spec->multiout.num_dacs = 1;    /* only use one dac */
12777         spec->multiout.dac_nids = spec->private_dac_nids;
12778         spec->multiout.dac_nids[0] = 2;
12779
12780         nid = cfg->line_out_pins[0];
12781         if (nid) {
12782                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
12783                                   "Front Playback Volume",
12784                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
12785                 if (err < 0)
12786                         return err;
12787                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12788                                   "Front Playback Switch",
12789                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12790                 if (err < 0)
12791                         return err;
12792         }
12793
12794         nid = cfg->speaker_pins[0];
12795         if (nid) {
12796                 if (!cfg->line_out_pins[0]) {
12797                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12798                                           "Speaker Playback Volume",
12799                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12800                                                               HDA_OUTPUT));
12801                         if (err < 0)
12802                                 return err;
12803                 }
12804                 if (nid == 0x16) {
12805                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12806                                           "Speaker Playback Switch",
12807                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12808                                                               HDA_OUTPUT));
12809                         if (err < 0)
12810                                 return err;
12811                 } else {
12812                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12813                                           "Speaker Playback Switch",
12814                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12815                                                               HDA_OUTPUT));
12816                         if (err < 0)
12817                                 return err;
12818                 }
12819         }
12820         nid = cfg->hp_pins[0];
12821         if (nid) {
12822                 /* spec->multiout.hp_nid = 2; */
12823                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
12824                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12825                                           "Headphone Playback Volume",
12826                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12827                                                               HDA_OUTPUT));
12828                         if (err < 0)
12829                                 return err;
12830                 }
12831                 if (nid == 0x16) {
12832                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12833                                           "Headphone Playback Switch",
12834                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12835                                                               HDA_OUTPUT));
12836                         if (err < 0)
12837                                 return err;
12838                 } else {
12839                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12840                                           "Headphone Playback Switch",
12841                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12842                                                               HDA_OUTPUT));
12843                         if (err < 0)
12844                                 return err;
12845                 }
12846         }
12847         return 0;
12848 }
12849
12850 static int alc269_auto_create_analog_input_ctls(struct alc_spec *spec,
12851                                                 const struct auto_pin_cfg *cfg)
12852 {
12853         int err;
12854
12855         err = alc880_auto_create_analog_input_ctls(spec, cfg);
12856         if (err < 0)
12857                 return err;
12858         /* digital-mic input pin is excluded in alc880_auto_create..()
12859          * because it's under 0x18
12860          */
12861         if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
12862             cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
12863                 struct hda_input_mux *imux = &spec->private_imux[0];
12864                 imux->items[imux->num_items].label = "Int Mic";
12865                 imux->items[imux->num_items].index = 0x05;
12866                 imux->num_items++;
12867         }
12868         return 0;
12869 }
12870
12871 #ifdef CONFIG_SND_HDA_POWER_SAVE
12872 #define alc269_loopbacks        alc880_loopbacks
12873 #endif
12874
12875 /* pcm configuration: identiacal with ALC880 */
12876 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
12877 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
12878 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
12879 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
12880
12881 static struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
12882         .substreams = 1,
12883         .channels_min = 2,
12884         .channels_max = 8,
12885         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
12886         /* NID is set in alc_build_pcms */
12887         .ops = {
12888                 .open = alc880_playback_pcm_open,
12889                 .prepare = alc880_playback_pcm_prepare,
12890                 .cleanup = alc880_playback_pcm_cleanup
12891         },
12892 };
12893
12894 static struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
12895         .substreams = 1,
12896         .channels_min = 2,
12897         .channels_max = 2,
12898         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
12899         /* NID is set in alc_build_pcms */
12900 };
12901
12902 /*
12903  * BIOS auto configuration
12904  */
12905 static int alc269_parse_auto_config(struct hda_codec *codec)
12906 {
12907         struct alc_spec *spec = codec->spec;
12908         int err;
12909         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
12910
12911         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12912                                            alc269_ignore);
12913         if (err < 0)
12914                 return err;
12915
12916         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
12917         if (err < 0)
12918                 return err;
12919         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
12920         if (err < 0)
12921                 return err;
12922
12923         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12924
12925         if (spec->autocfg.dig_outs)
12926                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
12927
12928         if (spec->kctls.list)
12929                 add_mixer(spec, spec->kctls.list);
12930
12931         add_verb(spec, alc269_init_verbs);
12932         spec->num_mux_defs = 1;
12933         spec->input_mux = &spec->private_imux[0];
12934         /* set default input source */
12935         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
12936                                   0, AC_VERB_SET_CONNECT_SEL,
12937                                   spec->input_mux->items[0].index);
12938
12939         err = alc_auto_add_mic_boost(codec);
12940         if (err < 0)
12941                 return err;
12942
12943         if (!spec->cap_mixer && !spec->no_analog)
12944                 set_capture_mixer(spec);
12945
12946         return 1;
12947 }
12948
12949 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
12950 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
12951 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
12952
12953
12954 /* init callback for auto-configuration model -- overriding the default init */
12955 static void alc269_auto_init(struct hda_codec *codec)
12956 {
12957         struct alc_spec *spec = codec->spec;
12958         alc269_auto_init_multi_out(codec);
12959         alc269_auto_init_hp_out(codec);
12960         alc269_auto_init_analog_input(codec);
12961         if (spec->unsol_event)
12962                 alc_inithook(codec);
12963 }
12964
12965 /*
12966  * configuration and preset
12967  */
12968 static const char *alc269_models[ALC269_MODEL_LAST] = {
12969         [ALC269_BASIC]                  = "basic",
12970         [ALC269_QUANTA_FL1]             = "quanta",
12971         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
12972         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901",
12973         [ALC269_FUJITSU]                = "fujitsu",
12974         [ALC269_LIFEBOOK]               = "lifebook"
12975 };
12976
12977 static struct snd_pci_quirk alc269_cfg_tbl[] = {
12978         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
12979         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
12980                       ALC269_ASUS_EEEPC_P703),
12981         SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_ASUS_EEEPC_P703),
12982         SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_ASUS_EEEPC_P703),
12983         SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_ASUS_EEEPC_P703),
12984         SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_ASUS_EEEPC_P703),
12985         SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_ASUS_EEEPC_P703),
12986         SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_ASUS_EEEPC_P703),
12987         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
12988                       ALC269_ASUS_EEEPC_P901),
12989         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
12990                       ALC269_ASUS_EEEPC_P901),
12991         SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_ASUS_EEEPC_P901),
12992         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
12993         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
12994         {}
12995 };
12996
12997 static struct alc_config_preset alc269_presets[] = {
12998         [ALC269_BASIC] = {
12999                 .mixers = { alc269_base_mixer },
13000                 .init_verbs = { alc269_init_verbs },
13001                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13002                 .dac_nids = alc269_dac_nids,
13003                 .hp_nid = 0x03,
13004                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13005                 .channel_mode = alc269_modes,
13006                 .input_mux = &alc269_capture_source,
13007         },
13008         [ALC269_QUANTA_FL1] = {
13009                 .mixers = { alc269_quanta_fl1_mixer },
13010                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
13011                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13012                 .dac_nids = alc269_dac_nids,
13013                 .hp_nid = 0x03,
13014                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13015                 .channel_mode = alc269_modes,
13016                 .input_mux = &alc269_capture_source,
13017                 .unsol_event = alc269_quanta_fl1_unsol_event,
13018                 .init_hook = alc269_quanta_fl1_init_hook,
13019         },
13020         [ALC269_ASUS_EEEPC_P703] = {
13021                 .mixers = { alc269_eeepc_mixer },
13022                 .cap_mixer = alc269_epc_capture_mixer,
13023                 .init_verbs = { alc269_init_verbs,
13024                                 alc269_eeepc_amic_init_verbs },
13025                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13026                 .dac_nids = alc269_dac_nids,
13027                 .hp_nid = 0x03,
13028                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13029                 .channel_mode = alc269_modes,
13030                 .input_mux = &alc269_eeepc_amic_capture_source,
13031                 .unsol_event = alc269_eeepc_amic_unsol_event,
13032                 .init_hook = alc269_eeepc_amic_inithook,
13033         },
13034         [ALC269_ASUS_EEEPC_P901] = {
13035                 .mixers = { alc269_eeepc_mixer },
13036                 .cap_mixer = alc269_epc_capture_mixer,
13037                 .init_verbs = { alc269_init_verbs,
13038                                 alc269_eeepc_dmic_init_verbs },
13039                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13040                 .dac_nids = alc269_dac_nids,
13041                 .hp_nid = 0x03,
13042                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13043                 .channel_mode = alc269_modes,
13044                 .input_mux = &alc269_eeepc_dmic_capture_source,
13045                 .unsol_event = alc269_eeepc_dmic_unsol_event,
13046                 .init_hook = alc269_eeepc_dmic_inithook,
13047         },
13048         [ALC269_FUJITSU] = {
13049                 .mixers = { alc269_fujitsu_mixer },
13050                 .cap_mixer = alc269_epc_capture_mixer,
13051                 .init_verbs = { alc269_init_verbs,
13052                                 alc269_eeepc_dmic_init_verbs },
13053                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13054                 .dac_nids = alc269_dac_nids,
13055                 .hp_nid = 0x03,
13056                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13057                 .channel_mode = alc269_modes,
13058                 .input_mux = &alc269_eeepc_dmic_capture_source,
13059                 .unsol_event = alc269_eeepc_dmic_unsol_event,
13060                 .init_hook = alc269_eeepc_dmic_inithook,
13061         },
13062         [ALC269_LIFEBOOK] = {
13063                 .mixers = { alc269_lifebook_mixer },
13064                 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
13065                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13066                 .dac_nids = alc269_dac_nids,
13067                 .hp_nid = 0x03,
13068                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13069                 .channel_mode = alc269_modes,
13070                 .input_mux = &alc269_capture_source,
13071                 .unsol_event = alc269_lifebook_unsol_event,
13072                 .init_hook = alc269_lifebook_init_hook,
13073         },
13074 };
13075
13076 static int patch_alc269(struct hda_codec *codec)
13077 {
13078         struct alc_spec *spec;
13079         int board_config;
13080         int err;
13081
13082         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13083         if (spec == NULL)
13084                 return -ENOMEM;
13085
13086         codec->spec = spec;
13087
13088         alc_fix_pll_init(codec, 0x20, 0x04, 15);
13089
13090         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
13091                                                   alc269_models,
13092                                                   alc269_cfg_tbl);
13093
13094         if (board_config < 0) {
13095                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
13096                        "trying auto-probe from BIOS...\n");
13097                 board_config = ALC269_AUTO;
13098         }
13099
13100         if (board_config == ALC269_AUTO) {
13101                 /* automatic parse from the BIOS config */
13102                 err = alc269_parse_auto_config(codec);
13103                 if (err < 0) {
13104                         alc_free(codec);
13105                         return err;
13106                 } else if (!err) {
13107                         printk(KERN_INFO
13108                                "hda_codec: Cannot set up configuration "
13109                                "from BIOS.  Using base mode...\n");
13110                         board_config = ALC269_BASIC;
13111                 }
13112         }
13113
13114         err = snd_hda_attach_beep_device(codec, 0x1);
13115         if (err < 0) {
13116                 alc_free(codec);
13117                 return err;
13118         }
13119
13120         if (board_config != ALC269_AUTO)
13121                 setup_preset(spec, &alc269_presets[board_config]);
13122
13123         spec->stream_name_analog = "ALC269 Analog";
13124         if (codec->subsystem_id == 0x17aa3bf8) {
13125                 /* Due to a hardware problem on Lenovo Ideadpad, we need to
13126                  * fix the sample rate of analog I/O to 44.1kHz
13127                  */
13128                 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
13129                 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
13130         } else {
13131                 spec->stream_analog_playback = &alc269_pcm_analog_playback;
13132                 spec->stream_analog_capture = &alc269_pcm_analog_capture;
13133         }
13134         spec->stream_name_digital = "ALC269 Digital";
13135         spec->stream_digital_playback = &alc269_pcm_digital_playback;
13136         spec->stream_digital_capture = &alc269_pcm_digital_capture;
13137
13138         spec->adc_nids = alc269_adc_nids;
13139         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
13140         spec->capsrc_nids = alc269_capsrc_nids;
13141         if (!spec->cap_mixer)
13142                 set_capture_mixer(spec);
13143         set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
13144
13145         codec->patch_ops = alc_patch_ops;
13146         if (board_config == ALC269_AUTO)
13147                 spec->init_hook = alc269_auto_init;
13148 #ifdef CONFIG_SND_HDA_POWER_SAVE
13149         if (!spec->loopback.amplist)
13150                 spec->loopback.amplist = alc269_loopbacks;
13151 #endif
13152         codec->proc_widget_hook = print_realtek_coef;
13153
13154         return 0;
13155 }
13156
13157 /*
13158  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
13159  */
13160
13161 /*
13162  * set the path ways for 2 channel output
13163  * need to set the codec line out and mic 1 pin widgets to inputs
13164  */
13165 static struct hda_verb alc861_threestack_ch2_init[] = {
13166         /* set pin widget 1Ah (line in) for input */
13167         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13168         /* set pin widget 18h (mic1/2) for input, for mic also enable
13169          * the vref
13170          */
13171         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13172
13173         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
13174 #if 0
13175         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13176         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
13177 #endif
13178         { } /* end */
13179 };
13180 /*
13181  * 6ch mode
13182  * need to set the codec line out and mic 1 pin widgets to outputs
13183  */
13184 static struct hda_verb alc861_threestack_ch6_init[] = {
13185         /* set pin widget 1Ah (line in) for output (Back Surround)*/
13186         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13187         /* set pin widget 18h (mic1) for output (CLFE)*/
13188         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13189
13190         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
13191         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
13192
13193         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
13194 #if 0
13195         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13196         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
13197 #endif
13198         { } /* end */
13199 };
13200
13201 static struct hda_channel_mode alc861_threestack_modes[2] = {
13202         { 2, alc861_threestack_ch2_init },
13203         { 6, alc861_threestack_ch6_init },
13204 };
13205 /* Set mic1 as input and unmute the mixer */
13206 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
13207         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13208         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13209         { } /* end */
13210 };
13211 /* Set mic1 as output and mute mixer */
13212 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
13213         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13214         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13215         { } /* end */
13216 };
13217
13218 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
13219         { 2, alc861_uniwill_m31_ch2_init },
13220         { 4, alc861_uniwill_m31_ch4_init },
13221 };
13222
13223 /* Set mic1 and line-in as input and unmute the mixer */
13224 static struct hda_verb alc861_asus_ch2_init[] = {
13225         /* set pin widget 1Ah (line in) for input */
13226         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13227         /* set pin widget 18h (mic1/2) for input, for mic also enable
13228          * the vref
13229          */
13230         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13231
13232         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
13233 #if 0
13234         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13235         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
13236 #endif
13237         { } /* end */
13238 };
13239 /* Set mic1 nad line-in as output and mute mixer */
13240 static struct hda_verb alc861_asus_ch6_init[] = {
13241         /* set pin widget 1Ah (line in) for output (Back Surround)*/
13242         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13243         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
13244         /* set pin widget 18h (mic1) for output (CLFE)*/
13245         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13246         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
13247         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
13248         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
13249
13250         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
13251 #if 0
13252         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13253         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
13254 #endif
13255         { } /* end */
13256 };
13257
13258 static struct hda_channel_mode alc861_asus_modes[2] = {
13259         { 2, alc861_asus_ch2_init },
13260         { 6, alc861_asus_ch6_init },
13261 };
13262
13263 /* patch-ALC861 */
13264
13265 static struct snd_kcontrol_new alc861_base_mixer[] = {
13266         /* output mixer control */
13267         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13268         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13269         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13270         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13271         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13272
13273         /*Input mixer control */
13274         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13275            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13276         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13277         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13278         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13279         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13280         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13281         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13282         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13283         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13284
13285         { } /* end */
13286 };
13287
13288 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
13289         /* output mixer control */
13290         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13291         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13292         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13293         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13294         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13295
13296         /* Input mixer control */
13297         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13298            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13299         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13300         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13301         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13302         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13303         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13304         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13305         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13306         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13307
13308         {
13309                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13310                 .name = "Channel Mode",
13311                 .info = alc_ch_mode_info,
13312                 .get = alc_ch_mode_get,
13313                 .put = alc_ch_mode_put,
13314                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
13315         },
13316         { } /* end */
13317 };
13318
13319 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
13320         /* output mixer control */
13321         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13322         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13323         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13324
13325         { } /* end */
13326 };
13327
13328 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
13329         /* output mixer control */
13330         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13331         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13332         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13333         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13334         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13335
13336         /* Input mixer control */
13337         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13338            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13339         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13340         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13341         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13342         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13343         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13344         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13345         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13346         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13347
13348         {
13349                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13350                 .name = "Channel Mode",
13351                 .info = alc_ch_mode_info,
13352                 .get = alc_ch_mode_get,
13353                 .put = alc_ch_mode_put,
13354                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
13355         },
13356         { } /* end */
13357 };
13358
13359 static struct snd_kcontrol_new alc861_asus_mixer[] = {
13360         /* output mixer control */
13361         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13362         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13363         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13364         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13365         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13366
13367         /* Input mixer control */
13368         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13369         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13370         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13371         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13372         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13373         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13374         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13375         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13376         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13377         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
13378
13379         {
13380                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13381                 .name = "Channel Mode",
13382                 .info = alc_ch_mode_info,
13383                 .get = alc_ch_mode_get,
13384                 .put = alc_ch_mode_put,
13385                 .private_value = ARRAY_SIZE(alc861_asus_modes),
13386         },
13387         { }
13388 };
13389
13390 /* additional mixer */
13391 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
13392         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13393         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13394         { }
13395 };
13396
13397 /*
13398  * generic initialization of ADC, input mixers and output mixers
13399  */
13400 static struct hda_verb alc861_base_init_verbs[] = {
13401         /*
13402          * Unmute ADC0 and set the default input to mic-in
13403          */
13404         /* port-A for surround (rear panel) */
13405         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13406         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
13407         /* port-B for mic-in (rear panel) with vref */
13408         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13409         /* port-C for line-in (rear panel) */
13410         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13411         /* port-D for Front */
13412         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13413         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13414         /* port-E for HP out (front panel) */
13415         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13416         /* route front PCM to HP */
13417         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13418         /* port-F for mic-in (front panel) with vref */
13419         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13420         /* port-G for CLFE (rear panel) */
13421         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13422         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13423         /* port-H for side (rear panel) */
13424         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13425         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
13426         /* CD-in */
13427         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13428         /* route front mic to ADC1*/
13429         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13430         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13431
13432         /* Unmute DAC0~3 & spdif out*/
13433         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13434         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13435         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13436         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13437         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13438
13439         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13440         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13441         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13442         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13443         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13444
13445         /* Unmute Stereo Mixer 15 */
13446         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13447         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13448         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13449         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13450
13451         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13452         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13453         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13454         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13455         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13456         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13457         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13458         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13459         /* hp used DAC 3 (Front) */
13460         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13461         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13462
13463         { }
13464 };
13465
13466 static struct hda_verb alc861_threestack_init_verbs[] = {
13467         /*
13468          * Unmute ADC0 and set the default input to mic-in
13469          */
13470         /* port-A for surround (rear panel) */
13471         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13472         /* port-B for mic-in (rear panel) with vref */
13473         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13474         /* port-C for line-in (rear panel) */
13475         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13476         /* port-D for Front */
13477         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13478         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13479         /* port-E for HP out (front panel) */
13480         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13481         /* route front PCM to HP */
13482         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13483         /* port-F for mic-in (front panel) with vref */
13484         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13485         /* port-G for CLFE (rear panel) */
13486         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13487         /* port-H for side (rear panel) */
13488         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13489         /* CD-in */
13490         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13491         /* route front mic to ADC1*/
13492         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13493         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13494         /* Unmute DAC0~3 & spdif out*/
13495         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13496         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13497         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13498         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13499         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13500
13501         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13502         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13503         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13504         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13505         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13506
13507         /* Unmute Stereo Mixer 15 */
13508         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13509         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13510         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13511         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13512
13513         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13514         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13515         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13516         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13517         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13518         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13519         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13520         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13521         /* hp used DAC 3 (Front) */
13522         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13523         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13524         { }
13525 };
13526
13527 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
13528         /*
13529          * Unmute ADC0 and set the default input to mic-in
13530          */
13531         /* port-A for surround (rear panel) */
13532         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13533         /* port-B for mic-in (rear panel) with vref */
13534         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13535         /* port-C for line-in (rear panel) */
13536         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13537         /* port-D for Front */
13538         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13539         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13540         /* port-E for HP out (front panel) */
13541         /* this has to be set to VREF80 */
13542         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13543         /* route front PCM to HP */
13544         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13545         /* port-F for mic-in (front panel) with vref */
13546         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13547         /* port-G for CLFE (rear panel) */
13548         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13549         /* port-H for side (rear panel) */
13550         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13551         /* CD-in */
13552         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13553         /* route front mic to ADC1*/
13554         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13555         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13556         /* Unmute DAC0~3 & spdif out*/
13557         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13558         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13559         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13560         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13561         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13562
13563         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13564         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13565         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13566         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13567         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13568
13569         /* Unmute Stereo Mixer 15 */
13570         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13571         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13572         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13573         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13574
13575         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13576         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13577         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13578         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13579         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13580         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13581         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13582         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13583         /* hp used DAC 3 (Front) */
13584         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13585         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13586         { }
13587 };
13588
13589 static struct hda_verb alc861_asus_init_verbs[] = {
13590         /*
13591          * Unmute ADC0 and set the default input to mic-in
13592          */
13593         /* port-A for surround (rear panel)
13594          * according to codec#0 this is the HP jack
13595          */
13596         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
13597         /* route front PCM to HP */
13598         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
13599         /* port-B for mic-in (rear panel) with vref */
13600         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13601         /* port-C for line-in (rear panel) */
13602         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13603         /* port-D for Front */
13604         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13605         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13606         /* port-E for HP out (front panel) */
13607         /* this has to be set to VREF80 */
13608         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13609         /* route front PCM to HP */
13610         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13611         /* port-F for mic-in (front panel) with vref */
13612         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13613         /* port-G for CLFE (rear panel) */
13614         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13615         /* port-H for side (rear panel) */
13616         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13617         /* CD-in */
13618         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13619         /* route front mic to ADC1*/
13620         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13621         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13622         /* Unmute DAC0~3 & spdif out*/
13623         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13624         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13625         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13626         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13627         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13628         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13629         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13630         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13631         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13632         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13633
13634         /* Unmute Stereo Mixer 15 */
13635         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13636         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13637         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13638         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13639
13640         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13641         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13642         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13643         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13644         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13645         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13646         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13647         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13648         /* hp used DAC 3 (Front) */
13649         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13650         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13651         { }
13652 };
13653
13654 /* additional init verbs for ASUS laptops */
13655 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
13656         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
13657         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
13658         { }
13659 };
13660
13661 /*
13662  * generic initialization of ADC, input mixers and output mixers
13663  */
13664 static struct hda_verb alc861_auto_init_verbs[] = {
13665         /*
13666          * Unmute ADC0 and set the default input to mic-in
13667          */
13668         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
13669         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13670
13671         /* Unmute DAC0~3 & spdif out*/
13672         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13673         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13674         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13675         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13676         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13677
13678         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13679         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13680         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13681         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13682         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13683
13684         /* Unmute Stereo Mixer 15 */
13685         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13686         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13687         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13688         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
13689
13690         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13691         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13692         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13693         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13694         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13695         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13696         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13697         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13698
13699         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13700         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13701         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13702         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13703         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13704         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13705         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13706         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13707
13708         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
13709
13710         { }
13711 };
13712
13713 static struct hda_verb alc861_toshiba_init_verbs[] = {
13714         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13715
13716         { }
13717 };
13718
13719 /* toggle speaker-output according to the hp-jack state */
13720 static void alc861_toshiba_automute(struct hda_codec *codec)
13721 {
13722         unsigned int present;
13723
13724         present = snd_hda_codec_read(codec, 0x0f, 0,
13725                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13726         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
13727                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
13728         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
13729                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
13730 }
13731
13732 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
13733                                        unsigned int res)
13734 {
13735         if ((res >> 26) == ALC880_HP_EVENT)
13736                 alc861_toshiba_automute(codec);
13737 }
13738
13739 /* pcm configuration: identiacal with ALC880 */
13740 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
13741 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
13742 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
13743 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
13744
13745
13746 #define ALC861_DIGOUT_NID       0x07
13747
13748 static struct hda_channel_mode alc861_8ch_modes[1] = {
13749         { 8, NULL }
13750 };
13751
13752 static hda_nid_t alc861_dac_nids[4] = {
13753         /* front, surround, clfe, side */
13754         0x03, 0x06, 0x05, 0x04
13755 };
13756
13757 static hda_nid_t alc660_dac_nids[3] = {
13758         /* front, clfe, surround */
13759         0x03, 0x05, 0x06
13760 };
13761
13762 static hda_nid_t alc861_adc_nids[1] = {
13763         /* ADC0-2 */
13764         0x08,
13765 };
13766
13767 static struct hda_input_mux alc861_capture_source = {
13768         .num_items = 5,
13769         .items = {
13770                 { "Mic", 0x0 },
13771                 { "Front Mic", 0x3 },
13772                 { "Line", 0x1 },
13773                 { "CD", 0x4 },
13774                 { "Mixer", 0x5 },
13775         },
13776 };
13777
13778 /* fill in the dac_nids table from the parsed pin configuration */
13779 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
13780                                      const struct auto_pin_cfg *cfg)
13781 {
13782         int i;
13783         hda_nid_t nid;
13784
13785         spec->multiout.dac_nids = spec->private_dac_nids;
13786         for (i = 0; i < cfg->line_outs; i++) {
13787                 nid = cfg->line_out_pins[i];
13788                 if (nid) {
13789                         if (i >= ARRAY_SIZE(alc861_dac_nids))
13790                                 continue;
13791                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
13792                 }
13793         }
13794         spec->multiout.num_dacs = cfg->line_outs;
13795         return 0;
13796 }
13797
13798 /* add playback controls from the parsed DAC table */
13799 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
13800                                              const struct auto_pin_cfg *cfg)
13801 {
13802         char name[32];
13803         static const char *chname[4] = {
13804                 "Front", "Surround", NULL /*CLFE*/, "Side"
13805         };
13806         hda_nid_t nid;
13807         int i, idx, err;
13808
13809         for (i = 0; i < cfg->line_outs; i++) {
13810                 nid = spec->multiout.dac_nids[i];
13811                 if (!nid)
13812                         continue;
13813                 if (nid == 0x05) {
13814                         /* Center/LFE */
13815                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13816                                           "Center Playback Switch",
13817                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
13818                                                               HDA_OUTPUT));
13819                         if (err < 0)
13820                                 return err;
13821                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13822                                           "LFE Playback Switch",
13823                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13824                                                               HDA_OUTPUT));
13825                         if (err < 0)
13826                                 return err;
13827                 } else {
13828                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
13829                              idx++)
13830                                 if (nid == alc861_dac_nids[idx])
13831                                         break;
13832                         sprintf(name, "%s Playback Switch", chname[idx]);
13833                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13834                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13835                                                               HDA_OUTPUT));
13836                         if (err < 0)
13837                                 return err;
13838                 }
13839         }
13840         return 0;
13841 }
13842
13843 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
13844 {
13845         int err;
13846         hda_nid_t nid;
13847
13848         if (!pin)
13849                 return 0;
13850
13851         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
13852                 nid = 0x03;
13853                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13854                                   "Headphone Playback Switch",
13855                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13856                 if (err < 0)
13857                         return err;
13858                 spec->multiout.hp_nid = nid;
13859         }
13860         return 0;
13861 }
13862
13863 /* create playback/capture controls for input pins */
13864 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
13865                                                 const struct auto_pin_cfg *cfg)
13866 {
13867         struct hda_input_mux *imux = &spec->private_imux[0];
13868         int i, err, idx, idx1;
13869
13870         for (i = 0; i < AUTO_PIN_LAST; i++) {
13871                 switch (cfg->input_pins[i]) {
13872                 case 0x0c:
13873                         idx1 = 1;
13874                         idx = 2;        /* Line In */
13875                         break;
13876                 case 0x0f:
13877                         idx1 = 2;
13878                         idx = 2;        /* Line In */
13879                         break;
13880                 case 0x0d:
13881                         idx1 = 0;
13882                         idx = 1;        /* Mic In */
13883                         break;
13884                 case 0x10:
13885                         idx1 = 3;
13886                         idx = 1;        /* Mic In */
13887                         break;
13888                 case 0x11:
13889                         idx1 = 4;
13890                         idx = 0;        /* CD */
13891                         break;
13892                 default:
13893                         continue;
13894                 }
13895
13896                 err = new_analog_input(spec, cfg->input_pins[i],
13897                                        auto_pin_cfg_labels[i], idx, 0x15);
13898                 if (err < 0)
13899                         return err;
13900
13901                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
13902                 imux->items[imux->num_items].index = idx1;
13903                 imux->num_items++;
13904         }
13905         return 0;
13906 }
13907
13908 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
13909                                               hda_nid_t nid,
13910                                               int pin_type, int dac_idx)
13911 {
13912         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
13913                             pin_type);
13914         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13915                             AMP_OUT_UNMUTE);
13916 }
13917
13918 static void alc861_auto_init_multi_out(struct hda_codec *codec)
13919 {
13920         struct alc_spec *spec = codec->spec;
13921         int i;
13922
13923         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
13924         for (i = 0; i < spec->autocfg.line_outs; i++) {
13925                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13926                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13927                 if (nid)
13928                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
13929                                                           spec->multiout.dac_nids[i]);
13930         }
13931 }
13932
13933 static void alc861_auto_init_hp_out(struct hda_codec *codec)
13934 {
13935         struct alc_spec *spec = codec->spec;
13936         hda_nid_t pin;
13937
13938         pin = spec->autocfg.hp_pins[0];
13939         if (pin) /* connect to front */
13940                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
13941                                                   spec->multiout.dac_nids[0]);
13942         pin = spec->autocfg.speaker_pins[0];
13943         if (pin)
13944                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13945 }
13946
13947 static void alc861_auto_init_analog_input(struct hda_codec *codec)
13948 {
13949         struct alc_spec *spec = codec->spec;
13950         int i;
13951
13952         for (i = 0; i < AUTO_PIN_LAST; i++) {
13953                 hda_nid_t nid = spec->autocfg.input_pins[i];
13954                 if (nid >= 0x0c && nid <= 0x11)
13955                         alc_set_input_pin(codec, nid, i);
13956         }
13957 }
13958
13959 /* parse the BIOS configuration and set up the alc_spec */
13960 /* return 1 if successful, 0 if the proper config is not found,
13961  * or a negative error code
13962  */
13963 static int alc861_parse_auto_config(struct hda_codec *codec)
13964 {
13965         struct alc_spec *spec = codec->spec;
13966         int err;
13967         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
13968
13969         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13970                                            alc861_ignore);
13971         if (err < 0)
13972                 return err;
13973         if (!spec->autocfg.line_outs)
13974                 return 0; /* can't find valid BIOS pin config */
13975
13976         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
13977         if (err < 0)
13978                 return err;
13979         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
13980         if (err < 0)
13981                 return err;
13982         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
13983         if (err < 0)
13984                 return err;
13985         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
13986         if (err < 0)
13987                 return err;
13988
13989         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13990
13991         if (spec->autocfg.dig_outs)
13992                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
13993
13994         if (spec->kctls.list)
13995                 add_mixer(spec, spec->kctls.list);
13996
13997         add_verb(spec, alc861_auto_init_verbs);
13998
13999         spec->num_mux_defs = 1;
14000         spec->input_mux = &spec->private_imux[0];
14001
14002         spec->adc_nids = alc861_adc_nids;
14003         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
14004         set_capture_mixer(spec);
14005
14006         return 1;
14007 }
14008
14009 /* additional initialization for auto-configuration model */
14010 static void alc861_auto_init(struct hda_codec *codec)
14011 {
14012         struct alc_spec *spec = codec->spec;
14013         alc861_auto_init_multi_out(codec);
14014         alc861_auto_init_hp_out(codec);
14015         alc861_auto_init_analog_input(codec);
14016         if (spec->unsol_event)
14017                 alc_inithook(codec);
14018 }
14019
14020 #ifdef CONFIG_SND_HDA_POWER_SAVE
14021 static struct hda_amp_list alc861_loopbacks[] = {
14022         { 0x15, HDA_INPUT, 0 },
14023         { 0x15, HDA_INPUT, 1 },
14024         { 0x15, HDA_INPUT, 2 },
14025         { 0x15, HDA_INPUT, 3 },
14026         { } /* end */
14027 };
14028 #endif
14029
14030
14031 /*
14032  * configuration and preset
14033  */
14034 static const char *alc861_models[ALC861_MODEL_LAST] = {
14035         [ALC861_3ST]            = "3stack",
14036         [ALC660_3ST]            = "3stack-660",
14037         [ALC861_3ST_DIG]        = "3stack-dig",
14038         [ALC861_6ST_DIG]        = "6stack-dig",
14039         [ALC861_UNIWILL_M31]    = "uniwill-m31",
14040         [ALC861_TOSHIBA]        = "toshiba",
14041         [ALC861_ASUS]           = "asus",
14042         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
14043         [ALC861_AUTO]           = "auto",
14044 };
14045
14046 static struct snd_pci_quirk alc861_cfg_tbl[] = {
14047         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
14048         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
14049         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
14050         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
14051         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
14052         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
14053         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
14054         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
14055          *        Any other models that need this preset?
14056          */
14057         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
14058         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
14059         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
14060         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
14061         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
14062         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
14063         /* FIXME: the below seems conflict */
14064         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
14065         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
14066         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
14067         {}
14068 };
14069
14070 static struct alc_config_preset alc861_presets[] = {
14071         [ALC861_3ST] = {
14072                 .mixers = { alc861_3ST_mixer },
14073                 .init_verbs = { alc861_threestack_init_verbs },
14074                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14075                 .dac_nids = alc861_dac_nids,
14076                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14077                 .channel_mode = alc861_threestack_modes,
14078                 .need_dac_fix = 1,
14079                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14080                 .adc_nids = alc861_adc_nids,
14081                 .input_mux = &alc861_capture_source,
14082         },
14083         [ALC861_3ST_DIG] = {
14084                 .mixers = { alc861_base_mixer },
14085                 .init_verbs = { alc861_threestack_init_verbs },
14086                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14087                 .dac_nids = alc861_dac_nids,
14088                 .dig_out_nid = ALC861_DIGOUT_NID,
14089                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14090                 .channel_mode = alc861_threestack_modes,
14091                 .need_dac_fix = 1,
14092                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14093                 .adc_nids = alc861_adc_nids,
14094                 .input_mux = &alc861_capture_source,
14095         },
14096         [ALC861_6ST_DIG] = {
14097                 .mixers = { alc861_base_mixer },
14098                 .init_verbs = { alc861_base_init_verbs },
14099                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14100                 .dac_nids = alc861_dac_nids,
14101                 .dig_out_nid = ALC861_DIGOUT_NID,
14102                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
14103                 .channel_mode = alc861_8ch_modes,
14104                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14105                 .adc_nids = alc861_adc_nids,
14106                 .input_mux = &alc861_capture_source,
14107         },
14108         [ALC660_3ST] = {
14109                 .mixers = { alc861_3ST_mixer },
14110                 .init_verbs = { alc861_threestack_init_verbs },
14111                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
14112                 .dac_nids = alc660_dac_nids,
14113                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14114                 .channel_mode = alc861_threestack_modes,
14115                 .need_dac_fix = 1,
14116                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14117                 .adc_nids = alc861_adc_nids,
14118                 .input_mux = &alc861_capture_source,
14119         },
14120         [ALC861_UNIWILL_M31] = {
14121                 .mixers = { alc861_uniwill_m31_mixer },
14122                 .init_verbs = { alc861_uniwill_m31_init_verbs },
14123                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14124                 .dac_nids = alc861_dac_nids,
14125                 .dig_out_nid = ALC861_DIGOUT_NID,
14126                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
14127                 .channel_mode = alc861_uniwill_m31_modes,
14128                 .need_dac_fix = 1,
14129                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14130                 .adc_nids = alc861_adc_nids,
14131                 .input_mux = &alc861_capture_source,
14132         },
14133         [ALC861_TOSHIBA] = {
14134                 .mixers = { alc861_toshiba_mixer },
14135                 .init_verbs = { alc861_base_init_verbs,
14136                                 alc861_toshiba_init_verbs },
14137                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14138                 .dac_nids = alc861_dac_nids,
14139                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
14140                 .channel_mode = alc883_3ST_2ch_modes,
14141                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14142                 .adc_nids = alc861_adc_nids,
14143                 .input_mux = &alc861_capture_source,
14144                 .unsol_event = alc861_toshiba_unsol_event,
14145                 .init_hook = alc861_toshiba_automute,
14146         },
14147         [ALC861_ASUS] = {
14148                 .mixers = { alc861_asus_mixer },
14149                 .init_verbs = { alc861_asus_init_verbs },
14150                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14151                 .dac_nids = alc861_dac_nids,
14152                 .dig_out_nid = ALC861_DIGOUT_NID,
14153                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
14154                 .channel_mode = alc861_asus_modes,
14155                 .need_dac_fix = 1,
14156                 .hp_nid = 0x06,
14157                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14158                 .adc_nids = alc861_adc_nids,
14159                 .input_mux = &alc861_capture_source,
14160         },
14161         [ALC861_ASUS_LAPTOP] = {
14162                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
14163                 .init_verbs = { alc861_asus_init_verbs,
14164                                 alc861_asus_laptop_init_verbs },
14165                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14166                 .dac_nids = alc861_dac_nids,
14167                 .dig_out_nid = ALC861_DIGOUT_NID,
14168                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
14169                 .channel_mode = alc883_3ST_2ch_modes,
14170                 .need_dac_fix = 1,
14171                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14172                 .adc_nids = alc861_adc_nids,
14173                 .input_mux = &alc861_capture_source,
14174         },
14175 };
14176
14177
14178 static int patch_alc861(struct hda_codec *codec)
14179 {
14180         struct alc_spec *spec;
14181         int board_config;
14182         int err;
14183
14184         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14185         if (spec == NULL)
14186                 return -ENOMEM;
14187
14188         codec->spec = spec;
14189
14190         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
14191                                                   alc861_models,
14192                                                   alc861_cfg_tbl);
14193
14194         if (board_config < 0) {
14195                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
14196                        "trying auto-probe from BIOS...\n");
14197                 board_config = ALC861_AUTO;
14198         }
14199
14200         if (board_config == ALC861_AUTO) {
14201                 /* automatic parse from the BIOS config */
14202                 err = alc861_parse_auto_config(codec);
14203                 if (err < 0) {
14204                         alc_free(codec);
14205                         return err;
14206                 } else if (!err) {
14207                         printk(KERN_INFO
14208                                "hda_codec: Cannot set up configuration "
14209                                "from BIOS.  Using base mode...\n");
14210                    board_config = ALC861_3ST_DIG;
14211                 }
14212         }
14213
14214         err = snd_hda_attach_beep_device(codec, 0x23);
14215         if (err < 0) {
14216                 alc_free(codec);
14217                 return err;
14218         }
14219
14220         if (board_config != ALC861_AUTO)
14221                 setup_preset(spec, &alc861_presets[board_config]);
14222
14223         spec->stream_name_analog = "ALC861 Analog";
14224         spec->stream_analog_playback = &alc861_pcm_analog_playback;
14225         spec->stream_analog_capture = &alc861_pcm_analog_capture;
14226
14227         spec->stream_name_digital = "ALC861 Digital";
14228         spec->stream_digital_playback = &alc861_pcm_digital_playback;
14229         spec->stream_digital_capture = &alc861_pcm_digital_capture;
14230
14231         set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
14232
14233         spec->vmaster_nid = 0x03;
14234
14235         codec->patch_ops = alc_patch_ops;
14236         if (board_config == ALC861_AUTO)
14237                 spec->init_hook = alc861_auto_init;
14238 #ifdef CONFIG_SND_HDA_POWER_SAVE
14239         if (!spec->loopback.amplist)
14240                 spec->loopback.amplist = alc861_loopbacks;
14241 #endif
14242         codec->proc_widget_hook = print_realtek_coef;
14243
14244         return 0;
14245 }
14246
14247 /*
14248  * ALC861-VD support
14249  *
14250  * Based on ALC882
14251  *
14252  * In addition, an independent DAC
14253  */
14254 #define ALC861VD_DIGOUT_NID     0x06
14255
14256 static hda_nid_t alc861vd_dac_nids[4] = {
14257         /* front, surr, clfe, side surr */
14258         0x02, 0x03, 0x04, 0x05
14259 };
14260
14261 /* dac_nids for ALC660vd are in a different order - according to
14262  * Realtek's driver.
14263  * This should probably tesult in a different mixer for 6stack models
14264  * of ALC660vd codecs, but for now there is only 3stack mixer
14265  * - and it is the same as in 861vd.
14266  * adc_nids in ALC660vd are (is) the same as in 861vd
14267  */
14268 static hda_nid_t alc660vd_dac_nids[3] = {
14269         /* front, rear, clfe, rear_surr */
14270         0x02, 0x04, 0x03
14271 };
14272
14273 static hda_nid_t alc861vd_adc_nids[1] = {
14274         /* ADC0 */
14275         0x09,
14276 };
14277
14278 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
14279
14280 /* input MUX */
14281 /* FIXME: should be a matrix-type input source selection */
14282 static struct hda_input_mux alc861vd_capture_source = {
14283         .num_items = 4,
14284         .items = {
14285                 { "Mic", 0x0 },
14286                 { "Front Mic", 0x1 },
14287                 { "Line", 0x2 },
14288                 { "CD", 0x4 },
14289         },
14290 };
14291
14292 static struct hda_input_mux alc861vd_dallas_capture_source = {
14293         .num_items = 2,
14294         .items = {
14295                 { "Ext Mic", 0x0 },
14296                 { "Int Mic", 0x1 },
14297         },
14298 };
14299
14300 static struct hda_input_mux alc861vd_hp_capture_source = {
14301         .num_items = 2,
14302         .items = {
14303                 { "Front Mic", 0x0 },
14304                 { "ATAPI Mic", 0x1 },
14305         },
14306 };
14307
14308 /*
14309  * 2ch mode
14310  */
14311 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
14312         { 2, NULL }
14313 };
14314
14315 /*
14316  * 6ch mode
14317  */
14318 static struct hda_verb alc861vd_6stack_ch6_init[] = {
14319         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14320         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14321         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14322         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14323         { } /* end */
14324 };
14325
14326 /*
14327  * 8ch mode
14328  */
14329 static struct hda_verb alc861vd_6stack_ch8_init[] = {
14330         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14331         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14332         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14333         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14334         { } /* end */
14335 };
14336
14337 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
14338         { 6, alc861vd_6stack_ch6_init },
14339         { 8, alc861vd_6stack_ch8_init },
14340 };
14341
14342 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
14343         {
14344                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14345                 .name = "Channel Mode",
14346                 .info = alc_ch_mode_info,
14347                 .get = alc_ch_mode_get,
14348                 .put = alc_ch_mode_put,
14349         },
14350         { } /* end */
14351 };
14352
14353 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14354  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14355  */
14356 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
14357         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14358         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14359
14360         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14361         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
14362
14363         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
14364                                 HDA_OUTPUT),
14365         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
14366                                 HDA_OUTPUT),
14367         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
14368         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
14369
14370         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
14371         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
14372
14373         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14374
14375         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14376         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14377         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14378
14379         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14380         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14381         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14382
14383         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14384         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14385
14386         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14387         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14388
14389         { } /* end */
14390 };
14391
14392 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
14393         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14394         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14395
14396         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14397
14398         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14399         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14400         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14401
14402         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14403         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14404         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14405
14406         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14407         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14408
14409         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14410         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14411
14412         { } /* end */
14413 };
14414
14415 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
14416         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14417         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
14418         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14419
14420         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14421
14422         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14423         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14424         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14425
14426         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14427         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14428         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14429
14430         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14431         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14432
14433         { } /* end */
14434 };
14435
14436 /* Pin assignment: Speaker=0x14, HP = 0x15,
14437  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
14438  */
14439 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
14440         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14441         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
14442         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14443         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14444         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
14445         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14446         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14447         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
14448         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14449         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14450         { } /* end */
14451 };
14452
14453 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
14454  *                 Front Mic=0x18, ATAPI Mic = 0x19,
14455  */
14456 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
14457         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14458         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14459         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14460         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14461         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14462         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14463         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14464         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14465
14466         { } /* end */
14467 };
14468
14469 /*
14470  * generic initialization of ADC, input mixers and output mixers
14471  */
14472 static struct hda_verb alc861vd_volume_init_verbs[] = {
14473         /*
14474          * Unmute ADC0 and set the default input to mic-in
14475          */
14476         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14477         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14478
14479         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
14480          * the analog-loopback mixer widget
14481          */
14482         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14483         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14484         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14485         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14486         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14487         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14488
14489         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
14490         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14491         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14492         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14493         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14494
14495         /*
14496          * Set up output mixers (0x02 - 0x05)
14497          */
14498         /* set vol=0 to output mixers */
14499         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14500         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14501         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14502         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14503
14504         /* set up input amps for analog loopback */
14505         /* Amp Indices: DAC = 0, mixer = 1 */
14506         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14507         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14508         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14509         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14510         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14511         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14512         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14513         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14514
14515         { }
14516 };
14517
14518 /*
14519  * 3-stack pin configuration:
14520  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
14521  */
14522 static struct hda_verb alc861vd_3stack_init_verbs[] = {
14523         /*
14524          * Set pin mode and muting
14525          */
14526         /* set front pin widgets 0x14 for output */
14527         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14528         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14529         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14530
14531         /* Mic (rear) pin: input vref at 80% */
14532         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14533         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14534         /* Front Mic pin: input vref at 80% */
14535         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14536         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14537         /* Line In pin: input */
14538         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14539         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14540         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14541         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14542         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14543         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14544         /* CD pin widget for input */
14545         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14546
14547         { }
14548 };
14549
14550 /*
14551  * 6-stack pin configuration:
14552  */
14553 static struct hda_verb alc861vd_6stack_init_verbs[] = {
14554         /*
14555          * Set pin mode and muting
14556          */
14557         /* set front pin widgets 0x14 for output */
14558         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14559         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14560         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14561
14562         /* Rear Pin: output 1 (0x0d) */
14563         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14564         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14565         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14566         /* CLFE Pin: output 2 (0x0e) */
14567         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14568         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14569         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
14570         /* Side Pin: output 3 (0x0f) */
14571         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14572         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14573         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
14574
14575         /* Mic (rear) pin: input vref at 80% */
14576         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14577         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14578         /* Front Mic pin: input vref at 80% */
14579         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14580         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14581         /* Line In pin: input */
14582         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14583         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14584         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14585         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14586         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14587         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14588         /* CD pin widget for input */
14589         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14590
14591         { }
14592 };
14593
14594 static struct hda_verb alc861vd_eapd_verbs[] = {
14595         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14596         { }
14597 };
14598
14599 static struct hda_verb alc660vd_eapd_verbs[] = {
14600         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14601         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
14602         { }
14603 };
14604
14605 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
14606         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14607         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14608         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
14609         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14610         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14611         {}
14612 };
14613
14614 /* toggle speaker-output according to the hp-jack state */
14615 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
14616 {
14617         unsigned int present;
14618         unsigned char bits;
14619
14620         present = snd_hda_codec_read(codec, 0x1b, 0,
14621                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14622         bits = present ? HDA_AMP_MUTE : 0;
14623         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14624                                  HDA_AMP_MUTE, bits);
14625 }
14626
14627 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
14628 {
14629         unsigned int present;
14630         unsigned char bits;
14631
14632         present = snd_hda_codec_read(codec, 0x18, 0,
14633                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14634         bits = present ? HDA_AMP_MUTE : 0;
14635         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
14636                                  HDA_AMP_MUTE, bits);
14637 }
14638
14639 static void alc861vd_lenovo_automute(struct hda_codec *codec)
14640 {
14641         alc861vd_lenovo_hp_automute(codec);
14642         alc861vd_lenovo_mic_automute(codec);
14643 }
14644
14645 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
14646                                         unsigned int res)
14647 {
14648         switch (res >> 26) {
14649         case ALC880_HP_EVENT:
14650                 alc861vd_lenovo_hp_automute(codec);
14651                 break;
14652         case ALC880_MIC_EVENT:
14653                 alc861vd_lenovo_mic_automute(codec);
14654                 break;
14655         }
14656 }
14657
14658 static struct hda_verb alc861vd_dallas_verbs[] = {
14659         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14660         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14661         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14662         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14663
14664         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14665         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14666         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14667         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14668         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14669         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14670         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14671         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14672
14673         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14674         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14675         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14676         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14677         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14678         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14679         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14680         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14681
14682         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14683         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14684         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14685         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14686         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14687         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14688         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14689         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14690
14691         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14692         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14693         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14694         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14695
14696         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14697         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14698         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14699
14700         { } /* end */
14701 };
14702
14703 /* toggle speaker-output according to the hp-jack state */
14704 static void alc861vd_dallas_automute(struct hda_codec *codec)
14705 {
14706         unsigned int present;
14707
14708         present = snd_hda_codec_read(codec, 0x15, 0,
14709                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14710         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14711                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14712 }
14713
14714 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
14715 {
14716         if ((res >> 26) == ALC880_HP_EVENT)
14717                 alc861vd_dallas_automute(codec);
14718 }
14719
14720 #ifdef CONFIG_SND_HDA_POWER_SAVE
14721 #define alc861vd_loopbacks      alc880_loopbacks
14722 #endif
14723
14724 /* pcm configuration: identiacal with ALC880 */
14725 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
14726 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
14727 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
14728 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
14729
14730 /*
14731  * configuration and preset
14732  */
14733 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
14734         [ALC660VD_3ST]          = "3stack-660",
14735         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
14736         [ALC660VD_ASUS_V1S]     = "asus-v1s",
14737         [ALC861VD_3ST]          = "3stack",
14738         [ALC861VD_3ST_DIG]      = "3stack-digout",
14739         [ALC861VD_6ST_DIG]      = "6stack-digout",
14740         [ALC861VD_LENOVO]       = "lenovo",
14741         [ALC861VD_DALLAS]       = "dallas",
14742         [ALC861VD_HP]           = "hp",
14743         [ALC861VD_AUTO]         = "auto",
14744 };
14745
14746 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
14747         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
14748         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
14749         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
14750         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
14751         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
14752         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
14753         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
14754         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
14755         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
14756         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
14757         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
14758         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
14759         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
14760         SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", ALC861VD_LENOVO),
14761         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
14762         {}
14763 };
14764
14765 static struct alc_config_preset alc861vd_presets[] = {
14766         [ALC660VD_3ST] = {
14767                 .mixers = { alc861vd_3st_mixer },
14768                 .init_verbs = { alc861vd_volume_init_verbs,
14769                                  alc861vd_3stack_init_verbs },
14770                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14771                 .dac_nids = alc660vd_dac_nids,
14772                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14773                 .channel_mode = alc861vd_3stack_2ch_modes,
14774                 .input_mux = &alc861vd_capture_source,
14775         },
14776         [ALC660VD_3ST_DIG] = {
14777                 .mixers = { alc861vd_3st_mixer },
14778                 .init_verbs = { alc861vd_volume_init_verbs,
14779                                  alc861vd_3stack_init_verbs },
14780                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14781                 .dac_nids = alc660vd_dac_nids,
14782                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14783                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14784                 .channel_mode = alc861vd_3stack_2ch_modes,
14785                 .input_mux = &alc861vd_capture_source,
14786         },
14787         [ALC861VD_3ST] = {
14788                 .mixers = { alc861vd_3st_mixer },
14789                 .init_verbs = { alc861vd_volume_init_verbs,
14790                                  alc861vd_3stack_init_verbs },
14791                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14792                 .dac_nids = alc861vd_dac_nids,
14793                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14794                 .channel_mode = alc861vd_3stack_2ch_modes,
14795                 .input_mux = &alc861vd_capture_source,
14796         },
14797         [ALC861VD_3ST_DIG] = {
14798                 .mixers = { alc861vd_3st_mixer },
14799                 .init_verbs = { alc861vd_volume_init_verbs,
14800                                  alc861vd_3stack_init_verbs },
14801                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14802                 .dac_nids = alc861vd_dac_nids,
14803                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14804                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14805                 .channel_mode = alc861vd_3stack_2ch_modes,
14806                 .input_mux = &alc861vd_capture_source,
14807         },
14808         [ALC861VD_6ST_DIG] = {
14809                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
14810                 .init_verbs = { alc861vd_volume_init_verbs,
14811                                 alc861vd_6stack_init_verbs },
14812                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14813                 .dac_nids = alc861vd_dac_nids,
14814                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14815                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
14816                 .channel_mode = alc861vd_6stack_modes,
14817                 .input_mux = &alc861vd_capture_source,
14818         },
14819         [ALC861VD_LENOVO] = {
14820                 .mixers = { alc861vd_lenovo_mixer },
14821                 .init_verbs = { alc861vd_volume_init_verbs,
14822                                 alc861vd_3stack_init_verbs,
14823                                 alc861vd_eapd_verbs,
14824                                 alc861vd_lenovo_unsol_verbs },
14825                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14826                 .dac_nids = alc660vd_dac_nids,
14827                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14828                 .channel_mode = alc861vd_3stack_2ch_modes,
14829                 .input_mux = &alc861vd_capture_source,
14830                 .unsol_event = alc861vd_lenovo_unsol_event,
14831                 .init_hook = alc861vd_lenovo_automute,
14832         },
14833         [ALC861VD_DALLAS] = {
14834                 .mixers = { alc861vd_dallas_mixer },
14835                 .init_verbs = { alc861vd_dallas_verbs },
14836                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14837                 .dac_nids = alc861vd_dac_nids,
14838                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14839                 .channel_mode = alc861vd_3stack_2ch_modes,
14840                 .input_mux = &alc861vd_dallas_capture_source,
14841                 .unsol_event = alc861vd_dallas_unsol_event,
14842                 .init_hook = alc861vd_dallas_automute,
14843         },
14844         [ALC861VD_HP] = {
14845                 .mixers = { alc861vd_hp_mixer },
14846                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
14847                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14848                 .dac_nids = alc861vd_dac_nids,
14849                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14850                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14851                 .channel_mode = alc861vd_3stack_2ch_modes,
14852                 .input_mux = &alc861vd_hp_capture_source,
14853                 .unsol_event = alc861vd_dallas_unsol_event,
14854                 .init_hook = alc861vd_dallas_automute,
14855         },
14856         [ALC660VD_ASUS_V1S] = {
14857                 .mixers = { alc861vd_lenovo_mixer },
14858                 .init_verbs = { alc861vd_volume_init_verbs,
14859                                 alc861vd_3stack_init_verbs,
14860                                 alc861vd_eapd_verbs,
14861                                 alc861vd_lenovo_unsol_verbs },
14862                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14863                 .dac_nids = alc660vd_dac_nids,
14864                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14865                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14866                 .channel_mode = alc861vd_3stack_2ch_modes,
14867                 .input_mux = &alc861vd_capture_source,
14868                 .unsol_event = alc861vd_lenovo_unsol_event,
14869                 .init_hook = alc861vd_lenovo_automute,
14870         },
14871 };
14872
14873 /*
14874  * BIOS auto configuration
14875  */
14876 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
14877                                 hda_nid_t nid, int pin_type, int dac_idx)
14878 {
14879         alc_set_pin_output(codec, nid, pin_type);
14880 }
14881
14882 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
14883 {
14884         struct alc_spec *spec = codec->spec;
14885         int i;
14886
14887         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
14888         for (i = 0; i <= HDA_SIDE; i++) {
14889                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14890                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14891                 if (nid)
14892                         alc861vd_auto_set_output_and_unmute(codec, nid,
14893                                                             pin_type, i);
14894         }
14895 }
14896
14897
14898 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
14899 {
14900         struct alc_spec *spec = codec->spec;
14901         hda_nid_t pin;
14902
14903         pin = spec->autocfg.hp_pins[0];
14904         if (pin) /* connect to front and  use dac 0 */
14905                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
14906         pin = spec->autocfg.speaker_pins[0];
14907         if (pin)
14908                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14909 }
14910
14911 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
14912 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
14913
14914 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
14915 {
14916         struct alc_spec *spec = codec->spec;
14917         int i;
14918
14919         for (i = 0; i < AUTO_PIN_LAST; i++) {
14920                 hda_nid_t nid = spec->autocfg.input_pins[i];
14921                 if (alc861vd_is_input_pin(nid)) {
14922                         alc_set_input_pin(codec, nid, i);
14923                         if (nid != ALC861VD_PIN_CD_NID &&
14924                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
14925                                 snd_hda_codec_write(codec, nid, 0,
14926                                                 AC_VERB_SET_AMP_GAIN_MUTE,
14927                                                 AMP_OUT_MUTE);
14928                 }
14929         }
14930 }
14931
14932 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
14933
14934 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
14935 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
14936
14937 /* add playback controls from the parsed DAC table */
14938 /* Based on ALC880 version. But ALC861VD has separate,
14939  * different NIDs for mute/unmute switch and volume control */
14940 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
14941                                              const struct auto_pin_cfg *cfg)
14942 {
14943         char name[32];
14944         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
14945         hda_nid_t nid_v, nid_s;
14946         int i, err;
14947
14948         for (i = 0; i < cfg->line_outs; i++) {
14949                 if (!spec->multiout.dac_nids[i])
14950                         continue;
14951                 nid_v = alc861vd_idx_to_mixer_vol(
14952                                 alc880_dac_to_idx(
14953                                         spec->multiout.dac_nids[i]));
14954                 nid_s = alc861vd_idx_to_mixer_switch(
14955                                 alc880_dac_to_idx(
14956                                         spec->multiout.dac_nids[i]));
14957
14958                 if (i == 2) {
14959                         /* Center/LFE */
14960                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14961                                           "Center Playback Volume",
14962                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
14963                                                               HDA_OUTPUT));
14964                         if (err < 0)
14965                                 return err;
14966                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14967                                           "LFE Playback Volume",
14968                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
14969                                                               HDA_OUTPUT));
14970                         if (err < 0)
14971                                 return err;
14972                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14973                                           "Center Playback Switch",
14974                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
14975                                                               HDA_INPUT));
14976                         if (err < 0)
14977                                 return err;
14978                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14979                                           "LFE Playback Switch",
14980                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
14981                                                               HDA_INPUT));
14982                         if (err < 0)
14983                                 return err;
14984                 } else {
14985                         sprintf(name, "%s Playback Volume", chname[i]);
14986                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14987                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
14988                                                               HDA_OUTPUT));
14989                         if (err < 0)
14990                                 return err;
14991                         sprintf(name, "%s Playback Switch", chname[i]);
14992                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14993                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
14994                                                               HDA_INPUT));
14995                         if (err < 0)
14996                                 return err;
14997                 }
14998         }
14999         return 0;
15000 }
15001
15002 /* add playback controls for speaker and HP outputs */
15003 /* Based on ALC880 version. But ALC861VD has separate,
15004  * different NIDs for mute/unmute switch and volume control */
15005 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
15006                                         hda_nid_t pin, const char *pfx)
15007 {
15008         hda_nid_t nid_v, nid_s;
15009         int err;
15010         char name[32];
15011
15012         if (!pin)
15013                 return 0;
15014
15015         if (alc880_is_fixed_pin(pin)) {
15016                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
15017                 /* specify the DAC as the extra output */
15018                 if (!spec->multiout.hp_nid)
15019                         spec->multiout.hp_nid = nid_v;
15020                 else
15021                         spec->multiout.extra_out_nid[0] = nid_v;
15022                 /* control HP volume/switch on the output mixer amp */
15023                 nid_v = alc861vd_idx_to_mixer_vol(
15024                                 alc880_fixed_pin_idx(pin));
15025                 nid_s = alc861vd_idx_to_mixer_switch(
15026                                 alc880_fixed_pin_idx(pin));
15027
15028                 sprintf(name, "%s Playback Volume", pfx);
15029                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
15030                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
15031                 if (err < 0)
15032                         return err;
15033                 sprintf(name, "%s Playback Switch", pfx);
15034                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
15035                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
15036                 if (err < 0)
15037                         return err;
15038         } else if (alc880_is_multi_pin(pin)) {
15039                 /* set manual connection */
15040                 /* we have only a switch on HP-out PIN */
15041                 sprintf(name, "%s Playback Switch", pfx);
15042                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
15043                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
15044                 if (err < 0)
15045                         return err;
15046         }
15047         return 0;
15048 }
15049
15050 /* parse the BIOS configuration and set up the alc_spec
15051  * return 1 if successful, 0 if the proper config is not found,
15052  * or a negative error code
15053  * Based on ALC880 version - had to change it to override
15054  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
15055 static int alc861vd_parse_auto_config(struct hda_codec *codec)
15056 {
15057         struct alc_spec *spec = codec->spec;
15058         int err;
15059         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
15060
15061         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
15062                                            alc861vd_ignore);
15063         if (err < 0)
15064                 return err;
15065         if (!spec->autocfg.line_outs)
15066                 return 0; /* can't find valid BIOS pin config */
15067
15068         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
15069         if (err < 0)
15070                 return err;
15071         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
15072         if (err < 0)
15073                 return err;
15074         err = alc861vd_auto_create_extra_out(spec,
15075                                              spec->autocfg.speaker_pins[0],
15076                                              "Speaker");
15077         if (err < 0)
15078                 return err;
15079         err = alc861vd_auto_create_extra_out(spec,
15080                                              spec->autocfg.hp_pins[0],
15081                                              "Headphone");
15082         if (err < 0)
15083                 return err;
15084         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
15085         if (err < 0)
15086                 return err;
15087
15088         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
15089
15090         if (spec->autocfg.dig_outs)
15091                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
15092
15093         if (spec->kctls.list)
15094                 add_mixer(spec, spec->kctls.list);
15095
15096         add_verb(spec, alc861vd_volume_init_verbs);
15097
15098         spec->num_mux_defs = 1;
15099         spec->input_mux = &spec->private_imux[0];
15100
15101         err = alc_auto_add_mic_boost(codec);
15102         if (err < 0)
15103                 return err;
15104
15105         return 1;
15106 }
15107
15108 /* additional initialization for auto-configuration model */
15109 static void alc861vd_auto_init(struct hda_codec *codec)
15110 {
15111         struct alc_spec *spec = codec->spec;
15112         alc861vd_auto_init_multi_out(codec);
15113         alc861vd_auto_init_hp_out(codec);
15114         alc861vd_auto_init_analog_input(codec);
15115         alc861vd_auto_init_input_src(codec);
15116         if (spec->unsol_event)
15117                 alc_inithook(codec);
15118 }
15119
15120 static int patch_alc861vd(struct hda_codec *codec)
15121 {
15122         struct alc_spec *spec;
15123         int err, board_config;
15124
15125         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
15126         if (spec == NULL)
15127                 return -ENOMEM;
15128
15129         codec->spec = spec;
15130
15131         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
15132                                                   alc861vd_models,
15133                                                   alc861vd_cfg_tbl);
15134
15135         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
15136                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
15137                         "ALC861VD, trying auto-probe from BIOS...\n");
15138                 board_config = ALC861VD_AUTO;
15139         }
15140
15141         if (board_config == ALC861VD_AUTO) {
15142                 /* automatic parse from the BIOS config */
15143                 err = alc861vd_parse_auto_config(codec);
15144                 if (err < 0) {
15145                         alc_free(codec);
15146                         return err;
15147                 } else if (!err) {
15148                         printk(KERN_INFO
15149                                "hda_codec: Cannot set up configuration "
15150                                "from BIOS.  Using base mode...\n");
15151                         board_config = ALC861VD_3ST;
15152                 }
15153         }
15154
15155         err = snd_hda_attach_beep_device(codec, 0x23);
15156         if (err < 0) {
15157                 alc_free(codec);
15158                 return err;
15159         }
15160
15161         if (board_config != ALC861VD_AUTO)
15162                 setup_preset(spec, &alc861vd_presets[board_config]);
15163
15164         if (codec->vendor_id == 0x10ec0660) {
15165                 spec->stream_name_analog = "ALC660-VD Analog";
15166                 spec->stream_name_digital = "ALC660-VD Digital";
15167                 /* always turn on EAPD */
15168                 add_verb(spec, alc660vd_eapd_verbs);
15169         } else {
15170                 spec->stream_name_analog = "ALC861VD Analog";
15171                 spec->stream_name_digital = "ALC861VD Digital";
15172         }
15173
15174         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
15175         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
15176
15177         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
15178         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
15179
15180         spec->adc_nids = alc861vd_adc_nids;
15181         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
15182         spec->capsrc_nids = alc861vd_capsrc_nids;
15183         spec->capture_style = CAPT_MIX;
15184
15185         set_capture_mixer(spec);
15186         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
15187
15188         spec->vmaster_nid = 0x02;
15189
15190         codec->patch_ops = alc_patch_ops;
15191
15192         if (board_config == ALC861VD_AUTO)
15193                 spec->init_hook = alc861vd_auto_init;
15194 #ifdef CONFIG_SND_HDA_POWER_SAVE
15195         if (!spec->loopback.amplist)
15196                 spec->loopback.amplist = alc861vd_loopbacks;
15197 #endif
15198         codec->proc_widget_hook = print_realtek_coef;
15199
15200         return 0;
15201 }
15202
15203 /*
15204  * ALC662 support
15205  *
15206  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
15207  * configuration.  Each pin widget can choose any input DACs and a mixer.
15208  * Each ADC is connected from a mixer of all inputs.  This makes possible
15209  * 6-channel independent captures.
15210  *
15211  * In addition, an independent DAC for the multi-playback (not used in this
15212  * driver yet).
15213  */
15214 #define ALC662_DIGOUT_NID       0x06
15215 #define ALC662_DIGIN_NID        0x0a
15216
15217 static hda_nid_t alc662_dac_nids[4] = {
15218         /* front, rear, clfe, rear_surr */
15219         0x02, 0x03, 0x04
15220 };
15221
15222 static hda_nid_t alc272_dac_nids[2] = {
15223         0x02, 0x03
15224 };
15225
15226 static hda_nid_t alc662_adc_nids[1] = {
15227         /* ADC1-2 */
15228         0x09,
15229 };
15230
15231 static hda_nid_t alc272_adc_nids[1] = {
15232         /* ADC1-2 */
15233         0x08,
15234 };
15235
15236 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
15237 static hda_nid_t alc272_capsrc_nids[1] = { 0x23 };
15238
15239
15240 /* input MUX */
15241 /* FIXME: should be a matrix-type input source selection */
15242 static struct hda_input_mux alc662_capture_source = {
15243         .num_items = 4,
15244         .items = {
15245                 { "Mic", 0x0 },
15246                 { "Front Mic", 0x1 },
15247                 { "Line", 0x2 },
15248                 { "CD", 0x4 },
15249         },
15250 };
15251
15252 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
15253         .num_items = 2,
15254         .items = {
15255                 { "Mic", 0x1 },
15256                 { "Line", 0x2 },
15257         },
15258 };
15259
15260 static struct hda_input_mux alc662_eeepc_capture_source = {
15261         .num_items = 2,
15262         .items = {
15263                 { "i-Mic", 0x1 },
15264                 { "e-Mic", 0x0 },
15265         },
15266 };
15267
15268 static struct hda_input_mux alc663_capture_source = {
15269         .num_items = 3,
15270         .items = {
15271                 { "Mic", 0x0 },
15272                 { "Front Mic", 0x1 },
15273                 { "Line", 0x2 },
15274         },
15275 };
15276
15277 static struct hda_input_mux alc663_m51va_capture_source = {
15278         .num_items = 2,
15279         .items = {
15280                 { "Ext-Mic", 0x0 },
15281                 { "D-Mic", 0x9 },
15282         },
15283 };
15284
15285 /*
15286  * 2ch mode
15287  */
15288 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
15289         { 2, NULL }
15290 };
15291
15292 /*
15293  * 2ch mode
15294  */
15295 static struct hda_verb alc662_3ST_ch2_init[] = {
15296         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
15297         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
15298         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
15299         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
15300         { } /* end */
15301 };
15302
15303 /*
15304  * 6ch mode
15305  */
15306 static struct hda_verb alc662_3ST_ch6_init[] = {
15307         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15308         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
15309         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
15310         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15311         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
15312         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
15313         { } /* end */
15314 };
15315
15316 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
15317         { 2, alc662_3ST_ch2_init },
15318         { 6, alc662_3ST_ch6_init },
15319 };
15320
15321 /*
15322  * 2ch mode
15323  */
15324 static struct hda_verb alc662_sixstack_ch6_init[] = {
15325         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15326         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15327         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15328         { } /* end */
15329 };
15330
15331 /*
15332  * 6ch mode
15333  */
15334 static struct hda_verb alc662_sixstack_ch8_init[] = {
15335         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15336         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15337         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15338         { } /* end */
15339 };
15340
15341 static struct hda_channel_mode alc662_5stack_modes[2] = {
15342         { 2, alc662_sixstack_ch6_init },
15343         { 6, alc662_sixstack_ch8_init },
15344 };
15345
15346 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
15347  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
15348  */
15349
15350 static struct snd_kcontrol_new alc662_base_mixer[] = {
15351         /* output mixer control */
15352         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
15353         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15354         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
15355         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15356         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15357         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15358         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15359         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15360         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15361
15362         /*Input mixer control */
15363         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
15364         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
15365         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
15366         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
15367         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
15368         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
15369         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
15370         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
15371         { } /* end */
15372 };
15373
15374 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
15375         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15376         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15377         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15378         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15379         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15380         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15381         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15382         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15383         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15384         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15385         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15386         { } /* end */
15387 };
15388
15389 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
15390         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15391         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15392         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15393         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15394         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15395         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15396         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15397         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15398         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15399         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15400         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15401         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15402         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15403         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15404         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15405         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15406         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15407         { } /* end */
15408 };
15409
15410 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
15411         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15412         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
15413         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15414         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
15415         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15416         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15417         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15418         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15419         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15420         { } /* end */
15421 };
15422
15423 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
15424         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15425
15426         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15427         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15428
15429         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
15430         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15431         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15432
15433         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15434         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15435         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15436         { } /* end */
15437 };
15438
15439 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
15440         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15441         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15442         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15443         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
15444         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15445         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15446         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
15447         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
15448         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15449         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
15450         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15451         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15452         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15453         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15454         { } /* end */
15455 };
15456
15457 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
15458         .ops = &snd_hda_bind_vol,
15459         .values = {
15460                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15461                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
15462                 0
15463         },
15464 };
15465
15466 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
15467         .ops = &snd_hda_bind_sw,
15468         .values = {
15469                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15470                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15471                 0
15472         },
15473 };
15474
15475 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
15476         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15477         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
15478         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15479         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15480         { } /* end */
15481 };
15482
15483 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
15484         .ops = &snd_hda_bind_sw,
15485         .values = {
15486                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15487                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15488                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15489                 0
15490         },
15491 };
15492
15493 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
15494         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15495         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
15496         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15497         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15498         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15499         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15500
15501         { } /* end */
15502 };
15503
15504 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
15505         .ops = &snd_hda_bind_sw,
15506         .values = {
15507                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15508                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15509                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15510                 0
15511         },
15512 };
15513
15514 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
15515         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15516         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
15517         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15518         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15519         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15520         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15521         { } /* end */
15522 };
15523
15524 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
15525         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15526         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15527         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15528         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15529         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15530         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15531         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15532         { } /* end */
15533 };
15534
15535 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
15536         .ops = &snd_hda_bind_vol,
15537         .values = {
15538                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15539                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
15540                 0
15541         },
15542 };
15543
15544 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
15545         .ops = &snd_hda_bind_sw,
15546         .values = {
15547                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15548                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
15549                 0
15550         },
15551 };
15552
15553 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
15554         HDA_BIND_VOL("Master Playback Volume",
15555                                 &alc663_asus_two_bind_master_vol),
15556         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15557         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15558         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15559         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15560         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15561         { } /* end */
15562 };
15563
15564 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
15565         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15566         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15567         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15568         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15569         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15570         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15571         { } /* end */
15572 };
15573
15574 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
15575         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15576         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15577         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15578         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15579         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15580
15581         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15582         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15583         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15584         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15585         { } /* end */
15586 };
15587
15588 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
15589         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15590         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15591         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15592
15593         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15594         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15595         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15596         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15597         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15598         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15599         { } /* end */
15600 };
15601
15602 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
15603         {
15604                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15605                 .name = "Channel Mode",
15606                 .info = alc_ch_mode_info,
15607                 .get = alc_ch_mode_get,
15608                 .put = alc_ch_mode_put,
15609         },
15610         { } /* end */
15611 };
15612
15613 static struct hda_verb alc662_init_verbs[] = {
15614         /* ADC: mute amp left and right */
15615         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15616         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15617         /* Front mixer: unmute input/output amp left and right (volume = 0) */
15618
15619         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15620         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15621         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15622         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15623         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15624
15625         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15626         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15627         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15628         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15629         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15630         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15631
15632         /* Front Pin: output 0 (0x0c) */
15633         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15634         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15635
15636         /* Rear Pin: output 1 (0x0d) */
15637         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15638         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15639
15640         /* CLFE Pin: output 2 (0x0e) */
15641         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15642         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15643
15644         /* Mic (rear) pin: input vref at 80% */
15645         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15646         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15647         /* Front Mic pin: input vref at 80% */
15648         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15649         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15650         /* Line In pin: input */
15651         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15652         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15653         /* Line-2 In: Headphone output (output 0 - 0x0c) */
15654         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15655         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15656         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
15657         /* CD pin widget for input */
15658         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15659
15660         /* FIXME: use matrix-type input source selection */
15661         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15662         /* Input mixer */
15663         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15664         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15665
15666         /* always trun on EAPD */
15667         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15668         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
15669
15670         { }
15671 };
15672
15673 static struct hda_verb alc662_sue_init_verbs[] = {
15674         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15675         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15676         {}
15677 };
15678
15679 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
15680         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15681         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15682         {}
15683 };
15684
15685 /* Set Unsolicited Event*/
15686 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
15687         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15688         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15689         {}
15690 };
15691
15692 /*
15693  * generic initialization of ADC, input mixers and output mixers
15694  */
15695 static struct hda_verb alc662_auto_init_verbs[] = {
15696         /*
15697          * Unmute ADC and set the default input to mic-in
15698          */
15699         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15700         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15701
15702         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
15703          * mixer widget
15704          * Note: PASD motherboards uses the Line In 2 as the input for front
15705          * panel mic (mic 2)
15706          */
15707         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
15708         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15709         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15710         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15711         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15712         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15713
15714         /*
15715          * Set up output mixers (0x0c - 0x0f)
15716          */
15717         /* set vol=0 to output mixers */
15718         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15719         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15720         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15721
15722         /* set up input amps for analog loopback */
15723         /* Amp Indices: DAC = 0, mixer = 1 */
15724         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15725         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15726         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15727         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15728         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15729         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15730
15731
15732         /* FIXME: use matrix-type input source selection */
15733         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15734         /* Input mixer */
15735         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15736         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15737         { }
15738 };
15739
15740 /* additional verbs for ALC663 */
15741 static struct hda_verb alc663_auto_init_verbs[] = {
15742         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15743         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15744         { }
15745 };
15746
15747 static struct hda_verb alc663_m51va_init_verbs[] = {
15748         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15749         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15750         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15751         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15752         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15753         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15754         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
15755         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15756         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15757         {}
15758 };
15759
15760 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
15761         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15762         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15763         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* 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         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15768         {}
15769 };
15770
15771 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
15772         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15773         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15774         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15775         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15776         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15777         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15778         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15779         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15780         {}
15781 };
15782
15783 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
15784         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15785         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15786         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15787         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15788         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15789         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15790         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15791         {}
15792 };
15793
15794 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
15795         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15796         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15797         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15798         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15799         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15800         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15801         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15802         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15803         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15804         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15805         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15806         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15807         {}
15808 };
15809
15810 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
15811         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15812         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15813         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15814         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
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         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15819         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15820         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15821         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15822         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15823         {}
15824 };
15825
15826 static struct hda_verb alc663_g71v_init_verbs[] = {
15827         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15828         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
15829         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
15830
15831         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15832         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15833         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15834
15835         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15836         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
15837         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15838         {}
15839 };
15840
15841 static struct hda_verb alc663_g50v_init_verbs[] = {
15842         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15843         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15844         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15845
15846         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15847         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15848         {}
15849 };
15850
15851 static struct hda_verb alc662_ecs_init_verbs[] = {
15852         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
15853         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15854         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15855         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15856         {}
15857 };
15858
15859 static struct hda_verb alc272_dell_zm1_init_verbs[] = {
15860         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15861         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15862         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15863         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15864         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15865         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15866         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15867         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15868         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
15869         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15870         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15871         {}
15872 };
15873
15874 static struct hda_verb alc272_dell_init_verbs[] = {
15875         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15876         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15877         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15878         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15879         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15880         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15881         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15882         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15883         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
15884         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15885         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15886         {}
15887 };
15888
15889 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
15890         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
15891         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
15892         { } /* end */
15893 };
15894
15895 static struct snd_kcontrol_new alc272_auto_capture_mixer[] = {
15896         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
15897         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
15898         { } /* end */
15899 };
15900
15901 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
15902 {
15903         unsigned int present;
15904         unsigned char bits;
15905
15906         present = snd_hda_codec_read(codec, 0x14, 0,
15907                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15908         bits = present ? HDA_AMP_MUTE : 0;
15909         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15910                                  HDA_AMP_MUTE, bits);
15911 }
15912
15913 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
15914 {
15915         unsigned int present;
15916         unsigned char bits;
15917
15918         present = snd_hda_codec_read(codec, 0x1b, 0,
15919                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15920         bits = present ? HDA_AMP_MUTE : 0;
15921         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15922                                  HDA_AMP_MUTE, bits);
15923         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15924                                  HDA_AMP_MUTE, bits);
15925 }
15926
15927 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
15928                                            unsigned int res)
15929 {
15930         if ((res >> 26) == ALC880_HP_EVENT)
15931                 alc662_lenovo_101e_all_automute(codec);
15932         if ((res >> 26) == ALC880_FRONT_EVENT)
15933                 alc662_lenovo_101e_ispeaker_automute(codec);
15934 }
15935
15936 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
15937 {
15938         unsigned int present;
15939
15940         present = snd_hda_codec_read(codec, 0x18, 0,
15941                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15942         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15943                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15944         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15945                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15946         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15947                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15948         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15949                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15950 }
15951
15952 /* unsolicited event for HP jack sensing */
15953 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
15954                                      unsigned int res)
15955 {
15956         if ((res >> 26) == ALC880_HP_EVENT)
15957                 alc262_hippo1_automute( codec );
15958
15959         if ((res >> 26) == ALC880_MIC_EVENT)
15960                 alc662_eeepc_mic_automute(codec);
15961 }
15962
15963 static void alc662_eeepc_inithook(struct hda_codec *codec)
15964 {
15965         alc262_hippo1_automute( codec );
15966         alc662_eeepc_mic_automute(codec);
15967 }
15968
15969 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
15970 {
15971         unsigned int mute;
15972         unsigned int present;
15973
15974         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
15975         present = snd_hda_codec_read(codec, 0x14, 0,
15976                                      AC_VERB_GET_PIN_SENSE, 0);
15977         present = (present & 0x80000000) != 0;
15978         if (present) {
15979                 /* mute internal speaker */
15980                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15981                                         HDA_AMP_MUTE, HDA_AMP_MUTE);
15982         } else {
15983                 /* unmute internal speaker if necessary */
15984                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
15985                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15986                                         HDA_AMP_MUTE, mute);
15987         }
15988 }
15989
15990 /* unsolicited event for HP jack sensing */
15991 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
15992                                           unsigned int res)
15993 {
15994         if ((res >> 26) == ALC880_HP_EVENT)
15995                 alc662_eeepc_ep20_automute(codec);
15996 }
15997
15998 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
15999 {
16000         alc662_eeepc_ep20_automute(codec);
16001 }
16002
16003 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
16004 {
16005         unsigned int present;
16006         unsigned char bits;
16007
16008         present = snd_hda_codec_read(codec, 0x21, 0,
16009                         AC_VERB_GET_PIN_SENSE, 0)
16010                         & AC_PINSENSE_PRESENCE;
16011         bits = present ? HDA_AMP_MUTE : 0;
16012         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16013                                 AMP_IN_MUTE(0), bits);
16014         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16015                                 AMP_IN_MUTE(0), bits);
16016 }
16017
16018 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
16019 {
16020         unsigned int present;
16021         unsigned char bits;
16022
16023         present = snd_hda_codec_read(codec, 0x21, 0,
16024                         AC_VERB_GET_PIN_SENSE, 0)
16025                         & AC_PINSENSE_PRESENCE;
16026         bits = present ? HDA_AMP_MUTE : 0;
16027         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16028                                 AMP_IN_MUTE(0), bits);
16029         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16030                                 AMP_IN_MUTE(0), bits);
16031         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16032                                 AMP_IN_MUTE(0), bits);
16033         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16034                                 AMP_IN_MUTE(0), bits);
16035 }
16036
16037 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
16038 {
16039         unsigned int present;
16040         unsigned char bits;
16041
16042         present = snd_hda_codec_read(codec, 0x15, 0,
16043                         AC_VERB_GET_PIN_SENSE, 0)
16044                         & AC_PINSENSE_PRESENCE;
16045         bits = present ? HDA_AMP_MUTE : 0;
16046         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16047                                 AMP_IN_MUTE(0), bits);
16048         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16049                                 AMP_IN_MUTE(0), bits);
16050         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16051                                 AMP_IN_MUTE(0), bits);
16052         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16053                                 AMP_IN_MUTE(0), bits);
16054 }
16055
16056 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
16057 {
16058         unsigned int present;
16059         unsigned char bits;
16060
16061         present = snd_hda_codec_read(codec, 0x1b, 0,
16062                         AC_VERB_GET_PIN_SENSE, 0)
16063                         & AC_PINSENSE_PRESENCE;
16064         bits = present ? 0 : PIN_OUT;
16065         snd_hda_codec_write(codec, 0x14, 0,
16066                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
16067 }
16068
16069 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
16070 {
16071         unsigned int present1, present2;
16072
16073         present1 = snd_hda_codec_read(codec, 0x21, 0,
16074                         AC_VERB_GET_PIN_SENSE, 0)
16075                         & AC_PINSENSE_PRESENCE;
16076         present2 = snd_hda_codec_read(codec, 0x15, 0,
16077                         AC_VERB_GET_PIN_SENSE, 0)
16078                         & AC_PINSENSE_PRESENCE;
16079
16080         if (present1 || present2) {
16081                 snd_hda_codec_write_cache(codec, 0x14, 0,
16082                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
16083         } else {
16084                 snd_hda_codec_write_cache(codec, 0x14, 0,
16085                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
16086         }
16087 }
16088
16089 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
16090 {
16091         unsigned int present1, present2;
16092
16093         present1 = snd_hda_codec_read(codec, 0x1b, 0,
16094                                 AC_VERB_GET_PIN_SENSE, 0)
16095                                 & AC_PINSENSE_PRESENCE;
16096         present2 = snd_hda_codec_read(codec, 0x15, 0,
16097                                 AC_VERB_GET_PIN_SENSE, 0)
16098                                 & AC_PINSENSE_PRESENCE;
16099
16100         if (present1 || present2) {
16101                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16102                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
16103                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16104                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
16105         } else {
16106                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16107                                 AMP_IN_MUTE(0), 0);
16108                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16109                                 AMP_IN_MUTE(0), 0);
16110         }
16111 }
16112
16113 static void alc663_m51va_mic_automute(struct hda_codec *codec)
16114 {
16115         unsigned int present;
16116
16117         present = snd_hda_codec_read(codec, 0x18, 0,
16118                         AC_VERB_GET_PIN_SENSE, 0)
16119                         & AC_PINSENSE_PRESENCE;
16120         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16121                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16122         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16123                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16124         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16125                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
16126         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16127                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
16128 }
16129
16130 static void alc663_m51va_unsol_event(struct hda_codec *codec,
16131                                            unsigned int res)
16132 {
16133         switch (res >> 26) {
16134         case ALC880_HP_EVENT:
16135                 alc663_m51va_speaker_automute(codec);
16136                 break;
16137         case ALC880_MIC_EVENT:
16138                 alc663_m51va_mic_automute(codec);
16139                 break;
16140         }
16141 }
16142
16143 static void alc663_m51va_inithook(struct hda_codec *codec)
16144 {
16145         alc663_m51va_speaker_automute(codec);
16146         alc663_m51va_mic_automute(codec);
16147 }
16148
16149 /* ***************** Mode1 ******************************/
16150 static void alc663_mode1_unsol_event(struct hda_codec *codec,
16151                                            unsigned int res)
16152 {
16153         switch (res >> 26) {
16154         case ALC880_HP_EVENT:
16155                 alc663_m51va_speaker_automute(codec);
16156                 break;
16157         case ALC880_MIC_EVENT:
16158                 alc662_eeepc_mic_automute(codec);
16159                 break;
16160         }
16161 }
16162
16163 static void alc663_mode1_inithook(struct hda_codec *codec)
16164 {
16165         alc663_m51va_speaker_automute(codec);
16166         alc662_eeepc_mic_automute(codec);
16167 }
16168 /* ***************** Mode2 ******************************/
16169 static void alc662_mode2_unsol_event(struct hda_codec *codec,
16170                                            unsigned int res)
16171 {
16172         switch (res >> 26) {
16173         case ALC880_HP_EVENT:
16174                 alc662_f5z_speaker_automute(codec);
16175                 break;
16176         case ALC880_MIC_EVENT:
16177                 alc662_eeepc_mic_automute(codec);
16178                 break;
16179         }
16180 }
16181
16182 static void alc662_mode2_inithook(struct hda_codec *codec)
16183 {
16184         alc662_f5z_speaker_automute(codec);
16185         alc662_eeepc_mic_automute(codec);
16186 }
16187 /* ***************** Mode3 ******************************/
16188 static void alc663_mode3_unsol_event(struct hda_codec *codec,
16189                                            unsigned int res)
16190 {
16191         switch (res >> 26) {
16192         case ALC880_HP_EVENT:
16193                 alc663_two_hp_m1_speaker_automute(codec);
16194                 break;
16195         case ALC880_MIC_EVENT:
16196                 alc662_eeepc_mic_automute(codec);
16197                 break;
16198         }
16199 }
16200
16201 static void alc663_mode3_inithook(struct hda_codec *codec)
16202 {
16203         alc663_two_hp_m1_speaker_automute(codec);
16204         alc662_eeepc_mic_automute(codec);
16205 }
16206 /* ***************** Mode4 ******************************/
16207 static void alc663_mode4_unsol_event(struct hda_codec *codec,
16208                                            unsigned int res)
16209 {
16210         switch (res >> 26) {
16211         case ALC880_HP_EVENT:
16212                 alc663_21jd_two_speaker_automute(codec);
16213                 break;
16214         case ALC880_MIC_EVENT:
16215                 alc662_eeepc_mic_automute(codec);
16216                 break;
16217         }
16218 }
16219
16220 static void alc663_mode4_inithook(struct hda_codec *codec)
16221 {
16222         alc663_21jd_two_speaker_automute(codec);
16223         alc662_eeepc_mic_automute(codec);
16224 }
16225 /* ***************** Mode5 ******************************/
16226 static void alc663_mode5_unsol_event(struct hda_codec *codec,
16227                                            unsigned int res)
16228 {
16229         switch (res >> 26) {
16230         case ALC880_HP_EVENT:
16231                 alc663_15jd_two_speaker_automute(codec);
16232                 break;
16233         case ALC880_MIC_EVENT:
16234                 alc662_eeepc_mic_automute(codec);
16235                 break;
16236         }
16237 }
16238
16239 static void alc663_mode5_inithook(struct hda_codec *codec)
16240 {
16241         alc663_15jd_two_speaker_automute(codec);
16242         alc662_eeepc_mic_automute(codec);
16243 }
16244 /* ***************** Mode6 ******************************/
16245 static void alc663_mode6_unsol_event(struct hda_codec *codec,
16246                                            unsigned int res)
16247 {
16248         switch (res >> 26) {
16249         case ALC880_HP_EVENT:
16250                 alc663_two_hp_m2_speaker_automute(codec);
16251                 break;
16252         case ALC880_MIC_EVENT:
16253                 alc662_eeepc_mic_automute(codec);
16254                 break;
16255         }
16256 }
16257
16258 static void alc663_mode6_inithook(struct hda_codec *codec)
16259 {
16260         alc663_two_hp_m2_speaker_automute(codec);
16261         alc662_eeepc_mic_automute(codec);
16262 }
16263
16264 static void alc663_g71v_hp_automute(struct hda_codec *codec)
16265 {
16266         unsigned int present;
16267         unsigned char bits;
16268
16269         present = snd_hda_codec_read(codec, 0x21, 0,
16270                                      AC_VERB_GET_PIN_SENSE, 0)
16271                 & AC_PINSENSE_PRESENCE;
16272         bits = present ? HDA_AMP_MUTE : 0;
16273         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16274                                  HDA_AMP_MUTE, bits);
16275         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16276                                  HDA_AMP_MUTE, bits);
16277 }
16278
16279 static void alc663_g71v_front_automute(struct hda_codec *codec)
16280 {
16281         unsigned int present;
16282         unsigned char bits;
16283
16284         present = snd_hda_codec_read(codec, 0x15, 0,
16285                                      AC_VERB_GET_PIN_SENSE, 0)
16286                 & AC_PINSENSE_PRESENCE;
16287         bits = present ? HDA_AMP_MUTE : 0;
16288         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16289                                  HDA_AMP_MUTE, bits);
16290 }
16291
16292 static void alc663_g71v_unsol_event(struct hda_codec *codec,
16293                                            unsigned int res)
16294 {
16295         switch (res >> 26) {
16296         case ALC880_HP_EVENT:
16297                 alc663_g71v_hp_automute(codec);
16298                 break;
16299         case ALC880_FRONT_EVENT:
16300                 alc663_g71v_front_automute(codec);
16301                 break;
16302         case ALC880_MIC_EVENT:
16303                 alc662_eeepc_mic_automute(codec);
16304                 break;
16305         }
16306 }
16307
16308 static void alc663_g71v_inithook(struct hda_codec *codec)
16309 {
16310         alc663_g71v_front_automute(codec);
16311         alc663_g71v_hp_automute(codec);
16312         alc662_eeepc_mic_automute(codec);
16313 }
16314
16315 static void alc663_g50v_unsol_event(struct hda_codec *codec,
16316                                            unsigned int res)
16317 {
16318         switch (res >> 26) {
16319         case ALC880_HP_EVENT:
16320                 alc663_m51va_speaker_automute(codec);
16321                 break;
16322         case ALC880_MIC_EVENT:
16323                 alc662_eeepc_mic_automute(codec);
16324                 break;
16325         }
16326 }
16327
16328 static void alc663_g50v_inithook(struct hda_codec *codec)
16329 {
16330         alc663_m51va_speaker_automute(codec);
16331         alc662_eeepc_mic_automute(codec);
16332 }
16333
16334 /* bind hp and internal speaker mute (with plug check) */
16335 static int alc662_ecs_master_sw_put(struct snd_kcontrol *kcontrol,
16336                                      struct snd_ctl_elem_value *ucontrol)
16337 {
16338         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
16339         long *valp = ucontrol->value.integer.value;
16340         int change;
16341
16342         change = snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
16343                                           HDA_AMP_MUTE,
16344                                           valp[0] ? 0 : HDA_AMP_MUTE);
16345         change |= snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
16346                                            HDA_AMP_MUTE,
16347                                            valp[1] ? 0 : HDA_AMP_MUTE);
16348         if (change)
16349                 alc262_hippo1_automute(codec);
16350         return change;
16351 }
16352
16353 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
16354         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16355         {
16356                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
16357                 .name = "Master Playback Switch",
16358                 .info = snd_hda_mixer_amp_switch_info,
16359                 .get = snd_hda_mixer_amp_switch_get,
16360                 .put = alc662_ecs_master_sw_put,
16361                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
16362         },
16363
16364         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
16365         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
16366         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
16367
16368         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
16369         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16370         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16371         { } /* end */
16372 };
16373
16374 #ifdef CONFIG_SND_HDA_POWER_SAVE
16375 #define alc662_loopbacks        alc880_loopbacks
16376 #endif
16377
16378
16379 /* pcm configuration: identiacal with ALC880 */
16380 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
16381 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
16382 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
16383 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
16384
16385 /*
16386  * configuration and preset
16387  */
16388 static const char *alc662_models[ALC662_MODEL_LAST] = {
16389         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
16390         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
16391         [ALC662_3ST_6ch]        = "3stack-6ch",
16392         [ALC662_5ST_DIG]        = "6stack-dig",
16393         [ALC662_LENOVO_101E]    = "lenovo-101e",
16394         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
16395         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
16396         [ALC662_ECS] = "ecs",
16397         [ALC663_ASUS_M51VA] = "m51va",
16398         [ALC663_ASUS_G71V] = "g71v",
16399         [ALC663_ASUS_H13] = "h13",
16400         [ALC663_ASUS_G50V] = "g50v",
16401         [ALC663_ASUS_MODE1] = "asus-mode1",
16402         [ALC662_ASUS_MODE2] = "asus-mode2",
16403         [ALC663_ASUS_MODE3] = "asus-mode3",
16404         [ALC663_ASUS_MODE4] = "asus-mode4",
16405         [ALC663_ASUS_MODE5] = "asus-mode5",
16406         [ALC663_ASUS_MODE6] = "asus-mode6",
16407         [ALC662_AUTO]           = "auto",
16408 };
16409
16410 static struct snd_pci_quirk alc662_cfg_tbl[] = {
16411         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
16412         SND_PCI_QUIRK(0x1028, 0x02d6, "DELL", ALC272_DELL),
16413         SND_PCI_QUIRK(0x1028, 0x02f4, "DELL ZM1", ALC272_DELL_ZM1),
16414         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
16415         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
16416         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
16417         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
16418         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
16419         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
16420         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
16421         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
16422         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
16423         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
16424         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
16425         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
16426         SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC663_ASUS_MODE3),
16427         SND_PCI_QUIRK(0x1043, 0x17c3, "ASUS UX20", ALC663_ASUS_M51VA),
16428         SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_ASUS_MODE2),
16429         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
16430         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
16431         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
16432         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
16433         SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC663_ASUS_MODE1),
16434         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
16435         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
16436         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
16437         /*SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),*/
16438         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
16439         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
16440         SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC663_ASUS_MODE1),
16441         SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC663_ASUS_MODE1),
16442         SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC663_ASUS_MODE1),
16443         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
16444         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
16445         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
16446         SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC663_ASUS_MODE1),
16447         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
16448         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
16449         SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC663_ASUS_MODE1),
16450         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
16451         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
16452         /*SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),*/
16453         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
16454         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
16455         SND_PCI_QUIRK(0x1043, 0x19d3, "ASUS NB", ALC663_ASUS_M51VA),
16456         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
16457         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
16458         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
16459         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
16460         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
16461         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
16462         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
16463                       ALC662_3ST_6ch_DIG),
16464         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
16465                       ALC662_3ST_6ch_DIG),
16466         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
16467         SND_PCI_QUIRK(0x1631, 0xc10c, "PB RS65", ALC663_ASUS_M51VA),
16468         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
16469         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
16470                                         ALC662_3ST_6ch_DIG),
16471         SND_PCI_QUIRK_MASK(0x1854, 0xf000, 0x2000, "ASUS H13-200x",
16472                            ALC663_ASUS_H13),
16473         {}
16474 };
16475
16476 static struct alc_config_preset alc662_presets[] = {
16477         [ALC662_3ST_2ch_DIG] = {
16478                 .mixers = { alc662_3ST_2ch_mixer },
16479                 .init_verbs = { alc662_init_verbs },
16480                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16481                 .dac_nids = alc662_dac_nids,
16482                 .dig_out_nid = ALC662_DIGOUT_NID,
16483                 .dig_in_nid = ALC662_DIGIN_NID,
16484                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16485                 .channel_mode = alc662_3ST_2ch_modes,
16486                 .input_mux = &alc662_capture_source,
16487         },
16488         [ALC662_3ST_6ch_DIG] = {
16489                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16490                 .init_verbs = { alc662_init_verbs },
16491                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16492                 .dac_nids = alc662_dac_nids,
16493                 .dig_out_nid = ALC662_DIGOUT_NID,
16494                 .dig_in_nid = ALC662_DIGIN_NID,
16495                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16496                 .channel_mode = alc662_3ST_6ch_modes,
16497                 .need_dac_fix = 1,
16498                 .input_mux = &alc662_capture_source,
16499         },
16500         [ALC662_3ST_6ch] = {
16501                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16502                 .init_verbs = { alc662_init_verbs },
16503                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16504                 .dac_nids = alc662_dac_nids,
16505                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16506                 .channel_mode = alc662_3ST_6ch_modes,
16507                 .need_dac_fix = 1,
16508                 .input_mux = &alc662_capture_source,
16509         },
16510         [ALC662_5ST_DIG] = {
16511                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
16512                 .init_verbs = { alc662_init_verbs },
16513                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16514                 .dac_nids = alc662_dac_nids,
16515                 .dig_out_nid = ALC662_DIGOUT_NID,
16516                 .dig_in_nid = ALC662_DIGIN_NID,
16517                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
16518                 .channel_mode = alc662_5stack_modes,
16519                 .input_mux = &alc662_capture_source,
16520         },
16521         [ALC662_LENOVO_101E] = {
16522                 .mixers = { alc662_lenovo_101e_mixer },
16523                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
16524                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16525                 .dac_nids = alc662_dac_nids,
16526                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16527                 .channel_mode = alc662_3ST_2ch_modes,
16528                 .input_mux = &alc662_lenovo_101e_capture_source,
16529                 .unsol_event = alc662_lenovo_101e_unsol_event,
16530                 .init_hook = alc662_lenovo_101e_all_automute,
16531         },
16532         [ALC662_ASUS_EEEPC_P701] = {
16533                 .mixers = { alc662_eeepc_p701_mixer },
16534                 .init_verbs = { alc662_init_verbs,
16535                                 alc662_eeepc_sue_init_verbs },
16536                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16537                 .dac_nids = alc662_dac_nids,
16538                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16539                 .channel_mode = alc662_3ST_2ch_modes,
16540                 .input_mux = &alc662_eeepc_capture_source,
16541                 .unsol_event = alc662_eeepc_unsol_event,
16542                 .init_hook = alc662_eeepc_inithook,
16543         },
16544         [ALC662_ASUS_EEEPC_EP20] = {
16545                 .mixers = { alc662_eeepc_ep20_mixer,
16546                             alc662_chmode_mixer },
16547                 .init_verbs = { alc662_init_verbs,
16548                                 alc662_eeepc_ep20_sue_init_verbs },
16549                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16550                 .dac_nids = alc662_dac_nids,
16551                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16552                 .channel_mode = alc662_3ST_6ch_modes,
16553                 .input_mux = &alc662_lenovo_101e_capture_source,
16554                 .unsol_event = alc662_eeepc_ep20_unsol_event,
16555                 .init_hook = alc662_eeepc_ep20_inithook,
16556         },
16557         [ALC662_ECS] = {
16558                 .mixers = { alc662_ecs_mixer },
16559                 .init_verbs = { alc662_init_verbs,
16560                                 alc662_ecs_init_verbs },
16561                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16562                 .dac_nids = alc662_dac_nids,
16563                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16564                 .channel_mode = alc662_3ST_2ch_modes,
16565                 .input_mux = &alc662_eeepc_capture_source,
16566                 .unsol_event = alc662_eeepc_unsol_event,
16567                 .init_hook = alc662_eeepc_inithook,
16568         },
16569         [ALC663_ASUS_M51VA] = {
16570                 .mixers = { alc663_m51va_mixer },
16571                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16572                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16573                 .dac_nids = alc662_dac_nids,
16574                 .dig_out_nid = ALC662_DIGOUT_NID,
16575                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16576                 .channel_mode = alc662_3ST_2ch_modes,
16577                 .input_mux = &alc663_m51va_capture_source,
16578                 .unsol_event = alc663_m51va_unsol_event,
16579                 .init_hook = alc663_m51va_inithook,
16580         },
16581         [ALC663_ASUS_G71V] = {
16582                 .mixers = { alc663_g71v_mixer },
16583                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
16584                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16585                 .dac_nids = alc662_dac_nids,
16586                 .dig_out_nid = ALC662_DIGOUT_NID,
16587                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16588                 .channel_mode = alc662_3ST_2ch_modes,
16589                 .input_mux = &alc662_eeepc_capture_source,
16590                 .unsol_event = alc663_g71v_unsol_event,
16591                 .init_hook = alc663_g71v_inithook,
16592         },
16593         [ALC663_ASUS_H13] = {
16594                 .mixers = { alc663_m51va_mixer },
16595                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16596                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16597                 .dac_nids = alc662_dac_nids,
16598                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16599                 .channel_mode = alc662_3ST_2ch_modes,
16600                 .input_mux = &alc663_m51va_capture_source,
16601                 .unsol_event = alc663_m51va_unsol_event,
16602                 .init_hook = alc663_m51va_inithook,
16603         },
16604         [ALC663_ASUS_G50V] = {
16605                 .mixers = { alc663_g50v_mixer },
16606                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
16607                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16608                 .dac_nids = alc662_dac_nids,
16609                 .dig_out_nid = ALC662_DIGOUT_NID,
16610                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16611                 .channel_mode = alc662_3ST_6ch_modes,
16612                 .input_mux = &alc663_capture_source,
16613                 .unsol_event = alc663_g50v_unsol_event,
16614                 .init_hook = alc663_g50v_inithook,
16615         },
16616         [ALC663_ASUS_MODE1] = {
16617                 .mixers = { alc663_m51va_mixer },
16618                 .cap_mixer = alc662_auto_capture_mixer,
16619                 .init_verbs = { alc662_init_verbs,
16620                                 alc663_21jd_amic_init_verbs },
16621                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16622                 .hp_nid = 0x03,
16623                 .dac_nids = alc662_dac_nids,
16624                 .dig_out_nid = ALC662_DIGOUT_NID,
16625                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16626                 .channel_mode = alc662_3ST_2ch_modes,
16627                 .input_mux = &alc662_eeepc_capture_source,
16628                 .unsol_event = alc663_mode1_unsol_event,
16629                 .init_hook = alc663_mode1_inithook,
16630         },
16631         [ALC662_ASUS_MODE2] = {
16632                 .mixers = { alc662_1bjd_mixer },
16633                 .cap_mixer = alc662_auto_capture_mixer,
16634                 .init_verbs = { alc662_init_verbs,
16635                                 alc662_1bjd_amic_init_verbs },
16636                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16637                 .dac_nids = alc662_dac_nids,
16638                 .dig_out_nid = ALC662_DIGOUT_NID,
16639                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16640                 .channel_mode = alc662_3ST_2ch_modes,
16641                 .input_mux = &alc662_eeepc_capture_source,
16642                 .unsol_event = alc662_mode2_unsol_event,
16643                 .init_hook = alc662_mode2_inithook,
16644         },
16645         [ALC663_ASUS_MODE3] = {
16646                 .mixers = { alc663_two_hp_m1_mixer },
16647                 .cap_mixer = alc662_auto_capture_mixer,
16648                 .init_verbs = { alc662_init_verbs,
16649                                 alc663_two_hp_amic_m1_init_verbs },
16650                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16651                 .hp_nid = 0x03,
16652                 .dac_nids = alc662_dac_nids,
16653                 .dig_out_nid = ALC662_DIGOUT_NID,
16654                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16655                 .channel_mode = alc662_3ST_2ch_modes,
16656                 .input_mux = &alc662_eeepc_capture_source,
16657                 .unsol_event = alc663_mode3_unsol_event,
16658                 .init_hook = alc663_mode3_inithook,
16659         },
16660         [ALC663_ASUS_MODE4] = {
16661                 .mixers = { alc663_asus_21jd_clfe_mixer },
16662                 .cap_mixer = alc662_auto_capture_mixer,
16663                 .init_verbs = { alc662_init_verbs,
16664                                 alc663_21jd_amic_init_verbs},
16665                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16666                 .hp_nid = 0x03,
16667                 .dac_nids = alc662_dac_nids,
16668                 .dig_out_nid = ALC662_DIGOUT_NID,
16669                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16670                 .channel_mode = alc662_3ST_2ch_modes,
16671                 .input_mux = &alc662_eeepc_capture_source,
16672                 .unsol_event = alc663_mode4_unsol_event,
16673                 .init_hook = alc663_mode4_inithook,
16674         },
16675         [ALC663_ASUS_MODE5] = {
16676                 .mixers = { alc663_asus_15jd_clfe_mixer },
16677                 .cap_mixer = alc662_auto_capture_mixer,
16678                 .init_verbs = { alc662_init_verbs,
16679                                 alc663_15jd_amic_init_verbs },
16680                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16681                 .hp_nid = 0x03,
16682                 .dac_nids = alc662_dac_nids,
16683                 .dig_out_nid = ALC662_DIGOUT_NID,
16684                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16685                 .channel_mode = alc662_3ST_2ch_modes,
16686                 .input_mux = &alc662_eeepc_capture_source,
16687                 .unsol_event = alc663_mode5_unsol_event,
16688                 .init_hook = alc663_mode5_inithook,
16689         },
16690         [ALC663_ASUS_MODE6] = {
16691                 .mixers = { alc663_two_hp_m2_mixer },
16692                 .cap_mixer = alc662_auto_capture_mixer,
16693                 .init_verbs = { alc662_init_verbs,
16694                                 alc663_two_hp_amic_m2_init_verbs },
16695                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16696                 .hp_nid = 0x03,
16697                 .dac_nids = alc662_dac_nids,
16698                 .dig_out_nid = ALC662_DIGOUT_NID,
16699                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16700                 .channel_mode = alc662_3ST_2ch_modes,
16701                 .input_mux = &alc662_eeepc_capture_source,
16702                 .unsol_event = alc663_mode6_unsol_event,
16703                 .init_hook = alc663_mode6_inithook,
16704         },
16705         [ALC272_DELL] = {
16706                 .mixers = { alc663_m51va_mixer },
16707                 .cap_mixer = alc272_auto_capture_mixer,
16708                 .init_verbs = { alc662_init_verbs, alc272_dell_init_verbs },
16709                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
16710                 .dac_nids = alc662_dac_nids,
16711                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16712                 .adc_nids = alc272_adc_nids,
16713                 .num_adc_nids = ARRAY_SIZE(alc272_adc_nids),
16714                 .capsrc_nids = alc272_capsrc_nids,
16715                 .channel_mode = alc662_3ST_2ch_modes,
16716                 .input_mux = &alc663_m51va_capture_source,
16717                 .unsol_event = alc663_m51va_unsol_event,
16718                 .init_hook = alc663_m51va_inithook,
16719         },
16720         [ALC272_DELL_ZM1] = {
16721                 .mixers = { alc663_m51va_mixer },
16722                 .cap_mixer = alc662_auto_capture_mixer,
16723                 .init_verbs = { alc662_init_verbs, alc272_dell_zm1_init_verbs },
16724                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
16725                 .dac_nids = alc662_dac_nids,
16726                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16727                 .adc_nids = alc662_adc_nids,
16728                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
16729                 .capsrc_nids = alc662_capsrc_nids,
16730                 .channel_mode = alc662_3ST_2ch_modes,
16731                 .input_mux = &alc663_m51va_capture_source,
16732                 .unsol_event = alc663_m51va_unsol_event,
16733                 .init_hook = alc663_m51va_inithook,
16734         },
16735 };
16736
16737
16738 /*
16739  * BIOS auto configuration
16740  */
16741
16742 /* add playback controls from the parsed DAC table */
16743 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
16744                                              const struct auto_pin_cfg *cfg)
16745 {
16746         char name[32];
16747         static const char *chname[4] = {
16748                 "Front", "Surround", NULL /*CLFE*/, "Side"
16749         };
16750         hda_nid_t nid;
16751         int i, err;
16752
16753         for (i = 0; i < cfg->line_outs; i++) {
16754                 if (!spec->multiout.dac_nids[i])
16755                         continue;
16756                 nid = alc880_idx_to_dac(i);
16757                 if (i == 2) {
16758                         /* Center/LFE */
16759                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16760                                           "Center Playback Volume",
16761                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
16762                                                               HDA_OUTPUT));
16763                         if (err < 0)
16764                                 return err;
16765                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16766                                           "LFE Playback Volume",
16767                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
16768                                                               HDA_OUTPUT));
16769                         if (err < 0)
16770                                 return err;
16771                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16772                                           "Center Playback Switch",
16773                                           HDA_COMPOSE_AMP_VAL(0x0e, 1, 0,
16774                                                               HDA_INPUT));
16775                         if (err < 0)
16776                                 return err;
16777                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16778                                           "LFE Playback Switch",
16779                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
16780                                                               HDA_INPUT));
16781                         if (err < 0)
16782                                 return err;
16783                 } else {
16784                         sprintf(name, "%s Playback Volume", chname[i]);
16785                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16786                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
16787                                                               HDA_OUTPUT));
16788                         if (err < 0)
16789                                 return err;
16790                         sprintf(name, "%s Playback Switch", chname[i]);
16791                         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16792                                 HDA_COMPOSE_AMP_VAL(alc880_idx_to_mixer(i),
16793                                                     3, 0, HDA_INPUT));
16794                         if (err < 0)
16795                                 return err;
16796                 }
16797         }
16798         return 0;
16799 }
16800
16801 /* add playback controls for speaker and HP outputs */
16802 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
16803                                         const char *pfx)
16804 {
16805         hda_nid_t nid;
16806         int err;
16807         char name[32];
16808
16809         if (!pin)
16810                 return 0;
16811
16812         if (pin == 0x17) {
16813                 /* ALC663 has a mono output pin on 0x17 */
16814                 sprintf(name, "%s Playback Switch", pfx);
16815                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16816                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
16817                 return err;
16818         }
16819
16820         if (alc880_is_fixed_pin(pin)) {
16821                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16822                 /* printk(KERN_DEBUG "DAC nid=%x\n",nid); */
16823                 /* specify the DAC as the extra output */
16824                 if (!spec->multiout.hp_nid)
16825                         spec->multiout.hp_nid = nid;
16826                 else
16827                         spec->multiout.extra_out_nid[0] = nid;
16828                 /* control HP volume/switch on the output mixer amp */
16829                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16830                 sprintf(name, "%s Playback Volume", pfx);
16831                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16832                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
16833                 if (err < 0)
16834                         return err;
16835                 sprintf(name, "%s Playback Switch", pfx);
16836                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
16837                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
16838                 if (err < 0)
16839                         return err;
16840         } else if (alc880_is_multi_pin(pin)) {
16841                 /* set manual connection */
16842                 /* we have only a switch on HP-out PIN */
16843                 sprintf(name, "%s Playback Switch", pfx);
16844                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16845                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
16846                 if (err < 0)
16847                         return err;
16848         }
16849         return 0;
16850 }
16851
16852 /* return the index of the src widget from the connection list of the nid.
16853  * return -1 if not found
16854  */
16855 static int alc662_input_pin_idx(struct hda_codec *codec, hda_nid_t nid,
16856                                 hda_nid_t src)
16857 {
16858         hda_nid_t conn_list[HDA_MAX_CONNECTIONS];
16859         int i, conns;
16860
16861         conns = snd_hda_get_connections(codec, nid, conn_list,
16862                                         ARRAY_SIZE(conn_list));
16863         if (conns < 0)
16864                 return -1;
16865         for (i = 0; i < conns; i++)
16866                 if (conn_list[i] == src)
16867                         return i;
16868         return -1;
16869 }
16870
16871 static int alc662_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
16872 {
16873         unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
16874         return (pincap & AC_PINCAP_IN) != 0;
16875 }
16876
16877 /* create playback/capture controls for input pins */
16878 static int alc662_auto_create_analog_input_ctls(struct hda_codec *codec,
16879                                                 const struct auto_pin_cfg *cfg)
16880 {
16881         struct alc_spec *spec = codec->spec;
16882         struct hda_input_mux *imux = &spec->private_imux[0];
16883         int i, err, idx;
16884
16885         for (i = 0; i < AUTO_PIN_LAST; i++) {
16886                 if (alc662_is_input_pin(codec, cfg->input_pins[i])) {
16887                         idx = alc662_input_pin_idx(codec, 0x0b,
16888                                                    cfg->input_pins[i]);
16889                         if (idx >= 0) {
16890                                 err = new_analog_input(spec, cfg->input_pins[i],
16891                                                        auto_pin_cfg_labels[i],
16892                                                        idx, 0x0b);
16893                                 if (err < 0)
16894                                         return err;
16895                         }
16896                         idx = alc662_input_pin_idx(codec, 0x22,
16897                                                    cfg->input_pins[i]);
16898                         if (idx >= 0) {
16899                                 imux->items[imux->num_items].label =
16900                                         auto_pin_cfg_labels[i];
16901                                 imux->items[imux->num_items].index = idx;
16902                                 imux->num_items++;
16903                         }
16904                 }
16905         }
16906         return 0;
16907 }
16908
16909 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
16910                                               hda_nid_t nid, int pin_type,
16911                                               int dac_idx)
16912 {
16913         alc_set_pin_output(codec, nid, pin_type);
16914         /* need the manual connection? */
16915         if (alc880_is_multi_pin(nid)) {
16916                 struct alc_spec *spec = codec->spec;
16917                 int idx = alc880_multi_pin_idx(nid);
16918                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
16919                                     AC_VERB_SET_CONNECT_SEL,
16920                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
16921         }
16922 }
16923
16924 static void alc662_auto_init_multi_out(struct hda_codec *codec)
16925 {
16926         struct alc_spec *spec = codec->spec;
16927         int i;
16928
16929         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
16930         for (i = 0; i <= HDA_SIDE; i++) {
16931                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
16932                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
16933                 if (nid)
16934                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
16935                                                           i);
16936         }
16937 }
16938
16939 static void alc662_auto_init_hp_out(struct hda_codec *codec)
16940 {
16941         struct alc_spec *spec = codec->spec;
16942         hda_nid_t pin;
16943
16944         pin = spec->autocfg.hp_pins[0];
16945         if (pin) /* connect to front */
16946                 /* use dac 0 */
16947                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
16948         pin = spec->autocfg.speaker_pins[0];
16949         if (pin)
16950                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
16951 }
16952
16953 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
16954
16955 static void alc662_auto_init_analog_input(struct hda_codec *codec)
16956 {
16957         struct alc_spec *spec = codec->spec;
16958         int i;
16959
16960         for (i = 0; i < AUTO_PIN_LAST; i++) {
16961                 hda_nid_t nid = spec->autocfg.input_pins[i];
16962                 if (alc662_is_input_pin(codec, nid)) {
16963                         alc_set_input_pin(codec, nid, i);
16964                         if (nid != ALC662_PIN_CD_NID &&
16965                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
16966                                 snd_hda_codec_write(codec, nid, 0,
16967                                                     AC_VERB_SET_AMP_GAIN_MUTE,
16968                                                     AMP_OUT_MUTE);
16969                 }
16970         }
16971 }
16972
16973 #define alc662_auto_init_input_src      alc882_auto_init_input_src
16974
16975 static int alc662_parse_auto_config(struct hda_codec *codec)
16976 {
16977         struct alc_spec *spec = codec->spec;
16978         int err;
16979         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
16980
16981         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
16982                                            alc662_ignore);
16983         if (err < 0)
16984                 return err;
16985         if (!spec->autocfg.line_outs)
16986                 return 0; /* can't find valid BIOS pin config */
16987
16988         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
16989         if (err < 0)
16990                 return err;
16991         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
16992         if (err < 0)
16993                 return err;
16994         err = alc662_auto_create_extra_out(spec,
16995                                            spec->autocfg.speaker_pins[0],
16996                                            "Speaker");
16997         if (err < 0)
16998                 return err;
16999         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
17000                                            "Headphone");
17001         if (err < 0)
17002                 return err;
17003         err = alc662_auto_create_analog_input_ctls(codec, &spec->autocfg);
17004         if (err < 0)
17005                 return err;
17006
17007         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
17008
17009         if (spec->autocfg.dig_outs)
17010                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
17011
17012         if (spec->kctls.list)
17013                 add_mixer(spec, spec->kctls.list);
17014
17015         spec->num_mux_defs = 1;
17016         spec->input_mux = &spec->private_imux[0];
17017
17018         add_verb(spec, alc662_auto_init_verbs);
17019         if (codec->vendor_id == 0x10ec0663)
17020                 add_verb(spec, alc663_auto_init_verbs);
17021
17022         err = alc_auto_add_mic_boost(codec);
17023         if (err < 0)
17024                 return err;
17025
17026         return 1;
17027 }
17028
17029 /* additional initialization for auto-configuration model */
17030 static void alc662_auto_init(struct hda_codec *codec)
17031 {
17032         struct alc_spec *spec = codec->spec;
17033         alc662_auto_init_multi_out(codec);
17034         alc662_auto_init_hp_out(codec);
17035         alc662_auto_init_analog_input(codec);
17036         alc662_auto_init_input_src(codec);
17037         if (spec->unsol_event)
17038                 alc_inithook(codec);
17039 }
17040
17041 static int patch_alc662(struct hda_codec *codec)
17042 {
17043         struct alc_spec *spec;
17044         int err, board_config;
17045
17046         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
17047         if (!spec)
17048                 return -ENOMEM;
17049
17050         codec->spec = spec;
17051
17052         alc_fix_pll_init(codec, 0x20, 0x04, 15);
17053
17054         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
17055                                                   alc662_models,
17056                                                   alc662_cfg_tbl);
17057         if (board_config < 0) {
17058                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
17059                        "trying auto-probe from BIOS...\n");
17060                 board_config = ALC662_AUTO;
17061         }
17062
17063         if (board_config == ALC662_AUTO) {
17064                 /* automatic parse from the BIOS config */
17065                 err = alc662_parse_auto_config(codec);
17066                 if (err < 0) {
17067                         alc_free(codec);
17068                         return err;
17069                 } else if (!err) {
17070                         printk(KERN_INFO
17071                                "hda_codec: Cannot set up configuration "
17072                                "from BIOS.  Using base mode...\n");
17073                         board_config = ALC662_3ST_2ch_DIG;
17074                 }
17075         }
17076
17077         err = snd_hda_attach_beep_device(codec, 0x1);
17078         if (err < 0) {
17079                 alc_free(codec);
17080                 return err;
17081         }
17082
17083         if (board_config != ALC662_AUTO)
17084                 setup_preset(spec, &alc662_presets[board_config]);
17085
17086         if (codec->vendor_id == 0x10ec0663) {
17087                 spec->stream_name_analog = "ALC663 Analog";
17088                 spec->stream_name_digital = "ALC663 Digital";
17089         } else if (codec->vendor_id == 0x10ec0272) {
17090                 spec->stream_name_analog = "ALC272 Analog";
17091                 spec->stream_name_digital = "ALC272 Digital";
17092         } else {
17093                 spec->stream_name_analog = "ALC662 Analog";
17094                 spec->stream_name_digital = "ALC662 Digital";
17095         }
17096
17097         spec->stream_analog_playback = &alc662_pcm_analog_playback;
17098         spec->stream_analog_capture = &alc662_pcm_analog_capture;
17099
17100         spec->stream_digital_playback = &alc662_pcm_digital_playback;
17101         spec->stream_digital_capture = &alc662_pcm_digital_capture;
17102
17103         spec->adc_nids = alc662_adc_nids;
17104         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
17105         spec->capsrc_nids = alc662_capsrc_nids;
17106         spec->capture_style = CAPT_MIX;
17107
17108         if (!spec->cap_mixer)
17109                 set_capture_mixer(spec);
17110         if (codec->vendor_id == 0x10ec0662)
17111                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
17112         else
17113                 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
17114
17115         spec->vmaster_nid = 0x02;
17116
17117         codec->patch_ops = alc_patch_ops;
17118         if (board_config == ALC662_AUTO)
17119                 spec->init_hook = alc662_auto_init;
17120 #ifdef CONFIG_SND_HDA_POWER_SAVE
17121         if (!spec->loopback.amplist)
17122                 spec->loopback.amplist = alc662_loopbacks;
17123 #endif
17124         codec->proc_widget_hook = print_realtek_coef;
17125
17126         return 0;
17127 }
17128
17129 /*
17130  * patch entries
17131  */
17132 static struct hda_codec_preset snd_hda_preset_realtek[] = {
17133         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
17134         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
17135         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
17136         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
17137         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
17138         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
17139         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
17140           .patch = patch_alc861 },
17141         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
17142         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
17143         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
17144         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
17145           .patch = patch_alc883 },
17146         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
17147           .patch = patch_alc662 },
17148         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
17149         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
17150         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
17151         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
17152         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
17153           .patch = patch_alc882 }, /* should be patch_alc883() in future */
17154         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
17155           .patch = patch_alc882 }, /* should be patch_alc883() in future */
17156         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
17157         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc883 },
17158         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
17159           .patch = patch_alc883 },
17160         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
17161         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
17162         {} /* terminator */
17163 };
17164
17165 MODULE_ALIAS("snd-hda-codec-id:10ec*");
17166
17167 MODULE_LICENSE("GPL");
17168 MODULE_DESCRIPTION("Realtek HD-audio codec");
17169
17170 static struct hda_codec_preset_list realtek_list = {
17171         .preset = snd_hda_preset_realtek,
17172         .owner = THIS_MODULE,
17173 };
17174
17175 static int __init patch_realtek_init(void)
17176 {
17177         return snd_hda_add_codec_preset(&realtek_list);
17178 }
17179
17180 static void __exit patch_realtek_exit(void)
17181 {
17182         snd_hda_delete_codec_preset(&realtek_list);
17183 }
17184
17185 module_init(patch_realtek_init)
17186 module_exit(patch_realtek_exit)