ALSA: hda - Add codec-specific proc hook
[safe/jmp/linux-2.6] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
33 #include "hda_patch.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 #ifdef CONFIG_SND_DEBUG
82         ALC260_TEST,
83 #endif
84         ALC260_AUTO,
85         ALC260_MODEL_LAST /* last tag */
86 };
87
88 /* ALC262 models */
89 enum {
90         ALC262_BASIC,
91         ALC262_HIPPO,
92         ALC262_HIPPO_1,
93         ALC262_FUJITSU,
94         ALC262_HP_BPC,
95         ALC262_HP_BPC_D7000_WL,
96         ALC262_HP_BPC_D7000_WF,
97         ALC262_HP_TC_T5735,
98         ALC262_HP_RP5700,
99         ALC262_BENQ_ED8,
100         ALC262_SONY_ASSAMD,
101         ALC262_BENQ_T31,
102         ALC262_ULTRA,
103         ALC262_LENOVO_3000,
104         ALC262_NEC,
105         ALC262_TOSHIBA_S06,
106         ALC262_TOSHIBA_RX1,
107         ALC262_AUTO,
108         ALC262_MODEL_LAST /* last tag */
109 };
110
111 /* ALC268 models */
112 enum {
113         ALC267_QUANTA_IL1,
114         ALC268_3ST,
115         ALC268_TOSHIBA,
116         ALC268_ACER,
117         ALC268_ACER_DMIC,
118         ALC268_ACER_ASPIRE_ONE,
119         ALC268_DELL,
120         ALC268_ZEPTO,
121 #ifdef CONFIG_SND_DEBUG
122         ALC268_TEST,
123 #endif
124         ALC268_AUTO,
125         ALC268_MODEL_LAST /* last tag */
126 };
127
128 /* ALC269 models */
129 enum {
130         ALC269_BASIC,
131         ALC269_QUANTA_FL1,
132         ALC269_ASUS_EEEPC_P703,
133         ALC269_ASUS_EEEPC_P901,
134         ALC269_FUJITSU,
135         ALC269_LIFEBOOK,
136         ALC269_AUTO,
137         ALC269_MODEL_LAST /* last tag */
138 };
139
140 /* ALC861 models */
141 enum {
142         ALC861_3ST,
143         ALC660_3ST,
144         ALC861_3ST_DIG,
145         ALC861_6ST_DIG,
146         ALC861_UNIWILL_M31,
147         ALC861_TOSHIBA,
148         ALC861_ASUS,
149         ALC861_ASUS_LAPTOP,
150         ALC861_AUTO,
151         ALC861_MODEL_LAST,
152 };
153
154 /* ALC861-VD models */
155 enum {
156         ALC660VD_3ST,
157         ALC660VD_3ST_DIG,
158         ALC660VD_ASUS_V1S,
159         ALC861VD_3ST,
160         ALC861VD_3ST_DIG,
161         ALC861VD_6ST_DIG,
162         ALC861VD_LENOVO,
163         ALC861VD_DALLAS,
164         ALC861VD_HP,
165         ALC861VD_AUTO,
166         ALC861VD_MODEL_LAST,
167 };
168
169 /* ALC662 models */
170 enum {
171         ALC662_3ST_2ch_DIG,
172         ALC662_3ST_6ch_DIG,
173         ALC662_3ST_6ch,
174         ALC662_5ST_DIG,
175         ALC662_LENOVO_101E,
176         ALC662_ASUS_EEEPC_P701,
177         ALC662_ASUS_EEEPC_EP20,
178         ALC663_ASUS_M51VA,
179         ALC663_ASUS_G71V,
180         ALC663_ASUS_H13,
181         ALC663_ASUS_G50V,
182         ALC662_ECS,
183         ALC663_ASUS_MODE1,
184         ALC662_ASUS_MODE2,
185         ALC663_ASUS_MODE3,
186         ALC663_ASUS_MODE4,
187         ALC663_ASUS_MODE5,
188         ALC663_ASUS_MODE6,
189         ALC662_AUTO,
190         ALC662_MODEL_LAST,
191 };
192
193 /* ALC882 models */
194 enum {
195         ALC882_3ST_DIG,
196         ALC882_6ST_DIG,
197         ALC882_ARIMA,
198         ALC882_W2JC,
199         ALC882_TARGA,
200         ALC882_ASUS_A7J,
201         ALC882_ASUS_A7M,
202         ALC885_MACPRO,
203         ALC885_MBP3,
204         ALC885_IMAC24,
205         ALC882_AUTO,
206         ALC882_MODEL_LAST,
207 };
208
209 /* ALC883 models */
210 enum {
211         ALC883_3ST_2ch_DIG,
212         ALC883_3ST_6ch_DIG,
213         ALC883_3ST_6ch,
214         ALC883_6ST_DIG,
215         ALC883_TARGA_DIG,
216         ALC883_TARGA_2ch_DIG,
217         ALC883_ACER,
218         ALC883_ACER_ASPIRE,
219         ALC888_ACER_ASPIRE_4930G,
220         ALC883_MEDION,
221         ALC883_MEDION_MD2,
222         ALC883_LAPTOP_EAPD,
223         ALC883_LENOVO_101E_2ch,
224         ALC883_LENOVO_NB0763,
225         ALC888_LENOVO_MS7195_DIG,
226         ALC888_LENOVO_SKY,
227         ALC883_HAIER_W66,
228         ALC888_3ST_HP,
229         ALC888_6ST_DELL,
230         ALC883_MITAC,
231         ALC883_CLEVO_M720,
232         ALC883_FUJITSU_PI2515,
233         ALC888_FUJITSU_XA3530,
234         ALC883_3ST_6ch_INTEL,
235         ALC888_ASUS_M90V,
236         ALC888_ASUS_EEE1601,
237         ALC1200_ASUS_P5Q,
238         ALC883_AUTO,
239         ALC883_MODEL_LAST,
240 };
241
242 /* for GPIO Poll */
243 #define GPIO_MASK       0x03
244
245 struct alc_spec {
246         /* codec parameterization */
247         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
248         unsigned int num_mixers;
249         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
250
251         const struct hda_verb *init_verbs[5];   /* initialization verbs
252                                                  * don't forget NULL
253                                                  * termination!
254                                                  */
255         unsigned int num_init_verbs;
256
257         char *stream_name_analog;       /* analog PCM stream */
258         struct hda_pcm_stream *stream_analog_playback;
259         struct hda_pcm_stream *stream_analog_capture;
260         struct hda_pcm_stream *stream_analog_alt_playback;
261         struct hda_pcm_stream *stream_analog_alt_capture;
262
263         char *stream_name_digital;      /* digital PCM stream */
264         struct hda_pcm_stream *stream_digital_playback;
265         struct hda_pcm_stream *stream_digital_capture;
266
267         /* playback */
268         struct hda_multi_out multiout;  /* playback set-up
269                                          * max_channels, dacs must be set
270                                          * dig_out_nid and hp_nid are optional
271                                          */
272         hda_nid_t alt_dac_nid;
273
274         /* capture */
275         unsigned int num_adc_nids;
276         hda_nid_t *adc_nids;
277         hda_nid_t *capsrc_nids;
278         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
279         unsigned char is_mix_capture;   /* matrix-style capture (non-mux) */
280
281         /* capture source */
282         unsigned int num_mux_defs;
283         const struct hda_input_mux *input_mux;
284         unsigned int cur_mux[3];
285
286         /* channel model */
287         const struct hda_channel_mode *channel_mode;
288         int num_channel_mode;
289         int need_dac_fix;
290
291         /* PCM information */
292         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
293
294         /* dynamic controls, init_verbs and input_mux */
295         struct auto_pin_cfg autocfg;
296         struct snd_array kctls;
297         struct hda_input_mux private_imux;
298         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
299
300         /* hooks */
301         void (*init_hook)(struct hda_codec *codec);
302         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
303
304         /* for pin sensing */
305         unsigned int sense_updated: 1;
306         unsigned int jack_present: 1;
307         unsigned int master_sw: 1;
308
309         /* for virtual master */
310         hda_nid_t vmaster_nid;
311 #ifdef CONFIG_SND_HDA_POWER_SAVE
312         struct hda_loopback_check loopback;
313 #endif
314
315         /* for PLL fix */
316         hda_nid_t pll_nid;
317         unsigned int pll_coef_idx, pll_coef_bit;
318
319 #ifdef SND_HDA_NEEDS_RESUME
320 #define ALC_MAX_PINS    16
321         unsigned int num_pins;
322         hda_nid_t pin_nids[ALC_MAX_PINS];
323         unsigned int pin_cfgs[ALC_MAX_PINS];
324 #endif
325 };
326
327 /*
328  * configuration template - to be copied to the spec instance
329  */
330 struct alc_config_preset {
331         struct snd_kcontrol_new *mixers[5]; /* should be identical size
332                                              * with spec
333                                              */
334         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
335         const struct hda_verb *init_verbs[5];
336         unsigned int num_dacs;
337         hda_nid_t *dac_nids;
338         hda_nid_t dig_out_nid;          /* optional */
339         hda_nid_t hp_nid;               /* optional */
340         unsigned int num_adc_nids;
341         hda_nid_t *adc_nids;
342         hda_nid_t *capsrc_nids;
343         hda_nid_t dig_in_nid;
344         unsigned int num_channel_mode;
345         const struct hda_channel_mode *channel_mode;
346         int need_dac_fix;
347         unsigned int num_mux_defs;
348         const struct hda_input_mux *input_mux;
349         void (*unsol_event)(struct hda_codec *, unsigned int);
350         void (*init_hook)(struct hda_codec *);
351 #ifdef CONFIG_SND_HDA_POWER_SAVE
352         struct hda_amp_list *loopbacks;
353 #endif
354 };
355
356
357 /*
358  * input MUX handling
359  */
360 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
361                              struct snd_ctl_elem_info *uinfo)
362 {
363         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
364         struct alc_spec *spec = codec->spec;
365         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
366         if (mux_idx >= spec->num_mux_defs)
367                 mux_idx = 0;
368         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
369 }
370
371 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
372                             struct snd_ctl_elem_value *ucontrol)
373 {
374         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
375         struct alc_spec *spec = codec->spec;
376         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
377
378         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
379         return 0;
380 }
381
382 static int alc_mux_enum_put(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         const struct hda_input_mux *imux;
388         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
389         unsigned int mux_idx;
390         hda_nid_t nid = spec->capsrc_nids ?
391                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
392
393         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
394         imux = &spec->input_mux[mux_idx];
395
396         if (spec->is_mix_capture) {
397                 /* Matrix-mixer style (e.g. ALC882) */
398                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
399                 unsigned int i, idx;
400
401                 idx = ucontrol->value.enumerated.item[0];
402                 if (idx >= imux->num_items)
403                         idx = imux->num_items - 1;
404                 if (*cur_val == idx)
405                         return 0;
406                 for (i = 0; i < imux->num_items; i++) {
407                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
408                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
409                                                  imux->items[i].index,
410                                                  HDA_AMP_MUTE, v);
411                 }
412                 *cur_val = idx;
413                 return 1;
414         } else {
415                 /* MUX style (e.g. ALC880) */
416                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
417                                              &spec->cur_mux[adc_idx]);
418         }
419 }
420
421 /*
422  * channel mode setting
423  */
424 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
425                             struct snd_ctl_elem_info *uinfo)
426 {
427         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
428         struct alc_spec *spec = codec->spec;
429         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
430                                     spec->num_channel_mode);
431 }
432
433 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
434                            struct snd_ctl_elem_value *ucontrol)
435 {
436         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
437         struct alc_spec *spec = codec->spec;
438         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
439                                    spec->num_channel_mode,
440                                    spec->multiout.max_channels);
441 }
442
443 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
444                            struct snd_ctl_elem_value *ucontrol)
445 {
446         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
447         struct alc_spec *spec = codec->spec;
448         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
449                                       spec->num_channel_mode,
450                                       &spec->multiout.max_channels);
451         if (err >= 0 && spec->need_dac_fix)
452                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
453         return err;
454 }
455
456 /*
457  * Control the mode of pin widget settings via the mixer.  "pc" is used
458  * instead of "%" to avoid consequences of accidently treating the % as
459  * being part of a format specifier.  Maximum allowed length of a value is
460  * 63 characters plus NULL terminator.
461  *
462  * Note: some retasking pin complexes seem to ignore requests for input
463  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
464  * are requested.  Therefore order this list so that this behaviour will not
465  * cause problems when mixer clients move through the enum sequentially.
466  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
467  * March 2006.
468  */
469 static char *alc_pin_mode_names[] = {
470         "Mic 50pc bias", "Mic 80pc bias",
471         "Line in", "Line out", "Headphone out",
472 };
473 static unsigned char alc_pin_mode_values[] = {
474         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
475 };
476 /* The control can present all 5 options, or it can limit the options based
477  * in the pin being assumed to be exclusively an input or an output pin.  In
478  * addition, "input" pins may or may not process the mic bias option
479  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
480  * accept requests for bias as of chip versions up to March 2006) and/or
481  * wiring in the computer.
482  */
483 #define ALC_PIN_DIR_IN              0x00
484 #define ALC_PIN_DIR_OUT             0x01
485 #define ALC_PIN_DIR_INOUT           0x02
486 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
487 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
488
489 /* Info about the pin modes supported by the different pin direction modes.
490  * For each direction the minimum and maximum values are given.
491  */
492 static signed char alc_pin_mode_dir_info[5][2] = {
493         { 0, 2 },    /* ALC_PIN_DIR_IN */
494         { 3, 4 },    /* ALC_PIN_DIR_OUT */
495         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
496         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
497         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
498 };
499 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
500 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
501 #define alc_pin_mode_n_items(_dir) \
502         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
503
504 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
505                              struct snd_ctl_elem_info *uinfo)
506 {
507         unsigned int item_num = uinfo->value.enumerated.item;
508         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
509
510         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
511         uinfo->count = 1;
512         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
513
514         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
515                 item_num = alc_pin_mode_min(dir);
516         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
517         return 0;
518 }
519
520 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
521                             struct snd_ctl_elem_value *ucontrol)
522 {
523         unsigned int i;
524         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
525         hda_nid_t nid = kcontrol->private_value & 0xffff;
526         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
527         long *valp = ucontrol->value.integer.value;
528         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
529                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
530                                                  0x00);
531
532         /* Find enumerated value for current pinctl setting */
533         i = alc_pin_mode_min(dir);
534         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
535                 i++;
536         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
537         return 0;
538 }
539
540 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
541                             struct snd_ctl_elem_value *ucontrol)
542 {
543         signed int change;
544         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
545         hda_nid_t nid = kcontrol->private_value & 0xffff;
546         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
547         long val = *ucontrol->value.integer.value;
548         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
549                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
550                                                  0x00);
551
552         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
553                 val = alc_pin_mode_min(dir);
554
555         change = pinctl != alc_pin_mode_values[val];
556         if (change) {
557                 /* Set pin mode to that requested */
558                 snd_hda_codec_write_cache(codec, nid, 0,
559                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
560                                           alc_pin_mode_values[val]);
561
562                 /* Also enable the retasking pin's input/output as required
563                  * for the requested pin mode.  Enum values of 2 or less are
564                  * input modes.
565                  *
566                  * Dynamically switching the input/output buffers probably
567                  * reduces noise slightly (particularly on input) so we'll
568                  * do it.  However, having both input and output buffers
569                  * enabled simultaneously doesn't seem to be problematic if
570                  * this turns out to be necessary in the future.
571                  */
572                 if (val <= 2) {
573                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
574                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
575                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
576                                                  HDA_AMP_MUTE, 0);
577                 } else {
578                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
579                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
580                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
581                                                  HDA_AMP_MUTE, 0);
582                 }
583         }
584         return change;
585 }
586
587 #define ALC_PIN_MODE(xname, nid, dir) \
588         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
589           .info = alc_pin_mode_info, \
590           .get = alc_pin_mode_get, \
591           .put = alc_pin_mode_put, \
592           .private_value = nid | (dir<<16) }
593
594 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
595  * together using a mask with more than one bit set.  This control is
596  * currently used only by the ALC260 test model.  At this stage they are not
597  * needed for any "production" models.
598  */
599 #ifdef CONFIG_SND_DEBUG
600 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
601
602 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
603                              struct snd_ctl_elem_value *ucontrol)
604 {
605         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
606         hda_nid_t nid = kcontrol->private_value & 0xffff;
607         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
608         long *valp = ucontrol->value.integer.value;
609         unsigned int val = snd_hda_codec_read(codec, nid, 0,
610                                               AC_VERB_GET_GPIO_DATA, 0x00);
611
612         *valp = (val & mask) != 0;
613         return 0;
614 }
615 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
616                              struct snd_ctl_elem_value *ucontrol)
617 {
618         signed int change;
619         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
620         hda_nid_t nid = kcontrol->private_value & 0xffff;
621         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
622         long val = *ucontrol->value.integer.value;
623         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
624                                                     AC_VERB_GET_GPIO_DATA,
625                                                     0x00);
626
627         /* Set/unset the masked GPIO bit(s) as needed */
628         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
629         if (val == 0)
630                 gpio_data &= ~mask;
631         else
632                 gpio_data |= mask;
633         snd_hda_codec_write_cache(codec, nid, 0,
634                                   AC_VERB_SET_GPIO_DATA, gpio_data);
635
636         return change;
637 }
638 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
639         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
640           .info = alc_gpio_data_info, \
641           .get = alc_gpio_data_get, \
642           .put = alc_gpio_data_put, \
643           .private_value = nid | (mask<<16) }
644 #endif   /* CONFIG_SND_DEBUG */
645
646 /* A switch control to allow the enabling of the digital IO pins on the
647  * ALC260.  This is incredibly simplistic; the intention of this control is
648  * to provide something in the test model allowing digital outputs to be
649  * identified if present.  If models are found which can utilise these
650  * outputs a more complete mixer control can be devised for those models if
651  * necessary.
652  */
653 #ifdef CONFIG_SND_DEBUG
654 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
655
656 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
657                               struct snd_ctl_elem_value *ucontrol)
658 {
659         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
660         hda_nid_t nid = kcontrol->private_value & 0xffff;
661         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
662         long *valp = ucontrol->value.integer.value;
663         unsigned int val = snd_hda_codec_read(codec, nid, 0,
664                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
665
666         *valp = (val & mask) != 0;
667         return 0;
668 }
669 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
670                               struct snd_ctl_elem_value *ucontrol)
671 {
672         signed int change;
673         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
674         hda_nid_t nid = kcontrol->private_value & 0xffff;
675         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
676         long val = *ucontrol->value.integer.value;
677         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
678                                                     AC_VERB_GET_DIGI_CONVERT_1,
679                                                     0x00);
680
681         /* Set/unset the masked control bit(s) as needed */
682         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
683         if (val==0)
684                 ctrl_data &= ~mask;
685         else
686                 ctrl_data |= mask;
687         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
688                                   ctrl_data);
689
690         return change;
691 }
692 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
693         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
694           .info = alc_spdif_ctrl_info, \
695           .get = alc_spdif_ctrl_get, \
696           .put = alc_spdif_ctrl_put, \
697           .private_value = nid | (mask<<16) }
698 #endif   /* CONFIG_SND_DEBUG */
699
700 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
701  * Again, this is only used in the ALC26x test models to help identify when
702  * the EAPD line must be asserted for features to work.
703  */
704 #ifdef CONFIG_SND_DEBUG
705 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
706
707 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
708                               struct snd_ctl_elem_value *ucontrol)
709 {
710         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
711         hda_nid_t nid = kcontrol->private_value & 0xffff;
712         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
713         long *valp = ucontrol->value.integer.value;
714         unsigned int val = snd_hda_codec_read(codec, nid, 0,
715                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
716
717         *valp = (val & mask) != 0;
718         return 0;
719 }
720
721 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
722                               struct snd_ctl_elem_value *ucontrol)
723 {
724         int change;
725         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
726         hda_nid_t nid = kcontrol->private_value & 0xffff;
727         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
728         long val = *ucontrol->value.integer.value;
729         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
730                                                     AC_VERB_GET_EAPD_BTLENABLE,
731                                                     0x00);
732
733         /* Set/unset the masked control bit(s) as needed */
734         change = (!val ? 0 : mask) != (ctrl_data & mask);
735         if (!val)
736                 ctrl_data &= ~mask;
737         else
738                 ctrl_data |= mask;
739         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
740                                   ctrl_data);
741
742         return change;
743 }
744
745 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
746         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
747           .info = alc_eapd_ctrl_info, \
748           .get = alc_eapd_ctrl_get, \
749           .put = alc_eapd_ctrl_put, \
750           .private_value = nid | (mask<<16) }
751 #endif   /* CONFIG_SND_DEBUG */
752
753 /*
754  */
755 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
756 {
757         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
758                 return;
759         spec->mixers[spec->num_mixers++] = mix;
760 }
761
762 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
763 {
764         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
765                 return;
766         spec->init_verbs[spec->num_init_verbs++] = verb;
767 }
768
769 #ifdef CONFIG_PROC_FS
770 /*
771  * hook for proc
772  */
773 static void print_realtek_coef(struct snd_info_buffer *buffer,
774                                struct hda_codec *codec, hda_nid_t nid)
775 {
776         int coeff;
777
778         if (nid != 0x20)
779                 return;
780         coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
781         snd_iprintf(buffer, "  Processing Coefficient: 0x%02x\n", coeff);
782         coeff = snd_hda_codec_read(codec, nid, 0,
783                                    AC_VERB_GET_COEF_INDEX, 0);
784         snd_iprintf(buffer, "  Coefficient Index: 0x%02x\n", coeff);
785 }
786 #else
787 #define print_realtek_coef      NULL
788 #endif
789
790 /*
791  * set up from the preset table
792  */
793 static void setup_preset(struct alc_spec *spec,
794                          const struct alc_config_preset *preset)
795 {
796         int i;
797
798         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
799                 add_mixer(spec, preset->mixers[i]);
800         spec->cap_mixer = preset->cap_mixer;
801         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
802              i++)
803                 add_verb(spec, preset->init_verbs[i]);
804
805         spec->channel_mode = preset->channel_mode;
806         spec->num_channel_mode = preset->num_channel_mode;
807         spec->need_dac_fix = preset->need_dac_fix;
808
809         spec->multiout.max_channels = spec->channel_mode[0].channels;
810
811         spec->multiout.num_dacs = preset->num_dacs;
812         spec->multiout.dac_nids = preset->dac_nids;
813         spec->multiout.dig_out_nid = preset->dig_out_nid;
814         spec->multiout.hp_nid = preset->hp_nid;
815
816         spec->num_mux_defs = preset->num_mux_defs;
817         if (!spec->num_mux_defs)
818                 spec->num_mux_defs = 1;
819         spec->input_mux = preset->input_mux;
820
821         spec->num_adc_nids = preset->num_adc_nids;
822         spec->adc_nids = preset->adc_nids;
823         spec->capsrc_nids = preset->capsrc_nids;
824         spec->dig_in_nid = preset->dig_in_nid;
825
826         spec->unsol_event = preset->unsol_event;
827         spec->init_hook = preset->init_hook;
828 #ifdef CONFIG_SND_HDA_POWER_SAVE
829         spec->loopback.amplist = preset->loopbacks;
830 #endif
831 }
832
833 /* Enable GPIO mask and set output */
834 static struct hda_verb alc_gpio1_init_verbs[] = {
835         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
836         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
837         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
838         { }
839 };
840
841 static struct hda_verb alc_gpio2_init_verbs[] = {
842         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
843         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
844         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
845         { }
846 };
847
848 static struct hda_verb alc_gpio3_init_verbs[] = {
849         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
850         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
851         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
852         { }
853 };
854
855 /*
856  * Fix hardware PLL issue
857  * On some codecs, the analog PLL gating control must be off while
858  * the default value is 1.
859  */
860 static void alc_fix_pll(struct hda_codec *codec)
861 {
862         struct alc_spec *spec = codec->spec;
863         unsigned int val;
864
865         if (!spec->pll_nid)
866                 return;
867         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
868                             spec->pll_coef_idx);
869         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
870                                  AC_VERB_GET_PROC_COEF, 0);
871         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
872                             spec->pll_coef_idx);
873         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
874                             val & ~(1 << spec->pll_coef_bit));
875 }
876
877 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
878                              unsigned int coef_idx, unsigned int coef_bit)
879 {
880         struct alc_spec *spec = codec->spec;
881         spec->pll_nid = nid;
882         spec->pll_coef_idx = coef_idx;
883         spec->pll_coef_bit = coef_bit;
884         alc_fix_pll(codec);
885 }
886
887 static void alc_sku_automute(struct hda_codec *codec)
888 {
889         struct alc_spec *spec = codec->spec;
890         unsigned int present;
891         unsigned int hp_nid = spec->autocfg.hp_pins[0];
892         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
893
894         /* need to execute and sync at first */
895         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
896         present = snd_hda_codec_read(codec, hp_nid, 0,
897                                      AC_VERB_GET_PIN_SENSE, 0);
898         spec->jack_present = (present & 0x80000000) != 0;
899         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
900                             spec->jack_present ? 0 : PIN_OUT);
901 }
902
903 #if 0 /* it's broken in some acses -- temporarily disabled */
904 static void alc_mic_automute(struct hda_codec *codec)
905 {
906         struct alc_spec *spec = codec->spec;
907         unsigned int present;
908         unsigned int mic_nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
909         unsigned int fmic_nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
910         unsigned int mix_nid = spec->capsrc_nids[0];
911         unsigned int capsrc_idx_mic, capsrc_idx_fmic;
912
913         capsrc_idx_mic = mic_nid - 0x18;
914         capsrc_idx_fmic = fmic_nid - 0x18;
915         present = snd_hda_codec_read(codec, mic_nid, 0,
916                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
917         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
918                     0x7000 | (capsrc_idx_mic << 8) | (present ? 0 : 0x80));
919         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
920                     0x7000 | (capsrc_idx_fmic << 8) | (present ? 0x80 : 0));
921         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, capsrc_idx_fmic,
922                          HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
923 }
924 #else
925 #define alc_mic_automute(codec) /* NOP */
926 #endif /* disabled */
927
928 /* unsolicited event for HP jack sensing */
929 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
930 {
931         if (codec->vendor_id == 0x10ec0880)
932                 res >>= 28;
933         else
934                 res >>= 26;
935         if (res == ALC880_HP_EVENT)
936                 alc_sku_automute(codec);
937
938         if (res == ALC880_MIC_EVENT)
939                 alc_mic_automute(codec);
940 }
941
942 static void alc_inithook(struct hda_codec *codec)
943 {
944         alc_sku_automute(codec);
945         alc_mic_automute(codec);
946 }
947
948 /* additional initialization for ALC888 variants */
949 static void alc888_coef_init(struct hda_codec *codec)
950 {
951         unsigned int tmp;
952
953         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
954         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
955         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
956         if ((tmp & 0xf0) == 2)
957                 /* alc888S-VC */
958                 snd_hda_codec_read(codec, 0x20, 0,
959                                    AC_VERB_SET_PROC_COEF, 0x830);
960          else
961                  /* alc888-VB */
962                  snd_hda_codec_read(codec, 0x20, 0,
963                                     AC_VERB_SET_PROC_COEF, 0x3030);
964 }
965
966 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
967  *      31 ~ 16 :       Manufacture ID
968  *      15 ~ 8  :       SKU ID
969  *      7  ~ 0  :       Assembly ID
970  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
971  */
972 static void alc_subsystem_id(struct hda_codec *codec,
973                              unsigned int porta, unsigned int porte,
974                              unsigned int portd)
975 {
976         unsigned int ass, tmp, i;
977         unsigned nid;
978         struct alc_spec *spec = codec->spec;
979
980         ass = codec->subsystem_id & 0xffff;
981         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
982                 goto do_sku;
983
984         /*
985          * 31~30        : port conetcivity
986          * 29~21        : reserve
987          * 20           : PCBEEP input
988          * 19~16        : Check sum (15:1)
989          * 15~1         : Custom
990          * 0            : override
991         */
992         nid = 0x1d;
993         if (codec->vendor_id == 0x10ec0260)
994                 nid = 0x17;
995         ass = snd_hda_codec_read(codec, nid, 0,
996                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
997         if (!(ass & 1) && !(ass & 0x100000))
998                 return;
999         if ((ass >> 30) != 1)   /* no physical connection */
1000                 return;
1001
1002         /* check sum */
1003         tmp = 0;
1004         for (i = 1; i < 16; i++) {
1005                 if ((ass >> i) & 1)
1006                         tmp++;
1007         }
1008         if (((ass >> 16) & 0xf) != tmp)
1009                 return;
1010 do_sku:
1011         /*
1012          * 0 : override
1013          * 1 :  Swap Jack
1014          * 2 : 0 --> Desktop, 1 --> Laptop
1015          * 3~5 : External Amplifier control
1016          * 7~6 : Reserved
1017         */
1018         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1019         switch (tmp) {
1020         case 1:
1021                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1022                 break;
1023         case 3:
1024                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1025                 break;
1026         case 7:
1027                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1028                 break;
1029         case 5: /* set EAPD output high */
1030                 switch (codec->vendor_id) {
1031                 case 0x10ec0260:
1032                         snd_hda_codec_write(codec, 0x0f, 0,
1033                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1034                         snd_hda_codec_write(codec, 0x10, 0,
1035                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1036                         break;
1037                 case 0x10ec0262:
1038                 case 0x10ec0267:
1039                 case 0x10ec0268:
1040                 case 0x10ec0269:
1041                 case 0x10ec0660:
1042                 case 0x10ec0662:
1043                 case 0x10ec0663:
1044                 case 0x10ec0862:
1045                 case 0x10ec0889:
1046                         snd_hda_codec_write(codec, 0x14, 0,
1047                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1048                         snd_hda_codec_write(codec, 0x15, 0,
1049                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1050                         break;
1051                 }
1052                 switch (codec->vendor_id) {
1053                 case 0x10ec0260:
1054                         snd_hda_codec_write(codec, 0x1a, 0,
1055                                             AC_VERB_SET_COEF_INDEX, 7);
1056                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1057                                                  AC_VERB_GET_PROC_COEF, 0);
1058                         snd_hda_codec_write(codec, 0x1a, 0,
1059                                             AC_VERB_SET_COEF_INDEX, 7);
1060                         snd_hda_codec_write(codec, 0x1a, 0,
1061                                             AC_VERB_SET_PROC_COEF,
1062                                             tmp | 0x2010);
1063                         break;
1064                 case 0x10ec0262:
1065                 case 0x10ec0880:
1066                 case 0x10ec0882:
1067                 case 0x10ec0883:
1068                 case 0x10ec0885:
1069                 case 0x10ec0889:
1070                         snd_hda_codec_write(codec, 0x20, 0,
1071                                             AC_VERB_SET_COEF_INDEX, 7);
1072                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1073                                                  AC_VERB_GET_PROC_COEF, 0);
1074                         snd_hda_codec_write(codec, 0x20, 0,
1075                                             AC_VERB_SET_COEF_INDEX, 7);
1076                         snd_hda_codec_write(codec, 0x20, 0,
1077                                             AC_VERB_SET_PROC_COEF,
1078                                             tmp | 0x2010);
1079                         break;
1080                 case 0x10ec0888:
1081                         /*alc888_coef_init(codec);*/ /* called in alc_init() */
1082                         break;
1083                 case 0x10ec0267:
1084                 case 0x10ec0268:
1085                         snd_hda_codec_write(codec, 0x20, 0,
1086                                             AC_VERB_SET_COEF_INDEX, 7);
1087                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1088                                                  AC_VERB_GET_PROC_COEF, 0);
1089                         snd_hda_codec_write(codec, 0x20, 0,
1090                                             AC_VERB_SET_COEF_INDEX, 7);
1091                         snd_hda_codec_write(codec, 0x20, 0,
1092                                             AC_VERB_SET_PROC_COEF,
1093                                             tmp | 0x3000);
1094                         break;
1095                 }
1096         default:
1097                 break;
1098         }
1099
1100         /* is laptop or Desktop and enable the function "Mute internal speaker
1101          * when the external headphone out jack is plugged"
1102          */
1103         if (!(ass & 0x8000))
1104                 return;
1105         /*
1106          * 10~8 : Jack location
1107          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1108          * 14~13: Resvered
1109          * 15   : 1 --> enable the function "Mute internal speaker
1110          *              when the external headphone out jack is plugged"
1111          */
1112         if (!spec->autocfg.speaker_pins[0]) {
1113                 if (spec->autocfg.line_out_pins[0])
1114                         spec->autocfg.speaker_pins[0] =
1115                                 spec->autocfg.line_out_pins[0];
1116                 else
1117                         return;
1118         }
1119
1120         if (!spec->autocfg.hp_pins[0]) {
1121                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1122                 if (tmp == 0)
1123                         spec->autocfg.hp_pins[0] = porta;
1124                 else if (tmp == 1)
1125                         spec->autocfg.hp_pins[0] = porte;
1126                 else if (tmp == 2)
1127                         spec->autocfg.hp_pins[0] = portd;
1128                 else
1129                         return;
1130         }
1131         if (spec->autocfg.hp_pins[0])
1132                 snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1133                         AC_VERB_SET_UNSOLICITED_ENABLE,
1134                         AC_USRSP_EN | ALC880_HP_EVENT);
1135
1136 #if 0 /* it's broken in some acses -- temporarily disabled */
1137         if (spec->autocfg.input_pins[AUTO_PIN_MIC] &&
1138                 spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC])
1139                 snd_hda_codec_write(codec,
1140                         spec->autocfg.input_pins[AUTO_PIN_MIC], 0,
1141                         AC_VERB_SET_UNSOLICITED_ENABLE,
1142                         AC_USRSP_EN | ALC880_MIC_EVENT);
1143 #endif /* disabled */
1144
1145         spec->unsol_event = alc_sku_unsol_event;
1146 }
1147
1148 /*
1149  * Fix-up pin default configurations
1150  */
1151
1152 struct alc_pincfg {
1153         hda_nid_t nid;
1154         u32 val;
1155 };
1156
1157 static void alc_fix_pincfg(struct hda_codec *codec,
1158                            const struct snd_pci_quirk *quirk,
1159                            const struct alc_pincfg **pinfix)
1160 {
1161         const struct alc_pincfg *cfg;
1162
1163         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1164         if (!quirk)
1165                 return;
1166
1167         cfg = pinfix[quirk->value];
1168         for (; cfg->nid; cfg++) {
1169                 int i;
1170                 u32 val = cfg->val;
1171                 for (i = 0; i < 4; i++) {
1172                         snd_hda_codec_write(codec, cfg->nid, 0,
1173                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
1174                                     val & 0xff);
1175                         val >>= 8;
1176                 }
1177         }
1178 }
1179
1180 /*
1181  * ALC888
1182  */
1183
1184 /*
1185  * 2ch mode
1186  */
1187 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1188 /* Mic-in jack as mic in */
1189         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1190         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1191 /* Line-in jack as Line in */
1192         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1193         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1194 /* Line-Out as Front */
1195         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1196         { } /* end */
1197 };
1198
1199 /*
1200  * 4ch mode
1201  */
1202 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1203 /* Mic-in jack as mic in */
1204         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1205         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1206 /* Line-in jack as Surround */
1207         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1208         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1209 /* Line-Out as Front */
1210         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1211         { } /* end */
1212 };
1213
1214 /*
1215  * 6ch mode
1216  */
1217 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1218 /* Mic-in jack as CLFE */
1219         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1220         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1221 /* Line-in jack as Surround */
1222         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1223         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1224 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1225         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1226         { } /* end */
1227 };
1228
1229 /*
1230  * 8ch mode
1231  */
1232 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1233 /* Mic-in jack as CLFE */
1234         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1235         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1236 /* Line-in jack as Surround */
1237         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1238         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1239 /* Line-Out as Side */
1240         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1241         { } /* end */
1242 };
1243
1244 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1245         { 2, alc888_4ST_ch2_intel_init },
1246         { 4, alc888_4ST_ch4_intel_init },
1247         { 6, alc888_4ST_ch6_intel_init },
1248         { 8, alc888_4ST_ch8_intel_init },
1249 };
1250
1251 /*
1252  * ALC888 Fujitsu Siemens Amillo xa3530
1253  */
1254
1255 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1256 /* Front Mic: set to PIN_IN (empty by default) */
1257         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1258 /* Connect Internal HP to Front */
1259         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1260         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1261         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1262 /* Connect Bass HP to Front */
1263         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1264         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1265         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1266 /* Connect Line-Out side jack (SPDIF) to Side */
1267         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1268         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1269         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1270 /* Connect Mic jack to CLFE */
1271         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1272         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1273         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1274 /* Connect Line-in jack to Surround */
1275         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1276         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1277         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1278 /* Connect HP out jack to Front */
1279         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1280         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1281         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1282 /* Enable unsolicited event for HP jack and Line-out jack */
1283         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1284         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1285         {}
1286 };
1287
1288 static void alc888_fujitsu_xa3530_automute(struct hda_codec *codec)
1289 {
1290         unsigned int present;
1291         unsigned int bits;
1292         /* Line out presence */
1293         present = snd_hda_codec_read(codec, 0x17, 0,
1294                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1295         /* HP out presence */
1296         present = present || snd_hda_codec_read(codec, 0x1b, 0,
1297                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1298         bits = present ? HDA_AMP_MUTE : 0;
1299         /* Toggle internal speakers muting */
1300         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1301                                  HDA_AMP_MUTE, bits);
1302         /* Toggle internal bass muting */
1303         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1304                                  HDA_AMP_MUTE, bits);
1305 }
1306
1307 static void alc888_fujitsu_xa3530_unsol_event(struct hda_codec *codec,
1308                 unsigned int res)
1309 {
1310         if (res >> 26 == ALC880_HP_EVENT)
1311                 alc888_fujitsu_xa3530_automute(codec);
1312 }
1313
1314
1315 /*
1316  * ALC888 Acer Aspire 4930G model
1317  */
1318
1319 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1320 /* Front Mic: set to PIN_IN (empty by default) */
1321         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1322 /* Unselect Front Mic by default in input mixer 3 */
1323         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1324 /* Enable unsolicited event for HP jack */
1325         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1326 /* Connect Internal HP to front */
1327         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1328         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1329         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1330 /* Connect HP out to front */
1331         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1332         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1333         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1334         { }
1335 };
1336
1337 static struct hda_input_mux alc888_2_capture_sources[2] = {
1338         /* Front mic only available on one ADC */
1339         {
1340                 .num_items = 4,
1341                 .items = {
1342                         { "Mic", 0x0 },
1343                         { "Line", 0x2 },
1344                         { "CD", 0x4 },
1345                         { "Front Mic", 0xb },
1346                 },
1347         },
1348         {
1349                 .num_items = 3,
1350                 .items = {
1351                         { "Mic", 0x0 },
1352                         { "Line", 0x2 },
1353                         { "CD", 0x4 },
1354                 },
1355         }
1356 };
1357
1358 static struct snd_kcontrol_new alc888_base_mixer[] = {
1359         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1360         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1361         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1362         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1363         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1364                 HDA_OUTPUT),
1365         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1366         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1367         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1368         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1369         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1370         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1371         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1372         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1373         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1374         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1375         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1376         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1377         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1378         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1379         { } /* end */
1380 };
1381
1382 static void alc888_acer_aspire_4930g_automute(struct hda_codec *codec)
1383 {
1384         unsigned int present;
1385         unsigned int bits;
1386         present = snd_hda_codec_read(codec, 0x15, 0,
1387                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1388         bits = present ? HDA_AMP_MUTE : 0;
1389         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1390                                  HDA_AMP_MUTE, bits);
1391 }
1392
1393 static void alc888_acer_aspire_4930g_unsol_event(struct hda_codec *codec,
1394                 unsigned int res)
1395 {
1396         if (res >> 26 == ALC880_HP_EVENT)
1397                 alc888_acer_aspire_4930g_automute(codec);
1398 }
1399
1400 /*
1401  * ALC880 3-stack model
1402  *
1403  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1404  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1405  *                 F-Mic = 0x1b, HP = 0x19
1406  */
1407
1408 static hda_nid_t alc880_dac_nids[4] = {
1409         /* front, rear, clfe, rear_surr */
1410         0x02, 0x05, 0x04, 0x03
1411 };
1412
1413 static hda_nid_t alc880_adc_nids[3] = {
1414         /* ADC0-2 */
1415         0x07, 0x08, 0x09,
1416 };
1417
1418 /* The datasheet says the node 0x07 is connected from inputs,
1419  * but it shows zero connection in the real implementation on some devices.
1420  * Note: this is a 915GAV bug, fixed on 915GLV
1421  */
1422 static hda_nid_t alc880_adc_nids_alt[2] = {
1423         /* ADC1-2 */
1424         0x08, 0x09,
1425 };
1426
1427 #define ALC880_DIGOUT_NID       0x06
1428 #define ALC880_DIGIN_NID        0x0a
1429
1430 static struct hda_input_mux alc880_capture_source = {
1431         .num_items = 4,
1432         .items = {
1433                 { "Mic", 0x0 },
1434                 { "Front Mic", 0x3 },
1435                 { "Line", 0x2 },
1436                 { "CD", 0x4 },
1437         },
1438 };
1439
1440 /* channel source setting (2/6 channel selection for 3-stack) */
1441 /* 2ch mode */
1442 static struct hda_verb alc880_threestack_ch2_init[] = {
1443         /* set line-in to input, mute it */
1444         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1445         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1446         /* set mic-in to input vref 80%, mute it */
1447         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1448         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1449         { } /* end */
1450 };
1451
1452 /* 6ch mode */
1453 static struct hda_verb alc880_threestack_ch6_init[] = {
1454         /* set line-in to output, unmute it */
1455         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1456         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1457         /* set mic-in to output, unmute it */
1458         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1459         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1460         { } /* end */
1461 };
1462
1463 static struct hda_channel_mode alc880_threestack_modes[2] = {
1464         { 2, alc880_threestack_ch2_init },
1465         { 6, alc880_threestack_ch6_init },
1466 };
1467
1468 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1469         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1470         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1471         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1472         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1473         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1474         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1475         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1476         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1477         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1478         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1479         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1480         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1481         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1482         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1483         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1484         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1485         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1486         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1487         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1488         {
1489                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1490                 .name = "Channel Mode",
1491                 .info = alc_ch_mode_info,
1492                 .get = alc_ch_mode_get,
1493                 .put = alc_ch_mode_put,
1494         },
1495         { } /* end */
1496 };
1497
1498 /* capture mixer elements */
1499 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1500                             struct snd_ctl_elem_info *uinfo)
1501 {
1502         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1503         struct alc_spec *spec = codec->spec;
1504         int err;
1505
1506         mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1507         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1508                                                       HDA_INPUT);
1509         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1510         mutex_unlock(&codec->spdif_mutex); /* reuse spdif_mutex */
1511         return err;
1512 }
1513
1514 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1515                            unsigned int size, unsigned int __user *tlv)
1516 {
1517         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1518         struct alc_spec *spec = codec->spec;
1519         int err;
1520
1521         mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1522         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1523                                                       HDA_INPUT);
1524         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1525         mutex_unlock(&codec->spdif_mutex); /* reuse spdif_mutex */
1526         return err;
1527 }
1528
1529 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1530                              struct snd_ctl_elem_value *ucontrol);
1531
1532 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1533                                  struct snd_ctl_elem_value *ucontrol,
1534                                  getput_call_t func)
1535 {
1536         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1537         struct alc_spec *spec = codec->spec;
1538         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1539         int err;
1540
1541         mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1542         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1543                                                       3, 0, HDA_INPUT);
1544         err = func(kcontrol, ucontrol);
1545         mutex_unlock(&codec->spdif_mutex); /* reuse spdif_mutex */
1546         return err;
1547 }
1548
1549 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1550                            struct snd_ctl_elem_value *ucontrol)
1551 {
1552         return alc_cap_getput_caller(kcontrol, ucontrol,
1553                                      snd_hda_mixer_amp_volume_get);
1554 }
1555
1556 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1557                            struct snd_ctl_elem_value *ucontrol)
1558 {
1559         return alc_cap_getput_caller(kcontrol, ucontrol,
1560                                      snd_hda_mixer_amp_volume_put);
1561 }
1562
1563 /* capture mixer elements */
1564 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1565
1566 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1567                           struct snd_ctl_elem_value *ucontrol)
1568 {
1569         return alc_cap_getput_caller(kcontrol, ucontrol,
1570                                      snd_hda_mixer_amp_switch_get);
1571 }
1572
1573 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1574                           struct snd_ctl_elem_value *ucontrol)
1575 {
1576         return alc_cap_getput_caller(kcontrol, ucontrol,
1577                                      snd_hda_mixer_amp_switch_put);
1578 }
1579
1580 #define DEFINE_CAPMIX(num) \
1581 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1582         { \
1583                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1584                 .name = "Capture Switch", \
1585                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1586                 .count = num, \
1587                 .info = alc_cap_sw_info, \
1588                 .get = alc_cap_sw_get, \
1589                 .put = alc_cap_sw_put, \
1590         }, \
1591         { \
1592                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1593                 .name = "Capture Volume", \
1594                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1595                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1596                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1597                 .count = num, \
1598                 .info = alc_cap_vol_info, \
1599                 .get = alc_cap_vol_get, \
1600                 .put = alc_cap_vol_put, \
1601                 .tlv = { .c = alc_cap_vol_tlv }, \
1602         }, \
1603         { \
1604                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1605                 /* .name = "Capture Source", */ \
1606                 .name = "Input Source", \
1607                 .count = num, \
1608                 .info = alc_mux_enum_info, \
1609                 .get = alc_mux_enum_get, \
1610                 .put = alc_mux_enum_put, \
1611         }, \
1612         { } /* end */ \
1613 }
1614
1615 /* up to three ADCs */
1616 DEFINE_CAPMIX(1);
1617 DEFINE_CAPMIX(2);
1618 DEFINE_CAPMIX(3);
1619
1620
1621 /*
1622  * ALC880 5-stack model
1623  *
1624  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1625  *      Side = 0x02 (0xd)
1626  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1627  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1628  */
1629
1630 /* additional mixers to alc880_three_stack_mixer */
1631 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1632         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1633         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1634         { } /* end */
1635 };
1636
1637 /* channel source setting (6/8 channel selection for 5-stack) */
1638 /* 6ch mode */
1639 static struct hda_verb alc880_fivestack_ch6_init[] = {
1640         /* set line-in to input, mute it */
1641         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1642         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1643         { } /* end */
1644 };
1645
1646 /* 8ch mode */
1647 static struct hda_verb alc880_fivestack_ch8_init[] = {
1648         /* set line-in to output, unmute it */
1649         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1650         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1651         { } /* end */
1652 };
1653
1654 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1655         { 6, alc880_fivestack_ch6_init },
1656         { 8, alc880_fivestack_ch8_init },
1657 };
1658
1659
1660 /*
1661  * ALC880 6-stack model
1662  *
1663  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1664  *      Side = 0x05 (0x0f)
1665  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1666  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1667  */
1668
1669 static hda_nid_t alc880_6st_dac_nids[4] = {
1670         /* front, rear, clfe, rear_surr */
1671         0x02, 0x03, 0x04, 0x05
1672 };
1673
1674 static struct hda_input_mux alc880_6stack_capture_source = {
1675         .num_items = 4,
1676         .items = {
1677                 { "Mic", 0x0 },
1678                 { "Front Mic", 0x1 },
1679                 { "Line", 0x2 },
1680                 { "CD", 0x4 },
1681         },
1682 };
1683
1684 /* fixed 8-channels */
1685 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1686         { 8, NULL },
1687 };
1688
1689 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1690         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1691         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1692         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1693         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1694         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1695         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1696         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1697         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1698         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1699         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1700         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1701         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1702         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1703         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1704         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1705         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1706         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1707         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1708         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1709         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1710         {
1711                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1712                 .name = "Channel Mode",
1713                 .info = alc_ch_mode_info,
1714                 .get = alc_ch_mode_get,
1715                 .put = alc_ch_mode_put,
1716         },
1717         { } /* end */
1718 };
1719
1720
1721 /*
1722  * ALC880 W810 model
1723  *
1724  * W810 has rear IO for:
1725  * Front (DAC 02)
1726  * Surround (DAC 03)
1727  * Center/LFE (DAC 04)
1728  * Digital out (06)
1729  *
1730  * The system also has a pair of internal speakers, and a headphone jack.
1731  * These are both connected to Line2 on the codec, hence to DAC 02.
1732  *
1733  * There is a variable resistor to control the speaker or headphone
1734  * volume. This is a hardware-only device without a software API.
1735  *
1736  * Plugging headphones in will disable the internal speakers. This is
1737  * implemented in hardware, not via the driver using jack sense. In
1738  * a similar fashion, plugging into the rear socket marked "front" will
1739  * disable both the speakers and headphones.
1740  *
1741  * For input, there's a microphone jack, and an "audio in" jack.
1742  * These may not do anything useful with this driver yet, because I
1743  * haven't setup any initialization verbs for these yet...
1744  */
1745
1746 static hda_nid_t alc880_w810_dac_nids[3] = {
1747         /* front, rear/surround, clfe */
1748         0x02, 0x03, 0x04
1749 };
1750
1751 /* fixed 6 channels */
1752 static struct hda_channel_mode alc880_w810_modes[1] = {
1753         { 6, NULL }
1754 };
1755
1756 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1757 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1758         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1759         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1760         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1761         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1762         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1763         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1764         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1765         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1766         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1767         { } /* end */
1768 };
1769
1770
1771 /*
1772  * Z710V model
1773  *
1774  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1775  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1776  *                 Line = 0x1a
1777  */
1778
1779 static hda_nid_t alc880_z71v_dac_nids[1] = {
1780         0x02
1781 };
1782 #define ALC880_Z71V_HP_DAC      0x03
1783
1784 /* fixed 2 channels */
1785 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1786         { 2, NULL }
1787 };
1788
1789 static struct snd_kcontrol_new alc880_z71v_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("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1793         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1794         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1795         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1796         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1797         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1798         { } /* end */
1799 };
1800
1801
1802 /*
1803  * ALC880 F1734 model
1804  *
1805  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1806  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1807  */
1808
1809 static hda_nid_t alc880_f1734_dac_nids[1] = {
1810         0x03
1811 };
1812 #define ALC880_F1734_HP_DAC     0x02
1813
1814 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1815         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1816         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1817         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1818         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1819         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1820         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1821         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1822         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1823         { } /* end */
1824 };
1825
1826 static struct hda_input_mux alc880_f1734_capture_source = {
1827         .num_items = 2,
1828         .items = {
1829                 { "Mic", 0x1 },
1830                 { "CD", 0x4 },
1831         },
1832 };
1833
1834
1835 /*
1836  * ALC880 ASUS model
1837  *
1838  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1839  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1840  *  Mic = 0x18, Line = 0x1a
1841  */
1842
1843 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1844 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1845
1846 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1847         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1848         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1849         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1850         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1851         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1852         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1853         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1854         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1855         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1856         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1857         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1858         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1859         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1860         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1861         {
1862                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1863                 .name = "Channel Mode",
1864                 .info = alc_ch_mode_info,
1865                 .get = alc_ch_mode_get,
1866                 .put = alc_ch_mode_put,
1867         },
1868         { } /* end */
1869 };
1870
1871 /*
1872  * ALC880 ASUS W1V model
1873  *
1874  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1875  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1876  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1877  */
1878
1879 /* additional mixers to alc880_asus_mixer */
1880 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1881         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1882         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1883         { } /* end */
1884 };
1885
1886 /* additional mixers to alc880_asus_mixer */
1887 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1888         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1889         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1890         { } /* end */
1891 };
1892
1893 /* TCL S700 */
1894 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1895         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1896         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1897         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1898         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1899         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1900         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1901         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1902         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1903         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1904         { } /* end */
1905 };
1906
1907 /* Uniwill */
1908 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1909         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1910         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1911         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1912         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1913         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1914         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1915         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1916         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1917         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1918         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1919         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1920         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1921         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1922         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1923         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1924         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1925         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1926         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1927         {
1928                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1929                 .name = "Channel Mode",
1930                 .info = alc_ch_mode_info,
1931                 .get = alc_ch_mode_get,
1932                 .put = alc_ch_mode_put,
1933         },
1934         { } /* end */
1935 };
1936
1937 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1938         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1939         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1940         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1941         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 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("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1945         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1946         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1947         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1948         { } /* end */
1949 };
1950
1951 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1952         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1953         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1954         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1955         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1956         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1957         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1958         { } /* end */
1959 };
1960
1961 /*
1962  * virtual master controls
1963  */
1964
1965 /*
1966  * slave controls for virtual master
1967  */
1968 static const char *alc_slave_vols[] = {
1969         "Front Playback Volume",
1970         "Surround Playback Volume",
1971         "Center Playback Volume",
1972         "LFE Playback Volume",
1973         "Side Playback Volume",
1974         "Headphone Playback Volume",
1975         "Speaker Playback Volume",
1976         "Mono Playback Volume",
1977         "Line-Out Playback Volume",
1978         "PCM Playback Volume",
1979         NULL,
1980 };
1981
1982 static const char *alc_slave_sws[] = {
1983         "Front Playback Switch",
1984         "Surround Playback Switch",
1985         "Center Playback Switch",
1986         "LFE Playback Switch",
1987         "Side Playback Switch",
1988         "Headphone Playback Switch",
1989         "Speaker Playback Switch",
1990         "Mono Playback Switch",
1991         "IEC958 Playback Switch",
1992         NULL,
1993 };
1994
1995 /*
1996  * build control elements
1997  */
1998
1999 static void alc_free_kctls(struct hda_codec *codec);
2000
2001 static int alc_build_controls(struct hda_codec *codec)
2002 {
2003         struct alc_spec *spec = codec->spec;
2004         int err;
2005         int i;
2006
2007         for (i = 0; i < spec->num_mixers; i++) {
2008                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2009                 if (err < 0)
2010                         return err;
2011         }
2012         if (spec->cap_mixer) {
2013                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2014                 if (err < 0)
2015                         return err;
2016         }
2017         if (spec->multiout.dig_out_nid) {
2018                 err = snd_hda_create_spdif_out_ctls(codec,
2019                                                     spec->multiout.dig_out_nid);
2020                 if (err < 0)
2021                         return err;
2022                 err = snd_hda_create_spdif_share_sw(codec,
2023                                                     &spec->multiout);
2024                 if (err < 0)
2025                         return err;
2026                 spec->multiout.share_spdif = 1;
2027         }
2028         if (spec->dig_in_nid) {
2029                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2030                 if (err < 0)
2031                         return err;
2032         }
2033
2034         /* if we have no master control, let's create it */
2035         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2036                 unsigned int vmaster_tlv[4];
2037                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2038                                         HDA_OUTPUT, vmaster_tlv);
2039                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2040                                           vmaster_tlv, alc_slave_vols);
2041                 if (err < 0)
2042                         return err;
2043         }
2044         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2045                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2046                                           NULL, alc_slave_sws);
2047                 if (err < 0)
2048                         return err;
2049         }
2050
2051         alc_free_kctls(codec); /* no longer needed */
2052         return 0;
2053 }
2054
2055
2056 /*
2057  * initialize the codec volumes, etc
2058  */
2059
2060 /*
2061  * generic initialization of ADC, input mixers and output mixers
2062  */
2063 static struct hda_verb alc880_volume_init_verbs[] = {
2064         /*
2065          * Unmute ADC0-2 and set the default input to mic-in
2066          */
2067         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2068         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2069         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2070         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2071         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2072         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2073
2074         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2075          * mixer widget
2076          * Note: PASD motherboards uses the Line In 2 as the input for front
2077          * panel mic (mic 2)
2078          */
2079         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2080         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2081         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2082         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2083         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2084         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2085         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2086         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2087
2088         /*
2089          * Set up output mixers (0x0c - 0x0f)
2090          */
2091         /* set vol=0 to output mixers */
2092         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2093         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2094         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2095         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2096         /* set up input amps for analog loopback */
2097         /* Amp Indices: DAC = 0, mixer = 1 */
2098         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2099         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2100         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2101         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2102         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2103         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2104         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2105         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2106
2107         { }
2108 };
2109
2110 /*
2111  * 3-stack pin configuration:
2112  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2113  */
2114 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2115         /*
2116          * preset connection lists of input pins
2117          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2118          */
2119         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2120         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2121         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2122
2123         /*
2124          * Set pin mode and muting
2125          */
2126         /* set front pin widgets 0x14 for output */
2127         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2128         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2129         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2130         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2131         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2132         /* Mic2 (as headphone out) for HP output */
2133         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2134         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2135         /* Line In pin widget for input */
2136         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2137         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2138         /* Line2 (as front mic) pin widget for input and vref at 80% */
2139         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2140         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2141         /* CD pin widget for input */
2142         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2143
2144         { }
2145 };
2146
2147 /*
2148  * 5-stack pin configuration:
2149  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2150  * line-in/side = 0x1a, f-mic = 0x1b
2151  */
2152 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2153         /*
2154          * preset connection lists of input pins
2155          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2156          */
2157         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2158         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2159
2160         /*
2161          * Set pin mode and muting
2162          */
2163         /* set pin widgets 0x14-0x17 for output */
2164         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2165         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2166         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2167         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2168         /* unmute pins for output (no gain on this amp) */
2169         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2170         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2171         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2172         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2173
2174         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2175         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2176         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2177         /* Mic2 (as headphone out) for HP output */
2178         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2179         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2180         /* Line In pin widget for input */
2181         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2182         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2183         /* Line2 (as front mic) pin widget for input and vref at 80% */
2184         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2185         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2186         /* CD pin widget for input */
2187         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2188
2189         { }
2190 };
2191
2192 /*
2193  * W810 pin configuration:
2194  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2195  */
2196 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2197         /* hphone/speaker input selector: front DAC */
2198         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2199
2200         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2201         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2202         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2203         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2204         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2205         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2206
2207         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2208         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2209
2210         { }
2211 };
2212
2213 /*
2214  * Z71V pin configuration:
2215  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2216  */
2217 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2218         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2219         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2220         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2221         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2222
2223         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2224         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2225         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2226         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2227
2228         { }
2229 };
2230
2231 /*
2232  * 6-stack pin configuration:
2233  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2234  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2235  */
2236 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2237         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2238
2239         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2240         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2241         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2242         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2243         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2244         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2245         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2246         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2247
2248         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2249         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2250         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2251         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2252         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2253         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2254         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2255         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2256         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2257
2258         { }
2259 };
2260
2261 /*
2262  * Uniwill pin configuration:
2263  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2264  * line = 0x1a
2265  */
2266 static struct hda_verb alc880_uniwill_init_verbs[] = {
2267         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2268
2269         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2270         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2271         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2272         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2273         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2274         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2275         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2276         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2277         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2278         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2279         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2280         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2281         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2282         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2283
2284         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2285         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2286         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2287         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2288         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2289         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2290         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2291         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2292         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2293
2294         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2295         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2296
2297         { }
2298 };
2299
2300 /*
2301 * Uniwill P53
2302 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2303  */
2304 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2305         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2306
2307         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2308         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2309         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2310         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2311         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2312         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2313         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2314         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2315         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2316         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2317         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2318         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2319
2320         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2321         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2322         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2323         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2324         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2325         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2326
2327         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2328         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2329
2330         { }
2331 };
2332
2333 static struct hda_verb alc880_beep_init_verbs[] = {
2334         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2335         { }
2336 };
2337
2338 /* toggle speaker-output according to the hp-jack state */
2339 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
2340 {
2341         unsigned int present;
2342         unsigned char bits;
2343
2344         present = snd_hda_codec_read(codec, 0x14, 0,
2345                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2346         bits = present ? HDA_AMP_MUTE : 0;
2347         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
2348                                  HDA_AMP_MUTE, bits);
2349         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
2350                                  HDA_AMP_MUTE, bits);
2351 }
2352
2353 /* auto-toggle front mic */
2354 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2355 {
2356         unsigned int present;
2357         unsigned char bits;
2358
2359         present = snd_hda_codec_read(codec, 0x18, 0,
2360                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2361         bits = present ? HDA_AMP_MUTE : 0;
2362         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2363 }
2364
2365 static void alc880_uniwill_automute(struct hda_codec *codec)
2366 {
2367         alc880_uniwill_hp_automute(codec);
2368         alc880_uniwill_mic_automute(codec);
2369 }
2370
2371 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2372                                        unsigned int res)
2373 {
2374         /* Looks like the unsol event is incompatible with the standard
2375          * definition.  4bit tag is placed at 28 bit!
2376          */
2377         switch (res >> 28) {
2378         case ALC880_HP_EVENT:
2379                 alc880_uniwill_hp_automute(codec);
2380                 break;
2381         case ALC880_MIC_EVENT:
2382                 alc880_uniwill_mic_automute(codec);
2383                 break;
2384         }
2385 }
2386
2387 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
2388 {
2389         unsigned int present;
2390         unsigned char bits;
2391
2392         present = snd_hda_codec_read(codec, 0x14, 0,
2393                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2394         bits = present ? HDA_AMP_MUTE : 0;
2395         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
2396 }
2397
2398 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2399 {
2400         unsigned int present;
2401
2402         present = snd_hda_codec_read(codec, 0x21, 0,
2403                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2404         present &= HDA_AMP_VOLMASK;
2405         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2406                                  HDA_AMP_VOLMASK, present);
2407         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2408                                  HDA_AMP_VOLMASK, present);
2409 }
2410
2411 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2412                                            unsigned int res)
2413 {
2414         /* Looks like the unsol event is incompatible with the standard
2415          * definition.  4bit tag is placed at 28 bit!
2416          */
2417         if ((res >> 28) == ALC880_HP_EVENT)
2418                 alc880_uniwill_p53_hp_automute(codec);
2419         if ((res >> 28) == ALC880_DCVOL_EVENT)
2420                 alc880_uniwill_p53_dcvol_automute(codec);
2421 }
2422
2423 /*
2424  * F1734 pin configuration:
2425  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2426  */
2427 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2428         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2429         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2430         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2431         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2432         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2433
2434         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2435         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2436         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2437         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2438
2439         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2440         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2441         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2442         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2443         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2444         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2445         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2446         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2447         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2448
2449         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2450         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2451
2452         { }
2453 };
2454
2455 /*
2456  * ASUS pin configuration:
2457  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2458  */
2459 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2460         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2461         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2462         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2463         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2464
2465         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2466         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2467         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2468         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2469         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2470         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2471         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2472         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2473
2474         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2475         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2476         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2477         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2478         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2479         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2480         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2481         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2482         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2483
2484         { }
2485 };
2486
2487 /* Enable GPIO mask and set output */
2488 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2489 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2490
2491 /* Clevo m520g init */
2492 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2493         /* headphone output */
2494         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2495         /* line-out */
2496         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2497         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2498         /* Line-in */
2499         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2500         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2501         /* CD */
2502         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2503         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2504         /* Mic1 (rear panel) */
2505         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2506         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2507         /* Mic2 (front panel) */
2508         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2509         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2510         /* headphone */
2511         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2512         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2513         /* change to EAPD mode */
2514         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2515         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2516
2517         { }
2518 };
2519
2520 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2521         /* change to EAPD mode */
2522         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2523         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2524
2525         /* Headphone output */
2526         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2527         /* Front output*/
2528         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2529         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2530
2531         /* Line In pin widget for input */
2532         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2533         /* CD pin widget for input */
2534         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2535         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2536         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2537
2538         /* change to EAPD mode */
2539         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2540         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2541
2542         { }
2543 };
2544
2545 /*
2546  * LG m1 express dual
2547  *
2548  * Pin assignment:
2549  *   Rear Line-In/Out (blue): 0x14
2550  *   Build-in Mic-In: 0x15
2551  *   Speaker-out: 0x17
2552  *   HP-Out (green): 0x1b
2553  *   Mic-In/Out (red): 0x19
2554  *   SPDIF-Out: 0x1e
2555  */
2556
2557 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2558 static hda_nid_t alc880_lg_dac_nids[3] = {
2559         0x05, 0x02, 0x03
2560 };
2561
2562 /* seems analog CD is not working */
2563 static struct hda_input_mux alc880_lg_capture_source = {
2564         .num_items = 3,
2565         .items = {
2566                 { "Mic", 0x1 },
2567                 { "Line", 0x5 },
2568                 { "Internal Mic", 0x6 },
2569         },
2570 };
2571
2572 /* 2,4,6 channel modes */
2573 static struct hda_verb alc880_lg_ch2_init[] = {
2574         /* set line-in and mic-in to input */
2575         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2576         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2577         { }
2578 };
2579
2580 static struct hda_verb alc880_lg_ch4_init[] = {
2581         /* set line-in to out and mic-in to input */
2582         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2583         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2584         { }
2585 };
2586
2587 static struct hda_verb alc880_lg_ch6_init[] = {
2588         /* set line-in and mic-in to output */
2589         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2590         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2591         { }
2592 };
2593
2594 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2595         { 2, alc880_lg_ch2_init },
2596         { 4, alc880_lg_ch4_init },
2597         { 6, alc880_lg_ch6_init },
2598 };
2599
2600 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2601         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2602         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2603         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2604         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2605         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2606         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2607         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2608         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2609         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2610         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2611         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2612         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2613         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2614         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2615         {
2616                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2617                 .name = "Channel Mode",
2618                 .info = alc_ch_mode_info,
2619                 .get = alc_ch_mode_get,
2620                 .put = alc_ch_mode_put,
2621         },
2622         { } /* end */
2623 };
2624
2625 static struct hda_verb alc880_lg_init_verbs[] = {
2626         /* set capture source to mic-in */
2627         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2628         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2629         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2630         /* mute all amp mixer inputs */
2631         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2632         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2633         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2634         /* line-in to input */
2635         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2636         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2637         /* built-in mic */
2638         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2639         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2640         /* speaker-out */
2641         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2642         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2643         /* mic-in to input */
2644         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2645         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2646         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2647         /* HP-out */
2648         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2649         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2650         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2651         /* jack sense */
2652         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2653         { }
2654 };
2655
2656 /* toggle speaker-output according to the hp-jack state */
2657 static void alc880_lg_automute(struct hda_codec *codec)
2658 {
2659         unsigned int present;
2660         unsigned char bits;
2661
2662         present = snd_hda_codec_read(codec, 0x1b, 0,
2663                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2664         bits = present ? HDA_AMP_MUTE : 0;
2665         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2666                                  HDA_AMP_MUTE, bits);
2667 }
2668
2669 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2670 {
2671         /* Looks like the unsol event is incompatible with the standard
2672          * definition.  4bit tag is placed at 28 bit!
2673          */
2674         if ((res >> 28) == 0x01)
2675                 alc880_lg_automute(codec);
2676 }
2677
2678 /*
2679  * LG LW20
2680  *
2681  * Pin assignment:
2682  *   Speaker-out: 0x14
2683  *   Mic-In: 0x18
2684  *   Built-in Mic-In: 0x19
2685  *   Line-In: 0x1b
2686  *   HP-Out: 0x1a
2687  *   SPDIF-Out: 0x1e
2688  */
2689
2690 static struct hda_input_mux alc880_lg_lw_capture_source = {
2691         .num_items = 3,
2692         .items = {
2693                 { "Mic", 0x0 },
2694                 { "Internal Mic", 0x1 },
2695                 { "Line In", 0x2 },
2696         },
2697 };
2698
2699 #define alc880_lg_lw_modes alc880_threestack_modes
2700
2701 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2702         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2703         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2704         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2705         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2706         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2707         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2708         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2709         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2710         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2711         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2712         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2713         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2714         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2715         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2716         {
2717                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2718                 .name = "Channel Mode",
2719                 .info = alc_ch_mode_info,
2720                 .get = alc_ch_mode_get,
2721                 .put = alc_ch_mode_put,
2722         },
2723         { } /* end */
2724 };
2725
2726 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2727         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2728         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2729         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2730
2731         /* set capture source to mic-in */
2732         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2733         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2734         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2735         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2736         /* speaker-out */
2737         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2738         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2739         /* HP-out */
2740         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2741         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2742         /* mic-in to input */
2743         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2744         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2745         /* built-in mic */
2746         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2747         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2748         /* jack sense */
2749         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2750         { }
2751 };
2752
2753 /* toggle speaker-output according to the hp-jack state */
2754 static void alc880_lg_lw_automute(struct hda_codec *codec)
2755 {
2756         unsigned int present;
2757         unsigned char bits;
2758
2759         present = snd_hda_codec_read(codec, 0x1b, 0,
2760                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2761         bits = present ? HDA_AMP_MUTE : 0;
2762         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2763                                  HDA_AMP_MUTE, bits);
2764 }
2765
2766 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2767 {
2768         /* Looks like the unsol event is incompatible with the standard
2769          * definition.  4bit tag is placed at 28 bit!
2770          */
2771         if ((res >> 28) == 0x01)
2772                 alc880_lg_lw_automute(codec);
2773 }
2774
2775 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2776         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2777         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2778         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2779         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2780         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2781         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2782         { } /* end */
2783 };
2784
2785 static struct hda_input_mux alc880_medion_rim_capture_source = {
2786         .num_items = 2,
2787         .items = {
2788                 { "Mic", 0x0 },
2789                 { "Internal Mic", 0x1 },
2790         },
2791 };
2792
2793 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2794         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2795
2796         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2797         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2798
2799         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2800         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2801         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2802         /* Mic2 (as headphone out) for HP output */
2803         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2804         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2805         /* Internal Speaker */
2806         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2807         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2808
2809         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2810         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2811
2812         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2813         { }
2814 };
2815
2816 /* toggle speaker-output according to the hp-jack state */
2817 static void alc880_medion_rim_automute(struct hda_codec *codec)
2818 {
2819         unsigned int present;
2820         unsigned char bits;
2821
2822         present = snd_hda_codec_read(codec, 0x14, 0,
2823                                      AC_VERB_GET_PIN_SENSE, 0)
2824                 & AC_PINSENSE_PRESENCE;
2825         bits = present ? HDA_AMP_MUTE : 0;
2826         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2827                                  HDA_AMP_MUTE, bits);
2828         if (present)
2829                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2830         else
2831                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2832 }
2833
2834 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2835                                           unsigned int res)
2836 {
2837         /* Looks like the unsol event is incompatible with the standard
2838          * definition.  4bit tag is placed at 28 bit!
2839          */
2840         if ((res >> 28) == ALC880_HP_EVENT)
2841                 alc880_medion_rim_automute(codec);
2842 }
2843
2844 #ifdef CONFIG_SND_HDA_POWER_SAVE
2845 static struct hda_amp_list alc880_loopbacks[] = {
2846         { 0x0b, HDA_INPUT, 0 },
2847         { 0x0b, HDA_INPUT, 1 },
2848         { 0x0b, HDA_INPUT, 2 },
2849         { 0x0b, HDA_INPUT, 3 },
2850         { 0x0b, HDA_INPUT, 4 },
2851         { } /* end */
2852 };
2853
2854 static struct hda_amp_list alc880_lg_loopbacks[] = {
2855         { 0x0b, HDA_INPUT, 1 },
2856         { 0x0b, HDA_INPUT, 6 },
2857         { 0x0b, HDA_INPUT, 7 },
2858         { } /* end */
2859 };
2860 #endif
2861
2862 /*
2863  * Common callbacks
2864  */
2865
2866 static int alc_init(struct hda_codec *codec)
2867 {
2868         struct alc_spec *spec = codec->spec;
2869         unsigned int i;
2870
2871         alc_fix_pll(codec);
2872         if (codec->vendor_id == 0x10ec0888)
2873                 alc888_coef_init(codec);
2874
2875         for (i = 0; i < spec->num_init_verbs; i++)
2876                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2877
2878         if (spec->init_hook)
2879                 spec->init_hook(codec);
2880
2881         return 0;
2882 }
2883
2884 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2885 {
2886         struct alc_spec *spec = codec->spec;
2887
2888         if (spec->unsol_event)
2889                 spec->unsol_event(codec, res);
2890 }
2891
2892 #ifdef CONFIG_SND_HDA_POWER_SAVE
2893 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2894 {
2895         struct alc_spec *spec = codec->spec;
2896         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2897 }
2898 #endif
2899
2900 /*
2901  * Analog playback callbacks
2902  */
2903 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2904                                     struct hda_codec *codec,
2905                                     struct snd_pcm_substream *substream)
2906 {
2907         struct alc_spec *spec = codec->spec;
2908         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2909                                              hinfo);
2910 }
2911
2912 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2913                                        struct hda_codec *codec,
2914                                        unsigned int stream_tag,
2915                                        unsigned int format,
2916                                        struct snd_pcm_substream *substream)
2917 {
2918         struct alc_spec *spec = codec->spec;
2919         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2920                                                 stream_tag, format, substream);
2921 }
2922
2923 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2924                                        struct hda_codec *codec,
2925                                        struct snd_pcm_substream *substream)
2926 {
2927         struct alc_spec *spec = codec->spec;
2928         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2929 }
2930
2931 /*
2932  * Digital out
2933  */
2934 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2935                                         struct hda_codec *codec,
2936                                         struct snd_pcm_substream *substream)
2937 {
2938         struct alc_spec *spec = codec->spec;
2939         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2940 }
2941
2942 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2943                                            struct hda_codec *codec,
2944                                            unsigned int stream_tag,
2945                                            unsigned int format,
2946                                            struct snd_pcm_substream *substream)
2947 {
2948         struct alc_spec *spec = codec->spec;
2949         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2950                                              stream_tag, format, substream);
2951 }
2952
2953 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2954                                          struct hda_codec *codec,
2955                                          struct snd_pcm_substream *substream)
2956 {
2957         struct alc_spec *spec = codec->spec;
2958         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2959 }
2960
2961 /*
2962  * Analog capture
2963  */
2964 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2965                                       struct hda_codec *codec,
2966                                       unsigned int stream_tag,
2967                                       unsigned int format,
2968                                       struct snd_pcm_substream *substream)
2969 {
2970         struct alc_spec *spec = codec->spec;
2971
2972         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2973                                    stream_tag, 0, format);
2974         return 0;
2975 }
2976
2977 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2978                                       struct hda_codec *codec,
2979                                       struct snd_pcm_substream *substream)
2980 {
2981         struct alc_spec *spec = codec->spec;
2982
2983         snd_hda_codec_cleanup_stream(codec,
2984                                      spec->adc_nids[substream->number + 1]);
2985         return 0;
2986 }
2987
2988
2989 /*
2990  */
2991 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2992         .substreams = 1,
2993         .channels_min = 2,
2994         .channels_max = 8,
2995         /* NID is set in alc_build_pcms */
2996         .ops = {
2997                 .open = alc880_playback_pcm_open,
2998                 .prepare = alc880_playback_pcm_prepare,
2999                 .cleanup = alc880_playback_pcm_cleanup
3000         },
3001 };
3002
3003 static struct hda_pcm_stream alc880_pcm_analog_capture = {
3004         .substreams = 1,
3005         .channels_min = 2,
3006         .channels_max = 2,
3007         /* NID is set in alc_build_pcms */
3008 };
3009
3010 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
3011         .substreams = 1,
3012         .channels_min = 2,
3013         .channels_max = 2,
3014         /* NID is set in alc_build_pcms */
3015 };
3016
3017 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
3018         .substreams = 2, /* can be overridden */
3019         .channels_min = 2,
3020         .channels_max = 2,
3021         /* NID is set in alc_build_pcms */
3022         .ops = {
3023                 .prepare = alc880_alt_capture_pcm_prepare,
3024                 .cleanup = alc880_alt_capture_pcm_cleanup
3025         },
3026 };
3027
3028 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3029         .substreams = 1,
3030         .channels_min = 2,
3031         .channels_max = 2,
3032         /* NID is set in alc_build_pcms */
3033         .ops = {
3034                 .open = alc880_dig_playback_pcm_open,
3035                 .close = alc880_dig_playback_pcm_close,
3036                 .prepare = alc880_dig_playback_pcm_prepare
3037         },
3038 };
3039
3040 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3041         .substreams = 1,
3042         .channels_min = 2,
3043         .channels_max = 2,
3044         /* NID is set in alc_build_pcms */
3045 };
3046
3047 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3048 static struct hda_pcm_stream alc_pcm_null_stream = {
3049         .substreams = 0,
3050         .channels_min = 0,
3051         .channels_max = 0,
3052 };
3053
3054 static int alc_build_pcms(struct hda_codec *codec)
3055 {
3056         struct alc_spec *spec = codec->spec;
3057         struct hda_pcm *info = spec->pcm_rec;
3058         int i;
3059
3060         codec->num_pcms = 1;
3061         codec->pcm_info = info;
3062
3063         info->name = spec->stream_name_analog;
3064         if (spec->stream_analog_playback) {
3065                 if (snd_BUG_ON(!spec->multiout.dac_nids))
3066                         return -EINVAL;
3067                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
3068                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
3069         }
3070         if (spec->stream_analog_capture) {
3071                 if (snd_BUG_ON(!spec->adc_nids))
3072                         return -EINVAL;
3073                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
3074                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
3075         }
3076
3077         if (spec->channel_mode) {
3078                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
3079                 for (i = 0; i < spec->num_channel_mode; i++) {
3080                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
3081                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
3082                         }
3083                 }
3084         }
3085
3086         /* SPDIF for stream index #1 */
3087         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3088                 codec->num_pcms = 2;
3089                 info = spec->pcm_rec + 1;
3090                 info->name = spec->stream_name_digital;
3091                 info->pcm_type = HDA_PCM_TYPE_SPDIF;
3092                 if (spec->multiout.dig_out_nid &&
3093                     spec->stream_digital_playback) {
3094                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
3095                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
3096                 }
3097                 if (spec->dig_in_nid &&
3098                     spec->stream_digital_capture) {
3099                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
3100                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
3101                 }
3102                 /* FIXME: do we need this for all Realtek codec models? */
3103                 codec->spdif_status_reset = 1;
3104         }
3105
3106         /* If the use of more than one ADC is requested for the current
3107          * model, configure a second analog capture-only PCM.
3108          */
3109         /* Additional Analaog capture for index #2 */
3110         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
3111             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3112                 codec->num_pcms = 3;
3113                 info = spec->pcm_rec + 2;
3114                 info->name = spec->stream_name_analog;
3115                 if (spec->alt_dac_nid) {
3116                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3117                                 *spec->stream_analog_alt_playback;
3118                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
3119                                 spec->alt_dac_nid;
3120                 } else {
3121                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3122                                 alc_pcm_null_stream;
3123                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
3124                 }
3125                 if (spec->num_adc_nids > 1) {
3126                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3127                                 *spec->stream_analog_alt_capture;
3128                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
3129                                 spec->adc_nids[1];
3130                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3131                                 spec->num_adc_nids - 1;
3132                 } else {
3133                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3134                                 alc_pcm_null_stream;
3135                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3136                 }
3137         }
3138
3139         return 0;
3140 }
3141
3142 static void alc_free_kctls(struct hda_codec *codec)
3143 {
3144         struct alc_spec *spec = codec->spec;
3145
3146         if (spec->kctls.list) {
3147                 struct snd_kcontrol_new *kctl = spec->kctls.list;
3148                 int i;
3149                 for (i = 0; i < spec->kctls.used; i++)
3150                         kfree(kctl[i].name);
3151         }
3152         snd_array_free(&spec->kctls);
3153 }
3154
3155 static void alc_free(struct hda_codec *codec)
3156 {
3157         struct alc_spec *spec = codec->spec;
3158
3159         if (!spec)
3160                 return;
3161
3162         alc_free_kctls(codec);
3163         kfree(spec);
3164         codec->spec = NULL; /* to be sure */
3165 }
3166
3167 #ifdef SND_HDA_NEEDS_RESUME
3168 static void store_pin_configs(struct hda_codec *codec)
3169 {
3170         struct alc_spec *spec = codec->spec;
3171         hda_nid_t nid, end_nid;
3172
3173         end_nid = codec->start_nid + codec->num_nodes;
3174         for (nid = codec->start_nid; nid < end_nid; nid++) {
3175                 unsigned int wid_caps = get_wcaps(codec, nid);
3176                 unsigned int wid_type =
3177                         (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3178                 if (wid_type != AC_WID_PIN)
3179                         continue;
3180                 if (spec->num_pins >= ARRAY_SIZE(spec->pin_nids))
3181                         break;
3182                 spec->pin_nids[spec->num_pins] = nid;
3183                 spec->pin_cfgs[spec->num_pins] =
3184                         snd_hda_codec_read(codec, nid, 0,
3185                                            AC_VERB_GET_CONFIG_DEFAULT, 0);
3186                 spec->num_pins++;
3187         }
3188 }
3189
3190 static void resume_pin_configs(struct hda_codec *codec)
3191 {
3192         struct alc_spec *spec = codec->spec;
3193         int i;
3194
3195         for (i = 0; i < spec->num_pins; i++) {
3196                 hda_nid_t pin_nid = spec->pin_nids[i];
3197                 unsigned int pin_config = spec->pin_cfgs[i];
3198                 snd_hda_codec_write(codec, pin_nid, 0,
3199                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
3200                                     pin_config & 0x000000ff);
3201                 snd_hda_codec_write(codec, pin_nid, 0,
3202                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
3203                                     (pin_config & 0x0000ff00) >> 8);
3204                 snd_hda_codec_write(codec, pin_nid, 0,
3205                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
3206                                     (pin_config & 0x00ff0000) >> 16);
3207                 snd_hda_codec_write(codec, pin_nid, 0,
3208                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
3209                                     pin_config >> 24);
3210         }
3211 }
3212
3213 static int alc_resume(struct hda_codec *codec)
3214 {
3215         resume_pin_configs(codec);
3216         codec->patch_ops.init(codec);
3217         snd_hda_codec_resume_amp(codec);
3218         snd_hda_codec_resume_cache(codec);
3219         return 0;
3220 }
3221 #else
3222 #define store_pin_configs(codec)
3223 #endif
3224
3225 /*
3226  */
3227 static struct hda_codec_ops alc_patch_ops = {
3228         .build_controls = alc_build_controls,
3229         .build_pcms = alc_build_pcms,
3230         .init = alc_init,
3231         .free = alc_free,
3232         .unsol_event = alc_unsol_event,
3233 #ifdef SND_HDA_NEEDS_RESUME
3234         .resume = alc_resume,
3235 #endif
3236 #ifdef CONFIG_SND_HDA_POWER_SAVE
3237         .check_power_status = alc_check_power_status,
3238 #endif
3239 };
3240
3241
3242 /*
3243  * Test configuration for debugging
3244  *
3245  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3246  * enum controls.
3247  */
3248 #ifdef CONFIG_SND_DEBUG
3249 static hda_nid_t alc880_test_dac_nids[4] = {
3250         0x02, 0x03, 0x04, 0x05
3251 };
3252
3253 static struct hda_input_mux alc880_test_capture_source = {
3254         .num_items = 7,
3255         .items = {
3256                 { "In-1", 0x0 },
3257                 { "In-2", 0x1 },
3258                 { "In-3", 0x2 },
3259                 { "In-4", 0x3 },
3260                 { "CD", 0x4 },
3261                 { "Front", 0x5 },
3262                 { "Surround", 0x6 },
3263         },
3264 };
3265
3266 static struct hda_channel_mode alc880_test_modes[4] = {
3267         { 2, NULL },
3268         { 4, NULL },
3269         { 6, NULL },
3270         { 8, NULL },
3271 };
3272
3273 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3274                                  struct snd_ctl_elem_info *uinfo)
3275 {
3276         static char *texts[] = {
3277                 "N/A", "Line Out", "HP Out",
3278                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3279         };
3280         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3281         uinfo->count = 1;
3282         uinfo->value.enumerated.items = 8;
3283         if (uinfo->value.enumerated.item >= 8)
3284                 uinfo->value.enumerated.item = 7;
3285         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3286         return 0;
3287 }
3288
3289 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3290                                 struct snd_ctl_elem_value *ucontrol)
3291 {
3292         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3293         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3294         unsigned int pin_ctl, item = 0;
3295
3296         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3297                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3298         if (pin_ctl & AC_PINCTL_OUT_EN) {
3299                 if (pin_ctl & AC_PINCTL_HP_EN)
3300                         item = 2;
3301                 else
3302                         item = 1;
3303         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3304                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3305                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3306                 case AC_PINCTL_VREF_50:  item = 4; break;
3307                 case AC_PINCTL_VREF_GRD: item = 5; break;
3308                 case AC_PINCTL_VREF_80:  item = 6; break;
3309                 case AC_PINCTL_VREF_100: item = 7; break;
3310                 }
3311         }
3312         ucontrol->value.enumerated.item[0] = item;
3313         return 0;
3314 }
3315
3316 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3317                                 struct snd_ctl_elem_value *ucontrol)
3318 {
3319         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3320         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3321         static unsigned int ctls[] = {
3322                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3323                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3324                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3325                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3326                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3327                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3328         };
3329         unsigned int old_ctl, new_ctl;
3330
3331         old_ctl = snd_hda_codec_read(codec, nid, 0,
3332                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3333         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3334         if (old_ctl != new_ctl) {
3335                 int val;
3336                 snd_hda_codec_write_cache(codec, nid, 0,
3337                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3338                                           new_ctl);
3339                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3340                         HDA_AMP_MUTE : 0;
3341                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3342                                          HDA_AMP_MUTE, val);
3343                 return 1;
3344         }
3345         return 0;
3346 }
3347
3348 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3349                                  struct snd_ctl_elem_info *uinfo)
3350 {
3351         static char *texts[] = {
3352                 "Front", "Surround", "CLFE", "Side"
3353         };
3354         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3355         uinfo->count = 1;
3356         uinfo->value.enumerated.items = 4;
3357         if (uinfo->value.enumerated.item >= 4)
3358                 uinfo->value.enumerated.item = 3;
3359         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3360         return 0;
3361 }
3362
3363 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3364                                 struct snd_ctl_elem_value *ucontrol)
3365 {
3366         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3367         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3368         unsigned int sel;
3369
3370         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3371         ucontrol->value.enumerated.item[0] = sel & 3;
3372         return 0;
3373 }
3374
3375 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3376                                 struct snd_ctl_elem_value *ucontrol)
3377 {
3378         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3379         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3380         unsigned int sel;
3381
3382         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3383         if (ucontrol->value.enumerated.item[0] != sel) {
3384                 sel = ucontrol->value.enumerated.item[0] & 3;
3385                 snd_hda_codec_write_cache(codec, nid, 0,
3386                                           AC_VERB_SET_CONNECT_SEL, sel);
3387                 return 1;
3388         }
3389         return 0;
3390 }
3391
3392 #define PIN_CTL_TEST(xname,nid) {                       \
3393                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3394                         .name = xname,                 \
3395                         .info = alc_test_pin_ctl_info, \
3396                         .get = alc_test_pin_ctl_get,   \
3397                         .put = alc_test_pin_ctl_put,   \
3398                         .private_value = nid           \
3399                         }
3400
3401 #define PIN_SRC_TEST(xname,nid) {                       \
3402                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3403                         .name = xname,                 \
3404                         .info = alc_test_pin_src_info, \
3405                         .get = alc_test_pin_src_get,   \
3406                         .put = alc_test_pin_src_put,   \
3407                         .private_value = nid           \
3408                         }
3409
3410 static struct snd_kcontrol_new alc880_test_mixer[] = {
3411         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3412         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3413         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3414         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3415         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3416         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3417         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3418         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3419         PIN_CTL_TEST("Front Pin Mode", 0x14),
3420         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3421         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3422         PIN_CTL_TEST("Side Pin Mode", 0x17),
3423         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3424         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3425         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3426         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3427         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3428         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3429         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3430         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3431         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3432         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3433         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3434         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3435         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3436         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3437         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3438         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3439         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3440         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3441         {
3442                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3443                 .name = "Channel Mode",
3444                 .info = alc_ch_mode_info,
3445                 .get = alc_ch_mode_get,
3446                 .put = alc_ch_mode_put,
3447         },
3448         { } /* end */
3449 };
3450
3451 static struct hda_verb alc880_test_init_verbs[] = {
3452         /* Unmute inputs of 0x0c - 0x0f */
3453         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3454         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3455         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3456         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3457         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3458         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3459         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3460         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3461         /* Vol output for 0x0c-0x0f */
3462         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3463         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3464         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3465         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3466         /* Set output pins 0x14-0x17 */
3467         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3468         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3469         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3470         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3471         /* Unmute output pins 0x14-0x17 */
3472         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3473         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3474         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3475         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3476         /* Set input pins 0x18-0x1c */
3477         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3478         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3479         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3480         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3481         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3482         /* Mute input pins 0x18-0x1b */
3483         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3484         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3485         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3486         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3487         /* ADC set up */
3488         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3489         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3490         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3491         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3492         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3493         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3494         /* Analog input/passthru */
3495         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3496         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3497         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3498         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3499         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3500         { }
3501 };
3502 #endif
3503
3504 /*
3505  */
3506
3507 static const char *alc880_models[ALC880_MODEL_LAST] = {
3508         [ALC880_3ST]            = "3stack",
3509         [ALC880_TCL_S700]       = "tcl",
3510         [ALC880_3ST_DIG]        = "3stack-digout",
3511         [ALC880_CLEVO]          = "clevo",
3512         [ALC880_5ST]            = "5stack",
3513         [ALC880_5ST_DIG]        = "5stack-digout",
3514         [ALC880_W810]           = "w810",
3515         [ALC880_Z71V]           = "z71v",
3516         [ALC880_6ST]            = "6stack",
3517         [ALC880_6ST_DIG]        = "6stack-digout",
3518         [ALC880_ASUS]           = "asus",
3519         [ALC880_ASUS_W1V]       = "asus-w1v",
3520         [ALC880_ASUS_DIG]       = "asus-dig",
3521         [ALC880_ASUS_DIG2]      = "asus-dig2",
3522         [ALC880_UNIWILL_DIG]    = "uniwill",
3523         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3524         [ALC880_FUJITSU]        = "fujitsu",
3525         [ALC880_F1734]          = "F1734",
3526         [ALC880_LG]             = "lg",
3527         [ALC880_LG_LW]          = "lg-lw",
3528         [ALC880_MEDION_RIM]     = "medion",
3529 #ifdef CONFIG_SND_DEBUG
3530         [ALC880_TEST]           = "test",
3531 #endif
3532         [ALC880_AUTO]           = "auto",
3533 };
3534
3535 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3536         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3537         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3538         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3539         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3540         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3541         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3542         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3543         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3544         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3545         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3546         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3547         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3548         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3549         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3550         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3551         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3552         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3553         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3554         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3555         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3556         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3557         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3558         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3559         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3560         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3561         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
3562         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3563         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3564         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3565         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3566         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3567         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3568         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3569         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3570         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3571         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3572         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3573         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3574         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3575         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3576         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3577         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3578         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3579         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3580         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3581         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3582         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3583         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3584         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3585         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3586         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3587         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3588         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3589         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3590         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3591         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3592         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3593         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3594         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3595         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3596         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3597         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3598         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3599         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3600         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3601         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3602         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3603         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3604         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
3605         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3606         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3607         {}
3608 };
3609
3610 /*
3611  * ALC880 codec presets
3612  */
3613 static struct alc_config_preset alc880_presets[] = {
3614         [ALC880_3ST] = {
3615                 .mixers = { alc880_three_stack_mixer },
3616                 .init_verbs = { alc880_volume_init_verbs,
3617                                 alc880_pin_3stack_init_verbs },
3618                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3619                 .dac_nids = alc880_dac_nids,
3620                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3621                 .channel_mode = alc880_threestack_modes,
3622                 .need_dac_fix = 1,
3623                 .input_mux = &alc880_capture_source,
3624         },
3625         [ALC880_3ST_DIG] = {
3626                 .mixers = { alc880_three_stack_mixer },
3627                 .init_verbs = { alc880_volume_init_verbs,
3628                                 alc880_pin_3stack_init_verbs },
3629                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3630                 .dac_nids = alc880_dac_nids,
3631                 .dig_out_nid = ALC880_DIGOUT_NID,
3632                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3633                 .channel_mode = alc880_threestack_modes,
3634                 .need_dac_fix = 1,
3635                 .input_mux = &alc880_capture_source,
3636         },
3637         [ALC880_TCL_S700] = {
3638                 .mixers = { alc880_tcl_s700_mixer },
3639                 .init_verbs = { alc880_volume_init_verbs,
3640                                 alc880_pin_tcl_S700_init_verbs,
3641                                 alc880_gpio2_init_verbs },
3642                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3643                 .dac_nids = alc880_dac_nids,
3644                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
3645                 .num_adc_nids = 1, /* single ADC */
3646                 .hp_nid = 0x03,
3647                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3648                 .channel_mode = alc880_2_jack_modes,
3649                 .input_mux = &alc880_capture_source,
3650         },
3651         [ALC880_5ST] = {
3652                 .mixers = { alc880_three_stack_mixer,
3653                             alc880_five_stack_mixer},
3654                 .init_verbs = { alc880_volume_init_verbs,
3655                                 alc880_pin_5stack_init_verbs },
3656                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3657                 .dac_nids = alc880_dac_nids,
3658                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3659                 .channel_mode = alc880_fivestack_modes,
3660                 .input_mux = &alc880_capture_source,
3661         },
3662         [ALC880_5ST_DIG] = {
3663                 .mixers = { alc880_three_stack_mixer,
3664                             alc880_five_stack_mixer },
3665                 .init_verbs = { alc880_volume_init_verbs,
3666                                 alc880_pin_5stack_init_verbs },
3667                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3668                 .dac_nids = alc880_dac_nids,
3669                 .dig_out_nid = ALC880_DIGOUT_NID,
3670                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3671                 .channel_mode = alc880_fivestack_modes,
3672                 .input_mux = &alc880_capture_source,
3673         },
3674         [ALC880_6ST] = {
3675                 .mixers = { alc880_six_stack_mixer },
3676                 .init_verbs = { alc880_volume_init_verbs,
3677                                 alc880_pin_6stack_init_verbs },
3678                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3679                 .dac_nids = alc880_6st_dac_nids,
3680                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3681                 .channel_mode = alc880_sixstack_modes,
3682                 .input_mux = &alc880_6stack_capture_source,
3683         },
3684         [ALC880_6ST_DIG] = {
3685                 .mixers = { alc880_six_stack_mixer },
3686                 .init_verbs = { alc880_volume_init_verbs,
3687                                 alc880_pin_6stack_init_verbs },
3688                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3689                 .dac_nids = alc880_6st_dac_nids,
3690                 .dig_out_nid = ALC880_DIGOUT_NID,
3691                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3692                 .channel_mode = alc880_sixstack_modes,
3693                 .input_mux = &alc880_6stack_capture_source,
3694         },
3695         [ALC880_W810] = {
3696                 .mixers = { alc880_w810_base_mixer },
3697                 .init_verbs = { alc880_volume_init_verbs,
3698                                 alc880_pin_w810_init_verbs,
3699                                 alc880_gpio2_init_verbs },
3700                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3701                 .dac_nids = alc880_w810_dac_nids,
3702                 .dig_out_nid = ALC880_DIGOUT_NID,
3703                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3704                 .channel_mode = alc880_w810_modes,
3705                 .input_mux = &alc880_capture_source,
3706         },
3707         [ALC880_Z71V] = {
3708                 .mixers = { alc880_z71v_mixer },
3709                 .init_verbs = { alc880_volume_init_verbs,
3710                                 alc880_pin_z71v_init_verbs },
3711                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3712                 .dac_nids = alc880_z71v_dac_nids,
3713                 .dig_out_nid = ALC880_DIGOUT_NID,
3714                 .hp_nid = 0x03,
3715                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3716                 .channel_mode = alc880_2_jack_modes,
3717                 .input_mux = &alc880_capture_source,
3718         },
3719         [ALC880_F1734] = {
3720                 .mixers = { alc880_f1734_mixer },
3721                 .init_verbs = { alc880_volume_init_verbs,
3722                                 alc880_pin_f1734_init_verbs },
3723                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3724                 .dac_nids = alc880_f1734_dac_nids,
3725                 .hp_nid = 0x02,
3726                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3727                 .channel_mode = alc880_2_jack_modes,
3728                 .input_mux = &alc880_f1734_capture_source,
3729                 .unsol_event = alc880_uniwill_p53_unsol_event,
3730                 .init_hook = alc880_uniwill_p53_hp_automute,
3731         },
3732         [ALC880_ASUS] = {
3733                 .mixers = { alc880_asus_mixer },
3734                 .init_verbs = { alc880_volume_init_verbs,
3735                                 alc880_pin_asus_init_verbs,
3736                                 alc880_gpio1_init_verbs },
3737                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3738                 .dac_nids = alc880_asus_dac_nids,
3739                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3740                 .channel_mode = alc880_asus_modes,
3741                 .need_dac_fix = 1,
3742                 .input_mux = &alc880_capture_source,
3743         },
3744         [ALC880_ASUS_DIG] = {
3745                 .mixers = { alc880_asus_mixer },
3746                 .init_verbs = { alc880_volume_init_verbs,
3747                                 alc880_pin_asus_init_verbs,
3748                                 alc880_gpio1_init_verbs },
3749                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3750                 .dac_nids = alc880_asus_dac_nids,
3751                 .dig_out_nid = ALC880_DIGOUT_NID,
3752                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3753                 .channel_mode = alc880_asus_modes,
3754                 .need_dac_fix = 1,
3755                 .input_mux = &alc880_capture_source,
3756         },
3757         [ALC880_ASUS_DIG2] = {
3758                 .mixers = { alc880_asus_mixer },
3759                 .init_verbs = { alc880_volume_init_verbs,
3760                                 alc880_pin_asus_init_verbs,
3761                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3762                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3763                 .dac_nids = alc880_asus_dac_nids,
3764                 .dig_out_nid = ALC880_DIGOUT_NID,
3765                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3766                 .channel_mode = alc880_asus_modes,
3767                 .need_dac_fix = 1,
3768                 .input_mux = &alc880_capture_source,
3769         },
3770         [ALC880_ASUS_W1V] = {
3771                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3772                 .init_verbs = { alc880_volume_init_verbs,
3773                                 alc880_pin_asus_init_verbs,
3774                                 alc880_gpio1_init_verbs },
3775                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3776                 .dac_nids = alc880_asus_dac_nids,
3777                 .dig_out_nid = ALC880_DIGOUT_NID,
3778                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3779                 .channel_mode = alc880_asus_modes,
3780                 .need_dac_fix = 1,
3781                 .input_mux = &alc880_capture_source,
3782         },
3783         [ALC880_UNIWILL_DIG] = {
3784                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3785                 .init_verbs = { alc880_volume_init_verbs,
3786                                 alc880_pin_asus_init_verbs },
3787                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3788                 .dac_nids = alc880_asus_dac_nids,
3789                 .dig_out_nid = ALC880_DIGOUT_NID,
3790                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3791                 .channel_mode = alc880_asus_modes,
3792                 .need_dac_fix = 1,
3793                 .input_mux = &alc880_capture_source,
3794         },
3795         [ALC880_UNIWILL] = {
3796                 .mixers = { alc880_uniwill_mixer },
3797                 .init_verbs = { alc880_volume_init_verbs,
3798                                 alc880_uniwill_init_verbs },
3799                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3800                 .dac_nids = alc880_asus_dac_nids,
3801                 .dig_out_nid = ALC880_DIGOUT_NID,
3802                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3803                 .channel_mode = alc880_threestack_modes,
3804                 .need_dac_fix = 1,
3805                 .input_mux = &alc880_capture_source,
3806                 .unsol_event = alc880_uniwill_unsol_event,
3807                 .init_hook = alc880_uniwill_automute,
3808         },
3809         [ALC880_UNIWILL_P53] = {
3810                 .mixers = { alc880_uniwill_p53_mixer },
3811                 .init_verbs = { alc880_volume_init_verbs,
3812                                 alc880_uniwill_p53_init_verbs },
3813                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3814                 .dac_nids = alc880_asus_dac_nids,
3815                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3816                 .channel_mode = alc880_threestack_modes,
3817                 .input_mux = &alc880_capture_source,
3818                 .unsol_event = alc880_uniwill_p53_unsol_event,
3819                 .init_hook = alc880_uniwill_p53_hp_automute,
3820         },
3821         [ALC880_FUJITSU] = {
3822                 .mixers = { alc880_fujitsu_mixer,
3823                             alc880_pcbeep_mixer, },
3824                 .init_verbs = { alc880_volume_init_verbs,
3825                                 alc880_uniwill_p53_init_verbs,
3826                                 alc880_beep_init_verbs },
3827                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3828                 .dac_nids = alc880_dac_nids,
3829                 .dig_out_nid = ALC880_DIGOUT_NID,
3830                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3831                 .channel_mode = alc880_2_jack_modes,
3832                 .input_mux = &alc880_capture_source,
3833                 .unsol_event = alc880_uniwill_p53_unsol_event,
3834                 .init_hook = alc880_uniwill_p53_hp_automute,
3835         },
3836         [ALC880_CLEVO] = {
3837                 .mixers = { alc880_three_stack_mixer },
3838                 .init_verbs = { alc880_volume_init_verbs,
3839                                 alc880_pin_clevo_init_verbs },
3840                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3841                 .dac_nids = alc880_dac_nids,
3842                 .hp_nid = 0x03,
3843                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3844                 .channel_mode = alc880_threestack_modes,
3845                 .need_dac_fix = 1,
3846                 .input_mux = &alc880_capture_source,
3847         },
3848         [ALC880_LG] = {
3849                 .mixers = { alc880_lg_mixer },
3850                 .init_verbs = { alc880_volume_init_verbs,
3851                                 alc880_lg_init_verbs },
3852                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3853                 .dac_nids = alc880_lg_dac_nids,
3854                 .dig_out_nid = ALC880_DIGOUT_NID,
3855                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3856                 .channel_mode = alc880_lg_ch_modes,
3857                 .need_dac_fix = 1,
3858                 .input_mux = &alc880_lg_capture_source,
3859                 .unsol_event = alc880_lg_unsol_event,
3860                 .init_hook = alc880_lg_automute,
3861 #ifdef CONFIG_SND_HDA_POWER_SAVE
3862                 .loopbacks = alc880_lg_loopbacks,
3863 #endif
3864         },
3865         [ALC880_LG_LW] = {
3866                 .mixers = { alc880_lg_lw_mixer },
3867                 .init_verbs = { alc880_volume_init_verbs,
3868                                 alc880_lg_lw_init_verbs },
3869                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3870                 .dac_nids = alc880_dac_nids,
3871                 .dig_out_nid = ALC880_DIGOUT_NID,
3872                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3873                 .channel_mode = alc880_lg_lw_modes,
3874                 .input_mux = &alc880_lg_lw_capture_source,
3875                 .unsol_event = alc880_lg_lw_unsol_event,
3876                 .init_hook = alc880_lg_lw_automute,
3877         },
3878         [ALC880_MEDION_RIM] = {
3879                 .mixers = { alc880_medion_rim_mixer },
3880                 .init_verbs = { alc880_volume_init_verbs,
3881                                 alc880_medion_rim_init_verbs,
3882                                 alc_gpio2_init_verbs },
3883                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3884                 .dac_nids = alc880_dac_nids,
3885                 .dig_out_nid = ALC880_DIGOUT_NID,
3886                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3887                 .channel_mode = alc880_2_jack_modes,
3888                 .input_mux = &alc880_medion_rim_capture_source,
3889                 .unsol_event = alc880_medion_rim_unsol_event,
3890                 .init_hook = alc880_medion_rim_automute,
3891         },
3892 #ifdef CONFIG_SND_DEBUG
3893         [ALC880_TEST] = {
3894                 .mixers = { alc880_test_mixer },
3895                 .init_verbs = { alc880_test_init_verbs },
3896                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3897                 .dac_nids = alc880_test_dac_nids,
3898                 .dig_out_nid = ALC880_DIGOUT_NID,
3899                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3900                 .channel_mode = alc880_test_modes,
3901                 .input_mux = &alc880_test_capture_source,
3902         },
3903 #endif
3904 };
3905
3906 /*
3907  * Automatic parse of I/O pins from the BIOS configuration
3908  */
3909
3910 enum {
3911         ALC_CTL_WIDGET_VOL,
3912         ALC_CTL_WIDGET_MUTE,
3913         ALC_CTL_BIND_MUTE,
3914 };
3915 static struct snd_kcontrol_new alc880_control_templates[] = {
3916         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3917         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3918         HDA_BIND_MUTE(NULL, 0, 0, 0),
3919 };
3920
3921 /* add dynamic controls */
3922 static int add_control(struct alc_spec *spec, int type, const char *name,
3923                        unsigned long val)
3924 {
3925         struct snd_kcontrol_new *knew;
3926
3927         snd_array_init(&spec->kctls, sizeof(*knew), 32);
3928         knew = snd_array_new(&spec->kctls);
3929         if (!knew)
3930                 return -ENOMEM;
3931         *knew = alc880_control_templates[type];
3932         knew->name = kstrdup(name, GFP_KERNEL);
3933         if (!knew->name)
3934                 return -ENOMEM;
3935         knew->private_value = val;
3936         return 0;
3937 }
3938
3939 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3940 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3941 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3942 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3943 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3944 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3945 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3946 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3947 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3948 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3949 #define ALC880_PIN_CD_NID               0x1c
3950
3951 /* fill in the dac_nids table from the parsed pin configuration */
3952 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3953                                      const struct auto_pin_cfg *cfg)
3954 {
3955         hda_nid_t nid;
3956         int assigned[4];
3957         int i, j;
3958
3959         memset(assigned, 0, sizeof(assigned));
3960         spec->multiout.dac_nids = spec->private_dac_nids;
3961
3962         /* check the pins hardwired to audio widget */
3963         for (i = 0; i < cfg->line_outs; i++) {
3964                 nid = cfg->line_out_pins[i];
3965                 if (alc880_is_fixed_pin(nid)) {
3966                         int idx = alc880_fixed_pin_idx(nid);
3967                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3968                         assigned[idx] = 1;
3969                 }
3970         }
3971         /* left pins can be connect to any audio widget */
3972         for (i = 0; i < cfg->line_outs; i++) {
3973                 nid = cfg->line_out_pins[i];
3974                 if (alc880_is_fixed_pin(nid))
3975                         continue;
3976                 /* search for an empty channel */
3977                 for (j = 0; j < cfg->line_outs; j++) {
3978                         if (!assigned[j]) {
3979                                 spec->multiout.dac_nids[i] =
3980                                         alc880_idx_to_dac(j);
3981                                 assigned[j] = 1;
3982                                 break;
3983                         }
3984                 }
3985         }
3986         spec->multiout.num_dacs = cfg->line_outs;
3987         return 0;
3988 }
3989
3990 /* add playback controls from the parsed DAC table */
3991 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3992                                              const struct auto_pin_cfg *cfg)
3993 {
3994         char name[32];
3995         static const char *chname[4] = {
3996                 "Front", "Surround", NULL /*CLFE*/, "Side"
3997         };
3998         hda_nid_t nid;
3999         int i, err;
4000
4001         for (i = 0; i < cfg->line_outs; i++) {
4002                 if (!spec->multiout.dac_nids[i])
4003                         continue;
4004                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
4005                 if (i == 2) {
4006                         /* Center/LFE */
4007                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4008                                           "Center Playback Volume",
4009                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
4010                                                               HDA_OUTPUT));
4011                         if (err < 0)
4012                                 return err;
4013                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4014                                           "LFE Playback Volume",
4015                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
4016                                                               HDA_OUTPUT));
4017                         if (err < 0)
4018                                 return err;
4019                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4020                                           "Center Playback Switch",
4021                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4022                                                               HDA_INPUT));
4023                         if (err < 0)
4024                                 return err;
4025                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4026                                           "LFE Playback Switch",
4027                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4028                                                               HDA_INPUT));
4029                         if (err < 0)
4030                                 return err;
4031                 } else {
4032                         sprintf(name, "%s Playback Volume", chname[i]);
4033                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4034                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4035                                                               HDA_OUTPUT));
4036                         if (err < 0)
4037                                 return err;
4038                         sprintf(name, "%s Playback Switch", chname[i]);
4039                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4040                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4041                                                               HDA_INPUT));
4042                         if (err < 0)
4043                                 return err;
4044                 }
4045         }
4046         return 0;
4047 }
4048
4049 /* add playback controls for speaker and HP outputs */
4050 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4051                                         const char *pfx)
4052 {
4053         hda_nid_t nid;
4054         int err;
4055         char name[32];
4056
4057         if (!pin)
4058                 return 0;
4059
4060         if (alc880_is_fixed_pin(pin)) {
4061                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
4062                 /* specify the DAC as the extra output */
4063                 if (!spec->multiout.hp_nid)
4064                         spec->multiout.hp_nid = nid;
4065                 else
4066                         spec->multiout.extra_out_nid[0] = nid;
4067                 /* control HP volume/switch on the output mixer amp */
4068                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4069                 sprintf(name, "%s Playback Volume", pfx);
4070                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4071                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4072                 if (err < 0)
4073                         return err;
4074                 sprintf(name, "%s Playback Switch", pfx);
4075                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4076                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4077                 if (err < 0)
4078                         return err;
4079         } else if (alc880_is_multi_pin(pin)) {
4080                 /* set manual connection */
4081                 /* we have only a switch on HP-out PIN */
4082                 sprintf(name, "%s Playback Switch", pfx);
4083                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4084                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4085                 if (err < 0)
4086                         return err;
4087         }
4088         return 0;
4089 }
4090
4091 /* create input playback/capture controls for the given pin */
4092 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4093                             const char *ctlname,
4094                             int idx, hda_nid_t mix_nid)
4095 {
4096         char name[32];
4097         int err;
4098
4099         sprintf(name, "%s Playback Volume", ctlname);
4100         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4101                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4102         if (err < 0)
4103                 return err;
4104         sprintf(name, "%s Playback Switch", ctlname);
4105         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4106                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4107         if (err < 0)
4108                 return err;
4109         return 0;
4110 }
4111
4112 /* create playback/capture controls for input pins */
4113 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
4114                                                 const struct auto_pin_cfg *cfg)
4115 {
4116         struct hda_input_mux *imux = &spec->private_imux;
4117         int i, err, idx;
4118
4119         for (i = 0; i < AUTO_PIN_LAST; i++) {
4120                 if (alc880_is_input_pin(cfg->input_pins[i])) {
4121                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
4122                         err = new_analog_input(spec, cfg->input_pins[i],
4123                                                auto_pin_cfg_labels[i],
4124                                                idx, 0x0b);
4125                         if (err < 0)
4126                                 return err;
4127                         imux->items[imux->num_items].label =
4128                                 auto_pin_cfg_labels[i];
4129                         imux->items[imux->num_items].index =
4130                                 alc880_input_pin_idx(cfg->input_pins[i]);
4131                         imux->num_items++;
4132                 }
4133         }
4134         return 0;
4135 }
4136
4137 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
4138                                unsigned int pin_type)
4139 {
4140         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4141                             pin_type);
4142         /* unmute pin */
4143         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4144                             AMP_OUT_UNMUTE);
4145 }
4146
4147 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
4148                                               hda_nid_t nid, int pin_type,
4149                                               int dac_idx)
4150 {
4151         alc_set_pin_output(codec, nid, pin_type);
4152         /* need the manual connection? */
4153         if (alc880_is_multi_pin(nid)) {
4154                 struct alc_spec *spec = codec->spec;
4155                 int idx = alc880_multi_pin_idx(nid);
4156                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
4157                                     AC_VERB_SET_CONNECT_SEL,
4158                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
4159         }
4160 }
4161
4162 static int get_pin_type(int line_out_type)
4163 {
4164         if (line_out_type == AUTO_PIN_HP_OUT)
4165                 return PIN_HP;
4166         else
4167                 return PIN_OUT;
4168 }
4169
4170 static void alc880_auto_init_multi_out(struct hda_codec *codec)
4171 {
4172         struct alc_spec *spec = codec->spec;
4173         int i;
4174
4175         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
4176         for (i = 0; i < spec->autocfg.line_outs; i++) {
4177                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4178                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4179                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
4180         }
4181 }
4182
4183 static void alc880_auto_init_extra_out(struct hda_codec *codec)
4184 {
4185         struct alc_spec *spec = codec->spec;
4186         hda_nid_t pin;
4187
4188         pin = spec->autocfg.speaker_pins[0];
4189         if (pin) /* connect to front */
4190                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
4191         pin = spec->autocfg.hp_pins[0];
4192         if (pin) /* connect to front */
4193                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
4194 }
4195
4196 static void alc880_auto_init_analog_input(struct hda_codec *codec)
4197 {
4198         struct alc_spec *spec = codec->spec;
4199         int i;
4200
4201         for (i = 0; i < AUTO_PIN_LAST; i++) {
4202                 hda_nid_t nid = spec->autocfg.input_pins[i];
4203                 if (alc880_is_input_pin(nid)) {
4204                         snd_hda_codec_write(codec, nid, 0,
4205                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
4206                                             i <= AUTO_PIN_FRONT_MIC ?
4207                                             PIN_VREF80 : PIN_IN);
4208                         if (nid != ALC880_PIN_CD_NID)
4209                                 snd_hda_codec_write(codec, nid, 0,
4210                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4211                                                     AMP_OUT_MUTE);
4212                 }
4213         }
4214 }
4215
4216 /* parse the BIOS configuration and set up the alc_spec */
4217 /* return 1 if successful, 0 if the proper config is not found,
4218  * or a negative error code
4219  */
4220 static int alc880_parse_auto_config(struct hda_codec *codec)
4221 {
4222         struct alc_spec *spec = codec->spec;
4223         int err;
4224         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4225
4226         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4227                                            alc880_ignore);
4228         if (err < 0)
4229                 return err;
4230         if (!spec->autocfg.line_outs)
4231                 return 0; /* can't find valid BIOS pin config */
4232
4233         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
4234         if (err < 0)
4235                 return err;
4236         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
4237         if (err < 0)
4238                 return err;
4239         err = alc880_auto_create_extra_out(spec,
4240                                            spec->autocfg.speaker_pins[0],
4241                                            "Speaker");
4242         if (err < 0)
4243                 return err;
4244         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
4245                                            "Headphone");
4246         if (err < 0)
4247                 return err;
4248         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
4249         if (err < 0)
4250                 return err;
4251
4252         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4253
4254         if (spec->autocfg.dig_out_pin)
4255                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
4256         if (spec->autocfg.dig_in_pin)
4257                 spec->dig_in_nid = ALC880_DIGIN_NID;
4258
4259         if (spec->kctls.list)
4260                 add_mixer(spec, spec->kctls.list);
4261
4262         add_verb(spec, alc880_volume_init_verbs);
4263
4264         spec->num_mux_defs = 1;
4265         spec->input_mux = &spec->private_imux;
4266
4267         store_pin_configs(codec);
4268         return 1;
4269 }
4270
4271 /* additional initialization for auto-configuration model */
4272 static void alc880_auto_init(struct hda_codec *codec)
4273 {
4274         struct alc_spec *spec = codec->spec;
4275         alc880_auto_init_multi_out(codec);
4276         alc880_auto_init_extra_out(codec);
4277         alc880_auto_init_analog_input(codec);
4278         if (spec->unsol_event)
4279                 alc_inithook(codec);
4280 }
4281
4282 /*
4283  * OK, here we have finally the patch for ALC880
4284  */
4285
4286 static void set_capture_mixer(struct alc_spec *spec)
4287 {
4288         static struct snd_kcontrol_new *caps[3] = {
4289                 alc_capture_mixer1,
4290                 alc_capture_mixer2,
4291                 alc_capture_mixer3,
4292         };
4293         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3)
4294                 spec->cap_mixer = caps[spec->num_adc_nids - 1];
4295 }
4296
4297 static int patch_alc880(struct hda_codec *codec)
4298 {
4299         struct alc_spec *spec;
4300         int board_config;
4301         int err;
4302
4303         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4304         if (spec == NULL)
4305                 return -ENOMEM;
4306
4307         codec->spec = spec;
4308
4309         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4310                                                   alc880_models,
4311                                                   alc880_cfg_tbl);
4312         if (board_config < 0) {
4313                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
4314                        "trying auto-probe from BIOS...\n");
4315                 board_config = ALC880_AUTO;
4316         }
4317
4318         if (board_config == ALC880_AUTO) {
4319                 /* automatic parse from the BIOS config */
4320                 err = alc880_parse_auto_config(codec);
4321                 if (err < 0) {
4322                         alc_free(codec);
4323                         return err;
4324                 } else if (!err) {
4325                         printk(KERN_INFO
4326                                "hda_codec: Cannot set up configuration "
4327                                "from BIOS.  Using 3-stack mode...\n");
4328                         board_config = ALC880_3ST;
4329                 }
4330         }
4331
4332         if (board_config != ALC880_AUTO)
4333                 setup_preset(spec, &alc880_presets[board_config]);
4334
4335         spec->stream_name_analog = "ALC880 Analog";
4336         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4337         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4338         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4339
4340         spec->stream_name_digital = "ALC880 Digital";
4341         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4342         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4343
4344         if (!spec->adc_nids && spec->input_mux) {
4345                 /* check whether NID 0x07 is valid */
4346                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4347                 /* get type */
4348                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
4349                 if (wcap != AC_WID_AUD_IN) {
4350                         spec->adc_nids = alc880_adc_nids_alt;
4351                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4352                 } else {
4353                         spec->adc_nids = alc880_adc_nids;
4354                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4355                 }
4356         }
4357         set_capture_mixer(spec);
4358
4359         spec->vmaster_nid = 0x0c;
4360
4361         codec->patch_ops = alc_patch_ops;
4362         if (board_config == ALC880_AUTO)
4363                 spec->init_hook = alc880_auto_init;
4364 #ifdef CONFIG_SND_HDA_POWER_SAVE
4365         if (!spec->loopback.amplist)
4366                 spec->loopback.amplist = alc880_loopbacks;
4367 #endif
4368         codec->proc_widget_hook = print_realtek_coef;
4369
4370         return 0;
4371 }
4372
4373
4374 /*
4375  * ALC260 support
4376  */
4377
4378 static hda_nid_t alc260_dac_nids[1] = {
4379         /* front */
4380         0x02,
4381 };
4382
4383 static hda_nid_t alc260_adc_nids[1] = {
4384         /* ADC0 */
4385         0x04,
4386 };
4387
4388 static hda_nid_t alc260_adc_nids_alt[1] = {
4389         /* ADC1 */
4390         0x05,
4391 };
4392
4393 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4394  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4395  */
4396 static hda_nid_t alc260_dual_adc_nids[2] = {
4397         /* ADC0, ADC1 */
4398         0x04, 0x05
4399 };
4400
4401 #define ALC260_DIGOUT_NID       0x03
4402 #define ALC260_DIGIN_NID        0x06
4403
4404 static struct hda_input_mux alc260_capture_source = {
4405         .num_items = 4,
4406         .items = {
4407                 { "Mic", 0x0 },
4408                 { "Front Mic", 0x1 },
4409                 { "Line", 0x2 },
4410                 { "CD", 0x4 },
4411         },
4412 };
4413
4414 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4415  * headphone jack and the internal CD lines since these are the only pins at
4416  * which audio can appear.  For flexibility, also allow the option of
4417  * recording the mixer output on the second ADC (ADC0 doesn't have a
4418  * connection to the mixer output).
4419  */
4420 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4421         {
4422                 .num_items = 3,
4423                 .items = {
4424                         { "Mic/Line", 0x0 },
4425                         { "CD", 0x4 },
4426                         { "Headphone", 0x2 },
4427                 },
4428         },
4429         {
4430                 .num_items = 4,
4431                 .items = {
4432                         { "Mic/Line", 0x0 },
4433                         { "CD", 0x4 },
4434                         { "Headphone", 0x2 },
4435                         { "Mixer", 0x5 },
4436                 },
4437         },
4438
4439 };
4440
4441 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4442  * the Fujitsu S702x, but jacks are marked differently.
4443  */
4444 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4445         {
4446                 .num_items = 4,
4447                 .items = {
4448                         { "Mic", 0x0 },
4449                         { "Line", 0x2 },
4450                         { "CD", 0x4 },
4451                         { "Headphone", 0x5 },
4452                 },
4453         },
4454         {
4455                 .num_items = 5,
4456                 .items = {
4457                         { "Mic", 0x0 },
4458                         { "Line", 0x2 },
4459                         { "CD", 0x4 },
4460                         { "Headphone", 0x6 },
4461                         { "Mixer", 0x5 },
4462                 },
4463         },
4464 };
4465 /*
4466  * This is just place-holder, so there's something for alc_build_pcms to look
4467  * at when it calculates the maximum number of channels. ALC260 has no mixer
4468  * element which allows changing the channel mode, so the verb list is
4469  * never used.
4470  */
4471 static struct hda_channel_mode alc260_modes[1] = {
4472         { 2, NULL },
4473 };
4474
4475
4476 /* Mixer combinations
4477  *
4478  * basic: base_output + input + pc_beep + capture
4479  * HP: base_output + input + capture_alt
4480  * HP_3013: hp_3013 + input + capture
4481  * fujitsu: fujitsu + capture
4482  * acer: acer + capture
4483  */
4484
4485 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
4486         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4487         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4488         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4489         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4490         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4491         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4492         { } /* end */
4493 };
4494
4495 static struct snd_kcontrol_new alc260_input_mixer[] = {
4496         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4497         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4498         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4499         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4500         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4501         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4502         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4503         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4504         { } /* end */
4505 };
4506
4507 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
4508         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
4509         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
4510         { } /* end */
4511 };
4512
4513 /* update HP, line and mono out pins according to the master switch */
4514 static void alc260_hp_master_update(struct hda_codec *codec,
4515                                     hda_nid_t hp, hda_nid_t line,
4516                                     hda_nid_t mono)
4517 {
4518         struct alc_spec *spec = codec->spec;
4519         unsigned int val = spec->master_sw ? PIN_HP : 0;
4520         /* change HP and line-out pins */
4521         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4522                             val);
4523         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4524                             val);
4525         /* mono (speaker) depending on the HP jack sense */
4526         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4527         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4528                             val);
4529 }
4530
4531 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4532                                    struct snd_ctl_elem_value *ucontrol)
4533 {
4534         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4535         struct alc_spec *spec = codec->spec;
4536         *ucontrol->value.integer.value = spec->master_sw;
4537         return 0;
4538 }
4539
4540 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4541                                    struct snd_ctl_elem_value *ucontrol)
4542 {
4543         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4544         struct alc_spec *spec = codec->spec;
4545         int val = !!*ucontrol->value.integer.value;
4546         hda_nid_t hp, line, mono;
4547
4548         if (val == spec->master_sw)
4549                 return 0;
4550         spec->master_sw = val;
4551         hp = (kcontrol->private_value >> 16) & 0xff;
4552         line = (kcontrol->private_value >> 8) & 0xff;
4553         mono = kcontrol->private_value & 0xff;
4554         alc260_hp_master_update(codec, hp, line, mono);
4555         return 1;
4556 }
4557
4558 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4559         {
4560                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4561                 .name = "Master Playback Switch",
4562                 .info = snd_ctl_boolean_mono_info,
4563                 .get = alc260_hp_master_sw_get,
4564                 .put = alc260_hp_master_sw_put,
4565                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4566         },
4567         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4568         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4569         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4570         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4571         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4572                               HDA_OUTPUT),
4573         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4574         { } /* end */
4575 };
4576
4577 static struct hda_verb alc260_hp_unsol_verbs[] = {
4578         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4579         {},
4580 };
4581
4582 static void alc260_hp_automute(struct hda_codec *codec)
4583 {
4584         struct alc_spec *spec = codec->spec;
4585         unsigned int present;
4586
4587         present = snd_hda_codec_read(codec, 0x10, 0,
4588                                      AC_VERB_GET_PIN_SENSE, 0);
4589         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4590         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4591 }
4592
4593 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4594 {
4595         if ((res >> 26) == ALC880_HP_EVENT)
4596                 alc260_hp_automute(codec);
4597 }
4598
4599 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4600         {
4601                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4602                 .name = "Master Playback Switch",
4603                 .info = snd_ctl_boolean_mono_info,
4604                 .get = alc260_hp_master_sw_get,
4605                 .put = alc260_hp_master_sw_put,
4606                 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
4607         },
4608         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4609         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4610         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4611         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4612         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4613         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4614         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4615         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4616         { } /* end */
4617 };
4618
4619 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
4620         .ops = &snd_hda_bind_vol,
4621         .values = {
4622                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
4623                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
4624                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
4625                 0
4626         },
4627 };
4628
4629 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
4630         .ops = &snd_hda_bind_sw,
4631         .values = {
4632                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
4633                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
4634                 0
4635         },
4636 };
4637
4638 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
4639         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
4640         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
4641         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
4642         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4643         { } /* end */
4644 };
4645
4646 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4647         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4648         {},
4649 };
4650
4651 static void alc260_hp_3013_automute(struct hda_codec *codec)
4652 {
4653         struct alc_spec *spec = codec->spec;
4654         unsigned int present;
4655
4656         present = snd_hda_codec_read(codec, 0x15, 0,
4657                                      AC_VERB_GET_PIN_SENSE, 0);
4658         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4659         alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
4660 }
4661
4662 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4663                                        unsigned int res)
4664 {
4665         if ((res >> 26) == ALC880_HP_EVENT)
4666                 alc260_hp_3013_automute(codec);
4667 }
4668
4669 static void alc260_hp_3012_automute(struct hda_codec *codec)
4670 {
4671         unsigned int present, bits;
4672
4673         present = snd_hda_codec_read(codec, 0x10, 0,
4674                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
4675
4676         bits = present ? 0 : PIN_OUT;
4677         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4678                             bits);
4679         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4680                             bits);
4681         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4682                             bits);
4683 }
4684
4685 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
4686                                        unsigned int res)
4687 {
4688         if ((res >> 26) == ALC880_HP_EVENT)
4689                 alc260_hp_3012_automute(codec);
4690 }
4691
4692 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
4693  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4694  */
4695 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4696         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4697         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4698         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4699         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4700         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4701         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4702         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4703         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4704         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4705         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4706         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4707         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4708         { } /* end */
4709 };
4710
4711 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4712  * versions of the ALC260 don't act on requests to enable mic bias from NID
4713  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4714  * datasheet doesn't mention this restriction.  At this stage it's not clear
4715  * whether this behaviour is intentional or is a hardware bug in chip
4716  * revisions available in early 2006.  Therefore for now allow the
4717  * "Headphone Jack Mode" control to span all choices, but if it turns out
4718  * that the lack of mic bias for this NID is intentional we could change the
4719  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4720  *
4721  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4722  * don't appear to make the mic bias available from the "line" jack, even
4723  * though the NID used for this jack (0x14) can supply it.  The theory is
4724  * that perhaps Acer have included blocking capacitors between the ALC260
4725  * and the output jack.  If this turns out to be the case for all such
4726  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4727  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4728  *
4729  * The C20x Tablet series have a mono internal speaker which is controlled
4730  * via the chip's Mono sum widget and pin complex, so include the necessary
4731  * controls for such models.  On models without a "mono speaker" the control
4732  * won't do anything.
4733  */
4734 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4735         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4736         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4737         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4738         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4739                               HDA_OUTPUT),
4740         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4741                            HDA_INPUT),
4742         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4743         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4744         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4745         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4746         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4747         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4748         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4749         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4750         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4751         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4752         { } /* end */
4753 };
4754
4755 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4756  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4757  */
4758 static struct snd_kcontrol_new alc260_will_mixer[] = {
4759         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4760         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4761         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4762         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4763         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4764         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4765         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4766         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4767         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4768         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4769         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4770         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4771         { } /* end */
4772 };
4773
4774 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4775  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4776  */
4777 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4778         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4779         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4780         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4781         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4782         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4783         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4784         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4785         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4786         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4787         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4788         { } /* end */
4789 };
4790
4791 /*
4792  * initialization verbs
4793  */
4794 static struct hda_verb alc260_init_verbs[] = {
4795         /* Line In pin widget for input */
4796         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4797         /* CD pin widget for input */
4798         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4799         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4800         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4801         /* Mic2 (front panel) pin widget for input and vref at 80% */
4802         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4803         /* LINE-2 is used for line-out in rear */
4804         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4805         /* select line-out */
4806         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4807         /* LINE-OUT pin */
4808         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4809         /* enable HP */
4810         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4811         /* enable Mono */
4812         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4813         /* mute capture amp left and right */
4814         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4815         /* set connection select to line in (default select for this ADC) */
4816         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4817         /* mute capture amp left and right */
4818         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4819         /* set connection select to line in (default select for this ADC) */
4820         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4821         /* set vol=0 Line-Out mixer amp left and right */
4822         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4823         /* unmute pin widget amp left and right (no gain on this amp) */
4824         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4825         /* set vol=0 HP mixer amp left and right */
4826         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4827         /* unmute pin widget amp left and right (no gain on this amp) */
4828         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4829         /* set vol=0 Mono mixer amp left and right */
4830         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4831         /* unmute pin widget amp left and right (no gain on this amp) */
4832         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4833         /* unmute LINE-2 out pin */
4834         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4835         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4836          * Line In 2 = 0x03
4837          */
4838         /* mute analog inputs */
4839         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4840         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4841         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4842         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4843         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4844         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4845         /* mute Front out path */
4846         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4847         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4848         /* mute Headphone out path */
4849         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4850         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4851         /* mute Mono out path */
4852         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4853         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4854         { }
4855 };
4856
4857 #if 0 /* should be identical with alc260_init_verbs? */
4858 static struct hda_verb alc260_hp_init_verbs[] = {
4859         /* Headphone and output */
4860         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4861         /* mono output */
4862         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4863         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4864         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4865         /* Mic2 (front panel) pin widget for input and vref at 80% */
4866         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4867         /* Line In pin widget for input */
4868         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4869         /* Line-2 pin widget for output */
4870         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4871         /* CD pin widget for input */
4872         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4873         /* unmute amp left and right */
4874         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4875         /* set connection select to line in (default select for this ADC) */
4876         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4877         /* unmute Line-Out mixer amp left and right (volume = 0) */
4878         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4879         /* mute pin widget amp left and right (no gain on this amp) */
4880         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4881         /* unmute HP mixer amp left and right (volume = 0) */
4882         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4883         /* mute pin widget amp left and right (no gain on this amp) */
4884         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4885         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4886          * Line In 2 = 0x03
4887          */
4888         /* mute analog inputs */
4889         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4890         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4891         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4892         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4893         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4894         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4895         /* Unmute Front out path */
4896         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4897         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4898         /* Unmute Headphone out path */
4899         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4900         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4901         /* Unmute Mono out path */
4902         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4903         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4904         { }
4905 };
4906 #endif
4907
4908 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4909         /* Line out and output */
4910         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4911         /* mono output */
4912         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4913         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4914         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4915         /* Mic2 (front panel) pin widget for input and vref at 80% */
4916         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4917         /* Line In pin widget for input */
4918         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4919         /* Headphone pin widget for output */
4920         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4921         /* CD pin widget for input */
4922         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4923         /* unmute amp left and right */
4924         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4925         /* set connection select to line in (default select for this ADC) */
4926         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4927         /* unmute Line-Out mixer amp left and right (volume = 0) */
4928         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4929         /* mute pin widget amp left and right (no gain on this amp) */
4930         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4931         /* unmute HP mixer amp left and right (volume = 0) */
4932         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4933         /* mute pin widget amp left and right (no gain on this amp) */
4934         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4935         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4936          * Line In 2 = 0x03
4937          */
4938         /* mute analog inputs */
4939         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4940         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4941         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4942         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4943         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4944         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4945         /* Unmute Front out path */
4946         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4947         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4948         /* Unmute Headphone out path */
4949         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4950         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4951         /* Unmute Mono out path */
4952         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4953         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4954         { }
4955 };
4956
4957 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4958  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4959  * audio = 0x16, internal speaker = 0x10.
4960  */
4961 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4962         /* Disable all GPIOs */
4963         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4964         /* Internal speaker is connected to headphone pin */
4965         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4966         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4967         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4968         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4969         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4970         /* Ensure all other unused pins are disabled and muted. */
4971         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4972         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4973         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4974         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4975         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4976         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4977         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4978         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4979
4980         /* Disable digital (SPDIF) pins */
4981         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4982         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4983
4984         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
4985          * when acting as an output.
4986          */
4987         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4988
4989         /* Start with output sum widgets muted and their output gains at min */
4990         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4991         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4992         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4993         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4994         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4995         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4996         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4997         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4998         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4999
5000         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
5001         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5002         /* Unmute Line1 pin widget output buffer since it starts as an output.
5003          * If the pin mode is changed by the user the pin mode control will
5004          * take care of enabling the pin's input/output buffers as needed.
5005          * Therefore there's no need to enable the input buffer at this
5006          * stage.
5007          */
5008         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5009         /* Unmute input buffer of pin widget used for Line-in (no equiv
5010          * mixer ctrl)
5011          */
5012         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5013
5014         /* Mute capture amp left and right */
5015         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5016         /* Set ADC connection select to match default mixer setting - line
5017          * in (on mic1 pin)
5018          */
5019         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5020
5021         /* Do the same for the second ADC: mute capture input amp and
5022          * set ADC connection to line in (on mic1 pin)
5023          */
5024         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5025         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5026
5027         /* Mute all inputs to mixer widget (even unconnected ones) */
5028         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5029         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5030         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5031         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5032         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5033         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5034         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5035         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5036
5037         { }
5038 };
5039
5040 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
5041  * similar laptops (adapted from Fujitsu init verbs).
5042  */
5043 static struct hda_verb alc260_acer_init_verbs[] = {
5044         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
5045          * the headphone jack.  Turn this on and rely on the standard mute
5046          * methods whenever the user wants to turn these outputs off.
5047          */
5048         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5049         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5050         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5051         /* Internal speaker/Headphone jack is connected to Line-out pin */
5052         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5053         /* Internal microphone/Mic jack is connected to Mic1 pin */
5054         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5055         /* Line In jack is connected to Line1 pin */
5056         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5057         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
5058         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5059         /* Ensure all other unused pins are disabled and muted. */
5060         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5061         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5062         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5063         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5064         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5065         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5066         /* Disable digital (SPDIF) pins */
5067         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5068         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5069
5070         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5071          * bus when acting as outputs.
5072          */
5073         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5074         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5075
5076         /* Start with output sum widgets muted and their output gains at min */
5077         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5078         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5079         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5080         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5081         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5082         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5083         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5084         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5085         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5086
5087         /* Unmute Line-out pin widget amp left and right
5088          * (no equiv mixer ctrl)
5089          */
5090         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5091         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
5092         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5093         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5094          * inputs. If the pin mode is changed by the user the pin mode control
5095          * will take care of enabling the pin's input/output buffers as needed.
5096          * Therefore there's no need to enable the input buffer at this
5097          * stage.
5098          */
5099         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5100         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5101
5102         /* Mute capture amp left and right */
5103         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5104         /* Set ADC connection select to match default mixer setting - mic
5105          * (on mic1 pin)
5106          */
5107         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5108
5109         /* Do similar with the second ADC: mute capture input amp and
5110          * set ADC connection to mic to match ALSA's default state.
5111          */
5112         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5113         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5114
5115         /* Mute all inputs to mixer widget (even unconnected ones) */
5116         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5117         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5118         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5119         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5120         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5121         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5122         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5123         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5124
5125         { }
5126 };
5127
5128 static struct hda_verb alc260_will_verbs[] = {
5129         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5130         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
5131         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
5132         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5133         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5134         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
5135         {}
5136 };
5137
5138 static struct hda_verb alc260_replacer_672v_verbs[] = {
5139         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5140         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5141         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
5142
5143         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5144         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5145         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5146
5147         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5148         {}
5149 };
5150
5151 /* toggle speaker-output according to the hp-jack state */
5152 static void alc260_replacer_672v_automute(struct hda_codec *codec)
5153 {
5154         unsigned int present;
5155
5156         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5157         present = snd_hda_codec_read(codec, 0x0f, 0,
5158                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5159         if (present) {
5160                 snd_hda_codec_write_cache(codec, 0x01, 0,
5161                                           AC_VERB_SET_GPIO_DATA, 1);
5162                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5163                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5164                                           PIN_HP);
5165         } else {
5166                 snd_hda_codec_write_cache(codec, 0x01, 0,
5167                                           AC_VERB_SET_GPIO_DATA, 0);
5168                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5169                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5170                                           PIN_OUT);
5171         }
5172 }
5173
5174 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
5175                                        unsigned int res)
5176 {
5177         if ((res >> 26) == ALC880_HP_EVENT)
5178                 alc260_replacer_672v_automute(codec);
5179 }
5180
5181 static struct hda_verb alc260_hp_dc7600_verbs[] = {
5182         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
5183         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5184         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5185         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5186         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5187         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5188         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5189         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5190         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5191         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5192         {}
5193 };
5194
5195 /* Test configuration for debugging, modelled after the ALC880 test
5196  * configuration.
5197  */
5198 #ifdef CONFIG_SND_DEBUG
5199 static hda_nid_t alc260_test_dac_nids[1] = {
5200         0x02,
5201 };
5202 static hda_nid_t alc260_test_adc_nids[2] = {
5203         0x04, 0x05,
5204 };
5205 /* For testing the ALC260, each input MUX needs its own definition since
5206  * the signal assignments are different.  This assumes that the first ADC
5207  * is NID 0x04.
5208  */
5209 static struct hda_input_mux alc260_test_capture_sources[2] = {
5210         {
5211                 .num_items = 7,
5212                 .items = {
5213                         { "MIC1 pin", 0x0 },
5214                         { "MIC2 pin", 0x1 },
5215                         { "LINE1 pin", 0x2 },
5216                         { "LINE2 pin", 0x3 },
5217                         { "CD pin", 0x4 },
5218                         { "LINE-OUT pin", 0x5 },
5219                         { "HP-OUT pin", 0x6 },
5220                 },
5221         },
5222         {
5223                 .num_items = 8,
5224                 .items = {
5225                         { "MIC1 pin", 0x0 },
5226                         { "MIC2 pin", 0x1 },
5227                         { "LINE1 pin", 0x2 },
5228                         { "LINE2 pin", 0x3 },
5229                         { "CD pin", 0x4 },
5230                         { "Mixer", 0x5 },
5231                         { "LINE-OUT pin", 0x6 },
5232                         { "HP-OUT pin", 0x7 },
5233                 },
5234         },
5235 };
5236 static struct snd_kcontrol_new alc260_test_mixer[] = {
5237         /* Output driver widgets */
5238         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5239         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5240         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5241         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
5242         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5243         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
5244
5245         /* Modes for retasking pin widgets
5246          * Note: the ALC260 doesn't seem to act on requests to enable mic
5247          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
5248          * mention this restriction.  At this stage it's not clear whether
5249          * this behaviour is intentional or is a hardware bug in chip
5250          * revisions available at least up until early 2006.  Therefore for
5251          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
5252          * choices, but if it turns out that the lack of mic bias for these
5253          * NIDs is intentional we could change their modes from
5254          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5255          */
5256         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
5257         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
5258         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
5259         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5260         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5261         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5262
5263         /* Loopback mixer controls */
5264         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5265         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5266         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5267         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5268         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5269         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5270         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5271         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5272         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5273         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5274         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
5275         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
5276         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5277         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5278         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5279         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5280
5281         /* Controls for GPIO pins, assuming they are configured as outputs */
5282         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5283         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5284         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5285         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5286
5287         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5288          * is ambigious as to which NID is which; testing on laptops which
5289          * make this output available should provide clarification.
5290          */
5291         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5292         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5293
5294         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5295          * this output to turn on an external amplifier.
5296          */
5297         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5298         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5299
5300         { } /* end */
5301 };
5302 static struct hda_verb alc260_test_init_verbs[] = {
5303         /* Enable all GPIOs as outputs with an initial value of 0 */
5304         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5305         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5306         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5307
5308         /* Enable retasking pins as output, initially without power amp */
5309         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5310         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5311         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5312         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5313         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5314         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5315
5316         /* Disable digital (SPDIF) pins initially, but users can enable
5317          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5318          * payload also sets the generation to 0, output to be in "consumer"
5319          * PCM format, copyright asserted, no pre-emphasis and no validity
5320          * control.
5321          */
5322         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5323         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5324
5325         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5326          * OUT1 sum bus when acting as an output.
5327          */
5328         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5329         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5330         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5331         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5332
5333         /* Start with output sum widgets muted and their output gains at min */
5334         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5335         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5336         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5337         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5338         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5339         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5340         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5341         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5342         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5343
5344         /* Unmute retasking pin widget output buffers since the default
5345          * state appears to be output.  As the pin mode is changed by the
5346          * user the pin mode control will take care of enabling the pin's
5347          * input/output buffers as needed.
5348          */
5349         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5350         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5351         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5352         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5353         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5354         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5355         /* Also unmute the mono-out pin widget */
5356         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5357
5358         /* Mute capture amp left and right */
5359         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5360         /* Set ADC connection select to match default mixer setting (mic1
5361          * pin)
5362          */
5363         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5364
5365         /* Do the same for the second ADC: mute capture input amp and
5366          * set ADC connection to mic1 pin
5367          */
5368         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5369         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5370
5371         /* Mute all inputs to mixer widget (even unconnected ones) */
5372         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5373         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5374         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5375         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5376         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5377         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5378         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5379         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5380
5381         { }
5382 };
5383 #endif
5384
5385 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5386 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5387
5388 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5389 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5390
5391 /*
5392  * for BIOS auto-configuration
5393  */
5394
5395 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5396                                         const char *pfx, int *vol_bits)
5397 {
5398         hda_nid_t nid_vol;
5399         unsigned long vol_val, sw_val;
5400         char name[32];
5401         int err;
5402
5403         if (nid >= 0x0f && nid < 0x11) {
5404                 nid_vol = nid - 0x7;
5405                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5406                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5407         } else if (nid == 0x11) {
5408                 nid_vol = nid - 0x7;
5409                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
5410                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
5411         } else if (nid >= 0x12 && nid <= 0x15) {
5412                 nid_vol = 0x08;
5413                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5414                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5415         } else
5416                 return 0; /* N/A */
5417
5418         if (!(*vol_bits & (1 << nid_vol))) {
5419                 /* first control for the volume widget */
5420                 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
5421                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
5422                 if (err < 0)
5423                         return err;
5424                 *vol_bits |= (1 << nid_vol);
5425         }
5426         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
5427         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
5428         if (err < 0)
5429                 return err;
5430         return 1;
5431 }
5432
5433 /* add playback controls from the parsed DAC table */
5434 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5435                                              const struct auto_pin_cfg *cfg)
5436 {
5437         hda_nid_t nid;
5438         int err;
5439         int vols = 0;
5440
5441         spec->multiout.num_dacs = 1;
5442         spec->multiout.dac_nids = spec->private_dac_nids;
5443         spec->multiout.dac_nids[0] = 0x02;
5444
5445         nid = cfg->line_out_pins[0];
5446         if (nid) {
5447                 err = alc260_add_playback_controls(spec, nid, "Front", &vols);
5448                 if (err < 0)
5449                         return err;
5450         }
5451
5452         nid = cfg->speaker_pins[0];
5453         if (nid) {
5454                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
5455                 if (err < 0)
5456                         return err;
5457         }
5458
5459         nid = cfg->hp_pins[0];
5460         if (nid) {
5461                 err = alc260_add_playback_controls(spec, nid, "Headphone",
5462                                                    &vols);
5463                 if (err < 0)
5464                         return err;
5465         }
5466         return 0;
5467 }
5468
5469 /* create playback/capture controls for input pins */
5470 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
5471                                                 const struct auto_pin_cfg *cfg)
5472 {
5473         struct hda_input_mux *imux = &spec->private_imux;
5474         int i, err, idx;
5475
5476         for (i = 0; i < AUTO_PIN_LAST; i++) {
5477                 if (cfg->input_pins[i] >= 0x12) {
5478                         idx = cfg->input_pins[i] - 0x12;
5479                         err = new_analog_input(spec, cfg->input_pins[i],
5480                                                auto_pin_cfg_labels[i], idx,
5481                                                0x07);
5482                         if (err < 0)
5483                                 return err;
5484                         imux->items[imux->num_items].label =
5485                                 auto_pin_cfg_labels[i];
5486                         imux->items[imux->num_items].index = idx;
5487                         imux->num_items++;
5488                 }
5489                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
5490                         idx = cfg->input_pins[i] - 0x09;
5491                         err = new_analog_input(spec, cfg->input_pins[i],
5492                                                auto_pin_cfg_labels[i], idx,
5493                                                0x07);
5494                         if (err < 0)
5495                                 return err;
5496                         imux->items[imux->num_items].label =
5497                                 auto_pin_cfg_labels[i];
5498                         imux->items[imux->num_items].index = idx;
5499                         imux->num_items++;
5500                 }
5501         }
5502         return 0;
5503 }
5504
5505 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
5506                                               hda_nid_t nid, int pin_type,
5507                                               int sel_idx)
5508 {
5509         alc_set_pin_output(codec, nid, pin_type);
5510         /* need the manual connection? */
5511         if (nid >= 0x12) {
5512                 int idx = nid - 0x12;
5513                 snd_hda_codec_write(codec, idx + 0x0b, 0,
5514                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
5515         }
5516 }
5517
5518 static void alc260_auto_init_multi_out(struct hda_codec *codec)
5519 {
5520         struct alc_spec *spec = codec->spec;
5521         hda_nid_t nid;
5522
5523         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
5524         nid = spec->autocfg.line_out_pins[0];
5525         if (nid) {
5526                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5527                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5528         }
5529
5530         nid = spec->autocfg.speaker_pins[0];
5531         if (nid)
5532                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5533
5534         nid = spec->autocfg.hp_pins[0];
5535         if (nid)
5536                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5537 }
5538
5539 #define ALC260_PIN_CD_NID               0x16
5540 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5541 {
5542         struct alc_spec *spec = codec->spec;
5543         int i;
5544
5545         for (i = 0; i < AUTO_PIN_LAST; i++) {
5546                 hda_nid_t nid = spec->autocfg.input_pins[i];
5547                 if (nid >= 0x12) {
5548                         snd_hda_codec_write(codec, nid, 0,
5549                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5550                                             i <= AUTO_PIN_FRONT_MIC ?
5551                                             PIN_VREF80 : PIN_IN);
5552                         if (nid != ALC260_PIN_CD_NID)
5553                                 snd_hda_codec_write(codec, nid, 0,
5554                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5555                                                     AMP_OUT_MUTE);
5556                 }
5557         }
5558 }
5559
5560 /*
5561  * generic initialization of ADC, input mixers and output mixers
5562  */
5563 static struct hda_verb alc260_volume_init_verbs[] = {
5564         /*
5565          * Unmute ADC0-1 and set the default input to mic-in
5566          */
5567         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5568         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5569         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5570         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5571
5572         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5573          * mixer widget
5574          * Note: PASD motherboards uses the Line In 2 as the input for
5575          * front panel mic (mic 2)
5576          */
5577         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5578         /* mute analog inputs */
5579         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5580         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5581         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5582         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5583         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5584
5585         /*
5586          * Set up output mixers (0x08 - 0x0a)
5587          */
5588         /* set vol=0 to output mixers */
5589         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5590         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5591         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5592         /* set up input amps for analog loopback */
5593         /* Amp Indices: DAC = 0, mixer = 1 */
5594         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5595         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5596         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5597         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5598         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5599         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5600
5601         { }
5602 };
5603
5604 static int alc260_parse_auto_config(struct hda_codec *codec)
5605 {
5606         struct alc_spec *spec = codec->spec;
5607         int err;
5608         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5609
5610         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5611                                            alc260_ignore);
5612         if (err < 0)
5613                 return err;
5614         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5615         if (err < 0)
5616                 return err;
5617         if (!spec->kctls.list)
5618                 return 0; /* can't find valid BIOS pin config */
5619         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5620         if (err < 0)
5621                 return err;
5622
5623         spec->multiout.max_channels = 2;
5624
5625         if (spec->autocfg.dig_out_pin)
5626                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5627         if (spec->kctls.list)
5628                 add_mixer(spec, spec->kctls.list);
5629
5630         add_verb(spec, alc260_volume_init_verbs);
5631
5632         spec->num_mux_defs = 1;
5633         spec->input_mux = &spec->private_imux;
5634
5635         store_pin_configs(codec);
5636         return 1;
5637 }
5638
5639 /* additional initialization for auto-configuration model */
5640 static void alc260_auto_init(struct hda_codec *codec)
5641 {
5642         struct alc_spec *spec = codec->spec;
5643         alc260_auto_init_multi_out(codec);
5644         alc260_auto_init_analog_input(codec);
5645         if (spec->unsol_event)
5646                 alc_inithook(codec);
5647 }
5648
5649 #ifdef CONFIG_SND_HDA_POWER_SAVE
5650 static struct hda_amp_list alc260_loopbacks[] = {
5651         { 0x07, HDA_INPUT, 0 },
5652         { 0x07, HDA_INPUT, 1 },
5653         { 0x07, HDA_INPUT, 2 },
5654         { 0x07, HDA_INPUT, 3 },
5655         { 0x07, HDA_INPUT, 4 },
5656         { } /* end */
5657 };
5658 #endif
5659
5660 /*
5661  * ALC260 configurations
5662  */
5663 static const char *alc260_models[ALC260_MODEL_LAST] = {
5664         [ALC260_BASIC]          = "basic",
5665         [ALC260_HP]             = "hp",
5666         [ALC260_HP_3013]        = "hp-3013",
5667         [ALC260_HP_DC7600]      = "hp-dc7600",
5668         [ALC260_FUJITSU_S702X]  = "fujitsu",
5669         [ALC260_ACER]           = "acer",
5670         [ALC260_WILL]           = "will",
5671         [ALC260_REPLACER_672V]  = "replacer",
5672 #ifdef CONFIG_SND_DEBUG
5673         [ALC260_TEST]           = "test",
5674 #endif
5675         [ALC260_AUTO]           = "auto",
5676 };
5677
5678 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5679         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5680         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5681         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5682         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5683         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5684         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
5685         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
5686         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5687         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5688         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5689         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5690         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5691         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5692         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5693         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5694         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5695         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5696         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5697         {}
5698 };
5699
5700 static struct alc_config_preset alc260_presets[] = {
5701         [ALC260_BASIC] = {
5702                 .mixers = { alc260_base_output_mixer,
5703                             alc260_input_mixer,
5704                             alc260_pc_beep_mixer },
5705                 .init_verbs = { alc260_init_verbs },
5706                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5707                 .dac_nids = alc260_dac_nids,
5708                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5709                 .adc_nids = alc260_adc_nids,
5710                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5711                 .channel_mode = alc260_modes,
5712                 .input_mux = &alc260_capture_source,
5713         },
5714         [ALC260_HP] = {
5715                 .mixers = { alc260_hp_output_mixer,
5716                             alc260_input_mixer },
5717                 .init_verbs = { alc260_init_verbs,
5718                                 alc260_hp_unsol_verbs },
5719                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5720                 .dac_nids = alc260_dac_nids,
5721                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5722                 .adc_nids = alc260_adc_nids_alt,
5723                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5724                 .channel_mode = alc260_modes,
5725                 .input_mux = &alc260_capture_source,
5726                 .unsol_event = alc260_hp_unsol_event,
5727                 .init_hook = alc260_hp_automute,
5728         },
5729         [ALC260_HP_DC7600] = {
5730                 .mixers = { alc260_hp_dc7600_mixer,
5731                             alc260_input_mixer },
5732                 .init_verbs = { alc260_init_verbs,
5733                                 alc260_hp_dc7600_verbs },
5734                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5735                 .dac_nids = alc260_dac_nids,
5736                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5737                 .adc_nids = alc260_adc_nids_alt,
5738                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5739                 .channel_mode = alc260_modes,
5740                 .input_mux = &alc260_capture_source,
5741                 .unsol_event = alc260_hp_3012_unsol_event,
5742                 .init_hook = alc260_hp_3012_automute,
5743         },
5744         [ALC260_HP_3013] = {
5745                 .mixers = { alc260_hp_3013_mixer,
5746                             alc260_input_mixer },
5747                 .init_verbs = { alc260_hp_3013_init_verbs,
5748                                 alc260_hp_3013_unsol_verbs },
5749                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5750                 .dac_nids = alc260_dac_nids,
5751                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5752                 .adc_nids = alc260_adc_nids_alt,
5753                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5754                 .channel_mode = alc260_modes,
5755                 .input_mux = &alc260_capture_source,
5756                 .unsol_event = alc260_hp_3013_unsol_event,
5757                 .init_hook = alc260_hp_3013_automute,
5758         },
5759         [ALC260_FUJITSU_S702X] = {
5760                 .mixers = { alc260_fujitsu_mixer },
5761                 .init_verbs = { alc260_fujitsu_init_verbs },
5762                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5763                 .dac_nids = alc260_dac_nids,
5764                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5765                 .adc_nids = alc260_dual_adc_nids,
5766                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5767                 .channel_mode = alc260_modes,
5768                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5769                 .input_mux = alc260_fujitsu_capture_sources,
5770         },
5771         [ALC260_ACER] = {
5772                 .mixers = { alc260_acer_mixer },
5773                 .init_verbs = { alc260_acer_init_verbs },
5774                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5775                 .dac_nids = alc260_dac_nids,
5776                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5777                 .adc_nids = alc260_dual_adc_nids,
5778                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5779                 .channel_mode = alc260_modes,
5780                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5781                 .input_mux = alc260_acer_capture_sources,
5782         },
5783         [ALC260_WILL] = {
5784                 .mixers = { alc260_will_mixer },
5785                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5786                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5787                 .dac_nids = alc260_dac_nids,
5788                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5789                 .adc_nids = alc260_adc_nids,
5790                 .dig_out_nid = ALC260_DIGOUT_NID,
5791                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5792                 .channel_mode = alc260_modes,
5793                 .input_mux = &alc260_capture_source,
5794         },
5795         [ALC260_REPLACER_672V] = {
5796                 .mixers = { alc260_replacer_672v_mixer },
5797                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5798                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5799                 .dac_nids = alc260_dac_nids,
5800                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5801                 .adc_nids = alc260_adc_nids,
5802                 .dig_out_nid = ALC260_DIGOUT_NID,
5803                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5804                 .channel_mode = alc260_modes,
5805                 .input_mux = &alc260_capture_source,
5806                 .unsol_event = alc260_replacer_672v_unsol_event,
5807                 .init_hook = alc260_replacer_672v_automute,
5808         },
5809 #ifdef CONFIG_SND_DEBUG
5810         [ALC260_TEST] = {
5811                 .mixers = { alc260_test_mixer },
5812                 .init_verbs = { alc260_test_init_verbs },
5813                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5814                 .dac_nids = alc260_test_dac_nids,
5815                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5816                 .adc_nids = alc260_test_adc_nids,
5817                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5818                 .channel_mode = alc260_modes,
5819                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5820                 .input_mux = alc260_test_capture_sources,
5821         },
5822 #endif
5823 };
5824
5825 static int patch_alc260(struct hda_codec *codec)
5826 {
5827         struct alc_spec *spec;
5828         int err, board_config;
5829
5830         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5831         if (spec == NULL)
5832                 return -ENOMEM;
5833
5834         codec->spec = spec;
5835
5836         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
5837                                                   alc260_models,
5838                                                   alc260_cfg_tbl);
5839         if (board_config < 0) {
5840                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
5841                            "trying auto-probe from BIOS...\n");
5842                 board_config = ALC260_AUTO;
5843         }
5844
5845         if (board_config == ALC260_AUTO) {
5846                 /* automatic parse from the BIOS config */
5847                 err = alc260_parse_auto_config(codec);
5848                 if (err < 0) {
5849                         alc_free(codec);
5850                         return err;
5851                 } else if (!err) {
5852                         printk(KERN_INFO
5853                                "hda_codec: Cannot set up configuration "
5854                                "from BIOS.  Using base mode...\n");
5855                         board_config = ALC260_BASIC;
5856                 }
5857         }
5858
5859         if (board_config != ALC260_AUTO)
5860                 setup_preset(spec, &alc260_presets[board_config]);
5861
5862         spec->stream_name_analog = "ALC260 Analog";
5863         spec->stream_analog_playback = &alc260_pcm_analog_playback;
5864         spec->stream_analog_capture = &alc260_pcm_analog_capture;
5865
5866         spec->stream_name_digital = "ALC260 Digital";
5867         spec->stream_digital_playback = &alc260_pcm_digital_playback;
5868         spec->stream_digital_capture = &alc260_pcm_digital_capture;
5869
5870         if (!spec->adc_nids && spec->input_mux) {
5871                 /* check whether NID 0x04 is valid */
5872                 unsigned int wcap = get_wcaps(codec, 0x04);
5873                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
5874                 /* get type */
5875                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
5876                         spec->adc_nids = alc260_adc_nids_alt;
5877                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
5878                 } else {
5879                         spec->adc_nids = alc260_adc_nids;
5880                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
5881                 }
5882         }
5883         set_capture_mixer(spec);
5884
5885         spec->vmaster_nid = 0x08;
5886
5887         codec->patch_ops = alc_patch_ops;
5888         if (board_config == ALC260_AUTO)
5889                 spec->init_hook = alc260_auto_init;
5890 #ifdef CONFIG_SND_HDA_POWER_SAVE
5891         if (!spec->loopback.amplist)
5892                 spec->loopback.amplist = alc260_loopbacks;
5893 #endif
5894         codec->proc_widget_hook = print_realtek_coef;
5895
5896         return 0;
5897 }
5898
5899
5900 /*
5901  * ALC882 support
5902  *
5903  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5904  * configuration.  Each pin widget can choose any input DACs and a mixer.
5905  * Each ADC is connected from a mixer of all inputs.  This makes possible
5906  * 6-channel independent captures.
5907  *
5908  * In addition, an independent DAC for the multi-playback (not used in this
5909  * driver yet).
5910  */
5911 #define ALC882_DIGOUT_NID       0x06
5912 #define ALC882_DIGIN_NID        0x0a
5913
5914 static struct hda_channel_mode alc882_ch_modes[1] = {
5915         { 8, NULL }
5916 };
5917
5918 static hda_nid_t alc882_dac_nids[4] = {
5919         /* front, rear, clfe, rear_surr */
5920         0x02, 0x03, 0x04, 0x05
5921 };
5922
5923 /* identical with ALC880 */
5924 #define alc882_adc_nids         alc880_adc_nids
5925 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5926
5927 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5928 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5929
5930 /* input MUX */
5931 /* FIXME: should be a matrix-type input source selection */
5932
5933 static struct hda_input_mux alc882_capture_source = {
5934         .num_items = 4,
5935         .items = {
5936                 { "Mic", 0x0 },
5937                 { "Front Mic", 0x1 },
5938                 { "Line", 0x2 },
5939                 { "CD", 0x4 },
5940         },
5941 };
5942 /*
5943  * 2ch mode
5944  */
5945 static struct hda_verb alc882_3ST_ch2_init[] = {
5946         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5947         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5948         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5949         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5950         { } /* end */
5951 };
5952
5953 /*
5954  * 6ch mode
5955  */
5956 static struct hda_verb alc882_3ST_ch6_init[] = {
5957         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5958         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5959         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5960         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5961         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5962         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5963         { } /* end */
5964 };
5965
5966 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5967         { 2, alc882_3ST_ch2_init },
5968         { 6, alc882_3ST_ch6_init },
5969 };
5970
5971 /*
5972  * 6ch mode
5973  */
5974 static struct hda_verb alc882_sixstack_ch6_init[] = {
5975         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5976         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5977         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5978         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5979         { } /* end */
5980 };
5981
5982 /*
5983  * 8ch mode
5984  */
5985 static struct hda_verb alc882_sixstack_ch8_init[] = {
5986         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5987         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5988         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5989         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5990         { } /* end */
5991 };
5992
5993 static struct hda_channel_mode alc882_sixstack_modes[2] = {
5994         { 6, alc882_sixstack_ch6_init },
5995         { 8, alc882_sixstack_ch8_init },
5996 };
5997
5998 /*
5999  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
6000  */
6001
6002 /*
6003  * 2ch mode
6004  */
6005 static struct hda_verb alc885_mbp_ch2_init[] = {
6006         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6007         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6008         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6009         { } /* end */
6010 };
6011
6012 /*
6013  * 6ch mode
6014  */
6015 static struct hda_verb alc885_mbp_ch6_init[] = {
6016         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6017         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6018         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6019         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6020         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6021         { } /* end */
6022 };
6023
6024 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
6025         { 2, alc885_mbp_ch2_init },
6026         { 6, alc885_mbp_ch6_init },
6027 };
6028
6029
6030 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6031  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6032  */
6033 static struct snd_kcontrol_new alc882_base_mixer[] = {
6034         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6035         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6036         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6037         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6038         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6039         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6040         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6041         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6042         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6043         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6044         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6045         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6046         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6047         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6048         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6049         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6050         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6051         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6052         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6053         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6054         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6055         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6056         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6057         { } /* end */
6058 };
6059
6060 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
6061         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6062         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
6063         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
6064         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
6065         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6066         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6067         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
6068         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
6069         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
6070         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
6071         { } /* end */
6072 };
6073 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
6074         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6075         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6076         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6077         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6078         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6079         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6080         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6081         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6082         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6083         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6084         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6085         { } /* end */
6086 };
6087
6088 static struct snd_kcontrol_new alc882_targa_mixer[] = {
6089         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6090         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6091         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6092         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6093         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6094         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6095         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6096         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6097         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6098         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6099         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6100         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6101         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6102         { } /* end */
6103 };
6104
6105 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
6106  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
6107  */
6108 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
6109         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6110         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6111         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6112         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
6113         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6114         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6115         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6116         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6117         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
6118         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
6119         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6120         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6121         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6122         { } /* end */
6123 };
6124
6125 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
6126         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6127         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6128         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6129         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6130         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6131         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6132         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6133         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6134         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6135         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6136         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6137         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6138         { } /* end */
6139 };
6140
6141 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
6142         {
6143                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6144                 .name = "Channel Mode",
6145                 .info = alc_ch_mode_info,
6146                 .get = alc_ch_mode_get,
6147                 .put = alc_ch_mode_put,
6148         },
6149         { } /* end */
6150 };
6151
6152 static struct hda_verb alc882_init_verbs[] = {
6153         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6154         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6155         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6156         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6157         /* Rear mixer */
6158         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6159         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6160         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6161         /* CLFE mixer */
6162         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6163         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6164         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6165         /* Side mixer */
6166         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6167         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6168         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6169
6170         /* Front Pin: output 0 (0x0c) */
6171         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6172         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6173         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6174         /* Rear Pin: output 1 (0x0d) */
6175         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6176         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6177         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6178         /* CLFE Pin: output 2 (0x0e) */
6179         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6180         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6181         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
6182         /* Side Pin: output 3 (0x0f) */
6183         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6184         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6185         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
6186         /* Mic (rear) pin: input vref at 80% */
6187         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6188         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6189         /* Front Mic pin: input vref at 80% */
6190         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6191         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6192         /* Line In pin: input */
6193         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6194         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6195         /* Line-2 In: Headphone output (output 0 - 0x0c) */
6196         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6197         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6198         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6199         /* CD pin widget for input */
6200         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6201
6202         /* FIXME: use matrix-type input source selection */
6203         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6204         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6205         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6206         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6207         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6208         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6209         /* Input mixer2 */
6210         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6211         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6212         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6213         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6214         /* Input mixer3 */
6215         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6216         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6217         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6218         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6219         /* ADC1: mute amp left and right */
6220         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6221         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6222         /* ADC2: mute amp left and right */
6223         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6224         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6225         /* ADC3: mute amp left and right */
6226         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6227         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6228
6229         { }
6230 };
6231
6232 static struct hda_verb alc882_eapd_verbs[] = {
6233         /* change to EAPD mode */
6234         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6235         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
6236         { }
6237 };
6238
6239 /* Mac Pro test */
6240 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
6241         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6242         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6243         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
6244         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
6245         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
6246         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
6247         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
6248         { } /* end */
6249 };
6250
6251 static struct hda_verb alc882_macpro_init_verbs[] = {
6252         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6253         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6254         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6255         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6256         /* Front Pin: output 0 (0x0c) */
6257         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6258         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6259         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6260         /* Front Mic pin: input vref at 80% */
6261         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6262         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6263         /* Speaker:  output */
6264         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6265         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6266         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
6267         /* Headphone output (output 0 - 0x0c) */
6268         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6269         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6270         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6271
6272         /* FIXME: use matrix-type input source selection */
6273         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6274         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6275         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6276         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6277         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6278         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6279         /* Input mixer2 */
6280         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6281         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6282         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6283         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6284         /* Input mixer3 */
6285         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6286         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6287         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6288         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6289         /* ADC1: mute amp left and right */
6290         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6291         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6292         /* ADC2: mute amp left and right */
6293         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6294         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6295         /* ADC3: mute amp left and right */
6296         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6297         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6298
6299         { }
6300 };
6301
6302 /* Macbook Pro rev3 */
6303 static struct hda_verb alc885_mbp3_init_verbs[] = {
6304         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6305         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6306         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6307         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6308         /* Rear mixer */
6309         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6310         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6311         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6312         /* Front Pin: output 0 (0x0c) */
6313         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6314         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6315         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6316         /* HP Pin: output 0 (0x0d) */
6317         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
6318         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6319         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6320         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6321         /* Mic (rear) pin: input vref at 80% */
6322         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6323         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6324         /* Front Mic pin: input vref at 80% */
6325         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6326         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6327         /* Line In pin: use output 1 when in LineOut mode */
6328         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6329         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6330         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
6331
6332         /* FIXME: use matrix-type input source selection */
6333         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6334         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6335         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6336         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6337         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6338         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6339         /* Input mixer2 */
6340         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6341         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6342         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6343         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6344         /* Input mixer3 */
6345         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6346         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6347         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6348         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6349         /* ADC1: mute amp left and right */
6350         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6351         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6352         /* ADC2: mute amp left and right */
6353         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6354         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6355         /* ADC3: mute amp left and right */
6356         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6357         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6358
6359         { }
6360 };
6361
6362 /* iMac 24 mixer. */
6363 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
6364         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6365         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
6366         { } /* end */
6367 };
6368
6369 /* iMac 24 init verbs. */
6370 static struct hda_verb alc885_imac24_init_verbs[] = {
6371         /* Internal speakers: output 0 (0x0c) */
6372         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6373         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6374         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6375         /* Internal speakers: output 0 (0x0c) */
6376         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6377         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6378         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
6379         /* Headphone: output 0 (0x0c) */
6380         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6381         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6382         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6383         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6384         /* Front Mic: input vref at 80% */
6385         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6386         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6387         { }
6388 };
6389
6390 /* Toggle speaker-output according to the hp-jack state */
6391 static void alc885_imac24_automute(struct hda_codec *codec)
6392 {
6393         unsigned int present;
6394
6395         present = snd_hda_codec_read(codec, 0x14, 0,
6396                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6397         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
6398                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6399         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
6400                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6401 }
6402
6403 /* Processes unsolicited events. */
6404 static void alc885_imac24_unsol_event(struct hda_codec *codec,
6405                                       unsigned int res)
6406 {
6407         /* Headphone insertion or removal. */
6408         if ((res >> 26) == ALC880_HP_EVENT)
6409                 alc885_imac24_automute(codec);
6410 }
6411
6412 static void alc885_mbp3_automute(struct hda_codec *codec)
6413 {
6414         unsigned int present;
6415
6416         present = snd_hda_codec_read(codec, 0x15, 0,
6417                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6418         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
6419                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6420         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6421                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
6422
6423 }
6424 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
6425                                     unsigned int res)
6426 {
6427         /* Headphone insertion or removal. */
6428         if ((res >> 26) == ALC880_HP_EVENT)
6429                 alc885_mbp3_automute(codec);
6430 }
6431
6432
6433 static struct hda_verb alc882_targa_verbs[] = {
6434         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6435         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6436
6437         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6438         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6439
6440         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6441         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6442         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6443
6444         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6445         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6446         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6447         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6448         { } /* end */
6449 };
6450
6451 /* toggle speaker-output according to the hp-jack state */
6452 static void alc882_targa_automute(struct hda_codec *codec)
6453 {
6454         unsigned int present;
6455
6456         present = snd_hda_codec_read(codec, 0x14, 0,
6457                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6458         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
6459                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6460         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6461                                   present ? 1 : 3);
6462 }
6463
6464 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
6465 {
6466         /* Looks like the unsol event is incompatible with the standard
6467          * definition.  4bit tag is placed at 26 bit!
6468          */
6469         if (((res >> 26) == ALC880_HP_EVENT)) {
6470                 alc882_targa_automute(codec);
6471         }
6472 }
6473
6474 static struct hda_verb alc882_asus_a7j_verbs[] = {
6475         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6476         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6477
6478         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6479         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6480         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6481
6482         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6483         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6484         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6485
6486         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6487         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6488         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6489         { } /* end */
6490 };
6491
6492 static struct hda_verb alc882_asus_a7m_verbs[] = {
6493         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6494         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6495
6496         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6497         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6498         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6499
6500         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6501         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6502         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6503
6504         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6505         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6506         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6507         { } /* end */
6508 };
6509
6510 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6511 {
6512         unsigned int gpiostate, gpiomask, gpiodir;
6513
6514         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6515                                        AC_VERB_GET_GPIO_DATA, 0);
6516
6517         if (!muted)
6518                 gpiostate |= (1 << pin);
6519         else
6520                 gpiostate &= ~(1 << pin);
6521
6522         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
6523                                       AC_VERB_GET_GPIO_MASK, 0);
6524         gpiomask |= (1 << pin);
6525
6526         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
6527                                      AC_VERB_GET_GPIO_DIRECTION, 0);
6528         gpiodir |= (1 << pin);
6529
6530
6531         snd_hda_codec_write(codec, codec->afg, 0,
6532                             AC_VERB_SET_GPIO_MASK, gpiomask);
6533         snd_hda_codec_write(codec, codec->afg, 0,
6534                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
6535
6536         msleep(1);
6537
6538         snd_hda_codec_write(codec, codec->afg, 0,
6539                             AC_VERB_SET_GPIO_DATA, gpiostate);
6540 }
6541
6542 /* set up GPIO at initialization */
6543 static void alc885_macpro_init_hook(struct hda_codec *codec)
6544 {
6545         alc882_gpio_mute(codec, 0, 0);
6546         alc882_gpio_mute(codec, 1, 0);
6547 }
6548
6549 /* set up GPIO and update auto-muting at initialization */
6550 static void alc885_imac24_init_hook(struct hda_codec *codec)
6551 {
6552         alc885_macpro_init_hook(codec);
6553         alc885_imac24_automute(codec);
6554 }
6555
6556 /*
6557  * generic initialization of ADC, input mixers and output mixers
6558  */
6559 static struct hda_verb alc882_auto_init_verbs[] = {
6560         /*
6561          * Unmute ADC0-2 and set the default input to mic-in
6562          */
6563         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6564         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6565         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6566         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6567         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6568         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6569
6570         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6571          * mixer widget
6572          * Note: PASD motherboards uses the Line In 2 as the input for
6573          * front panel mic (mic 2)
6574          */
6575         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6576         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6577         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6578         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6579         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6580         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6581
6582         /*
6583          * Set up output mixers (0x0c - 0x0f)
6584          */
6585         /* set vol=0 to output mixers */
6586         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6587         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6588         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6589         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6590         /* set up input amps for analog loopback */
6591         /* Amp Indices: DAC = 0, mixer = 1 */
6592         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6593         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6594         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6595         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6596         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6597         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6598         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6599         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6600         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6601         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6602
6603         /* FIXME: use matrix-type input source selection */
6604         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6605         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6606         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6607         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6608         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6609         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6610         /* Input mixer2 */
6611         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6612         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6613         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6614         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6615         /* Input mixer3 */
6616         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6617         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6618         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6619         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6620
6621         { }
6622 };
6623
6624 #ifdef CONFIG_SND_HDA_POWER_SAVE
6625 #define alc882_loopbacks        alc880_loopbacks
6626 #endif
6627
6628 /* pcm configuration: identiacal with ALC880 */
6629 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6630 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6631 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6632 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6633
6634 /*
6635  * configuration and preset
6636  */
6637 static const char *alc882_models[ALC882_MODEL_LAST] = {
6638         [ALC882_3ST_DIG]        = "3stack-dig",
6639         [ALC882_6ST_DIG]        = "6stack-dig",
6640         [ALC882_ARIMA]          = "arima",
6641         [ALC882_W2JC]           = "w2jc",
6642         [ALC882_TARGA]          = "targa",
6643         [ALC882_ASUS_A7J]       = "asus-a7j",
6644         [ALC882_ASUS_A7M]       = "asus-a7m",
6645         [ALC885_MACPRO]         = "macpro",
6646         [ALC885_MBP3]           = "mbp3",
6647         [ALC885_IMAC24]         = "imac24",
6648         [ALC882_AUTO]           = "auto",
6649 };
6650
6651 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6652         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6653         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6654         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6655         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6656         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6657         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6658         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6659         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6660         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6661         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6662         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6663         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6664         {}
6665 };
6666
6667 static struct alc_config_preset alc882_presets[] = {
6668         [ALC882_3ST_DIG] = {
6669                 .mixers = { alc882_base_mixer },
6670                 .init_verbs = { alc882_init_verbs },
6671                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6672                 .dac_nids = alc882_dac_nids,
6673                 .dig_out_nid = ALC882_DIGOUT_NID,
6674                 .dig_in_nid = ALC882_DIGIN_NID,
6675                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6676                 .channel_mode = alc882_ch_modes,
6677                 .need_dac_fix = 1,
6678                 .input_mux = &alc882_capture_source,
6679         },
6680         [ALC882_6ST_DIG] = {
6681                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6682                 .init_verbs = { alc882_init_verbs },
6683                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6684                 .dac_nids = alc882_dac_nids,
6685                 .dig_out_nid = ALC882_DIGOUT_NID,
6686                 .dig_in_nid = ALC882_DIGIN_NID,
6687                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6688                 .channel_mode = alc882_sixstack_modes,
6689                 .input_mux = &alc882_capture_source,
6690         },
6691         [ALC882_ARIMA] = {
6692                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6693                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6694                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6695                 .dac_nids = alc882_dac_nids,
6696                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6697                 .channel_mode = alc882_sixstack_modes,
6698                 .input_mux = &alc882_capture_source,
6699         },
6700         [ALC882_W2JC] = {
6701                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6702                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6703                                 alc880_gpio1_init_verbs },
6704                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6705                 .dac_nids = alc882_dac_nids,
6706                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6707                 .channel_mode = alc880_threestack_modes,
6708                 .need_dac_fix = 1,
6709                 .input_mux = &alc882_capture_source,
6710                 .dig_out_nid = ALC882_DIGOUT_NID,
6711         },
6712         [ALC885_MBP3] = {
6713                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6714                 .init_verbs = { alc885_mbp3_init_verbs,
6715                                 alc880_gpio1_init_verbs },
6716                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6717                 .dac_nids = alc882_dac_nids,
6718                 .channel_mode = alc885_mbp_6ch_modes,
6719                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
6720                 .input_mux = &alc882_capture_source,
6721                 .dig_out_nid = ALC882_DIGOUT_NID,
6722                 .dig_in_nid = ALC882_DIGIN_NID,
6723                 .unsol_event = alc885_mbp3_unsol_event,
6724                 .init_hook = alc885_mbp3_automute,
6725         },
6726         [ALC885_MACPRO] = {
6727                 .mixers = { alc882_macpro_mixer },
6728                 .init_verbs = { alc882_macpro_init_verbs },
6729                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6730                 .dac_nids = alc882_dac_nids,
6731                 .dig_out_nid = ALC882_DIGOUT_NID,
6732                 .dig_in_nid = ALC882_DIGIN_NID,
6733                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6734                 .channel_mode = alc882_ch_modes,
6735                 .input_mux = &alc882_capture_source,
6736                 .init_hook = alc885_macpro_init_hook,
6737         },
6738         [ALC885_IMAC24] = {
6739                 .mixers = { alc885_imac24_mixer },
6740                 .init_verbs = { alc885_imac24_init_verbs },
6741                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6742                 .dac_nids = alc882_dac_nids,
6743                 .dig_out_nid = ALC882_DIGOUT_NID,
6744                 .dig_in_nid = ALC882_DIGIN_NID,
6745                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6746                 .channel_mode = alc882_ch_modes,
6747                 .input_mux = &alc882_capture_source,
6748                 .unsol_event = alc885_imac24_unsol_event,
6749                 .init_hook = alc885_imac24_init_hook,
6750         },
6751         [ALC882_TARGA] = {
6752                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
6753                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6754                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6755                 .dac_nids = alc882_dac_nids,
6756                 .dig_out_nid = ALC882_DIGOUT_NID,
6757                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6758                 .adc_nids = alc882_adc_nids,
6759                 .capsrc_nids = alc882_capsrc_nids,
6760                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6761                 .channel_mode = alc882_3ST_6ch_modes,
6762                 .need_dac_fix = 1,
6763                 .input_mux = &alc882_capture_source,
6764                 .unsol_event = alc882_targa_unsol_event,
6765                 .init_hook = alc882_targa_automute,
6766         },
6767         [ALC882_ASUS_A7J] = {
6768                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
6769                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6770                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6771                 .dac_nids = alc882_dac_nids,
6772                 .dig_out_nid = ALC882_DIGOUT_NID,
6773                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6774                 .adc_nids = alc882_adc_nids,
6775                 .capsrc_nids = alc882_capsrc_nids,
6776                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6777                 .channel_mode = alc882_3ST_6ch_modes,
6778                 .need_dac_fix = 1,
6779                 .input_mux = &alc882_capture_source,
6780         },
6781         [ALC882_ASUS_A7M] = {
6782                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6783                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6784                                 alc880_gpio1_init_verbs,
6785                                 alc882_asus_a7m_verbs },
6786                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6787                 .dac_nids = alc882_dac_nids,
6788                 .dig_out_nid = ALC882_DIGOUT_NID,
6789                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6790                 .channel_mode = alc880_threestack_modes,
6791                 .need_dac_fix = 1,
6792                 .input_mux = &alc882_capture_source,
6793         },
6794 };
6795
6796
6797 /*
6798  * Pin config fixes
6799  */
6800 enum {
6801         PINFIX_ABIT_AW9D_MAX
6802 };
6803
6804 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6805         { 0x15, 0x01080104 }, /* side */
6806         { 0x16, 0x01011012 }, /* rear */
6807         { 0x17, 0x01016011 }, /* clfe */
6808         { }
6809 };
6810
6811 static const struct alc_pincfg *alc882_pin_fixes[] = {
6812         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6813 };
6814
6815 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6816         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6817         {}
6818 };
6819
6820 /*
6821  * BIOS auto configuration
6822  */
6823 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6824                                               hda_nid_t nid, int pin_type,
6825                                               int dac_idx)
6826 {
6827         /* set as output */
6828         struct alc_spec *spec = codec->spec;
6829         int idx;
6830
6831         alc_set_pin_output(codec, nid, pin_type);
6832         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6833                 idx = 4;
6834         else
6835                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6836         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6837
6838 }
6839
6840 static void alc882_auto_init_multi_out(struct hda_codec *codec)
6841 {
6842         struct alc_spec *spec = codec->spec;
6843         int i;
6844
6845         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6846         for (i = 0; i <= HDA_SIDE; i++) {
6847                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6848                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6849                 if (nid)
6850                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6851                                                           i);
6852         }
6853 }
6854
6855 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6856 {
6857         struct alc_spec *spec = codec->spec;
6858         hda_nid_t pin;
6859
6860         pin = spec->autocfg.hp_pins[0];
6861         if (pin) /* connect to front */
6862                 /* use dac 0 */
6863                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6864         pin = spec->autocfg.speaker_pins[0];
6865         if (pin)
6866                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6867 }
6868
6869 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6870 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6871
6872 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6873 {
6874         struct alc_spec *spec = codec->spec;
6875         int i;
6876
6877         for (i = 0; i < AUTO_PIN_LAST; i++) {
6878                 hda_nid_t nid = spec->autocfg.input_pins[i];
6879                 unsigned int vref;
6880                 if (!nid)
6881                         continue;
6882                 vref = PIN_IN;
6883                 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6884                         unsigned int pincap;
6885                         pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
6886                         if ((pincap >> AC_PINCAP_VREF_SHIFT) &
6887                             AC_PINCAP_VREF_80)
6888                                 vref = PIN_VREF80;
6889                 }
6890                 snd_hda_codec_write(codec, nid, 0,
6891                                     AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6892                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6893                         snd_hda_codec_write(codec, nid, 0,
6894                                             AC_VERB_SET_AMP_GAIN_MUTE,
6895                                             AMP_OUT_MUTE);
6896         }
6897 }
6898
6899 static void alc882_auto_init_input_src(struct hda_codec *codec)
6900 {
6901         struct alc_spec *spec = codec->spec;
6902         const struct hda_input_mux *imux = spec->input_mux;
6903         int c;
6904
6905         for (c = 0; c < spec->num_adc_nids; c++) {
6906                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
6907                 hda_nid_t nid = spec->capsrc_nids[c];
6908                 int conns, mute, idx, item;
6909
6910                 conns = snd_hda_get_connections(codec, nid, conn_list,
6911                                                 ARRAY_SIZE(conn_list));
6912                 if (conns < 0)
6913                         continue;
6914                 for (idx = 0; idx < conns; idx++) {
6915                         /* if the current connection is the selected one,
6916                          * unmute it as default - otherwise mute it
6917                          */
6918                         mute = AMP_IN_MUTE(idx);
6919                         for (item = 0; item < imux->num_items; item++) {
6920                                 if (imux->items[item].index == idx) {
6921                                         if (spec->cur_mux[c] == item)
6922                                                 mute = AMP_IN_UNMUTE(idx);
6923                                         break;
6924                                 }
6925                         }
6926                         snd_hda_codec_write(codec, nid, 0,
6927                                             AC_VERB_SET_AMP_GAIN_MUTE, mute);
6928                 }
6929         }
6930 }
6931
6932 /* add mic boosts if needed */
6933 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6934 {
6935         struct alc_spec *spec = codec->spec;
6936         int err;
6937         hda_nid_t nid;
6938
6939         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6940         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6941                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6942                                   "Mic Boost",
6943                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6944                 if (err < 0)
6945                         return err;
6946         }
6947         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6948         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6949                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6950                                   "Front Mic Boost",
6951                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6952                 if (err < 0)
6953                         return err;
6954         }
6955         return 0;
6956 }
6957
6958 /* almost identical with ALC880 parser... */
6959 static int alc882_parse_auto_config(struct hda_codec *codec)
6960 {
6961         struct alc_spec *spec = codec->spec;
6962         int err = alc880_parse_auto_config(codec);
6963
6964         if (err < 0)
6965                 return err;
6966         else if (!err)
6967                 return 0; /* no config found */
6968
6969         err = alc_auto_add_mic_boost(codec);
6970         if (err < 0)
6971                 return err;
6972
6973         /* hack - override the init verbs */
6974         spec->init_verbs[0] = alc882_auto_init_verbs;
6975
6976         return 1; /* config found */
6977 }
6978
6979 /* additional initialization for auto-configuration model */
6980 static void alc882_auto_init(struct hda_codec *codec)
6981 {
6982         struct alc_spec *spec = codec->spec;
6983         alc882_auto_init_multi_out(codec);
6984         alc882_auto_init_hp_out(codec);
6985         alc882_auto_init_analog_input(codec);
6986         alc882_auto_init_input_src(codec);
6987         if (spec->unsol_event)
6988                 alc_inithook(codec);
6989 }
6990
6991 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
6992
6993 static int patch_alc882(struct hda_codec *codec)
6994 {
6995         struct alc_spec *spec;
6996         int err, board_config;
6997
6998         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6999         if (spec == NULL)
7000                 return -ENOMEM;
7001
7002         codec->spec = spec;
7003
7004         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
7005                                                   alc882_models,
7006                                                   alc882_cfg_tbl);
7007
7008         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
7009                 /* Pick up systems that don't supply PCI SSID */
7010                 switch (codec->subsystem_id) {
7011                 case 0x106b0c00: /* Mac Pro */
7012                         board_config = ALC885_MACPRO;
7013                         break;
7014                 case 0x106b1000: /* iMac 24 */
7015                 case 0x106b2800: /* AppleTV */
7016                         board_config = ALC885_IMAC24;
7017                         break;
7018                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
7019                 case 0x106b00a4: /* MacbookPro4,1 */
7020                 case 0x106b2c00: /* Macbook Pro rev3 */
7021                 case 0x106b3600: /* Macbook 3.1 */
7022                         board_config = ALC885_MBP3;
7023                         break;
7024                 default:
7025                         /* ALC889A is handled better as ALC888-compatible */
7026                         if (codec->revision_id == 0x100101 ||
7027                             codec->revision_id == 0x100103) {
7028                                 alc_free(codec);
7029                                 return patch_alc883(codec);
7030                         }
7031                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
7032                                          "trying auto-probe from BIOS...\n");
7033                         board_config = ALC882_AUTO;
7034                 }
7035         }
7036
7037         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
7038
7039         if (board_config == ALC882_AUTO) {
7040                 /* automatic parse from the BIOS config */
7041                 err = alc882_parse_auto_config(codec);
7042                 if (err < 0) {
7043                         alc_free(codec);
7044                         return err;
7045                 } else if (!err) {
7046                         printk(KERN_INFO
7047                                "hda_codec: Cannot set up configuration "
7048                                "from BIOS.  Using base mode...\n");
7049                         board_config = ALC882_3ST_DIG;
7050                 }
7051         }
7052
7053         if (board_config != ALC882_AUTO)
7054                 setup_preset(spec, &alc882_presets[board_config]);
7055
7056         if (codec->vendor_id == 0x10ec0885) {
7057                 spec->stream_name_analog = "ALC885 Analog";
7058                 spec->stream_name_digital = "ALC885 Digital";
7059         } else {
7060                 spec->stream_name_analog = "ALC882 Analog";
7061                 spec->stream_name_digital = "ALC882 Digital";
7062         }
7063
7064         spec->stream_analog_playback = &alc882_pcm_analog_playback;
7065         spec->stream_analog_capture = &alc882_pcm_analog_capture;
7066         /* FIXME: setup DAC5 */
7067         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
7068         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
7069
7070         spec->stream_digital_playback = &alc882_pcm_digital_playback;
7071         spec->stream_digital_capture = &alc882_pcm_digital_capture;
7072
7073         spec->is_mix_capture = 1; /* matrix-style capture */
7074         if (!spec->adc_nids && spec->input_mux) {
7075                 /* check whether NID 0x07 is valid */
7076                 unsigned int wcap = get_wcaps(codec, 0x07);
7077                 /* get type */
7078                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
7079                 if (wcap != AC_WID_AUD_IN) {
7080                         spec->adc_nids = alc882_adc_nids_alt;
7081                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
7082                         spec->capsrc_nids = alc882_capsrc_nids_alt;
7083                 } else {
7084                         spec->adc_nids = alc882_adc_nids;
7085                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
7086                         spec->capsrc_nids = alc882_capsrc_nids;
7087                 }
7088         }
7089         set_capture_mixer(spec);
7090
7091         spec->vmaster_nid = 0x0c;
7092
7093         codec->patch_ops = alc_patch_ops;
7094         if (board_config == ALC882_AUTO)
7095                 spec->init_hook = alc882_auto_init;
7096 #ifdef CONFIG_SND_HDA_POWER_SAVE
7097         if (!spec->loopback.amplist)
7098                 spec->loopback.amplist = alc882_loopbacks;
7099 #endif
7100         codec->proc_widget_hook = print_realtek_coef;
7101
7102         return 0;
7103 }
7104
7105 /*
7106  * ALC883 support
7107  *
7108  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
7109  * configuration.  Each pin widget can choose any input DACs and a mixer.
7110  * Each ADC is connected from a mixer of all inputs.  This makes possible
7111  * 6-channel independent captures.
7112  *
7113  * In addition, an independent DAC for the multi-playback (not used in this
7114  * driver yet).
7115  */
7116 #define ALC883_DIGOUT_NID       0x06
7117 #define ALC883_DIGIN_NID        0x0a
7118
7119 #define ALC1200_DIGOUT_NID      0x10
7120
7121 static hda_nid_t alc883_dac_nids[4] = {
7122         /* front, rear, clfe, rear_surr */
7123         0x02, 0x03, 0x04, 0x05
7124 };
7125
7126 static hda_nid_t alc883_adc_nids[2] = {
7127         /* ADC1-2 */
7128         0x08, 0x09,
7129 };
7130
7131 static hda_nid_t alc883_adc_nids_alt[1] = {
7132         /* ADC1 */
7133         0x08,
7134 };
7135
7136 static hda_nid_t alc883_adc_nids_rev[2] = {
7137         /* ADC2-1 */
7138         0x09, 0x08
7139 };
7140
7141 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
7142
7143 static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
7144
7145 /* input MUX */
7146 /* FIXME: should be a matrix-type input source selection */
7147
7148 static struct hda_input_mux alc883_capture_source = {
7149         .num_items = 4,
7150         .items = {
7151                 { "Mic", 0x0 },
7152                 { "Front Mic", 0x1 },
7153                 { "Line", 0x2 },
7154                 { "CD", 0x4 },
7155         },
7156 };
7157
7158 static struct hda_input_mux alc883_3stack_6ch_intel = {
7159         .num_items = 4,
7160         .items = {
7161                 { "Mic", 0x1 },
7162                 { "Front Mic", 0x0 },
7163                 { "Line", 0x2 },
7164                 { "CD", 0x4 },
7165         },
7166 };
7167
7168 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
7169         .num_items = 2,
7170         .items = {
7171                 { "Mic", 0x1 },
7172                 { "Line", 0x2 },
7173         },
7174 };
7175
7176 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
7177         .num_items = 4,
7178         .items = {
7179                 { "Mic", 0x0 },
7180                 { "iMic", 0x1 },
7181                 { "Line", 0x2 },
7182                 { "CD", 0x4 },
7183         },
7184 };
7185
7186 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
7187         .num_items = 2,
7188         .items = {
7189                 { "Mic", 0x0 },
7190                 { "Int Mic", 0x1 },
7191         },
7192 };
7193
7194 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
7195         .num_items = 3,
7196         .items = {
7197                 { "Mic", 0x0 },
7198                 { "Front Mic", 0x1 },
7199                 { "Line", 0x4 },
7200         },
7201 };
7202
7203 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
7204         .num_items = 2,
7205         .items = {
7206                 { "Mic", 0x0 },
7207                 { "Line", 0x2 },
7208         },
7209 };
7210
7211 /*
7212  * 2ch mode
7213  */
7214 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
7215         { 2, NULL }
7216 };
7217
7218 /*
7219  * 2ch mode
7220  */
7221 static struct hda_verb alc883_3ST_ch2_init[] = {
7222         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7223         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7224         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7225         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7226         { } /* end */
7227 };
7228
7229 /*
7230  * 4ch mode
7231  */
7232 static struct hda_verb alc883_3ST_ch4_init[] = {
7233         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7234         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7235         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7236         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7237         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7238         { } /* end */
7239 };
7240
7241 /*
7242  * 6ch mode
7243  */
7244 static struct hda_verb alc883_3ST_ch6_init[] = {
7245         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7246         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7247         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7248         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7249         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7250         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7251         { } /* end */
7252 };
7253
7254 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
7255         { 2, alc883_3ST_ch2_init },
7256         { 4, alc883_3ST_ch4_init },
7257         { 6, alc883_3ST_ch6_init },
7258 };
7259
7260 /*
7261  * 2ch mode
7262  */
7263 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
7264         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7265         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7266         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7267         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7268         { } /* end */
7269 };
7270
7271 /*
7272  * 4ch mode
7273  */
7274 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
7275         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7276         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7277         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7278         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7279         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7280         { } /* end */
7281 };
7282
7283 /*
7284  * 6ch mode
7285  */
7286 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
7287         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7288         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7289         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
7290         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7291         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7292         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7293         { } /* end */
7294 };
7295
7296 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
7297         { 2, alc883_3ST_ch2_intel_init },
7298         { 4, alc883_3ST_ch4_intel_init },
7299         { 6, alc883_3ST_ch6_intel_init },
7300 };
7301
7302 /*
7303  * 6ch mode
7304  */
7305 static struct hda_verb alc883_sixstack_ch6_init[] = {
7306         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7307         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7308         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7309         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7310         { } /* end */
7311 };
7312
7313 /*
7314  * 8ch mode
7315  */
7316 static struct hda_verb alc883_sixstack_ch8_init[] = {
7317         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7318         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7319         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7320         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7321         { } /* end */
7322 };
7323
7324 static struct hda_channel_mode alc883_sixstack_modes[2] = {
7325         { 6, alc883_sixstack_ch6_init },
7326         { 8, alc883_sixstack_ch8_init },
7327 };
7328
7329 static struct hda_verb alc883_medion_eapd_verbs[] = {
7330         /* eanable EAPD on medion laptop */
7331         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7332         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7333         { }
7334 };
7335
7336 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
7337  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
7338  */
7339
7340 static struct snd_kcontrol_new alc883_base_mixer[] = {
7341         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7342         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7343         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7344         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7345         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7346         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7347         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7348         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7349         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7350         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7351         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7352         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7353         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7354         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7355         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7356         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7357         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7358         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7359         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7360         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7361         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7362         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7363         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7364         { } /* end */
7365 };
7366
7367 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7368         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7369         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7370         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7371         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7372         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7373         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7374         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7375         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7376         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7377         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7378         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7379         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7380         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7381         { } /* end */
7382 };
7383
7384 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7385         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7386         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7387         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7388         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7389         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7390         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7391         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7392         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7393         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7394         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7395         { } /* end */
7396 };
7397
7398 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7399         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7400         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7401         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7402         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7403         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7404         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7405         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7406         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7407         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7408         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7409         { } /* end */
7410 };
7411
7412 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7413         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7414         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7415         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7416         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7417         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7418         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7419         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7420         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7421         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7422         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7423         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7424         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7425         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7426         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7427         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7428         { } /* end */
7429 };
7430
7431 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7432         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7433         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7434         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7435         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7436         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7437         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7438         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7439         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7440         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7441         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7442         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7443         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7444         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7445         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7446         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7447         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7448         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7449         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7450         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7451         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7452         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7453         { } /* end */
7454 };
7455
7456 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7457         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7458         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7459         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7460         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7461         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7462                               HDA_OUTPUT),
7463         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7464         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7465         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7466         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7467         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7468         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7469         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7470         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7471         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7472         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7473         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7474         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7475         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7476         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7477         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7478         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7479         { } /* end */
7480 };
7481
7482 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7483         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7484         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7485         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7486         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7487         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7488         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7489         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7490         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7491         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7492         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7493         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7494         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7495         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7496         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7497         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7498         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7499         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7500         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7501         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7502         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7503         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7504         { } /* end */
7505 };
7506
7507 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
7508         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7509         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7510         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7511         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7512         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7513         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7514         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7515         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7516         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7517         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7518         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7519         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7520         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7521         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7522         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7523         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7524         { } /* end */
7525 };
7526
7527 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
7528         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7529         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7530         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7531         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7532         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7533         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7534         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7535         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7536         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7537         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7538         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7539         { } /* end */
7540 };
7541
7542 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7543         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7544         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7545         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7546         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7547         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7548         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7549         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7550         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7551         { } /* end */
7552 };
7553
7554 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7555         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7556         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7557         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7558         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7559         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7560         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7561         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7562         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7563         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7564         { } /* end */
7565 };
7566
7567 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7568         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7569         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7570         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7571         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7572         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7573         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7574         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7575         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7576         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7577         { } /* end */
7578 };
7579
7580 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7581         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7582         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7583         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7584         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7585         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, 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         { } /* end */
7590 };
7591
7592 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
7593         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7594         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7595         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
7596         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
7597         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
7598                                                 0x0d, 1, 0x0, HDA_OUTPUT),
7599         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
7600         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
7601         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
7602         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7603         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7604         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7605         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
7606         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7607         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7608         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7609         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7610         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7611         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7612         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7613         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7614         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7615         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7616         { } /* end */
7617 };
7618
7619 static struct hda_bind_ctls alc883_bind_cap_vol = {
7620         .ops = &snd_hda_bind_vol,
7621         .values = {
7622                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7623                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7624                 0
7625         },
7626 };
7627
7628 static struct hda_bind_ctls alc883_bind_cap_switch = {
7629         .ops = &snd_hda_bind_sw,
7630         .values = {
7631                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7632                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7633                 0
7634         },
7635 };
7636
7637 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
7638         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7639         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7640         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7641         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7642         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7643         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7644         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7645         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7646         { } /* end */
7647 };
7648
7649 static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
7650         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
7651         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
7652         {
7653                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7654                 /* .name = "Capture Source", */
7655                 .name = "Input Source",
7656                 .count = 1,
7657                 .info = alc_mux_enum_info,
7658                 .get = alc_mux_enum_get,
7659                 .put = alc_mux_enum_put,
7660         },
7661         { } /* end */
7662 };
7663
7664 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7665         {
7666                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7667                 .name = "Channel Mode",
7668                 .info = alc_ch_mode_info,
7669                 .get = alc_ch_mode_get,
7670                 .put = alc_ch_mode_put,
7671         },
7672         { } /* end */
7673 };
7674
7675 static struct hda_verb alc883_init_verbs[] = {
7676         /* ADC1: mute amp left and right */
7677         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7678         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7679         /* ADC2: mute amp left and right */
7680         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7681         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7682         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7683         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7684         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7685         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7686         /* Rear mixer */
7687         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7688         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7689         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7690         /* CLFE mixer */
7691         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7692         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7693         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7694         /* Side mixer */
7695         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7696         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7697         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7698
7699         /* mute analog input loopbacks */
7700         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7701         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7702         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7703         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7704         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7705
7706         /* Front Pin: output 0 (0x0c) */
7707         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7708         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7709         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7710         /* Rear Pin: output 1 (0x0d) */
7711         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7712         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7713         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7714         /* CLFE Pin: output 2 (0x0e) */
7715         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7716         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7717         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7718         /* Side Pin: output 3 (0x0f) */
7719         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7720         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7721         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7722         /* Mic (rear) pin: input vref at 80% */
7723         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7724         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7725         /* Front Mic pin: input vref at 80% */
7726         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7727         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7728         /* Line In pin: input */
7729         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7730         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7731         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7732         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7733         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7734         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7735         /* CD pin widget for input */
7736         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7737
7738         /* FIXME: use matrix-type input source selection */
7739         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7740         /* Input mixer2 */
7741         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7742         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7743         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7744         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7745         /* Input mixer3 */
7746         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7747         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7748         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7749         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7750         { }
7751 };
7752
7753 /* toggle speaker-output according to the hp-jack state */
7754 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7755 {
7756         unsigned int present;
7757
7758         present = snd_hda_codec_read(codec, 0x15, 0,
7759                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7760         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7761                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7762         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7763                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7764 }
7765
7766 /* auto-toggle front mic */
7767 /*
7768 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7769 {
7770         unsigned int present;
7771         unsigned char bits;
7772
7773         present = snd_hda_codec_read(codec, 0x18, 0,
7774                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7775         bits = present ? HDA_AMP_MUTE : 0;
7776         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7777 }
7778 */
7779
7780 static void alc883_mitac_automute(struct hda_codec *codec)
7781 {
7782         alc883_mitac_hp_automute(codec);
7783         /* alc883_mitac_mic_automute(codec); */
7784 }
7785
7786 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7787                                            unsigned int res)
7788 {
7789         switch (res >> 26) {
7790         case ALC880_HP_EVENT:
7791                 alc883_mitac_hp_automute(codec);
7792                 break;
7793         case ALC880_MIC_EVENT:
7794                 /* alc883_mitac_mic_automute(codec); */
7795                 break;
7796         }
7797 }
7798
7799 static struct hda_verb alc883_mitac_verbs[] = {
7800         /* HP */
7801         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7802         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7803         /* Subwoofer */
7804         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7805         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7806
7807         /* enable unsolicited event */
7808         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7809         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7810
7811         { } /* end */
7812 };
7813
7814 static struct hda_verb alc883_clevo_m720_verbs[] = {
7815         /* HP */
7816         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7817         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7818         /* Int speaker */
7819         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7820         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7821
7822         /* enable unsolicited event */
7823         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7824         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7825
7826         { } /* end */
7827 };
7828
7829 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7830         /* HP */
7831         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7832         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7833         /* Subwoofer */
7834         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7835         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7836
7837         /* enable unsolicited event */
7838         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7839
7840         { } /* end */
7841 };
7842
7843 static struct hda_verb alc883_tagra_verbs[] = {
7844         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7845         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7846
7847         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7848         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7849
7850         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7851         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7852         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7853
7854         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7855         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7856         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7857         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7858
7859         { } /* end */
7860 };
7861
7862 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7863         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7864         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7865         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7866         { } /* end */
7867 };
7868
7869 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7870         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7871         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7872         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7873         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7874         { } /* end */
7875 };
7876
7877 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7878         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7879         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7880         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7881         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7882         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7883         { } /* end */
7884 };
7885
7886 static struct hda_verb alc883_haier_w66_verbs[] = {
7887         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7888         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7889
7890         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7891
7892         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7893         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7894         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7895         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7896         { } /* end */
7897 };
7898
7899 static struct hda_verb alc888_lenovo_sky_verbs[] = {
7900         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7901         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7902         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7903         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7904         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7905         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7906         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7907         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7908         { } /* end */
7909 };
7910
7911 static struct hda_verb alc888_3st_hp_verbs[] = {
7912         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7913         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7914         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7915         { }
7916 };
7917
7918 static struct hda_verb alc888_6st_dell_verbs[] = {
7919         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7920         { }
7921 };
7922
7923 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7924         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7925         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7926         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7927         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7928         { }
7929 };
7930
7931 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7932         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7933         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7934         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7935         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7936         { }
7937 };
7938
7939 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7940         { 2, alc888_3st_hp_2ch_init },
7941         { 6, alc888_3st_hp_6ch_init },
7942 };
7943
7944 /* toggle front-jack and RCA according to the hp-jack state */
7945 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7946 {
7947         unsigned int present;
7948
7949         present = snd_hda_codec_read(codec, 0x1b, 0,
7950                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7951         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7952                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7953         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7954                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7955 }
7956
7957 /* toggle RCA according to the front-jack state */
7958 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7959 {
7960         unsigned int present;
7961
7962         present = snd_hda_codec_read(codec, 0x14, 0,
7963                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7964         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7965                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7966 }
7967
7968 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7969                                              unsigned int res)
7970 {
7971         if ((res >> 26) == ALC880_HP_EVENT)
7972                 alc888_lenovo_ms7195_front_automute(codec);
7973         if ((res >> 26) == ALC880_FRONT_EVENT)
7974                 alc888_lenovo_ms7195_rca_automute(codec);
7975 }
7976
7977 static struct hda_verb alc883_medion_md2_verbs[] = {
7978         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7979         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7980
7981         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7982
7983         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7984         { } /* end */
7985 };
7986
7987 /* toggle speaker-output according to the hp-jack state */
7988 static void alc883_medion_md2_automute(struct hda_codec *codec)
7989 {
7990         unsigned int present;
7991
7992         present = snd_hda_codec_read(codec, 0x14, 0,
7993                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7994         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7995                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7996 }
7997
7998 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
7999                                           unsigned int res)
8000 {
8001         if ((res >> 26) == ALC880_HP_EVENT)
8002                 alc883_medion_md2_automute(codec);
8003 }
8004
8005 /* toggle speaker-output according to the hp-jack state */
8006 static void alc883_tagra_automute(struct hda_codec *codec)
8007 {
8008         unsigned int present;
8009         unsigned char bits;
8010
8011         present = snd_hda_codec_read(codec, 0x14, 0,
8012                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8013         bits = present ? HDA_AMP_MUTE : 0;
8014         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
8015                                  HDA_AMP_MUTE, bits);
8016         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
8017                                   present ? 1 : 3);
8018 }
8019
8020 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
8021 {
8022         if ((res >> 26) == ALC880_HP_EVENT)
8023                 alc883_tagra_automute(codec);
8024 }
8025
8026 /* toggle speaker-output according to the hp-jack state */
8027 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
8028 {
8029         unsigned int present;
8030         unsigned char bits;
8031
8032         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
8033                 & AC_PINSENSE_PRESENCE;
8034         bits = present ? HDA_AMP_MUTE : 0;
8035         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8036                                  HDA_AMP_MUTE, bits);
8037 }
8038
8039 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8040 {
8041         unsigned int present;
8042
8043         present = snd_hda_codec_read(codec, 0x18, 0,
8044                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8045         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8046                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8047 }
8048
8049 static void alc883_clevo_m720_automute(struct hda_codec *codec)
8050 {
8051         alc883_clevo_m720_hp_automute(codec);
8052         alc883_clevo_m720_mic_automute(codec);
8053 }
8054
8055 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8056                                            unsigned int res)
8057 {
8058         switch (res >> 26) {
8059         case ALC880_HP_EVENT:
8060                 alc883_clevo_m720_hp_automute(codec);
8061                 break;
8062         case ALC880_MIC_EVENT:
8063                 alc883_clevo_m720_mic_automute(codec);
8064                 break;
8065         }
8066 }
8067
8068 /* toggle speaker-output according to the hp-jack state */
8069 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
8070 {
8071         unsigned int present;
8072         unsigned char bits;
8073
8074         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8075                 & AC_PINSENSE_PRESENCE;
8076         bits = present ? HDA_AMP_MUTE : 0;
8077         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8078                                  HDA_AMP_MUTE, bits);
8079 }
8080
8081 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
8082                                                   unsigned int res)
8083 {
8084         if ((res >> 26) == ALC880_HP_EVENT)
8085                 alc883_2ch_fujitsu_pi2515_automute(codec);
8086 }
8087
8088 static void alc883_haier_w66_automute(struct hda_codec *codec)
8089 {
8090         unsigned int present;
8091         unsigned char bits;
8092
8093         present = snd_hda_codec_read(codec, 0x1b, 0,
8094                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8095         bits = present ? 0x80 : 0;
8096         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8097                                  0x80, bits);
8098 }
8099
8100 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
8101                                          unsigned int res)
8102 {
8103         if ((res >> 26) == ALC880_HP_EVENT)
8104                 alc883_haier_w66_automute(codec);
8105 }
8106
8107 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8108 {
8109         unsigned int present;
8110         unsigned char bits;
8111
8112         present = snd_hda_codec_read(codec, 0x14, 0,
8113                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8114         bits = present ? HDA_AMP_MUTE : 0;
8115         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8116                                  HDA_AMP_MUTE, bits);
8117 }
8118
8119 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8120 {
8121         unsigned int present;
8122         unsigned char bits;
8123
8124         present = snd_hda_codec_read(codec, 0x1b, 0,
8125                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8126         bits = present ? HDA_AMP_MUTE : 0;
8127         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8128                                  HDA_AMP_MUTE, bits);
8129         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8130                                  HDA_AMP_MUTE, bits);
8131 }
8132
8133 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8134                                            unsigned int res)
8135 {
8136         if ((res >> 26) == ALC880_HP_EVENT)
8137                 alc883_lenovo_101e_all_automute(codec);
8138         if ((res >> 26) == ALC880_FRONT_EVENT)
8139                 alc883_lenovo_101e_ispeaker_automute(codec);
8140 }
8141
8142 /* toggle speaker-output according to the hp-jack state */
8143 static void alc883_acer_aspire_automute(struct hda_codec *codec)
8144 {
8145         unsigned int present;
8146
8147         present = snd_hda_codec_read(codec, 0x14, 0,
8148                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8149         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8150                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8151         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8152                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8153 }
8154
8155 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
8156                                            unsigned int res)
8157 {
8158         if ((res >> 26) == ALC880_HP_EVENT)
8159                 alc883_acer_aspire_automute(codec);
8160 }
8161
8162 static struct hda_verb alc883_acer_eapd_verbs[] = {
8163         /* HP Pin: output 0 (0x0c) */
8164         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8165         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8166         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8167         /* Front Pin: output 0 (0x0c) */
8168         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8169         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8170         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8171         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
8172         /* eanable EAPD on medion laptop */
8173         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8174         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8175         /* enable unsolicited event */
8176         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8177         { }
8178 };
8179
8180 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
8181 {
8182         unsigned int present;
8183
8184         present = snd_hda_codec_read(codec, 0x1b, 0,
8185                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8186         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8187                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8188         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8189                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8190         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8191                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8192         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8193                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8194 }
8195
8196 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
8197                                              unsigned int res)
8198 {
8199         switch (res >> 26) {
8200         case ALC880_HP_EVENT:
8201                 printk("hp_event\n");
8202                 alc888_6st_dell_front_automute(codec);
8203                 break;
8204         }
8205 }
8206
8207 static void alc888_lenovo_sky_front_automute(struct hda_codec *codec)
8208 {
8209         unsigned int mute;
8210         unsigned int present;
8211
8212         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8213         present = snd_hda_codec_read(codec, 0x1b, 0,
8214                                      AC_VERB_GET_PIN_SENSE, 0);
8215         present = (present & 0x80000000) != 0;
8216         if (present) {
8217                 /* mute internal speaker */
8218                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8219                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8220                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8221                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8222                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8223                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8224                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8225                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8226                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8227                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8228         } else {
8229                 /* unmute internal speaker if necessary */
8230                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8231                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8232                                          HDA_AMP_MUTE, mute);
8233                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8234                                          HDA_AMP_MUTE, mute);
8235                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8236                                          HDA_AMP_MUTE, mute);
8237                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8238                                          HDA_AMP_MUTE, mute);
8239                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8240                                          HDA_AMP_MUTE, mute);
8241         }
8242 }
8243
8244 static void alc883_lenovo_sky_unsol_event(struct hda_codec *codec,
8245                                              unsigned int res)
8246 {
8247         if ((res >> 26) == ALC880_HP_EVENT)
8248                 alc888_lenovo_sky_front_automute(codec);
8249 }
8250
8251 /*
8252  * generic initialization of ADC, input mixers and output mixers
8253  */
8254 static struct hda_verb alc883_auto_init_verbs[] = {
8255         /*
8256          * Unmute ADC0-2 and set the default input to mic-in
8257          */
8258         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8259         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8260         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8261         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8262
8263         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8264          * mixer widget
8265          * Note: PASD motherboards uses the Line In 2 as the input for
8266          * front panel mic (mic 2)
8267          */
8268         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8269         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8270         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8271         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8272         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8273         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8274
8275         /*
8276          * Set up output mixers (0x0c - 0x0f)
8277          */
8278         /* set vol=0 to output mixers */
8279         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8280         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8281         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8282         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8283         /* set up input amps for analog loopback */
8284         /* Amp Indices: DAC = 0, mixer = 1 */
8285         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8286         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8287         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8288         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8289         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8290         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8291         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8292         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8293         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8294         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8295
8296         /* FIXME: use matrix-type input source selection */
8297         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8298         /* Input mixer1 */
8299         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8300         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8301         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8302         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8303         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8304         /* Input mixer2 */
8305         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8306         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8307         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8308         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8309         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8310
8311         { }
8312 };
8313
8314 static struct hda_verb alc888_asus_m90v_verbs[] = {
8315         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8316         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8317         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8318         /* enable unsolicited event */
8319         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8320         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8321         { } /* end */
8322 };
8323
8324 static void alc883_nb_mic_automute(struct hda_codec *codec)
8325 {
8326         unsigned int present;
8327
8328         present = snd_hda_codec_read(codec, 0x18, 0,
8329                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8330         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8331                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
8332         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8333                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
8334 }
8335
8336 static void alc883_M90V_speaker_automute(struct hda_codec *codec)
8337 {
8338         unsigned int present;
8339         unsigned char bits;
8340
8341         present = snd_hda_codec_read(codec, 0x1b, 0,
8342                                      AC_VERB_GET_PIN_SENSE, 0)
8343                 & AC_PINSENSE_PRESENCE;
8344         bits = present ? 0 : PIN_OUT;
8345         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8346                             bits);
8347         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8348                             bits);
8349         snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8350                             bits);
8351 }
8352
8353 static void alc883_mode2_unsol_event(struct hda_codec *codec,
8354                                            unsigned int res)
8355 {
8356         switch (res >> 26) {
8357         case ALC880_HP_EVENT:
8358                 alc883_M90V_speaker_automute(codec);
8359                 break;
8360         case ALC880_MIC_EVENT:
8361                 alc883_nb_mic_automute(codec);
8362                 break;
8363         }
8364 }
8365
8366 static void alc883_mode2_inithook(struct hda_codec *codec)
8367 {
8368         alc883_M90V_speaker_automute(codec);
8369         alc883_nb_mic_automute(codec);
8370 }
8371
8372 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8373         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8374         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8375         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8376         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8377         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8378         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8379         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8380         /* enable unsolicited event */
8381         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8382         { } /* end */
8383 };
8384
8385 static void alc883_eee1601_speaker_automute(struct hda_codec *codec)
8386 {
8387         unsigned int present;
8388         unsigned char bits;
8389
8390         present = snd_hda_codec_read(codec, 0x14, 0,
8391                                      AC_VERB_GET_PIN_SENSE, 0)
8392                 & AC_PINSENSE_PRESENCE;
8393         bits = present ? 0 : PIN_OUT;
8394         snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8395                             bits);
8396 }
8397
8398 static void alc883_eee1601_unsol_event(struct hda_codec *codec,
8399                                            unsigned int res)
8400 {
8401         switch (res >> 26) {
8402         case ALC880_HP_EVENT:
8403                 alc883_eee1601_speaker_automute(codec);
8404                 break;
8405         }
8406 }
8407
8408 static void alc883_eee1601_inithook(struct hda_codec *codec)
8409 {
8410         alc883_eee1601_speaker_automute(codec);
8411 }
8412
8413 #ifdef CONFIG_SND_HDA_POWER_SAVE
8414 #define alc883_loopbacks        alc880_loopbacks
8415 #endif
8416
8417 /* pcm configuration: identiacal with ALC880 */
8418 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
8419 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
8420 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
8421 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
8422 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
8423
8424 /*
8425  * configuration and preset
8426  */
8427 static const char *alc883_models[ALC883_MODEL_LAST] = {
8428         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
8429         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8430         [ALC883_3ST_6ch]        = "3stack-6ch",
8431         [ALC883_6ST_DIG]        = "6stack-dig",
8432         [ALC883_TARGA_DIG]      = "targa-dig",
8433         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8434         [ALC883_ACER]           = "acer",
8435         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8436         [ALC888_ACER_ASPIRE_4930G]      = "acer-aspire-4930g",
8437         [ALC883_MEDION]         = "medion",
8438         [ALC883_MEDION_MD2]     = "medion-md2",
8439         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8440         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8441         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8442         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8443         [ALC888_LENOVO_SKY] = "lenovo-sky",
8444         [ALC883_HAIER_W66]      = "haier-w66",
8445         [ALC888_3ST_HP]         = "3stack-hp",
8446         [ALC888_6ST_DELL]       = "6stack-dell",
8447         [ALC883_MITAC]          = "mitac",
8448         [ALC883_CLEVO_M720]     = "clevo-m720",
8449         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8450         [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
8451         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8452         [ALC1200_ASUS_P5Q]      = "asus-p5q",
8453         [ALC883_AUTO]           = "auto",
8454 };
8455
8456 static struct snd_pci_quirk alc883_cfg_tbl[] = {
8457         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
8458         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8459         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
8460         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8461         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8462         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8463         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
8464                 ALC888_ACER_ASPIRE_4930G),
8465         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
8466         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8467         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8468         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8469         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8470         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8471         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8472         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8473         SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
8474         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8475         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8476         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
8477         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8478         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8479         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
8480         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8481         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
8482         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8483         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8484         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8485         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8486         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8487         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8488         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8489         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8490         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8491         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8492         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8493         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8494         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8495         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8496         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8497         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8498         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8499         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8500         SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
8501         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8502         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8503         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8504         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8505         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8506         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8507         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8508         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
8509         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8510         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8511         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
8512         SND_PCI_QUIRK(0x1734, 0x113d, "Fujitsu AMILO Xa3530",
8513                 ALC888_FUJITSU_XA3530),
8514         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8515         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8516         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8517         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8518         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
8519         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8520         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
8521         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8522         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8523         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8524         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8525         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8526         {}
8527 };
8528
8529 static struct alc_config_preset alc883_presets[] = {
8530         [ALC883_3ST_2ch_DIG] = {
8531                 .mixers = { alc883_3ST_2ch_mixer },
8532                 .init_verbs = { alc883_init_verbs },
8533                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8534                 .dac_nids = alc883_dac_nids,
8535                 .dig_out_nid = ALC883_DIGOUT_NID,
8536                 .dig_in_nid = ALC883_DIGIN_NID,
8537                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8538                 .channel_mode = alc883_3ST_2ch_modes,
8539                 .input_mux = &alc883_capture_source,
8540         },
8541         [ALC883_3ST_6ch_DIG] = {
8542                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8543                 .init_verbs = { alc883_init_verbs },
8544                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8545                 .dac_nids = alc883_dac_nids,
8546                 .dig_out_nid = ALC883_DIGOUT_NID,
8547                 .dig_in_nid = ALC883_DIGIN_NID,
8548                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8549                 .channel_mode = alc883_3ST_6ch_modes,
8550                 .need_dac_fix = 1,
8551                 .input_mux = &alc883_capture_source,
8552         },
8553         [ALC883_3ST_6ch] = {
8554                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8555                 .init_verbs = { alc883_init_verbs },
8556                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8557                 .dac_nids = alc883_dac_nids,
8558                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8559                 .channel_mode = alc883_3ST_6ch_modes,
8560                 .need_dac_fix = 1,
8561                 .input_mux = &alc883_capture_source,
8562         },
8563         [ALC883_3ST_6ch_INTEL] = {
8564                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
8565                 .init_verbs = { alc883_init_verbs },
8566                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8567                 .dac_nids = alc883_dac_nids,
8568                 .dig_out_nid = ALC883_DIGOUT_NID,
8569                 .dig_in_nid = ALC883_DIGIN_NID,
8570                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
8571                 .channel_mode = alc883_3ST_6ch_intel_modes,
8572                 .need_dac_fix = 1,
8573                 .input_mux = &alc883_3stack_6ch_intel,
8574         },
8575         [ALC883_6ST_DIG] = {
8576                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8577                 .init_verbs = { alc883_init_verbs },
8578                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8579                 .dac_nids = alc883_dac_nids,
8580                 .dig_out_nid = ALC883_DIGOUT_NID,
8581                 .dig_in_nid = ALC883_DIGIN_NID,
8582                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8583                 .channel_mode = alc883_sixstack_modes,
8584                 .input_mux = &alc883_capture_source,
8585         },
8586         [ALC883_TARGA_DIG] = {
8587                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
8588                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8589                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8590                 .dac_nids = alc883_dac_nids,
8591                 .dig_out_nid = ALC883_DIGOUT_NID,
8592                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8593                 .channel_mode = alc883_3ST_6ch_modes,
8594                 .need_dac_fix = 1,
8595                 .input_mux = &alc883_capture_source,
8596                 .unsol_event = alc883_tagra_unsol_event,
8597                 .init_hook = alc883_tagra_automute,
8598         },
8599         [ALC883_TARGA_2ch_DIG] = {
8600                 .mixers = { alc883_tagra_2ch_mixer},
8601                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8602                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8603                 .dac_nids = alc883_dac_nids,
8604                 .adc_nids = alc883_adc_nids_alt,
8605                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8606                 .dig_out_nid = ALC883_DIGOUT_NID,
8607                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8608                 .channel_mode = alc883_3ST_2ch_modes,
8609                 .input_mux = &alc883_capture_source,
8610                 .unsol_event = alc883_tagra_unsol_event,
8611                 .init_hook = alc883_tagra_automute,
8612         },
8613         [ALC883_ACER] = {
8614                 .mixers = { alc883_base_mixer },
8615                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
8616                  * and the headphone jack.  Turn this on and rely on the
8617                  * standard mute methods whenever the user wants to turn
8618                  * these outputs off.
8619                  */
8620                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
8621                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8622                 .dac_nids = alc883_dac_nids,
8623                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8624                 .channel_mode = alc883_3ST_2ch_modes,
8625                 .input_mux = &alc883_capture_source,
8626         },
8627         [ALC883_ACER_ASPIRE] = {
8628                 .mixers = { alc883_acer_aspire_mixer },
8629                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
8630                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8631                 .dac_nids = alc883_dac_nids,
8632                 .dig_out_nid = ALC883_DIGOUT_NID,
8633                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8634                 .channel_mode = alc883_3ST_2ch_modes,
8635                 .input_mux = &alc883_capture_source,
8636                 .unsol_event = alc883_acer_aspire_unsol_event,
8637                 .init_hook = alc883_acer_aspire_automute,
8638         },
8639         [ALC888_ACER_ASPIRE_4930G] = {
8640                 .mixers = { alc888_base_mixer,
8641                                 alc883_chmode_mixer },
8642                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
8643                                 alc888_acer_aspire_4930g_verbs },
8644                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8645                 .dac_nids = alc883_dac_nids,
8646                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
8647                 .adc_nids = alc883_adc_nids_rev,
8648                 .capsrc_nids = alc883_capsrc_nids_rev,
8649                 .dig_out_nid = ALC883_DIGOUT_NID,
8650                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8651                 .channel_mode = alc883_3ST_6ch_modes,
8652                 .need_dac_fix = 1,
8653                 .num_mux_defs =
8654                         ARRAY_SIZE(alc888_2_capture_sources),
8655                 .input_mux = alc888_2_capture_sources,
8656                 .unsol_event = alc888_acer_aspire_4930g_unsol_event,
8657                 .init_hook = alc888_acer_aspire_4930g_automute,
8658         },
8659         [ALC883_MEDION] = {
8660                 .mixers = { alc883_fivestack_mixer,
8661                             alc883_chmode_mixer },
8662                 .init_verbs = { alc883_init_verbs,
8663                                 alc883_medion_eapd_verbs },
8664                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8665                 .dac_nids = alc883_dac_nids,
8666                 .adc_nids = alc883_adc_nids_alt,
8667                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8668                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8669                 .channel_mode = alc883_sixstack_modes,
8670                 .input_mux = &alc883_capture_source,
8671         },
8672         [ALC883_MEDION_MD2] = {
8673                 .mixers = { alc883_medion_md2_mixer},
8674                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
8675                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8676                 .dac_nids = alc883_dac_nids,
8677                 .dig_out_nid = ALC883_DIGOUT_NID,
8678                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8679                 .channel_mode = alc883_3ST_2ch_modes,
8680                 .input_mux = &alc883_capture_source,
8681                 .unsol_event = alc883_medion_md2_unsol_event,
8682                 .init_hook = alc883_medion_md2_automute,
8683         },
8684         [ALC883_LAPTOP_EAPD] = {
8685                 .mixers = { alc883_base_mixer },
8686                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
8687                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8688                 .dac_nids = alc883_dac_nids,
8689                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8690                 .channel_mode = alc883_3ST_2ch_modes,
8691                 .input_mux = &alc883_capture_source,
8692         },
8693         [ALC883_CLEVO_M720] = {
8694                 .mixers = { alc883_clevo_m720_mixer },
8695                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
8696                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8697                 .dac_nids = alc883_dac_nids,
8698                 .dig_out_nid = ALC883_DIGOUT_NID,
8699                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8700                 .channel_mode = alc883_3ST_2ch_modes,
8701                 .input_mux = &alc883_capture_source,
8702                 .unsol_event = alc883_clevo_m720_unsol_event,
8703                 .init_hook = alc883_clevo_m720_automute,
8704         },
8705         [ALC883_LENOVO_101E_2ch] = {
8706                 .mixers = { alc883_lenovo_101e_2ch_mixer},
8707                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
8708                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8709                 .dac_nids = alc883_dac_nids,
8710                 .adc_nids = alc883_adc_nids_alt,
8711                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8712                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8713                 .channel_mode = alc883_3ST_2ch_modes,
8714                 .input_mux = &alc883_lenovo_101e_capture_source,
8715                 .unsol_event = alc883_lenovo_101e_unsol_event,
8716                 .init_hook = alc883_lenovo_101e_all_automute,
8717         },
8718         [ALC883_LENOVO_NB0763] = {
8719                 .mixers = { alc883_lenovo_nb0763_mixer },
8720                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
8721                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8722                 .dac_nids = alc883_dac_nids,
8723                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8724                 .channel_mode = alc883_3ST_2ch_modes,
8725                 .need_dac_fix = 1,
8726                 .input_mux = &alc883_lenovo_nb0763_capture_source,
8727                 .unsol_event = alc883_medion_md2_unsol_event,
8728                 .init_hook = alc883_medion_md2_automute,
8729         },
8730         [ALC888_LENOVO_MS7195_DIG] = {
8731                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8732                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
8733                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8734                 .dac_nids = alc883_dac_nids,
8735                 .dig_out_nid = ALC883_DIGOUT_NID,
8736                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8737                 .channel_mode = alc883_3ST_6ch_modes,
8738                 .need_dac_fix = 1,
8739                 .input_mux = &alc883_capture_source,
8740                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
8741                 .init_hook = alc888_lenovo_ms7195_front_automute,
8742         },
8743         [ALC883_HAIER_W66] = {
8744                 .mixers = { alc883_tagra_2ch_mixer},
8745                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
8746                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8747                 .dac_nids = alc883_dac_nids,
8748                 .dig_out_nid = ALC883_DIGOUT_NID,
8749                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8750                 .channel_mode = alc883_3ST_2ch_modes,
8751                 .input_mux = &alc883_capture_source,
8752                 .unsol_event = alc883_haier_w66_unsol_event,
8753                 .init_hook = alc883_haier_w66_automute,
8754         },
8755         [ALC888_3ST_HP] = {
8756                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8757                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
8758                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8759                 .dac_nids = alc883_dac_nids,
8760                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
8761                 .channel_mode = alc888_3st_hp_modes,
8762                 .need_dac_fix = 1,
8763                 .input_mux = &alc883_capture_source,
8764         },
8765         [ALC888_6ST_DELL] = {
8766                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8767                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
8768                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8769                 .dac_nids = alc883_dac_nids,
8770                 .dig_out_nid = ALC883_DIGOUT_NID,
8771                 .dig_in_nid = ALC883_DIGIN_NID,
8772                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8773                 .channel_mode = alc883_sixstack_modes,
8774                 .input_mux = &alc883_capture_source,
8775                 .unsol_event = alc888_6st_dell_unsol_event,
8776                 .init_hook = alc888_6st_dell_front_automute,
8777         },
8778         [ALC883_MITAC] = {
8779                 .mixers = { alc883_mitac_mixer },
8780                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
8781                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8782                 .dac_nids = alc883_dac_nids,
8783                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8784                 .channel_mode = alc883_3ST_2ch_modes,
8785                 .input_mux = &alc883_capture_source,
8786                 .unsol_event = alc883_mitac_unsol_event,
8787                 .init_hook = alc883_mitac_automute,
8788         },
8789         [ALC883_FUJITSU_PI2515] = {
8790                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
8791                 .init_verbs = { alc883_init_verbs,
8792                                 alc883_2ch_fujitsu_pi2515_verbs},
8793                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8794                 .dac_nids = alc883_dac_nids,
8795                 .dig_out_nid = ALC883_DIGOUT_NID,
8796                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8797                 .channel_mode = alc883_3ST_2ch_modes,
8798                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8799                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8800                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8801         },
8802         [ALC888_FUJITSU_XA3530] = {
8803                 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
8804                 .init_verbs = { alc883_init_verbs,
8805                         alc888_fujitsu_xa3530_verbs },
8806                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8807                 .dac_nids = alc883_dac_nids,
8808                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
8809                 .adc_nids = alc883_adc_nids_rev,
8810                 .capsrc_nids = alc883_capsrc_nids_rev,
8811                 .dig_out_nid = ALC883_DIGOUT_NID,
8812                 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
8813                 .channel_mode = alc888_4ST_8ch_intel_modes,
8814                 .num_mux_defs =
8815                         ARRAY_SIZE(alc888_2_capture_sources),
8816                 .input_mux = alc888_2_capture_sources,
8817                 .unsol_event = alc888_fujitsu_xa3530_unsol_event,
8818                 .init_hook = alc888_fujitsu_xa3530_automute,
8819         },
8820         [ALC888_LENOVO_SKY] = {
8821                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
8822                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
8823                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8824                 .dac_nids = alc883_dac_nids,
8825                 .dig_out_nid = ALC883_DIGOUT_NID,
8826                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8827                 .channel_mode = alc883_sixstack_modes,
8828                 .need_dac_fix = 1,
8829                 .input_mux = &alc883_lenovo_sky_capture_source,
8830                 .unsol_event = alc883_lenovo_sky_unsol_event,
8831                 .init_hook = alc888_lenovo_sky_front_automute,
8832         },
8833         [ALC888_ASUS_M90V] = {
8834                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8835                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
8836                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8837                 .dac_nids = alc883_dac_nids,
8838                 .dig_out_nid = ALC883_DIGOUT_NID,
8839                 .dig_in_nid = ALC883_DIGIN_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_fujitsu_pi2515_capture_source,
8844                 .unsol_event = alc883_mode2_unsol_event,
8845                 .init_hook = alc883_mode2_inithook,
8846         },
8847         [ALC888_ASUS_EEE1601] = {
8848                 .mixers = { alc883_asus_eee1601_mixer },
8849                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
8850                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
8851                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8852                 .dac_nids = alc883_dac_nids,
8853                 .dig_out_nid = ALC883_DIGOUT_NID,
8854                 .dig_in_nid = ALC883_DIGIN_NID,
8855                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8856                 .channel_mode = alc883_3ST_2ch_modes,
8857                 .need_dac_fix = 1,
8858                 .input_mux = &alc883_asus_eee1601_capture_source,
8859                 .unsol_event = alc883_eee1601_unsol_event,
8860                 .init_hook = alc883_eee1601_inithook,
8861         },
8862         [ALC1200_ASUS_P5Q] = {
8863                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8864                 .init_verbs = { alc883_init_verbs },
8865                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8866                 .dac_nids = alc883_dac_nids,
8867                 .dig_out_nid = ALC1200_DIGOUT_NID,
8868                 .dig_in_nid = ALC883_DIGIN_NID,
8869                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8870                 .channel_mode = alc883_sixstack_modes,
8871                 .input_mux = &alc883_capture_source,
8872         },
8873 };
8874
8875
8876 /*
8877  * BIOS auto configuration
8878  */
8879 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
8880                                               hda_nid_t nid, int pin_type,
8881                                               int dac_idx)
8882 {
8883         /* set as output */
8884         struct alc_spec *spec = codec->spec;
8885         int idx;
8886
8887         alc_set_pin_output(codec, nid, pin_type);
8888         if (spec->multiout.dac_nids[dac_idx] == 0x25)
8889                 idx = 4;
8890         else
8891                 idx = spec->multiout.dac_nids[dac_idx] - 2;
8892         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
8893
8894 }
8895
8896 static void alc883_auto_init_multi_out(struct hda_codec *codec)
8897 {
8898         struct alc_spec *spec = codec->spec;
8899         int i;
8900
8901         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
8902         for (i = 0; i <= HDA_SIDE; i++) {
8903                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
8904                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
8905                 if (nid)
8906                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
8907                                                           i);
8908         }
8909 }
8910
8911 static void alc883_auto_init_hp_out(struct hda_codec *codec)
8912 {
8913         struct alc_spec *spec = codec->spec;
8914         hda_nid_t pin;
8915
8916         pin = spec->autocfg.hp_pins[0];
8917         if (pin) /* connect to front */
8918                 /* use dac 0 */
8919                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8920         pin = spec->autocfg.speaker_pins[0];
8921         if (pin)
8922                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
8923 }
8924
8925 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
8926 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
8927
8928 static void alc883_auto_init_analog_input(struct hda_codec *codec)
8929 {
8930         struct alc_spec *spec = codec->spec;
8931         int i;
8932
8933         for (i = 0; i < AUTO_PIN_LAST; i++) {
8934                 hda_nid_t nid = spec->autocfg.input_pins[i];
8935                 if (alc883_is_input_pin(nid)) {
8936                         snd_hda_codec_write(codec, nid, 0,
8937                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
8938                                             (i <= AUTO_PIN_FRONT_MIC ?
8939                                              PIN_VREF80 : PIN_IN));
8940                         if (nid != ALC883_PIN_CD_NID)
8941                                 snd_hda_codec_write(codec, nid, 0,
8942                                                     AC_VERB_SET_AMP_GAIN_MUTE,
8943                                                     AMP_OUT_MUTE);
8944                 }
8945         }
8946 }
8947
8948 #define alc883_auto_init_input_src      alc882_auto_init_input_src
8949
8950 /* almost identical with ALC880 parser... */
8951 static int alc883_parse_auto_config(struct hda_codec *codec)
8952 {
8953         struct alc_spec *spec = codec->spec;
8954         int err = alc880_parse_auto_config(codec);
8955
8956         if (err < 0)
8957                 return err;
8958         else if (!err)
8959                 return 0; /* no config found */
8960
8961         err = alc_auto_add_mic_boost(codec);
8962         if (err < 0)
8963                 return err;
8964
8965         /* hack - override the init verbs */
8966         spec->init_verbs[0] = alc883_auto_init_verbs;
8967
8968         return 1; /* config found */
8969 }
8970
8971 /* additional initialization for auto-configuration model */
8972 static void alc883_auto_init(struct hda_codec *codec)
8973 {
8974         struct alc_spec *spec = codec->spec;
8975         alc883_auto_init_multi_out(codec);
8976         alc883_auto_init_hp_out(codec);
8977         alc883_auto_init_analog_input(codec);
8978         alc883_auto_init_input_src(codec);
8979         if (spec->unsol_event)
8980                 alc_inithook(codec);
8981 }
8982
8983 static int patch_alc883(struct hda_codec *codec)
8984 {
8985         struct alc_spec *spec;
8986         int err, board_config;
8987
8988         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8989         if (spec == NULL)
8990                 return -ENOMEM;
8991
8992         codec->spec = spec;
8993
8994         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
8995
8996         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
8997                                                   alc883_models,
8998                                                   alc883_cfg_tbl);
8999         if (board_config < 0) {
9000                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
9001                        "trying auto-probe from BIOS...\n");
9002                 board_config = ALC883_AUTO;
9003         }
9004
9005         if (board_config == ALC883_AUTO) {
9006                 /* automatic parse from the BIOS config */
9007                 err = alc883_parse_auto_config(codec);
9008                 if (err < 0) {
9009                         alc_free(codec);
9010                         return err;
9011                 } else if (!err) {
9012                         printk(KERN_INFO
9013                                "hda_codec: Cannot set up configuration "
9014                                "from BIOS.  Using base mode...\n");
9015                         board_config = ALC883_3ST_2ch_DIG;
9016                 }
9017         }
9018
9019         if (board_config != ALC883_AUTO)
9020                 setup_preset(spec, &alc883_presets[board_config]);
9021
9022         switch (codec->vendor_id) {
9023         case 0x10ec0888:
9024                 if (codec->revision_id == 0x100101) {
9025                         spec->stream_name_analog = "ALC1200 Analog";
9026                         spec->stream_name_digital = "ALC1200 Digital";
9027                 } else {
9028                         spec->stream_name_analog = "ALC888 Analog";
9029                         spec->stream_name_digital = "ALC888 Digital";
9030                 }
9031                 break;
9032         case 0x10ec0889:
9033                 spec->stream_name_analog = "ALC889 Analog";
9034                 spec->stream_name_digital = "ALC889 Digital";
9035                 break;
9036         default:
9037                 spec->stream_name_analog = "ALC883 Analog";
9038                 spec->stream_name_digital = "ALC883 Digital";
9039                 break;
9040         }
9041
9042         spec->stream_analog_playback = &alc883_pcm_analog_playback;
9043         spec->stream_analog_capture = &alc883_pcm_analog_capture;
9044         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
9045
9046         spec->stream_digital_playback = &alc883_pcm_digital_playback;
9047         spec->stream_digital_capture = &alc883_pcm_digital_capture;
9048
9049         if (!spec->num_adc_nids) {
9050                 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9051                 spec->adc_nids = alc883_adc_nids;
9052         }
9053         if (!spec->capsrc_nids)
9054                 spec->capsrc_nids = alc883_capsrc_nids;
9055         spec->is_mix_capture = 1; /* matrix-style capture */
9056         if (!spec->cap_mixer)
9057                 set_capture_mixer(spec);
9058
9059         spec->vmaster_nid = 0x0c;
9060
9061         codec->patch_ops = alc_patch_ops;
9062         if (board_config == ALC883_AUTO)
9063                 spec->init_hook = alc883_auto_init;
9064
9065 #ifdef CONFIG_SND_HDA_POWER_SAVE
9066         if (!spec->loopback.amplist)
9067                 spec->loopback.amplist = alc883_loopbacks;
9068 #endif
9069         codec->proc_widget_hook = print_realtek_coef;
9070
9071         return 0;
9072 }
9073
9074 /*
9075  * ALC262 support
9076  */
9077
9078 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
9079 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
9080
9081 #define alc262_dac_nids         alc260_dac_nids
9082 #define alc262_adc_nids         alc882_adc_nids
9083 #define alc262_adc_nids_alt     alc882_adc_nids_alt
9084 #define alc262_capsrc_nids      alc882_capsrc_nids
9085 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
9086
9087 #define alc262_modes            alc260_modes
9088 #define alc262_capture_source   alc882_capture_source
9089
9090 static hda_nid_t alc262_dmic_adc_nids[1] = {
9091         /* ADC0 */
9092         0x09
9093 };
9094
9095 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
9096
9097 static struct snd_kcontrol_new alc262_base_mixer[] = {
9098         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9099         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9100         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9101         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9102         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9103         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9104         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9105         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9106         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9107         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9108         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9109         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9110         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9111            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
9112         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
9113         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9114         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9115         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
9116         { } /* end */
9117 };
9118
9119 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
9120         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9121         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9122         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9123         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9124         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9125         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9126         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9127         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9128         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9129         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9130         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9131         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9132         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9133            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
9134         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
9135         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9136         { } /* end */
9137 };
9138
9139 /* update HP, line and mono-out pins according to the master switch */
9140 static void alc262_hp_master_update(struct hda_codec *codec)
9141 {
9142         struct alc_spec *spec = codec->spec;
9143         int val = spec->master_sw;
9144
9145         /* HP & line-out */
9146         snd_hda_codec_write_cache(codec, 0x1b, 0,
9147                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9148                                   val ? PIN_HP : 0);
9149         snd_hda_codec_write_cache(codec, 0x15, 0,
9150                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9151                                   val ? PIN_HP : 0);
9152         /* mono (speaker) depending on the HP jack sense */
9153         val = val && !spec->jack_present;
9154         snd_hda_codec_write_cache(codec, 0x16, 0,
9155                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9156                                   val ? PIN_OUT : 0);
9157 }
9158
9159 static void alc262_hp_bpc_automute(struct hda_codec *codec)
9160 {
9161         struct alc_spec *spec = codec->spec;
9162         unsigned int presence;
9163         presence = snd_hda_codec_read(codec, 0x1b, 0,
9164                                       AC_VERB_GET_PIN_SENSE, 0);
9165         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9166         alc262_hp_master_update(codec);
9167 }
9168
9169 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
9170 {
9171         if ((res >> 26) != ALC880_HP_EVENT)
9172                 return;
9173         alc262_hp_bpc_automute(codec);
9174 }
9175
9176 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
9177 {
9178         struct alc_spec *spec = codec->spec;
9179         unsigned int presence;
9180         presence = snd_hda_codec_read(codec, 0x15, 0,
9181                                       AC_VERB_GET_PIN_SENSE, 0);
9182         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9183         alc262_hp_master_update(codec);
9184 }
9185
9186 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
9187                                            unsigned int res)
9188 {
9189         if ((res >> 26) != ALC880_HP_EVENT)
9190                 return;
9191         alc262_hp_wildwest_automute(codec);
9192 }
9193
9194 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
9195                                    struct snd_ctl_elem_value *ucontrol)
9196 {
9197         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9198         struct alc_spec *spec = codec->spec;
9199         *ucontrol->value.integer.value = spec->master_sw;
9200         return 0;
9201 }
9202
9203 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
9204                                    struct snd_ctl_elem_value *ucontrol)
9205 {
9206         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9207         struct alc_spec *spec = codec->spec;
9208         int val = !!*ucontrol->value.integer.value;
9209
9210         if (val == spec->master_sw)
9211                 return 0;
9212         spec->master_sw = val;
9213         alc262_hp_master_update(codec);
9214         return 1;
9215 }
9216
9217 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
9218         {
9219                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9220                 .name = "Master Playback Switch",
9221                 .info = snd_ctl_boolean_mono_info,
9222                 .get = alc262_hp_master_sw_get,
9223                 .put = alc262_hp_master_sw_put,
9224         },
9225         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9226         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9227         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9228         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9229                               HDA_OUTPUT),
9230         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9231                             HDA_OUTPUT),
9232         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9233         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9234         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9235         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9236         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9237         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9238         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9239         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9240         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9241         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9242         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9243         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9244         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
9245         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
9246         { } /* end */
9247 };
9248
9249 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
9250         {
9251                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9252                 .name = "Master Playback Switch",
9253                 .info = snd_ctl_boolean_mono_info,
9254                 .get = alc262_hp_master_sw_get,
9255                 .put = alc262_hp_master_sw_put,
9256         },
9257         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9258         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9259         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9260         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9261         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9262                               HDA_OUTPUT),
9263         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9264                             HDA_OUTPUT),
9265         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
9266         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
9267         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
9268         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9269         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9270         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9271         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9272         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9273         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9274         { } /* end */
9275 };
9276
9277 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
9278         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9279         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9280         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
9281         { } /* end */
9282 };
9283
9284 /* mute/unmute internal speaker according to the hp jack and mute state */
9285 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
9286 {
9287         struct alc_spec *spec = codec->spec;
9288
9289         if (force || !spec->sense_updated) {
9290                 unsigned int present;
9291                 present = snd_hda_codec_read(codec, 0x15, 0,
9292                                              AC_VERB_GET_PIN_SENSE, 0);
9293                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9294                 spec->sense_updated = 1;
9295         }
9296         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
9297                                  spec->jack_present ? HDA_AMP_MUTE : 0);
9298 }
9299
9300 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
9301                                         unsigned int res)
9302 {
9303         if ((res >> 26) != ALC880_HP_EVENT)
9304                 return;
9305         alc262_hp_t5735_automute(codec, 1);
9306 }
9307
9308 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
9309 {
9310         alc262_hp_t5735_automute(codec, 1);
9311 }
9312
9313 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
9314         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9315         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9316         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9317         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9318         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9319         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9320         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9321         { } /* end */
9322 };
9323
9324 static struct hda_verb alc262_hp_t5735_verbs[] = {
9325         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9326         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9327
9328         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9329         { }
9330 };
9331
9332 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
9333         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9334         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9335         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
9336         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
9337         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9338         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9339         { } /* end */
9340 };
9341
9342 static struct hda_verb alc262_hp_rp5700_verbs[] = {
9343         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9344         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9345         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9346         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9347         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9348         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9349         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9350         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9351         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9352         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9353         {}
9354 };
9355
9356 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
9357         .num_items = 1,
9358         .items = {
9359                 { "Line", 0x1 },
9360         },
9361 };
9362
9363 /* bind hp and internal speaker mute (with plug check) */
9364 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
9365                                      struct snd_ctl_elem_value *ucontrol)
9366 {
9367         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9368         long *valp = ucontrol->value.integer.value;
9369         int change;
9370
9371         /* change hp mute */
9372         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
9373                                           HDA_AMP_MUTE,
9374                                           valp[0] ? 0 : HDA_AMP_MUTE);
9375         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
9376                                            HDA_AMP_MUTE,
9377                                            valp[1] ? 0 : HDA_AMP_MUTE);
9378         if (change) {
9379                 /* change speaker according to HP jack state */
9380                 struct alc_spec *spec = codec->spec;
9381                 unsigned int mute;
9382                 if (spec->jack_present)
9383                         mute = HDA_AMP_MUTE;
9384                 else
9385                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
9386                                                       HDA_OUTPUT, 0);
9387                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9388                                          HDA_AMP_MUTE, mute);
9389         }
9390         return change;
9391 }
9392
9393 static struct snd_kcontrol_new alc262_sony_mixer[] = {
9394         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9395         {
9396                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9397                 .name = "Master Playback Switch",
9398                 .info = snd_hda_mixer_amp_switch_info,
9399                 .get = snd_hda_mixer_amp_switch_get,
9400                 .put = alc262_sony_master_sw_put,
9401                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9402         },
9403         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9404         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9405         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9406         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9407         { } /* end */
9408 };
9409
9410 static struct snd_kcontrol_new alc262_benq_t31_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_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9414         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9415         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9416         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9417         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9418         { } /* end */
9419 };
9420
9421 #define alc262_capture_mixer            alc882_capture_mixer
9422 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
9423
9424 /*
9425  * generic initialization of ADC, input mixers and output mixers
9426  */
9427 static struct hda_verb alc262_init_verbs[] = {
9428         /*
9429          * Unmute ADC0-2 and set the default input to mic-in
9430          */
9431         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9432         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9433         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9434         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9435         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9436         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9437
9438         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9439          * mixer widget
9440          * Note: PASD motherboards uses the Line In 2 as the input for
9441          * front panel mic (mic 2)
9442          */
9443         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9444         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9445         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9446         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9447         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9448         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9449
9450         /*
9451          * Set up output mixers (0x0c - 0x0e)
9452          */
9453         /* set vol=0 to output mixers */
9454         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9455         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9456         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9457         /* set up input amps for analog loopback */
9458         /* Amp Indices: DAC = 0, mixer = 1 */
9459         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9460         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9461         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9462         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9463         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9464         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9465
9466         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9467         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9468         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9469         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9470         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9471         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9472
9473         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9474         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9475         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9476         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9477         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9478
9479         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9480         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9481
9482         /* FIXME: use matrix-type input source selection */
9483         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9484         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9485         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9486         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9487         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9488         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9489         /* Input mixer2 */
9490         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9491         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9492         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9493         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9494         /* Input mixer3 */
9495         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9496         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9497         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9498         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9499
9500         { }
9501 };
9502
9503 static struct hda_verb alc262_eapd_verbs[] = {
9504         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9505         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9506         { }
9507 };
9508
9509 static struct hda_verb alc262_hippo_unsol_verbs[] = {
9510         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9511         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9512         {}
9513 };
9514
9515 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
9516         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9517         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9518         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9519
9520         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9521         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9522         {}
9523 };
9524
9525 static struct hda_verb alc262_sony_unsol_verbs[] = {
9526         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9527         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9528         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
9529
9530         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9531         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9532         {}
9533 };
9534
9535 static struct hda_input_mux alc262_dmic_capture_source = {
9536         .num_items = 2,
9537         .items = {
9538                 { "Int DMic", 0x9 },
9539                 { "Mic", 0x0 },
9540         },
9541 };
9542
9543 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
9544         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9545         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9546         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9547         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9548         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9549         { } /* end */
9550 };
9551
9552 static struct hda_verb alc262_toshiba_s06_verbs[] = {
9553         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9554         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9555         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9556         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9557         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
9558         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9559         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
9560         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9561         {}
9562 };
9563
9564 static void alc262_dmic_automute(struct hda_codec *codec)
9565 {
9566         unsigned int present;
9567
9568         present = snd_hda_codec_read(codec, 0x18, 0,
9569                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9570         snd_hda_codec_write(codec, 0x22, 0,
9571                                 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x09);
9572 }
9573
9574 /* toggle speaker-output according to the hp-jack state */
9575 static void alc262_toshiba_s06_speaker_automute(struct hda_codec *codec)
9576 {
9577         unsigned int present;
9578         unsigned char bits;
9579
9580         present = snd_hda_codec_read(codec, 0x15, 0,
9581                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9582         bits = present ? 0 : PIN_OUT;
9583         snd_hda_codec_write(codec, 0x14, 0,
9584                                         AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
9585 }
9586
9587
9588
9589 /* unsolicited event for HP jack sensing */
9590 static void alc262_toshiba_s06_unsol_event(struct hda_codec *codec,
9591                                        unsigned int res)
9592 {
9593         if ((res >> 26) == ALC880_HP_EVENT)
9594                 alc262_toshiba_s06_speaker_automute(codec);
9595         if ((res >> 26) == ALC880_MIC_EVENT)
9596                 alc262_dmic_automute(codec);
9597
9598 }
9599
9600 static void alc262_toshiba_s06_init_hook(struct hda_codec *codec)
9601 {
9602         alc262_toshiba_s06_speaker_automute(codec);
9603         alc262_dmic_automute(codec);
9604 }
9605
9606 /* mute/unmute internal speaker according to the hp jack and mute state */
9607 static void alc262_hippo_automute(struct hda_codec *codec)
9608 {
9609         struct alc_spec *spec = codec->spec;
9610         unsigned int mute;
9611         unsigned int present;
9612
9613         /* need to execute and sync at first */
9614         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9615         present = snd_hda_codec_read(codec, 0x15, 0,
9616                                      AC_VERB_GET_PIN_SENSE, 0);
9617         spec->jack_present = (present & 0x80000000) != 0;
9618         if (spec->jack_present) {
9619                 /* mute internal speaker */
9620                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9621                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9622         } else {
9623                 /* unmute internal speaker if necessary */
9624                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
9625                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9626                                          HDA_AMP_MUTE, mute);
9627         }
9628 }
9629
9630 /* unsolicited event for HP jack sensing */
9631 static void alc262_hippo_unsol_event(struct hda_codec *codec,
9632                                        unsigned int res)
9633 {
9634         if ((res >> 26) != ALC880_HP_EVENT)
9635                 return;
9636         alc262_hippo_automute(codec);
9637 }
9638
9639 static void alc262_hippo1_automute(struct hda_codec *codec)
9640 {
9641         unsigned int mute;
9642         unsigned int present;
9643
9644         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9645         present = snd_hda_codec_read(codec, 0x1b, 0,
9646                                      AC_VERB_GET_PIN_SENSE, 0);
9647         present = (present & 0x80000000) != 0;
9648         if (present) {
9649                 /* mute internal speaker */
9650                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9651                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9652         } else {
9653                 /* unmute internal speaker if necessary */
9654                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9655                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9656                                          HDA_AMP_MUTE, mute);
9657         }
9658 }
9659
9660 /* unsolicited event for HP jack sensing */
9661 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
9662                                        unsigned int res)
9663 {
9664         if ((res >> 26) != ALC880_HP_EVENT)
9665                 return;
9666         alc262_hippo1_automute(codec);
9667 }
9668
9669 /*
9670  * nec model
9671  *  0x15 = headphone
9672  *  0x16 = internal speaker
9673  *  0x18 = external mic
9674  */
9675
9676 static struct snd_kcontrol_new alc262_nec_mixer[] = {
9677         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9678         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
9679
9680         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9681         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9682         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9683
9684         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9685         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9686         { } /* end */
9687 };
9688
9689 static struct hda_verb alc262_nec_verbs[] = {
9690         /* Unmute Speaker */
9691         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9692
9693         /* Headphone */
9694         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9695         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9696
9697         /* External mic to headphone */
9698         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9699         /* External mic to speaker */
9700         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9701         {}
9702 };
9703
9704 /*
9705  * fujitsu model
9706  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
9707  *  0x1b = port replicator headphone out
9708  */
9709
9710 #define ALC_HP_EVENT    0x37
9711
9712 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
9713         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9714         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9715         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9716         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9717         {}
9718 };
9719
9720 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
9721         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9722         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9723         {}
9724 };
9725
9726 static struct hda_input_mux alc262_fujitsu_capture_source = {
9727         .num_items = 3,
9728         .items = {
9729                 { "Mic", 0x0 },
9730                 { "Int Mic", 0x1 },
9731                 { "CD", 0x4 },
9732         },
9733 };
9734
9735 static struct hda_input_mux alc262_HP_capture_source = {
9736         .num_items = 5,
9737         .items = {
9738                 { "Mic", 0x0 },
9739                 { "Front Mic", 0x1 },
9740                 { "Line", 0x2 },
9741                 { "CD", 0x4 },
9742                 { "AUX IN", 0x6 },
9743         },
9744 };
9745
9746 static struct hda_input_mux alc262_HP_D7000_capture_source = {
9747         .num_items = 4,
9748         .items = {
9749                 { "Mic", 0x0 },
9750                 { "Front Mic", 0x2 },
9751                 { "Line", 0x1 },
9752                 { "CD", 0x4 },
9753         },
9754 };
9755
9756 /* mute/unmute internal speaker according to the hp jacks and mute state */
9757 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
9758 {
9759         struct alc_spec *spec = codec->spec;
9760         unsigned int mute;
9761
9762         if (force || !spec->sense_updated) {
9763                 unsigned int present;
9764                 /* need to execute and sync at first */
9765                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
9766                 /* check laptop HP jack */
9767                 present = snd_hda_codec_read(codec, 0x14, 0,
9768                                              AC_VERB_GET_PIN_SENSE, 0);
9769                 /* need to execute and sync at first */
9770                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9771                 /* check docking HP jack */
9772                 present |= snd_hda_codec_read(codec, 0x1b, 0,
9773                                               AC_VERB_GET_PIN_SENSE, 0);
9774                 if (present & AC_PINSENSE_PRESENCE)
9775                         spec->jack_present = 1;
9776                 else
9777                         spec->jack_present = 0;
9778                 spec->sense_updated = 1;
9779         }
9780         /* unmute internal speaker only if both HPs are unplugged and
9781          * master switch is on
9782          */
9783         if (spec->jack_present)
9784                 mute = HDA_AMP_MUTE;
9785         else
9786                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9787         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9788                                  HDA_AMP_MUTE, mute);
9789 }
9790
9791 /* unsolicited event for HP jack sensing */
9792 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
9793                                        unsigned int res)
9794 {
9795         if ((res >> 26) != ALC_HP_EVENT)
9796                 return;
9797         alc262_fujitsu_automute(codec, 1);
9798 }
9799
9800 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
9801 {
9802         alc262_fujitsu_automute(codec, 1);
9803 }
9804
9805 /* bind volumes of both NID 0x0c and 0x0d */
9806 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
9807         .ops = &snd_hda_bind_vol,
9808         .values = {
9809                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
9810                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
9811                 0
9812         },
9813 };
9814
9815 /* mute/unmute internal speaker according to the hp jack and mute state */
9816 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
9817 {
9818         struct alc_spec *spec = codec->spec;
9819         unsigned int mute;
9820
9821         if (force || !spec->sense_updated) {
9822                 unsigned int present_int_hp;
9823                 /* need to execute and sync at first */
9824                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9825                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
9826                                         AC_VERB_GET_PIN_SENSE, 0);
9827                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
9828                 spec->sense_updated = 1;
9829         }
9830         if (spec->jack_present) {
9831                 /* mute internal speaker */
9832                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9833                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9834                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9835                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9836         } else {
9837                 /* unmute internal speaker if necessary */
9838                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9839                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9840                                          HDA_AMP_MUTE, mute);
9841                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9842                                          HDA_AMP_MUTE, mute);
9843         }
9844 }
9845
9846 /* unsolicited event for HP jack sensing */
9847 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
9848                                        unsigned int res)
9849 {
9850         if ((res >> 26) != ALC_HP_EVENT)
9851                 return;
9852         alc262_lenovo_3000_automute(codec, 1);
9853 }
9854
9855 /* bind hp and internal speaker mute (with plug check) */
9856 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
9857                                          struct snd_ctl_elem_value *ucontrol)
9858 {
9859         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9860         long *valp = ucontrol->value.integer.value;
9861         int change;
9862
9863         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9864                                                  HDA_AMP_MUTE,
9865                                                  valp ? 0 : HDA_AMP_MUTE);
9866         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9867                                                  HDA_AMP_MUTE,
9868                                                  valp ? 0 : HDA_AMP_MUTE);
9869
9870         if (change)
9871                 alc262_fujitsu_automute(codec, 0);
9872         return change;
9873 }
9874
9875 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
9876         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9877         {
9878                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9879                 .name = "Master Playback Switch",
9880                 .info = snd_hda_mixer_amp_switch_info,
9881                 .get = snd_hda_mixer_amp_switch_get,
9882                 .put = alc262_fujitsu_master_sw_put,
9883                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9884         },
9885         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9886         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9887         HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
9888         HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
9889         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9890         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9891         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9892         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9893         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9894         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9895         { } /* end */
9896 };
9897
9898 /* bind hp and internal speaker mute (with plug check) */
9899 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
9900                                          struct snd_ctl_elem_value *ucontrol)
9901 {
9902         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9903         long *valp = ucontrol->value.integer.value;
9904         int change;
9905
9906         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9907                                                  HDA_AMP_MUTE,
9908                                                  valp ? 0 : HDA_AMP_MUTE);
9909
9910         if (change)
9911                 alc262_lenovo_3000_automute(codec, 0);
9912         return change;
9913 }
9914
9915 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
9916         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9917         {
9918                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9919                 .name = "Master Playback Switch",
9920                 .info = snd_hda_mixer_amp_switch_info,
9921                 .get = snd_hda_mixer_amp_switch_get,
9922                 .put = alc262_lenovo_3000_master_sw_put,
9923                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
9924         },
9925         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9926         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9927         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9928         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9929         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9930         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9931         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9932         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9933         { } /* end */
9934 };
9935
9936 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
9937         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9938         {
9939                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9940                 .name = "Master Playback Switch",
9941                 .info = snd_hda_mixer_amp_switch_info,
9942                 .get = snd_hda_mixer_amp_switch_get,
9943                 .put = alc262_sony_master_sw_put,
9944                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9945         },
9946         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9947         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9948         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9949         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9950         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9951         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9952         { } /* end */
9953 };
9954
9955 /* additional init verbs for Benq laptops */
9956 static struct hda_verb alc262_EAPD_verbs[] = {
9957         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9958         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
9959         {}
9960 };
9961
9962 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
9963         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9964         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9965
9966         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9967         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
9968         {}
9969 };
9970
9971 /* Samsung Q1 Ultra Vista model setup */
9972 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
9973         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9974         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
9975         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9976         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9977         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
9978         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
9979         { } /* end */
9980 };
9981
9982 static struct hda_verb alc262_ultra_verbs[] = {
9983         /* output mixer */
9984         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9985         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9986         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9987         /* speaker */
9988         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9989         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9990         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9991         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9992         /* HP */
9993         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9994         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9995         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9996         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9997         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9998         /* internal mic */
9999         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10000         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10001         /* ADC, choose mic */
10002         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10003         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10004         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10005         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10006         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10007         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10008         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10009         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10010         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10011         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
10012         {}
10013 };
10014
10015 /* mute/unmute internal speaker according to the hp jack and mute state */
10016 static void alc262_ultra_automute(struct hda_codec *codec)
10017 {
10018         struct alc_spec *spec = codec->spec;
10019         unsigned int mute;
10020
10021         mute = 0;
10022         /* auto-mute only when HP is used as HP */
10023         if (!spec->cur_mux[0]) {
10024                 unsigned int present;
10025                 /* need to execute and sync at first */
10026                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10027                 present = snd_hda_codec_read(codec, 0x15, 0,
10028                                              AC_VERB_GET_PIN_SENSE, 0);
10029                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10030                 if (spec->jack_present)
10031                         mute = HDA_AMP_MUTE;
10032         }
10033         /* mute/unmute internal speaker */
10034         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10035                                  HDA_AMP_MUTE, mute);
10036         /* mute/unmute HP */
10037         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10038                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
10039 }
10040
10041 /* unsolicited event for HP jack sensing */
10042 static void alc262_ultra_unsol_event(struct hda_codec *codec,
10043                                        unsigned int res)
10044 {
10045         if ((res >> 26) != ALC880_HP_EVENT)
10046                 return;
10047         alc262_ultra_automute(codec);
10048 }
10049
10050 static struct hda_input_mux alc262_ultra_capture_source = {
10051         .num_items = 2,
10052         .items = {
10053                 { "Mic", 0x1 },
10054                 { "Headphone", 0x7 },
10055         },
10056 };
10057
10058 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
10059                                      struct snd_ctl_elem_value *ucontrol)
10060 {
10061         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10062         struct alc_spec *spec = codec->spec;
10063         int ret;
10064
10065         ret = alc_mux_enum_put(kcontrol, ucontrol);
10066         if (!ret)
10067                 return 0;
10068         /* reprogram the HP pin as mic or HP according to the input source */
10069         snd_hda_codec_write_cache(codec, 0x15, 0,
10070                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10071                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
10072         alc262_ultra_automute(codec); /* mute/unmute HP */
10073         return ret;
10074 }
10075
10076 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10077         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10078         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10079         {
10080                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10081                 .name = "Capture Source",
10082                 .info = alc_mux_enum_info,
10083                 .get = alc_mux_enum_get,
10084                 .put = alc262_ultra_mux_enum_put,
10085         },
10086         { } /* end */
10087 };
10088
10089 /* add playback controls from the parsed DAC table */
10090 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
10091                                              const struct auto_pin_cfg *cfg)
10092 {
10093         hda_nid_t nid;
10094         int err;
10095
10096         spec->multiout.num_dacs = 1;    /* only use one dac */
10097         spec->multiout.dac_nids = spec->private_dac_nids;
10098         spec->multiout.dac_nids[0] = 2;
10099
10100         nid = cfg->line_out_pins[0];
10101         if (nid) {
10102                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10103                                   "Front Playback Volume",
10104                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
10105                 if (err < 0)
10106                         return err;
10107                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10108                                   "Front Playback Switch",
10109                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
10110                 if (err < 0)
10111                         return err;
10112         }
10113
10114         nid = cfg->speaker_pins[0];
10115         if (nid) {
10116                 if (nid == 0x16) {
10117                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10118                                           "Speaker Playback Volume",
10119                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10120                                                               HDA_OUTPUT));
10121                         if (err < 0)
10122                                 return err;
10123                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10124                                           "Speaker Playback Switch",
10125                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10126                                                               HDA_OUTPUT));
10127                         if (err < 0)
10128                                 return err;
10129                 } else {
10130                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10131                                           "Speaker Playback Switch",
10132                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10133                                                               HDA_OUTPUT));
10134                         if (err < 0)
10135                                 return err;
10136                 }
10137         }
10138         nid = cfg->hp_pins[0];
10139         if (nid) {
10140                 /* spec->multiout.hp_nid = 2; */
10141                 if (nid == 0x16) {
10142                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10143                                           "Headphone Playback Volume",
10144                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10145                                                               HDA_OUTPUT));
10146                         if (err < 0)
10147                                 return err;
10148                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10149                                           "Headphone Playback Switch",
10150                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10151                                                               HDA_OUTPUT));
10152                         if (err < 0)
10153                                 return err;
10154                 } else {
10155                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10156                                           "Headphone Playback Switch",
10157                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10158                                                               HDA_OUTPUT));
10159                         if (err < 0)
10160                                 return err;
10161                 }
10162         }
10163         return 0;
10164 }
10165
10166 /* identical with ALC880 */
10167 #define alc262_auto_create_analog_input_ctls \
10168         alc880_auto_create_analog_input_ctls
10169
10170 /*
10171  * generic initialization of ADC, input mixers and output mixers
10172  */
10173 static struct hda_verb alc262_volume_init_verbs[] = {
10174         /*
10175          * Unmute ADC0-2 and set the default input to mic-in
10176          */
10177         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10178         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10179         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10180         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10181         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10182         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10183
10184         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10185          * mixer widget
10186          * Note: PASD motherboards uses the Line In 2 as the input for
10187          * front panel mic (mic 2)
10188          */
10189         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10190         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10191         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10192         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10193         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10194         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10195
10196         /*
10197          * Set up output mixers (0x0c - 0x0f)
10198          */
10199         /* set vol=0 to output mixers */
10200         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10201         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10202         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10203
10204         /* set up input amps for analog loopback */
10205         /* Amp Indices: DAC = 0, mixer = 1 */
10206         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10207         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10208         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10209         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10210         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10211         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10212
10213         /* FIXME: use matrix-type input source selection */
10214         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10215         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10216         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10217         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10218         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10219         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10220         /* Input mixer2 */
10221         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10222         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10223         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10224         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10225         /* Input mixer3 */
10226         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10227         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10228         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10229         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10230
10231         { }
10232 };
10233
10234 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
10235         /*
10236          * Unmute ADC0-2 and set the default input to mic-in
10237          */
10238         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10239         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10240         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10241         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10242         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10243         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10244
10245         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10246          * mixer widget
10247          * Note: PASD motherboards uses the Line In 2 as the input for
10248          * front panel mic (mic 2)
10249          */
10250         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10251         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10252         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10253         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10254         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10255         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10256         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10257         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10258
10259         /*
10260          * Set up output mixers (0x0c - 0x0e)
10261          */
10262         /* set vol=0 to output mixers */
10263         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10264         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10265         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10266
10267         /* set up input amps for analog loopback */
10268         /* Amp Indices: DAC = 0, mixer = 1 */
10269         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10270         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10271         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10272         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10273         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10274         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10275
10276         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10277         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10278         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10279
10280         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10281         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10282
10283         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10284         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10285
10286         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10287         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10288         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10289         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10290         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10291
10292         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10293         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10294         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10295         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10296         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10297         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10298
10299
10300         /* FIXME: use matrix-type input source selection */
10301         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10302         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10303         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10304         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10305         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10306         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10307         /* Input mixer2 */
10308         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10309         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10310         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10311         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10312         /* Input mixer3 */
10313         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10314         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10315         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10316         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10317
10318         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10319
10320         { }
10321 };
10322
10323 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
10324         /*
10325          * Unmute ADC0-2 and set the default input to mic-in
10326          */
10327         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10328         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10329         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10330         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10331         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10332         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10333
10334         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10335          * mixer widget
10336          * Note: PASD motherboards uses the Line In 2 as the input for front
10337          * panel mic (mic 2)
10338          */
10339         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10340         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10341         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10342         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10343         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10344         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10345         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10346         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10347         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10348         /*
10349          * Set up output mixers (0x0c - 0x0e)
10350          */
10351         /* set vol=0 to output mixers */
10352         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10353         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10354         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10355
10356         /* set up input amps for analog loopback */
10357         /* Amp Indices: DAC = 0, mixer = 1 */
10358         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10359         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10360         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10361         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10362         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10363         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10364
10365
10366         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
10367         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
10368         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
10369         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
10370         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10371         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
10372         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
10373
10374         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10375         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10376
10377         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10378         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10379
10380         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
10381         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10382         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10383         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10384         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10385         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10386
10387         /* FIXME: use matrix-type input source selection */
10388         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10389         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10390         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
10391         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
10392         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
10393         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
10394         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
10395         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
10396         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
10397         /* Input mixer2 */
10398         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10399         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10400         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10401         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10402         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10403         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10404         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10405         /* Input mixer3 */
10406         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10407         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10408         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10409         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10410         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10411         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10412         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10413
10414         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10415
10416         { }
10417 };
10418
10419 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
10420
10421         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
10422         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10423         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
10424
10425         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
10426         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10427         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10428         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10429
10430         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
10431         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10432         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10433         {}
10434 };
10435
10436
10437 #ifdef CONFIG_SND_HDA_POWER_SAVE
10438 #define alc262_loopbacks        alc880_loopbacks
10439 #endif
10440
10441 /* pcm configuration: identiacal with ALC880 */
10442 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
10443 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
10444 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
10445 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
10446
10447 /*
10448  * BIOS auto configuration
10449  */
10450 static int alc262_parse_auto_config(struct hda_codec *codec)
10451 {
10452         struct alc_spec *spec = codec->spec;
10453         int err;
10454         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
10455
10456         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10457                                            alc262_ignore);
10458         if (err < 0)
10459                 return err;
10460         if (!spec->autocfg.line_outs)
10461                 return 0; /* can't find valid BIOS pin config */
10462         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
10463         if (err < 0)
10464                 return err;
10465         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
10466         if (err < 0)
10467                 return err;
10468
10469         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10470
10471         if (spec->autocfg.dig_out_pin)
10472                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
10473         if (spec->autocfg.dig_in_pin)
10474                 spec->dig_in_nid = ALC262_DIGIN_NID;
10475
10476         if (spec->kctls.list)
10477                 add_mixer(spec, spec->kctls.list);
10478
10479         add_verb(spec, alc262_volume_init_verbs);
10480         spec->num_mux_defs = 1;
10481         spec->input_mux = &spec->private_imux;
10482
10483         err = alc_auto_add_mic_boost(codec);
10484         if (err < 0)
10485                 return err;
10486
10487         store_pin_configs(codec);
10488         return 1;
10489 }
10490
10491 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
10492 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
10493 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
10494 #define alc262_auto_init_input_src      alc882_auto_init_input_src
10495
10496
10497 /* init callback for auto-configuration model -- overriding the default init */
10498 static void alc262_auto_init(struct hda_codec *codec)
10499 {
10500         struct alc_spec *spec = codec->spec;
10501         alc262_auto_init_multi_out(codec);
10502         alc262_auto_init_hp_out(codec);
10503         alc262_auto_init_analog_input(codec);
10504         alc262_auto_init_input_src(codec);
10505         if (spec->unsol_event)
10506                 alc_inithook(codec);
10507 }
10508
10509 /*
10510  * configuration and preset
10511  */
10512 static const char *alc262_models[ALC262_MODEL_LAST] = {
10513         [ALC262_BASIC]          = "basic",
10514         [ALC262_HIPPO]          = "hippo",
10515         [ALC262_HIPPO_1]        = "hippo_1",
10516         [ALC262_FUJITSU]        = "fujitsu",
10517         [ALC262_HP_BPC]         = "hp-bpc",
10518         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
10519         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
10520         [ALC262_HP_RP5700]      = "hp-rp5700",
10521         [ALC262_BENQ_ED8]       = "benq",
10522         [ALC262_BENQ_T31]       = "benq-t31",
10523         [ALC262_SONY_ASSAMD]    = "sony-assamd",
10524         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
10525         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
10526         [ALC262_ULTRA]          = "ultra",
10527         [ALC262_LENOVO_3000]    = "lenovo-3000",
10528         [ALC262_NEC]            = "nec",
10529         [ALC262_AUTO]           = "auto",
10530 };
10531
10532 static struct snd_pci_quirk alc262_cfg_tbl[] = {
10533         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
10534         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
10535         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
10536         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
10537         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
10538         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
10539         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
10540         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
10541         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
10542         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
10543         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
10544         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
10545         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
10546         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
10547         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
10548         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
10549         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
10550         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
10551         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
10552         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
10553         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
10554         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
10555                       ALC262_HP_TC_T5735),
10556         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
10557         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10558         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
10559         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10560         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10561         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
10562         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
10563                       ALC262_TOSHIBA_RX1),
10564         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
10565         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
10566         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
10567         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
10568         SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
10569         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
10570         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
10571         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
10572         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
10573         {}
10574 };
10575
10576 static struct alc_config_preset alc262_presets[] = {
10577         [ALC262_BASIC] = {
10578                 .mixers = { alc262_base_mixer },
10579                 .init_verbs = { alc262_init_verbs },
10580                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10581                 .dac_nids = alc262_dac_nids,
10582                 .hp_nid = 0x03,
10583                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10584                 .channel_mode = alc262_modes,
10585                 .input_mux = &alc262_capture_source,
10586         },
10587         [ALC262_HIPPO] = {
10588                 .mixers = { alc262_base_mixer },
10589                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
10590                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10591                 .dac_nids = alc262_dac_nids,
10592                 .hp_nid = 0x03,
10593                 .dig_out_nid = ALC262_DIGOUT_NID,
10594                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10595                 .channel_mode = alc262_modes,
10596                 .input_mux = &alc262_capture_source,
10597                 .unsol_event = alc262_hippo_unsol_event,
10598                 .init_hook = alc262_hippo_automute,
10599         },
10600         [ALC262_HIPPO_1] = {
10601                 .mixers = { alc262_hippo1_mixer },
10602                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
10603                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10604                 .dac_nids = alc262_dac_nids,
10605                 .hp_nid = 0x02,
10606                 .dig_out_nid = ALC262_DIGOUT_NID,
10607                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10608                 .channel_mode = alc262_modes,
10609                 .input_mux = &alc262_capture_source,
10610                 .unsol_event = alc262_hippo1_unsol_event,
10611                 .init_hook = alc262_hippo1_automute,
10612         },
10613         [ALC262_FUJITSU] = {
10614                 .mixers = { alc262_fujitsu_mixer },
10615                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10616                                 alc262_fujitsu_unsol_verbs },
10617                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10618                 .dac_nids = alc262_dac_nids,
10619                 .hp_nid = 0x03,
10620                 .dig_out_nid = ALC262_DIGOUT_NID,
10621                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10622                 .channel_mode = alc262_modes,
10623                 .input_mux = &alc262_fujitsu_capture_source,
10624                 .unsol_event = alc262_fujitsu_unsol_event,
10625                 .init_hook = alc262_fujitsu_init_hook,
10626         },
10627         [ALC262_HP_BPC] = {
10628                 .mixers = { alc262_HP_BPC_mixer },
10629                 .init_verbs = { alc262_HP_BPC_init_verbs },
10630                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10631                 .dac_nids = alc262_dac_nids,
10632                 .hp_nid = 0x03,
10633                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10634                 .channel_mode = alc262_modes,
10635                 .input_mux = &alc262_HP_capture_source,
10636                 .unsol_event = alc262_hp_bpc_unsol_event,
10637                 .init_hook = alc262_hp_bpc_automute,
10638         },
10639         [ALC262_HP_BPC_D7000_WF] = {
10640                 .mixers = { alc262_HP_BPC_WildWest_mixer },
10641                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10642                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10643                 .dac_nids = alc262_dac_nids,
10644                 .hp_nid = 0x03,
10645                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10646                 .channel_mode = alc262_modes,
10647                 .input_mux = &alc262_HP_D7000_capture_source,
10648                 .unsol_event = alc262_hp_wildwest_unsol_event,
10649                 .init_hook = alc262_hp_wildwest_automute,
10650         },
10651         [ALC262_HP_BPC_D7000_WL] = {
10652                 .mixers = { alc262_HP_BPC_WildWest_mixer,
10653                             alc262_HP_BPC_WildWest_option_mixer },
10654                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10655                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10656                 .dac_nids = alc262_dac_nids,
10657                 .hp_nid = 0x03,
10658                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10659                 .channel_mode = alc262_modes,
10660                 .input_mux = &alc262_HP_D7000_capture_source,
10661                 .unsol_event = alc262_hp_wildwest_unsol_event,
10662                 .init_hook = alc262_hp_wildwest_automute,
10663         },
10664         [ALC262_HP_TC_T5735] = {
10665                 .mixers = { alc262_hp_t5735_mixer },
10666                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
10667                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10668                 .dac_nids = alc262_dac_nids,
10669                 .hp_nid = 0x03,
10670                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10671                 .channel_mode = alc262_modes,
10672                 .input_mux = &alc262_capture_source,
10673                 .unsol_event = alc262_hp_t5735_unsol_event,
10674                 .init_hook = alc262_hp_t5735_init_hook,
10675         },
10676         [ALC262_HP_RP5700] = {
10677                 .mixers = { alc262_hp_rp5700_mixer },
10678                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
10679                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10680                 .dac_nids = alc262_dac_nids,
10681                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10682                 .channel_mode = alc262_modes,
10683                 .input_mux = &alc262_hp_rp5700_capture_source,
10684         },
10685         [ALC262_BENQ_ED8] = {
10686                 .mixers = { alc262_base_mixer },
10687                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
10688                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10689                 .dac_nids = alc262_dac_nids,
10690                 .hp_nid = 0x03,
10691                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10692                 .channel_mode = alc262_modes,
10693                 .input_mux = &alc262_capture_source,
10694         },
10695         [ALC262_SONY_ASSAMD] = {
10696                 .mixers = { alc262_sony_mixer },
10697                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
10698                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10699                 .dac_nids = alc262_dac_nids,
10700                 .hp_nid = 0x02,
10701                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10702                 .channel_mode = alc262_modes,
10703                 .input_mux = &alc262_capture_source,
10704                 .unsol_event = alc262_hippo_unsol_event,
10705                 .init_hook = alc262_hippo_automute,
10706         },
10707         [ALC262_BENQ_T31] = {
10708                 .mixers = { alc262_benq_t31_mixer },
10709                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
10710                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10711                 .dac_nids = alc262_dac_nids,
10712                 .hp_nid = 0x03,
10713                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10714                 .channel_mode = alc262_modes,
10715                 .input_mux = &alc262_capture_source,
10716                 .unsol_event = alc262_hippo_unsol_event,
10717                 .init_hook = alc262_hippo_automute,
10718         },
10719         [ALC262_ULTRA] = {
10720                 .mixers = { alc262_ultra_mixer },
10721                 .cap_mixer = alc262_ultra_capture_mixer,
10722                 .init_verbs = { alc262_ultra_verbs },
10723                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10724                 .dac_nids = alc262_dac_nids,
10725                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10726                 .channel_mode = alc262_modes,
10727                 .input_mux = &alc262_ultra_capture_source,
10728                 .adc_nids = alc262_adc_nids, /* ADC0 */
10729                 .capsrc_nids = alc262_capsrc_nids,
10730                 .num_adc_nids = 1, /* single ADC */
10731                 .unsol_event = alc262_ultra_unsol_event,
10732                 .init_hook = alc262_ultra_automute,
10733         },
10734         [ALC262_LENOVO_3000] = {
10735                 .mixers = { alc262_lenovo_3000_mixer },
10736                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10737                                 alc262_lenovo_3000_unsol_verbs },
10738                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10739                 .dac_nids = alc262_dac_nids,
10740                 .hp_nid = 0x03,
10741                 .dig_out_nid = ALC262_DIGOUT_NID,
10742                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10743                 .channel_mode = alc262_modes,
10744                 .input_mux = &alc262_fujitsu_capture_source,
10745                 .unsol_event = alc262_lenovo_3000_unsol_event,
10746         },
10747         [ALC262_NEC] = {
10748                 .mixers = { alc262_nec_mixer },
10749                 .init_verbs = { alc262_nec_verbs },
10750                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10751                 .dac_nids = alc262_dac_nids,
10752                 .hp_nid = 0x03,
10753                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10754                 .channel_mode = alc262_modes,
10755                 .input_mux = &alc262_capture_source,
10756         },
10757         [ALC262_TOSHIBA_S06] = {
10758                 .mixers = { alc262_toshiba_s06_mixer },
10759                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
10760                                                         alc262_eapd_verbs },
10761                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10762                 .capsrc_nids = alc262_dmic_capsrc_nids,
10763                 .dac_nids = alc262_dac_nids,
10764                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
10765                 .dig_out_nid = ALC262_DIGOUT_NID,
10766                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10767                 .channel_mode = alc262_modes,
10768                 .input_mux = &alc262_dmic_capture_source,
10769                 .unsol_event = alc262_toshiba_s06_unsol_event,
10770                 .init_hook = alc262_toshiba_s06_init_hook,
10771         },
10772         [ALC262_TOSHIBA_RX1] = {
10773                 .mixers = { alc262_toshiba_rx1_mixer },
10774                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
10775                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10776                 .dac_nids = alc262_dac_nids,
10777                 .hp_nid = 0x03,
10778                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10779                 .channel_mode = alc262_modes,
10780                 .input_mux = &alc262_capture_source,
10781                 .unsol_event = alc262_hippo_unsol_event,
10782                 .init_hook = alc262_hippo_automute,
10783         },
10784 };
10785
10786 static int patch_alc262(struct hda_codec *codec)
10787 {
10788         struct alc_spec *spec;
10789         int board_config;
10790         int err;
10791
10792         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10793         if (spec == NULL)
10794                 return -ENOMEM;
10795
10796         codec->spec = spec;
10797 #if 0
10798         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
10799          * under-run
10800          */
10801         {
10802         int tmp;
10803         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10804         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
10805         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10806         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
10807         }
10808 #endif
10809
10810         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
10811
10812         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
10813                                                   alc262_models,
10814                                                   alc262_cfg_tbl);
10815
10816         if (board_config < 0) {
10817                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
10818                        "trying auto-probe from BIOS...\n");
10819                 board_config = ALC262_AUTO;
10820         }
10821
10822         if (board_config == ALC262_AUTO) {
10823                 /* automatic parse from the BIOS config */
10824                 err = alc262_parse_auto_config(codec);
10825                 if (err < 0) {
10826                         alc_free(codec);
10827                         return err;
10828                 } else if (!err) {
10829                         printk(KERN_INFO
10830                                "hda_codec: Cannot set up configuration "
10831                                "from BIOS.  Using base mode...\n");
10832                         board_config = ALC262_BASIC;
10833                 }
10834         }
10835
10836         if (board_config != ALC262_AUTO)
10837                 setup_preset(spec, &alc262_presets[board_config]);
10838
10839         spec->stream_name_analog = "ALC262 Analog";
10840         spec->stream_analog_playback = &alc262_pcm_analog_playback;
10841         spec->stream_analog_capture = &alc262_pcm_analog_capture;
10842
10843         spec->stream_name_digital = "ALC262 Digital";
10844         spec->stream_digital_playback = &alc262_pcm_digital_playback;
10845         spec->stream_digital_capture = &alc262_pcm_digital_capture;
10846
10847         spec->is_mix_capture = 1;
10848         if (!spec->adc_nids && spec->input_mux) {
10849                 /* check whether NID 0x07 is valid */
10850                 unsigned int wcap = get_wcaps(codec, 0x07);
10851
10852                 /* get type */
10853                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10854                 if (wcap != AC_WID_AUD_IN) {
10855                         spec->adc_nids = alc262_adc_nids_alt;
10856                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
10857                         spec->capsrc_nids = alc262_capsrc_nids_alt;
10858                 } else {
10859                         spec->adc_nids = alc262_adc_nids;
10860                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
10861                         spec->capsrc_nids = alc262_capsrc_nids;
10862                 }
10863         }
10864         if (!spec->cap_mixer)
10865                 set_capture_mixer(spec);
10866
10867         spec->vmaster_nid = 0x0c;
10868
10869         codec->patch_ops = alc_patch_ops;
10870         if (board_config == ALC262_AUTO)
10871                 spec->init_hook = alc262_auto_init;
10872 #ifdef CONFIG_SND_HDA_POWER_SAVE
10873         if (!spec->loopback.amplist)
10874                 spec->loopback.amplist = alc262_loopbacks;
10875 #endif
10876         codec->proc_widget_hook = print_realtek_coef;
10877
10878         return 0;
10879 }
10880
10881 /*
10882  *  ALC268 channel source setting (2 channel)
10883  */
10884 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
10885 #define alc268_modes            alc260_modes
10886
10887 static hda_nid_t alc268_dac_nids[2] = {
10888         /* front, hp */
10889         0x02, 0x03
10890 };
10891
10892 static hda_nid_t alc268_adc_nids[2] = {
10893         /* ADC0-1 */
10894         0x08, 0x07
10895 };
10896
10897 static hda_nid_t alc268_adc_nids_alt[1] = {
10898         /* ADC0 */
10899         0x08
10900 };
10901
10902 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
10903
10904 static struct snd_kcontrol_new alc268_base_mixer[] = {
10905         /* output mixer control */
10906         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10907         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10908         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10909         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10910         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10911         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10912         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10913         { }
10914 };
10915
10916 /* bind Beep switches of both NID 0x0f and 0x10 */
10917 static struct hda_bind_ctls alc268_bind_beep_sw = {
10918         .ops = &snd_hda_bind_sw,
10919         .values = {
10920                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
10921                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
10922                 0
10923         },
10924 };
10925
10926 static struct snd_kcontrol_new alc268_beep_mixer[] = {
10927         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
10928         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
10929         { }
10930 };
10931
10932 static struct hda_verb alc268_eapd_verbs[] = {
10933         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10934         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10935         { }
10936 };
10937
10938 /* Toshiba specific */
10939 #define alc268_toshiba_automute alc262_hippo_automute
10940
10941 static struct hda_verb alc268_toshiba_verbs[] = {
10942         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10943         { } /* end */
10944 };
10945
10946 static struct hda_input_mux alc268_acer_lc_capture_source = {
10947         .num_items = 2,
10948         .items = {
10949                 { "i-Mic", 0x6 },
10950                 { "E-Mic", 0x0 },
10951         },
10952 };
10953
10954 /* Acer specific */
10955 /* bind volumes of both NID 0x02 and 0x03 */
10956 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
10957         .ops = &snd_hda_bind_vol,
10958         .values = {
10959                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
10960                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
10961                 0
10962         },
10963 };
10964
10965 /* mute/unmute internal speaker according to the hp jack and mute state */
10966 static void alc268_acer_automute(struct hda_codec *codec, int force)
10967 {
10968         struct alc_spec *spec = codec->spec;
10969         unsigned int mute;
10970
10971         if (force || !spec->sense_updated) {
10972                 unsigned int present;
10973                 present = snd_hda_codec_read(codec, 0x14, 0,
10974                                          AC_VERB_GET_PIN_SENSE, 0);
10975                 spec->jack_present = (present & 0x80000000) != 0;
10976                 spec->sense_updated = 1;
10977         }
10978         if (spec->jack_present)
10979                 mute = HDA_AMP_MUTE; /* mute internal speaker */
10980         else /* unmute internal speaker if necessary */
10981                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10982         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10983                                  HDA_AMP_MUTE, mute);
10984 }
10985
10986
10987 /* bind hp and internal speaker mute (with plug check) */
10988 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
10989                                      struct snd_ctl_elem_value *ucontrol)
10990 {
10991         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10992         long *valp = ucontrol->value.integer.value;
10993         int change;
10994
10995         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
10996                                           HDA_AMP_MUTE,
10997                                           valp[0] ? 0 : HDA_AMP_MUTE);
10998         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
10999                                            HDA_AMP_MUTE,
11000                                            valp[1] ? 0 : HDA_AMP_MUTE);
11001         if (change)
11002                 alc268_acer_automute(codec, 0);
11003         return change;
11004 }
11005
11006 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
11007         /* output mixer control */
11008         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11009         {
11010                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11011                 .name = "Master Playback Switch",
11012                 .info = snd_hda_mixer_amp_switch_info,
11013                 .get = snd_hda_mixer_amp_switch_get,
11014                 .put = alc268_acer_master_sw_put,
11015                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11016         },
11017         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
11018         { }
11019 };
11020
11021 static struct snd_kcontrol_new alc268_acer_mixer[] = {
11022         /* output mixer control */
11023         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11024         {
11025                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11026                 .name = "Master Playback Switch",
11027                 .info = snd_hda_mixer_amp_switch_info,
11028                 .get = snd_hda_mixer_amp_switch_get,
11029                 .put = alc268_acer_master_sw_put,
11030                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11031         },
11032         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11033         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11034         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11035         { }
11036 };
11037
11038 static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
11039         /* output mixer control */
11040         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11041         {
11042                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11043                 .name = "Master Playback Switch",
11044                 .info = snd_hda_mixer_amp_switch_info,
11045                 .get = snd_hda_mixer_amp_switch_get,
11046                 .put = alc268_acer_master_sw_put,
11047                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11048         },
11049         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11050         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11051         { }
11052 };
11053
11054 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
11055         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11056         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11057         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11058         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11059         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
11060         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
11061         { }
11062 };
11063
11064 static struct hda_verb alc268_acer_verbs[] = {
11065         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
11066         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11067         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11068         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11069         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11070         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11071         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11072         { }
11073 };
11074
11075 /* unsolicited event for HP jack sensing */
11076 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
11077                                        unsigned int res)
11078 {
11079         if ((res >> 26) != ALC880_HP_EVENT)
11080                 return;
11081         alc268_toshiba_automute(codec);
11082 }
11083
11084 static void alc268_acer_unsol_event(struct hda_codec *codec,
11085                                        unsigned int res)
11086 {
11087         if ((res >> 26) != ALC880_HP_EVENT)
11088                 return;
11089         alc268_acer_automute(codec, 1);
11090 }
11091
11092 static void alc268_acer_init_hook(struct hda_codec *codec)
11093 {
11094         alc268_acer_automute(codec, 1);
11095 }
11096
11097 /* toggle speaker-output according to the hp-jack state */
11098 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
11099 {
11100         unsigned int present;
11101         unsigned char bits;
11102
11103         present = snd_hda_codec_read(codec, 0x15, 0,
11104                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11105         bits = present ? AMP_IN_MUTE(0) : 0;
11106         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
11107                                 AMP_IN_MUTE(0), bits);
11108         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
11109                                 AMP_IN_MUTE(0), bits);
11110 }
11111
11112
11113 static void alc268_acer_mic_automute(struct hda_codec *codec)
11114 {
11115         unsigned int present;
11116
11117         present = snd_hda_codec_read(codec, 0x18, 0,
11118                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11119         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
11120                             present ? 0x0 : 0x6);
11121 }
11122
11123 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
11124                                     unsigned int res)
11125 {
11126         if ((res >> 26) == ALC880_HP_EVENT)
11127                 alc268_aspire_one_speaker_automute(codec);
11128         if ((res >> 26) == ALC880_MIC_EVENT)
11129                 alc268_acer_mic_automute(codec);
11130 }
11131
11132 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
11133 {
11134         alc268_aspire_one_speaker_automute(codec);
11135         alc268_acer_mic_automute(codec);
11136 }
11137
11138 static struct snd_kcontrol_new alc268_dell_mixer[] = {
11139         /* output mixer control */
11140         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11141         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11142         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11143         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11144         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11145         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11146         { }
11147 };
11148
11149 static struct hda_verb alc268_dell_verbs[] = {
11150         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11151         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11152         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11153         { }
11154 };
11155
11156 /* mute/unmute internal speaker according to the hp jack and mute state */
11157 static void alc268_dell_automute(struct hda_codec *codec)
11158 {
11159         unsigned int present;
11160         unsigned int mute;
11161
11162         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
11163         if (present & 0x80000000)
11164                 mute = HDA_AMP_MUTE;
11165         else
11166                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
11167         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
11168                                  HDA_AMP_MUTE, mute);
11169 }
11170
11171 static void alc268_dell_unsol_event(struct hda_codec *codec,
11172                                     unsigned int res)
11173 {
11174         if ((res >> 26) != ALC880_HP_EVENT)
11175                 return;
11176         alc268_dell_automute(codec);
11177 }
11178
11179 #define alc268_dell_init_hook   alc268_dell_automute
11180
11181 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
11182         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11183         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11184         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11185         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11186         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11187         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
11188         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
11189         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
11190         { }
11191 };
11192
11193 static struct hda_verb alc267_quanta_il1_verbs[] = {
11194         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11195         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
11196         { }
11197 };
11198
11199 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
11200 {
11201         unsigned int present;
11202
11203         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
11204                 & AC_PINSENSE_PRESENCE;
11205         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
11206                             present ? 0 : PIN_OUT);
11207 }
11208
11209 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
11210 {
11211         unsigned int present;
11212
11213         present = snd_hda_codec_read(codec, 0x18, 0,
11214                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11215         snd_hda_codec_write(codec, 0x23, 0,
11216                             AC_VERB_SET_CONNECT_SEL,
11217                             present ? 0x00 : 0x01);
11218 }
11219
11220 static void alc267_quanta_il1_automute(struct hda_codec *codec)
11221 {
11222         alc267_quanta_il1_hp_automute(codec);
11223         alc267_quanta_il1_mic_automute(codec);
11224 }
11225
11226 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
11227                                            unsigned int res)
11228 {
11229         switch (res >> 26) {
11230         case ALC880_HP_EVENT:
11231                 alc267_quanta_il1_hp_automute(codec);
11232                 break;
11233         case ALC880_MIC_EVENT:
11234                 alc267_quanta_il1_mic_automute(codec);
11235                 break;
11236         }
11237 }
11238
11239 /*
11240  * generic initialization of ADC, input mixers and output mixers
11241  */
11242 static struct hda_verb alc268_base_init_verbs[] = {
11243         /* Unmute DAC0-1 and set vol = 0 */
11244         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11245         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11246         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11247         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11248         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11249         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11250
11251         /*
11252          * Set up output mixers (0x0c - 0x0e)
11253          */
11254         /* set vol=0 to output mixers */
11255         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11256         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11257         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11258         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
11259
11260         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11261         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11262
11263         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11264         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
11265         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11266         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11267         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11268         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11269         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11270         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11271
11272         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11273         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11274         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11275         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11276         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11277         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11278         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11279
11280         /* set PCBEEP vol = 0, mute connections */
11281         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11282         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11283         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11284
11285         /* Unmute Selector 23h,24h and set the default input to mic-in */
11286
11287         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
11288         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11289         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
11290         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11291
11292         { }
11293 };
11294
11295 /*
11296  * generic initialization of ADC, input mixers and output mixers
11297  */
11298 static struct hda_verb alc268_volume_init_verbs[] = {
11299         /* set output DAC */
11300         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11301         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11302         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11303         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11304
11305         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11306         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11307         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11308         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11309         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11310
11311         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11312         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11313         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11314         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11315         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11316
11317         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11318         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11319         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11320         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11321
11322         /* set PCBEEP vol = 0, mute connections */
11323         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11324         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11325         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11326
11327         { }
11328 };
11329
11330 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
11331         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11332         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11333         {
11334                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11335                 /* The multiple "Capture Source" controls confuse alsamixer
11336                  * So call somewhat different..
11337                  */
11338                 /* .name = "Capture Source", */
11339                 .name = "Input Source",
11340                 .count = 1,
11341                 .info = alc_mux_enum_info,
11342                 .get = alc_mux_enum_get,
11343                 .put = alc_mux_enum_put,
11344         },
11345         { } /* end */
11346 };
11347
11348 static struct snd_kcontrol_new alc268_capture_mixer[] = {
11349         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11350         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11351         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
11352         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
11353         {
11354                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11355                 /* The multiple "Capture Source" controls confuse alsamixer
11356                  * So call somewhat different..
11357                  */
11358                 /* .name = "Capture Source", */
11359                 .name = "Input Source",
11360                 .count = 2,
11361                 .info = alc_mux_enum_info,
11362                 .get = alc_mux_enum_get,
11363                 .put = alc_mux_enum_put,
11364         },
11365         { } /* end */
11366 };
11367
11368 static struct hda_input_mux alc268_capture_source = {
11369         .num_items = 4,
11370         .items = {
11371                 { "Mic", 0x0 },
11372                 { "Front Mic", 0x1 },
11373                 { "Line", 0x2 },
11374                 { "CD", 0x3 },
11375         },
11376 };
11377
11378 static struct hda_input_mux alc268_acer_capture_source = {
11379         .num_items = 3,
11380         .items = {
11381                 { "Mic", 0x0 },
11382                 { "Internal Mic", 0x1 },
11383                 { "Line", 0x2 },
11384         },
11385 };
11386
11387 static struct hda_input_mux alc268_acer_dmic_capture_source = {
11388         .num_items = 3,
11389         .items = {
11390                 { "Mic", 0x0 },
11391                 { "Internal Mic", 0x6 },
11392                 { "Line", 0x2 },
11393         },
11394 };
11395
11396 #ifdef CONFIG_SND_DEBUG
11397 static struct snd_kcontrol_new alc268_test_mixer[] = {
11398         /* Volume widgets */
11399         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11400         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11401         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
11402         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
11403         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
11404         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
11405         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
11406         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
11407         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
11408         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
11409         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
11410         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
11411         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
11412         /* The below appears problematic on some hardwares */
11413         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
11414         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11415         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
11416         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
11417         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
11418
11419         /* Modes for retasking pin widgets */
11420         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
11421         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
11422         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
11423         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
11424
11425         /* Controls for GPIO pins, assuming they are configured as outputs */
11426         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
11427         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
11428         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
11429         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
11430
11431         /* Switches to allow the digital SPDIF output pin to be enabled.
11432          * The ALC268 does not have an SPDIF input.
11433          */
11434         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
11435
11436         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
11437          * this output to turn on an external amplifier.
11438          */
11439         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
11440         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
11441
11442         { } /* end */
11443 };
11444 #endif
11445
11446 /* create input playback/capture controls for the given pin */
11447 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
11448                                     const char *ctlname, int idx)
11449 {
11450         char name[32];
11451         int err;
11452
11453         sprintf(name, "%s Playback Volume", ctlname);
11454         if (nid == 0x14) {
11455                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11456                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
11457                                                       HDA_OUTPUT));
11458                 if (err < 0)
11459                         return err;
11460         } else if (nid == 0x15) {
11461                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11462                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
11463                                                       HDA_OUTPUT));
11464                 if (err < 0)
11465                         return err;
11466         } else
11467                 return -1;
11468         sprintf(name, "%s Playback Switch", ctlname);
11469         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11470                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
11471         if (err < 0)
11472                 return err;
11473         return 0;
11474 }
11475
11476 /* add playback controls from the parsed DAC table */
11477 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
11478                                              const struct auto_pin_cfg *cfg)
11479 {
11480         hda_nid_t nid;
11481         int err;
11482
11483         spec->multiout.num_dacs = 2;    /* only use one dac */
11484         spec->multiout.dac_nids = spec->private_dac_nids;
11485         spec->multiout.dac_nids[0] = 2;
11486         spec->multiout.dac_nids[1] = 3;
11487
11488         nid = cfg->line_out_pins[0];
11489         if (nid)
11490                 alc268_new_analog_output(spec, nid, "Front", 0);
11491
11492         nid = cfg->speaker_pins[0];
11493         if (nid == 0x1d) {
11494                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
11495                                   "Speaker Playback Volume",
11496                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
11497                 if (err < 0)
11498                         return err;
11499         }
11500         nid = cfg->hp_pins[0];
11501         if (nid)
11502                 alc268_new_analog_output(spec, nid, "Headphone", 0);
11503
11504         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
11505         if (nid == 0x16) {
11506                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11507                                   "Mono Playback Switch",
11508                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
11509                 if (err < 0)
11510                         return err;
11511         }
11512         return 0;
11513 }
11514
11515 /* create playback/capture controls for input pins */
11516 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
11517                                                 const struct auto_pin_cfg *cfg)
11518 {
11519         struct hda_input_mux *imux = &spec->private_imux;
11520         int i, idx1;
11521
11522         for (i = 0; i < AUTO_PIN_LAST; i++) {
11523                 switch(cfg->input_pins[i]) {
11524                 case 0x18:
11525                         idx1 = 0;       /* Mic 1 */
11526                         break;
11527                 case 0x19:
11528                         idx1 = 1;       /* Mic 2 */
11529                         break;
11530                 case 0x1a:
11531                         idx1 = 2;       /* Line In */
11532                         break;
11533                 case 0x1c:
11534                         idx1 = 3;       /* CD */
11535                         break;
11536                 case 0x12:
11537                 case 0x13:
11538                         idx1 = 6;       /* digital mics */
11539                         break;
11540                 default:
11541                         continue;
11542                 }
11543                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
11544                 imux->items[imux->num_items].index = idx1;
11545                 imux->num_items++;
11546         }
11547         return 0;
11548 }
11549
11550 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
11551 {
11552         struct alc_spec *spec = codec->spec;
11553         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
11554         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
11555         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
11556         unsigned int    dac_vol1, dac_vol2;
11557
11558         if (speaker_nid) {
11559                 snd_hda_codec_write(codec, speaker_nid, 0,
11560                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
11561                 snd_hda_codec_write(codec, 0x0f, 0,
11562                                     AC_VERB_SET_AMP_GAIN_MUTE,
11563                                     AMP_IN_UNMUTE(1));
11564                 snd_hda_codec_write(codec, 0x10, 0,
11565                                     AC_VERB_SET_AMP_GAIN_MUTE,
11566                                     AMP_IN_UNMUTE(1));
11567         } else {
11568                 snd_hda_codec_write(codec, 0x0f, 0,
11569                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11570                 snd_hda_codec_write(codec, 0x10, 0,
11571                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11572         }
11573
11574         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
11575         if (line_nid == 0x14)
11576                 dac_vol2 = AMP_OUT_ZERO;
11577         else if (line_nid == 0x15)
11578                 dac_vol1 = AMP_OUT_ZERO;
11579         if (hp_nid == 0x14)
11580                 dac_vol2 = AMP_OUT_ZERO;
11581         else if (hp_nid == 0x15)
11582                 dac_vol1 = AMP_OUT_ZERO;
11583         if (line_nid != 0x16 || hp_nid != 0x16 ||
11584             spec->autocfg.line_out_pins[1] != 0x16 ||
11585             spec->autocfg.line_out_pins[2] != 0x16)
11586                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
11587
11588         snd_hda_codec_write(codec, 0x02, 0,
11589                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
11590         snd_hda_codec_write(codec, 0x03, 0,
11591                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
11592 }
11593
11594 /* pcm configuration: identiacal with ALC880 */
11595 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
11596 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
11597 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
11598 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
11599
11600 /*
11601  * BIOS auto configuration
11602  */
11603 static int alc268_parse_auto_config(struct hda_codec *codec)
11604 {
11605         struct alc_spec *spec = codec->spec;
11606         int err;
11607         static hda_nid_t alc268_ignore[] = { 0 };
11608
11609         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11610                                            alc268_ignore);
11611         if (err < 0)
11612                 return err;
11613         if (!spec->autocfg.line_outs)
11614                 return 0; /* can't find valid BIOS pin config */
11615
11616         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
11617         if (err < 0)
11618                 return err;
11619         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
11620         if (err < 0)
11621                 return err;
11622
11623         spec->multiout.max_channels = 2;
11624
11625         /* digital only support output */
11626         if (spec->autocfg.dig_out_pin)
11627                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
11628
11629         if (spec->kctls.list)
11630                 add_mixer(spec, spec->kctls.list);
11631
11632         if (spec->autocfg.speaker_pins[0] != 0x1d)
11633                 add_mixer(spec, alc268_beep_mixer);
11634
11635         add_verb(spec, alc268_volume_init_verbs);
11636         spec->num_mux_defs = 1;
11637         spec->input_mux = &spec->private_imux;
11638
11639         err = alc_auto_add_mic_boost(codec);
11640         if (err < 0)
11641                 return err;
11642
11643         store_pin_configs(codec);
11644         return 1;
11645 }
11646
11647 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
11648 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
11649 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
11650
11651 /* init callback for auto-configuration model -- overriding the default init */
11652 static void alc268_auto_init(struct hda_codec *codec)
11653 {
11654         struct alc_spec *spec = codec->spec;
11655         alc268_auto_init_multi_out(codec);
11656         alc268_auto_init_hp_out(codec);
11657         alc268_auto_init_mono_speaker_out(codec);
11658         alc268_auto_init_analog_input(codec);
11659         if (spec->unsol_event)
11660                 alc_inithook(codec);
11661 }
11662
11663 /*
11664  * configuration and preset
11665  */
11666 static const char *alc268_models[ALC268_MODEL_LAST] = {
11667         [ALC267_QUANTA_IL1]     = "quanta-il1",
11668         [ALC268_3ST]            = "3stack",
11669         [ALC268_TOSHIBA]        = "toshiba",
11670         [ALC268_ACER]           = "acer",
11671         [ALC268_ACER_DMIC]      = "acer-dmic",
11672         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
11673         [ALC268_DELL]           = "dell",
11674         [ALC268_ZEPTO]          = "zepto",
11675 #ifdef CONFIG_SND_DEBUG
11676         [ALC268_TEST]           = "test",
11677 #endif
11678         [ALC268_AUTO]           = "auto",
11679 };
11680
11681 static struct snd_pci_quirk alc268_cfg_tbl[] = {
11682         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
11683         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
11684         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
11685         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
11686         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
11687         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
11688                                                 ALC268_ACER_ASPIRE_ONE),
11689         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
11690         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
11691         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
11692         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
11693         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
11694         SND_PCI_QUIRK(0x1179, 0xff64, "TOSHIBA L305", ALC268_TOSHIBA),
11695         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
11696         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
11697         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
11698         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
11699         {}
11700 };
11701
11702 static struct alc_config_preset alc268_presets[] = {
11703         [ALC267_QUANTA_IL1] = {
11704                 .mixers = { alc267_quanta_il1_mixer },
11705                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11706                                 alc267_quanta_il1_verbs },
11707                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11708                 .dac_nids = alc268_dac_nids,
11709                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11710                 .adc_nids = alc268_adc_nids_alt,
11711                 .hp_nid = 0x03,
11712                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11713                 .channel_mode = alc268_modes,
11714                 .input_mux = &alc268_capture_source,
11715                 .unsol_event = alc267_quanta_il1_unsol_event,
11716                 .init_hook = alc267_quanta_il1_automute,
11717         },
11718         [ALC268_3ST] = {
11719                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11720                             alc268_beep_mixer },
11721                 .init_verbs = { alc268_base_init_verbs },
11722                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11723                 .dac_nids = alc268_dac_nids,
11724                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11725                 .adc_nids = alc268_adc_nids_alt,
11726                 .capsrc_nids = alc268_capsrc_nids,
11727                 .hp_nid = 0x03,
11728                 .dig_out_nid = ALC268_DIGOUT_NID,
11729                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11730                 .channel_mode = alc268_modes,
11731                 .input_mux = &alc268_capture_source,
11732         },
11733         [ALC268_TOSHIBA] = {
11734                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11735                             alc268_beep_mixer },
11736                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11737                                 alc268_toshiba_verbs },
11738                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11739                 .dac_nids = alc268_dac_nids,
11740                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11741                 .adc_nids = alc268_adc_nids_alt,
11742                 .capsrc_nids = alc268_capsrc_nids,
11743                 .hp_nid = 0x03,
11744                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11745                 .channel_mode = alc268_modes,
11746                 .input_mux = &alc268_capture_source,
11747                 .unsol_event = alc268_toshiba_unsol_event,
11748                 .init_hook = alc268_toshiba_automute,
11749         },
11750         [ALC268_ACER] = {
11751                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
11752                             alc268_beep_mixer },
11753                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11754                                 alc268_acer_verbs },
11755                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11756                 .dac_nids = alc268_dac_nids,
11757                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11758                 .adc_nids = alc268_adc_nids_alt,
11759                 .capsrc_nids = alc268_capsrc_nids,
11760                 .hp_nid = 0x02,
11761                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11762                 .channel_mode = alc268_modes,
11763                 .input_mux = &alc268_acer_capture_source,
11764                 .unsol_event = alc268_acer_unsol_event,
11765                 .init_hook = alc268_acer_init_hook,
11766         },
11767         [ALC268_ACER_DMIC] = {
11768                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
11769                             alc268_beep_mixer },
11770                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11771                                 alc268_acer_verbs },
11772                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11773                 .dac_nids = alc268_dac_nids,
11774                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11775                 .adc_nids = alc268_adc_nids_alt,
11776                 .capsrc_nids = alc268_capsrc_nids,
11777                 .hp_nid = 0x02,
11778                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11779                 .channel_mode = alc268_modes,
11780                 .input_mux = &alc268_acer_dmic_capture_source,
11781                 .unsol_event = alc268_acer_unsol_event,
11782                 .init_hook = alc268_acer_init_hook,
11783         },
11784         [ALC268_ACER_ASPIRE_ONE] = {
11785                 .mixers = { alc268_acer_aspire_one_mixer,
11786                                 alc268_capture_alt_mixer },
11787                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11788                                 alc268_acer_aspire_one_verbs },
11789                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11790                 .dac_nids = alc268_dac_nids,
11791                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11792                 .adc_nids = alc268_adc_nids_alt,
11793                 .capsrc_nids = alc268_capsrc_nids,
11794                 .hp_nid = 0x03,
11795                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11796                 .channel_mode = alc268_modes,
11797                 .input_mux = &alc268_acer_lc_capture_source,
11798                 .unsol_event = alc268_acer_lc_unsol_event,
11799                 .init_hook = alc268_acer_lc_init_hook,
11800         },
11801         [ALC268_DELL] = {
11802                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
11803                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11804                                 alc268_dell_verbs },
11805                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11806                 .dac_nids = alc268_dac_nids,
11807                 .hp_nid = 0x02,
11808                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11809                 .channel_mode = alc268_modes,
11810                 .unsol_event = alc268_dell_unsol_event,
11811                 .init_hook = alc268_dell_init_hook,
11812                 .input_mux = &alc268_capture_source,
11813         },
11814         [ALC268_ZEPTO] = {
11815                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11816                             alc268_beep_mixer },
11817                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11818                                 alc268_toshiba_verbs },
11819                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11820                 .dac_nids = alc268_dac_nids,
11821                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11822                 .adc_nids = alc268_adc_nids_alt,
11823                 .capsrc_nids = alc268_capsrc_nids,
11824                 .hp_nid = 0x03,
11825                 .dig_out_nid = ALC268_DIGOUT_NID,
11826                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11827                 .channel_mode = alc268_modes,
11828                 .input_mux = &alc268_capture_source,
11829                 .unsol_event = alc268_toshiba_unsol_event,
11830                 .init_hook = alc268_toshiba_automute
11831         },
11832 #ifdef CONFIG_SND_DEBUG
11833         [ALC268_TEST] = {
11834                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
11835                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11836                                 alc268_volume_init_verbs },
11837                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11838                 .dac_nids = alc268_dac_nids,
11839                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11840                 .adc_nids = alc268_adc_nids_alt,
11841                 .capsrc_nids = alc268_capsrc_nids,
11842                 .hp_nid = 0x03,
11843                 .dig_out_nid = ALC268_DIGOUT_NID,
11844                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11845                 .channel_mode = alc268_modes,
11846                 .input_mux = &alc268_capture_source,
11847         },
11848 #endif
11849 };
11850
11851 static int patch_alc268(struct hda_codec *codec)
11852 {
11853         struct alc_spec *spec;
11854         int board_config;
11855         int err;
11856
11857         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
11858         if (spec == NULL)
11859                 return -ENOMEM;
11860
11861         codec->spec = spec;
11862
11863         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
11864                                                   alc268_models,
11865                                                   alc268_cfg_tbl);
11866
11867         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
11868                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
11869                        "trying auto-probe from BIOS...\n");
11870                 board_config = ALC268_AUTO;
11871         }
11872
11873         if (board_config == ALC268_AUTO) {
11874                 /* automatic parse from the BIOS config */
11875                 err = alc268_parse_auto_config(codec);
11876                 if (err < 0) {
11877                         alc_free(codec);
11878                         return err;
11879                 } else if (!err) {
11880                         printk(KERN_INFO
11881                                "hda_codec: Cannot set up configuration "
11882                                "from BIOS.  Using base mode...\n");
11883                         board_config = ALC268_3ST;
11884                 }
11885         }
11886
11887         if (board_config != ALC268_AUTO)
11888                 setup_preset(spec, &alc268_presets[board_config]);
11889
11890         if (codec->vendor_id == 0x10ec0267) {
11891                 spec->stream_name_analog = "ALC267 Analog";
11892                 spec->stream_name_digital = "ALC267 Digital";
11893         } else {
11894                 spec->stream_name_analog = "ALC268 Analog";
11895                 spec->stream_name_digital = "ALC268 Digital";
11896         }
11897
11898         spec->stream_analog_playback = &alc268_pcm_analog_playback;
11899         spec->stream_analog_capture = &alc268_pcm_analog_capture;
11900         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
11901
11902         spec->stream_digital_playback = &alc268_pcm_digital_playback;
11903
11904         if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
11905                 /* override the amp caps for beep generator */
11906                 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
11907                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
11908                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
11909                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
11910                                           (0 << AC_AMPCAP_MUTE_SHIFT));
11911
11912         if (!spec->adc_nids && spec->input_mux) {
11913                 /* check whether NID 0x07 is valid */
11914                 unsigned int wcap = get_wcaps(codec, 0x07);
11915                 int i;
11916
11917                 /* get type */
11918                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
11919                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
11920                         spec->adc_nids = alc268_adc_nids_alt;
11921                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
11922                         add_mixer(spec, alc268_capture_alt_mixer);
11923                 } else {
11924                         spec->adc_nids = alc268_adc_nids;
11925                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
11926                         add_mixer(spec, alc268_capture_mixer);
11927                 }
11928                 spec->capsrc_nids = alc268_capsrc_nids;
11929                 /* set default input source */
11930                 for (i = 0; i < spec->num_adc_nids; i++)
11931                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
11932                                 0, AC_VERB_SET_CONNECT_SEL,
11933                                 spec->input_mux->items[0].index);
11934         }
11935
11936         spec->vmaster_nid = 0x02;
11937
11938         codec->patch_ops = alc_patch_ops;
11939         if (board_config == ALC268_AUTO)
11940                 spec->init_hook = alc268_auto_init;
11941
11942         codec->proc_widget_hook = print_realtek_coef;
11943
11944         return 0;
11945 }
11946
11947 /*
11948  *  ALC269 channel source setting (2 channel)
11949  */
11950 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
11951
11952 #define alc269_dac_nids         alc260_dac_nids
11953
11954 static hda_nid_t alc269_adc_nids[1] = {
11955         /* ADC1 */
11956         0x08,
11957 };
11958
11959 static hda_nid_t alc269_capsrc_nids[1] = {
11960         0x23,
11961 };
11962
11963 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
11964  *       not a mux!
11965  */
11966
11967 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
11968         .num_items = 2,
11969         .items = {
11970                 { "i-Mic", 0x5 },
11971                 { "e-Mic", 0x0 },
11972         },
11973 };
11974
11975 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
11976         .num_items = 2,
11977         .items = {
11978                 { "i-Mic", 0x1 },
11979                 { "e-Mic", 0x0 },
11980         },
11981 };
11982
11983 #define alc269_modes            alc260_modes
11984 #define alc269_capture_source   alc880_lg_lw_capture_source
11985
11986 static struct snd_kcontrol_new alc269_base_mixer[] = {
11987         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11988         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11989         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11990         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11991         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11992         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11993         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
11994         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
11995         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11996         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11997         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11998         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11999         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12000         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
12001         { } /* end */
12002 };
12003
12004 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
12005         /* output mixer control */
12006         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12007         {
12008                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12009                 .name = "Master Playback Switch",
12010                 .info = snd_hda_mixer_amp_switch_info,
12011                 .get = snd_hda_mixer_amp_switch_get,
12012                 .put = alc268_acer_master_sw_put,
12013                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12014         },
12015         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12016         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12017         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12018         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12019         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12020         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12021         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
12022         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
12023         { }
12024 };
12025
12026 static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12027         /* output mixer control */
12028         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12029         {
12030                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12031                 .name = "Master Playback Switch",
12032                 .info = snd_hda_mixer_amp_switch_info,
12033                 .get = snd_hda_mixer_amp_switch_get,
12034                 .put = alc268_acer_master_sw_put,
12035                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12036         },
12037         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12038         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12039         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12040         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12041         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12042         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12043         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
12044         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
12045         HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
12046         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
12047         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
12048         { }
12049 };
12050
12051 /* bind volumes of both NID 0x0c and 0x0d */
12052 static struct hda_bind_ctls alc269_epc_bind_vol = {
12053         .ops = &snd_hda_bind_vol,
12054         .values = {
12055                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
12056                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
12057                 0
12058         },
12059 };
12060
12061 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12062         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12063         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
12064         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12065         { } /* end */
12066 };
12067
12068 /* capture mixer elements */
12069 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
12070         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12071         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12072         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12073         { } /* end */
12074 };
12075
12076 /* FSC amilo */
12077 static struct snd_kcontrol_new alc269_fujitsu_mixer[] = {
12078         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12079         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12080         HDA_BIND_VOL("PCM Playback Volume", &alc269_epc_bind_vol),
12081         { } /* end */
12082 };
12083
12084 /* beep control */
12085 static struct snd_kcontrol_new alc269_beep_mixer[] = {
12086         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
12087         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
12088         { } /* end */
12089 };
12090
12091 static struct hda_verb alc269_quanta_fl1_verbs[] = {
12092         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12093         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12094         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12095         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12096         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12097         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12098         { }
12099 };
12100
12101 static struct hda_verb alc269_lifebook_verbs[] = {
12102         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12103         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
12104         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12105         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12106         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12107         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12108         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12109         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12110         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12111         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12112         { }
12113 };
12114
12115 /* toggle speaker-output according to the hp-jack state */
12116 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
12117 {
12118         unsigned int present;
12119         unsigned char bits;
12120
12121         present = snd_hda_codec_read(codec, 0x15, 0,
12122                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12123         bits = present ? AMP_IN_MUTE(0) : 0;
12124         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12125                         AMP_IN_MUTE(0), bits);
12126         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12127                         AMP_IN_MUTE(0), bits);
12128
12129         snd_hda_codec_write(codec, 0x20, 0,
12130                         AC_VERB_SET_COEF_INDEX, 0x0c);
12131         snd_hda_codec_write(codec, 0x20, 0,
12132                         AC_VERB_SET_PROC_COEF, 0x680);
12133
12134         snd_hda_codec_write(codec, 0x20, 0,
12135                         AC_VERB_SET_COEF_INDEX, 0x0c);
12136         snd_hda_codec_write(codec, 0x20, 0,
12137                         AC_VERB_SET_PROC_COEF, 0x480);
12138 }
12139
12140 /* toggle speaker-output according to the hp-jacks state */
12141 static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
12142 {
12143         unsigned int present;
12144         unsigned char bits;
12145
12146         /* Check laptop headphone socket */
12147         present = snd_hda_codec_read(codec, 0x15, 0,
12148                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12149
12150         /* Check port replicator headphone socket */
12151         present |= snd_hda_codec_read(codec, 0x1a, 0,
12152                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12153
12154         bits = present ? AMP_IN_MUTE(0) : 0;
12155         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12156                         AMP_IN_MUTE(0), bits);
12157         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12158                         AMP_IN_MUTE(0), bits);
12159
12160         snd_hda_codec_write(codec, 0x20, 0,
12161                         AC_VERB_SET_COEF_INDEX, 0x0c);
12162         snd_hda_codec_write(codec, 0x20, 0,
12163                         AC_VERB_SET_PROC_COEF, 0x680);
12164
12165         snd_hda_codec_write(codec, 0x20, 0,
12166                         AC_VERB_SET_COEF_INDEX, 0x0c);
12167         snd_hda_codec_write(codec, 0x20, 0,
12168                         AC_VERB_SET_PROC_COEF, 0x480);
12169 }
12170
12171 static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
12172 {
12173         unsigned int present;
12174
12175         present = snd_hda_codec_read(codec, 0x18, 0,
12176                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12177         snd_hda_codec_write(codec, 0x23, 0,
12178                             AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
12179 }
12180
12181 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
12182 {
12183         unsigned int present_laptop;
12184         unsigned int present_dock;
12185
12186         present_laptop = snd_hda_codec_read(codec, 0x18, 0,
12187                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12188
12189         present_dock = snd_hda_codec_read(codec, 0x1b, 0,
12190                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12191
12192         /* Laptop mic port overrides dock mic port, design decision */
12193         if (present_dock)
12194                 snd_hda_codec_write(codec, 0x23, 0,
12195                                 AC_VERB_SET_CONNECT_SEL, 0x3);
12196         if (present_laptop)
12197                 snd_hda_codec_write(codec, 0x23, 0,
12198                                 AC_VERB_SET_CONNECT_SEL, 0x0);
12199         if (!present_dock && !present_laptop)
12200                 snd_hda_codec_write(codec, 0x23, 0,
12201                                 AC_VERB_SET_CONNECT_SEL, 0x1);
12202 }
12203
12204 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
12205                                     unsigned int res)
12206 {
12207         if ((res >> 26) == ALC880_HP_EVENT)
12208                 alc269_quanta_fl1_speaker_automute(codec);
12209         if ((res >> 26) == ALC880_MIC_EVENT)
12210                 alc269_quanta_fl1_mic_automute(codec);
12211 }
12212
12213 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
12214                                         unsigned int res)
12215 {
12216         if ((res >> 26) == ALC880_HP_EVENT)
12217                 alc269_lifebook_speaker_automute(codec);
12218         if ((res >> 26) == ALC880_MIC_EVENT)
12219                 alc269_lifebook_mic_autoswitch(codec);
12220 }
12221
12222 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
12223 {
12224         alc269_quanta_fl1_speaker_automute(codec);
12225         alc269_quanta_fl1_mic_automute(codec);
12226 }
12227
12228 static void alc269_lifebook_init_hook(struct hda_codec *codec)
12229 {
12230         alc269_lifebook_speaker_automute(codec);
12231         alc269_lifebook_mic_autoswitch(codec);
12232 }
12233
12234 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
12235         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12236         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
12237         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12238         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
12239         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12240         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12241         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12242         {}
12243 };
12244
12245 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
12246         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12247         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
12248         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12249         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
12250         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12251         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12252         {}
12253 };
12254
12255 /* toggle speaker-output according to the hp-jack state */
12256 static void alc269_speaker_automute(struct hda_codec *codec)
12257 {
12258         unsigned int present;
12259         unsigned char bits;
12260
12261         present = snd_hda_codec_read(codec, 0x15, 0,
12262                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12263         bits = present ? AMP_IN_MUTE(0) : 0;
12264         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12265                                 AMP_IN_MUTE(0), bits);
12266         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12267                                 AMP_IN_MUTE(0), bits);
12268 }
12269
12270 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
12271 {
12272         unsigned int present;
12273
12274         present = snd_hda_codec_read(codec, 0x18, 0,
12275                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12276         snd_hda_codec_write(codec, 0x23, 0,
12277                                 AC_VERB_SET_CONNECT_SEL,  (present ? 0 : 5));
12278 }
12279
12280 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
12281 {
12282         unsigned int present;
12283
12284         present = snd_hda_codec_read(codec, 0x18, 0,
12285                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12286         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12287                                 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
12288         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12289                                 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
12290 }
12291
12292 /* unsolicited event for HP jack sensing */
12293 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
12294                                      unsigned int res)
12295 {
12296         if ((res >> 26) == ALC880_HP_EVENT)
12297                 alc269_speaker_automute(codec);
12298
12299         if ((res >> 26) == ALC880_MIC_EVENT)
12300                 alc269_eeepc_dmic_automute(codec);
12301 }
12302
12303 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
12304 {
12305         alc269_speaker_automute(codec);
12306         alc269_eeepc_dmic_automute(codec);
12307 }
12308
12309 /* unsolicited event for HP jack sensing */
12310 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
12311                                      unsigned int res)
12312 {
12313         if ((res >> 26) == ALC880_HP_EVENT)
12314                 alc269_speaker_automute(codec);
12315
12316         if ((res >> 26) == ALC880_MIC_EVENT)
12317                 alc269_eeepc_amic_automute(codec);
12318 }
12319
12320 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
12321 {
12322         alc269_speaker_automute(codec);
12323         alc269_eeepc_amic_automute(codec);
12324 }
12325
12326 /*
12327  * generic initialization of ADC, input mixers and output mixers
12328  */
12329 static struct hda_verb alc269_init_verbs[] = {
12330         /*
12331          * Unmute ADC0 and set the default input to mic-in
12332          */
12333         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12334
12335         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
12336          * analog-loopback mixer widget
12337          * Note: PASD motherboards uses the Line In 2 as the input for
12338          * front panel mic (mic 2)
12339          */
12340         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12341         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12342         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12343         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12344         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12345         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12346
12347         /*
12348          * Set up output mixers (0x0c - 0x0e)
12349          */
12350         /* set vol=0 to output mixers */
12351         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12352         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12353
12354         /* set up input amps for analog loopback */
12355         /* Amp Indices: DAC = 0, mixer = 1 */
12356         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12357         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12358         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12359         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12360         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12361         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12362
12363         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12364         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12365         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12366         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12367         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12368         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12369         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12370
12371         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12372         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12373         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12374         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12375         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12376         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12377         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12378
12379         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12380         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12381
12382         /* FIXME: use matrix-type input source selection */
12383         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
12384         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
12385         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12386         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12387         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12388         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12389
12390         /* set EAPD */
12391         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
12392         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
12393         { }
12394 };
12395
12396 /* add playback controls from the parsed DAC table */
12397 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
12398                                              const struct auto_pin_cfg *cfg)
12399 {
12400         hda_nid_t nid;
12401         int err;
12402
12403         spec->multiout.num_dacs = 1;    /* only use one dac */
12404         spec->multiout.dac_nids = spec->private_dac_nids;
12405         spec->multiout.dac_nids[0] = 2;
12406
12407         nid = cfg->line_out_pins[0];
12408         if (nid) {
12409                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
12410                                   "Front Playback Volume",
12411                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
12412                 if (err < 0)
12413                         return err;
12414                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12415                                   "Front Playback Switch",
12416                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12417                 if (err < 0)
12418                         return err;
12419         }
12420
12421         nid = cfg->speaker_pins[0];
12422         if (nid) {
12423                 if (!cfg->line_out_pins[0]) {
12424                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12425                                           "Speaker Playback Volume",
12426                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12427                                                               HDA_OUTPUT));
12428                         if (err < 0)
12429                                 return err;
12430                 }
12431                 if (nid == 0x16) {
12432                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12433                                           "Speaker Playback Switch",
12434                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12435                                                               HDA_OUTPUT));
12436                         if (err < 0)
12437                                 return err;
12438                 } else {
12439                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12440                                           "Speaker Playback Switch",
12441                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12442                                                               HDA_OUTPUT));
12443                         if (err < 0)
12444                                 return err;
12445                 }
12446         }
12447         nid = cfg->hp_pins[0];
12448         if (nid) {
12449                 /* spec->multiout.hp_nid = 2; */
12450                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
12451                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12452                                           "Headphone Playback Volume",
12453                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12454                                                               HDA_OUTPUT));
12455                         if (err < 0)
12456                                 return err;
12457                 }
12458                 if (nid == 0x16) {
12459                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12460                                           "Headphone Playback Switch",
12461                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12462                                                               HDA_OUTPUT));
12463                         if (err < 0)
12464                                 return err;
12465                 } else {
12466                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12467                                           "Headphone Playback Switch",
12468                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12469                                                               HDA_OUTPUT));
12470                         if (err < 0)
12471                                 return err;
12472                 }
12473         }
12474         return 0;
12475 }
12476
12477 static int alc269_auto_create_analog_input_ctls(struct alc_spec *spec,
12478                                                 const struct auto_pin_cfg *cfg)
12479 {
12480         int err;
12481
12482         err = alc880_auto_create_analog_input_ctls(spec, cfg);
12483         if (err < 0)
12484                 return err;
12485         /* digital-mic input pin is excluded in alc880_auto_create..()
12486          * because it's under 0x18
12487          */
12488         if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
12489             cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
12490                 struct hda_input_mux *imux = &spec->private_imux;
12491                 imux->items[imux->num_items].label = "Int Mic";
12492                 imux->items[imux->num_items].index = 0x05;
12493                 imux->num_items++;
12494         }
12495         return 0;
12496 }
12497
12498 #ifdef CONFIG_SND_HDA_POWER_SAVE
12499 #define alc269_loopbacks        alc880_loopbacks
12500 #endif
12501
12502 /* pcm configuration: identiacal with ALC880 */
12503 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
12504 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
12505 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
12506 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
12507
12508 /*
12509  * BIOS auto configuration
12510  */
12511 static int alc269_parse_auto_config(struct hda_codec *codec)
12512 {
12513         struct alc_spec *spec = codec->spec;
12514         int i, err;
12515         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
12516
12517         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12518                                            alc269_ignore);
12519         if (err < 0)
12520                 return err;
12521
12522         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
12523         if (err < 0)
12524                 return err;
12525         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
12526         if (err < 0)
12527                 return err;
12528
12529         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12530
12531         if (spec->autocfg.dig_out_pin)
12532                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
12533
12534         if (spec->kctls.list)
12535                 add_mixer(spec, spec->kctls.list);
12536
12537         /* create a beep mixer control if the pin 0x1d isn't assigned */
12538         for (i = 0; i < ARRAY_SIZE(spec->autocfg.input_pins); i++)
12539                 if (spec->autocfg.input_pins[i] == 0x1d)
12540                         break;
12541         if (i >= ARRAY_SIZE(spec->autocfg.input_pins))
12542                 add_mixer(spec, alc269_beep_mixer);
12543
12544         add_verb(spec, alc269_init_verbs);
12545         spec->num_mux_defs = 1;
12546         spec->input_mux = &spec->private_imux;
12547         /* set default input source */
12548         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
12549                                   0, AC_VERB_SET_CONNECT_SEL,
12550                                   spec->input_mux->items[0].index);
12551
12552         err = alc_auto_add_mic_boost(codec);
12553         if (err < 0)
12554                 return err;
12555
12556         if (!spec->cap_mixer)
12557                 set_capture_mixer(spec);
12558
12559         store_pin_configs(codec);
12560         return 1;
12561 }
12562
12563 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
12564 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
12565 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
12566
12567
12568 /* init callback for auto-configuration model -- overriding the default init */
12569 static void alc269_auto_init(struct hda_codec *codec)
12570 {
12571         struct alc_spec *spec = codec->spec;
12572         alc269_auto_init_multi_out(codec);
12573         alc269_auto_init_hp_out(codec);
12574         alc269_auto_init_analog_input(codec);
12575         if (spec->unsol_event)
12576                 alc_inithook(codec);
12577 }
12578
12579 /*
12580  * configuration and preset
12581  */
12582 static const char *alc269_models[ALC269_MODEL_LAST] = {
12583         [ALC269_BASIC]                  = "basic",
12584         [ALC269_QUANTA_FL1]             = "quanta",
12585         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
12586         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901",
12587         [ALC269_FUJITSU]                = "fujitsu",
12588         [ALC269_LIFEBOOK]               = "lifebook"
12589 };
12590
12591 static struct snd_pci_quirk alc269_cfg_tbl[] = {
12592         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
12593         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
12594                       ALC269_ASUS_EEEPC_P703),
12595         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
12596                       ALC269_ASUS_EEEPC_P901),
12597         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
12598                       ALC269_ASUS_EEEPC_P901),
12599         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
12600         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
12601         {}
12602 };
12603
12604 static struct alc_config_preset alc269_presets[] = {
12605         [ALC269_BASIC] = {
12606                 .mixers = { alc269_base_mixer },
12607                 .init_verbs = { alc269_init_verbs },
12608                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12609                 .dac_nids = alc269_dac_nids,
12610                 .hp_nid = 0x03,
12611                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12612                 .channel_mode = alc269_modes,
12613                 .input_mux = &alc269_capture_source,
12614         },
12615         [ALC269_QUANTA_FL1] = {
12616                 .mixers = { alc269_quanta_fl1_mixer },
12617                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
12618                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12619                 .dac_nids = alc269_dac_nids,
12620                 .hp_nid = 0x03,
12621                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12622                 .channel_mode = alc269_modes,
12623                 .input_mux = &alc269_capture_source,
12624                 .unsol_event = alc269_quanta_fl1_unsol_event,
12625                 .init_hook = alc269_quanta_fl1_init_hook,
12626         },
12627         [ALC269_ASUS_EEEPC_P703] = {
12628                 .mixers = { alc269_eeepc_mixer },
12629                 .cap_mixer = alc269_epc_capture_mixer,
12630                 .init_verbs = { alc269_init_verbs,
12631                                 alc269_eeepc_amic_init_verbs },
12632                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12633                 .dac_nids = alc269_dac_nids,
12634                 .hp_nid = 0x03,
12635                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12636                 .channel_mode = alc269_modes,
12637                 .input_mux = &alc269_eeepc_amic_capture_source,
12638                 .unsol_event = alc269_eeepc_amic_unsol_event,
12639                 .init_hook = alc269_eeepc_amic_inithook,
12640         },
12641         [ALC269_ASUS_EEEPC_P901] = {
12642                 .mixers = { alc269_eeepc_mixer },
12643                 .cap_mixer = alc269_epc_capture_mixer,
12644                 .init_verbs = { alc269_init_verbs,
12645                                 alc269_eeepc_dmic_init_verbs },
12646                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12647                 .dac_nids = alc269_dac_nids,
12648                 .hp_nid = 0x03,
12649                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12650                 .channel_mode = alc269_modes,
12651                 .input_mux = &alc269_eeepc_dmic_capture_source,
12652                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12653                 .init_hook = alc269_eeepc_dmic_inithook,
12654         },
12655         [ALC269_FUJITSU] = {
12656                 .mixers = { alc269_fujitsu_mixer, alc269_beep_mixer },
12657                 .cap_mixer = alc269_epc_capture_mixer,
12658                 .init_verbs = { alc269_init_verbs,
12659                                 alc269_eeepc_dmic_init_verbs },
12660                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12661                 .dac_nids = alc269_dac_nids,
12662                 .hp_nid = 0x03,
12663                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12664                 .channel_mode = alc269_modes,
12665                 .input_mux = &alc269_eeepc_dmic_capture_source,
12666                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12667                 .init_hook = alc269_eeepc_dmic_inithook,
12668         },
12669         [ALC269_LIFEBOOK] = {
12670                 .mixers = { alc269_lifebook_mixer },
12671                 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
12672                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12673                 .dac_nids = alc269_dac_nids,
12674                 .hp_nid = 0x03,
12675                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12676                 .channel_mode = alc269_modes,
12677                 .input_mux = &alc269_capture_source,
12678                 .unsol_event = alc269_lifebook_unsol_event,
12679                 .init_hook = alc269_lifebook_init_hook,
12680         },
12681 };
12682
12683 static int patch_alc269(struct hda_codec *codec)
12684 {
12685         struct alc_spec *spec;
12686         int board_config;
12687         int err;
12688
12689         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12690         if (spec == NULL)
12691                 return -ENOMEM;
12692
12693         codec->spec = spec;
12694
12695         alc_fix_pll_init(codec, 0x20, 0x04, 15);
12696
12697         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
12698                                                   alc269_models,
12699                                                   alc269_cfg_tbl);
12700
12701         if (board_config < 0) {
12702                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
12703                        "trying auto-probe from BIOS...\n");
12704                 board_config = ALC269_AUTO;
12705         }
12706
12707         if (board_config == ALC269_AUTO) {
12708                 /* automatic parse from the BIOS config */
12709                 err = alc269_parse_auto_config(codec);
12710                 if (err < 0) {
12711                         alc_free(codec);
12712                         return err;
12713                 } else if (!err) {
12714                         printk(KERN_INFO
12715                                "hda_codec: Cannot set up configuration "
12716                                "from BIOS.  Using base mode...\n");
12717                         board_config = ALC269_BASIC;
12718                 }
12719         }
12720
12721         if (board_config != ALC269_AUTO)
12722                 setup_preset(spec, &alc269_presets[board_config]);
12723
12724         spec->stream_name_analog = "ALC269 Analog";
12725         spec->stream_analog_playback = &alc269_pcm_analog_playback;
12726         spec->stream_analog_capture = &alc269_pcm_analog_capture;
12727
12728         spec->stream_name_digital = "ALC269 Digital";
12729         spec->stream_digital_playback = &alc269_pcm_digital_playback;
12730         spec->stream_digital_capture = &alc269_pcm_digital_capture;
12731
12732         spec->adc_nids = alc269_adc_nids;
12733         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
12734         spec->capsrc_nids = alc269_capsrc_nids;
12735         if (!spec->cap_mixer)
12736                 set_capture_mixer(spec);
12737
12738         codec->patch_ops = alc_patch_ops;
12739         if (board_config == ALC269_AUTO)
12740                 spec->init_hook = alc269_auto_init;
12741 #ifdef CONFIG_SND_HDA_POWER_SAVE
12742         if (!spec->loopback.amplist)
12743                 spec->loopback.amplist = alc269_loopbacks;
12744 #endif
12745         codec->proc_widget_hook = print_realtek_coef;
12746
12747         return 0;
12748 }
12749
12750 /*
12751  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
12752  */
12753
12754 /*
12755  * set the path ways for 2 channel output
12756  * need to set the codec line out and mic 1 pin widgets to inputs
12757  */
12758 static struct hda_verb alc861_threestack_ch2_init[] = {
12759         /* set pin widget 1Ah (line in) for input */
12760         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12761         /* set pin widget 18h (mic1/2) for input, for mic also enable
12762          * the vref
12763          */
12764         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12765
12766         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12767 #if 0
12768         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12769         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12770 #endif
12771         { } /* end */
12772 };
12773 /*
12774  * 6ch mode
12775  * need to set the codec line out and mic 1 pin widgets to outputs
12776  */
12777 static struct hda_verb alc861_threestack_ch6_init[] = {
12778         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12779         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12780         /* set pin widget 18h (mic1) for output (CLFE)*/
12781         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12782
12783         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12784         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12785
12786         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12787 #if 0
12788         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12789         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12790 #endif
12791         { } /* end */
12792 };
12793
12794 static struct hda_channel_mode alc861_threestack_modes[2] = {
12795         { 2, alc861_threestack_ch2_init },
12796         { 6, alc861_threestack_ch6_init },
12797 };
12798 /* Set mic1 as input and unmute the mixer */
12799 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
12800         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12801         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12802         { } /* end */
12803 };
12804 /* Set mic1 as output and mute mixer */
12805 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
12806         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12807         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12808         { } /* end */
12809 };
12810
12811 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
12812         { 2, alc861_uniwill_m31_ch2_init },
12813         { 4, alc861_uniwill_m31_ch4_init },
12814 };
12815
12816 /* Set mic1 and line-in as input and unmute the mixer */
12817 static struct hda_verb alc861_asus_ch2_init[] = {
12818         /* set pin widget 1Ah (line in) for input */
12819         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12820         /* set pin widget 18h (mic1/2) for input, for mic also enable
12821          * the vref
12822          */
12823         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12824
12825         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12826 #if 0
12827         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12828         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12829 #endif
12830         { } /* end */
12831 };
12832 /* Set mic1 nad line-in as output and mute mixer */
12833 static struct hda_verb alc861_asus_ch6_init[] = {
12834         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12835         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12836         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12837         /* set pin widget 18h (mic1) for output (CLFE)*/
12838         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12839         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12840         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12841         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12842
12843         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12844 #if 0
12845         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12846         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12847 #endif
12848         { } /* end */
12849 };
12850
12851 static struct hda_channel_mode alc861_asus_modes[2] = {
12852         { 2, alc861_asus_ch2_init },
12853         { 6, alc861_asus_ch6_init },
12854 };
12855
12856 /* patch-ALC861 */
12857
12858 static struct snd_kcontrol_new alc861_base_mixer[] = {
12859         /* output mixer control */
12860         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12861         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12862         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12863         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12864         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12865
12866         /*Input mixer control */
12867         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12868            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12869         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12870         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12871         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12872         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12873         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12874         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12875         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12876         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12877
12878         { } /* end */
12879 };
12880
12881 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
12882         /* output mixer control */
12883         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12884         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12885         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12886         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12887         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12888
12889         /* Input mixer control */
12890         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12891            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12892         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12893         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12894         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12895         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12896         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12897         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12898         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12899         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12900
12901         {
12902                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12903                 .name = "Channel Mode",
12904                 .info = alc_ch_mode_info,
12905                 .get = alc_ch_mode_get,
12906                 .put = alc_ch_mode_put,
12907                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
12908         },
12909         { } /* end */
12910 };
12911
12912 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
12913         /* output mixer control */
12914         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12915         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12916         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12917
12918         { } /* end */
12919 };
12920
12921 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
12922         /* output mixer control */
12923         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12924         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12925         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12926         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12927         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12928
12929         /* Input mixer control */
12930         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12931            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12932         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12933         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12934         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12935         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12936         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12937         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12938         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12939         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12940
12941         {
12942                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12943                 .name = "Channel Mode",
12944                 .info = alc_ch_mode_info,
12945                 .get = alc_ch_mode_get,
12946                 .put = alc_ch_mode_put,
12947                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
12948         },
12949         { } /* end */
12950 };
12951
12952 static struct snd_kcontrol_new alc861_asus_mixer[] = {
12953         /* output mixer control */
12954         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12955         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12956         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12957         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12958         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12959
12960         /* Input mixer control */
12961         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12962         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12963         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12964         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12965         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12966         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12967         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12968         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12969         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12970         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
12971
12972         {
12973                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12974                 .name = "Channel Mode",
12975                 .info = alc_ch_mode_info,
12976                 .get = alc_ch_mode_get,
12977                 .put = alc_ch_mode_put,
12978                 .private_value = ARRAY_SIZE(alc861_asus_modes),
12979         },
12980         { }
12981 };
12982
12983 /* additional mixer */
12984 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
12985         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12986         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12987         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
12988         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
12989         { }
12990 };
12991
12992 /*
12993  * generic initialization of ADC, input mixers and output mixers
12994  */
12995 static struct hda_verb alc861_base_init_verbs[] = {
12996         /*
12997          * Unmute ADC0 and set the default input to mic-in
12998          */
12999         /* port-A for surround (rear panel) */
13000         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13001         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
13002         /* port-B for mic-in (rear panel) with vref */
13003         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13004         /* port-C for line-in (rear panel) */
13005         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13006         /* port-D for Front */
13007         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13008         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13009         /* port-E for HP out (front panel) */
13010         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13011         /* route front PCM to HP */
13012         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13013         /* port-F for mic-in (front panel) with vref */
13014         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13015         /* port-G for CLFE (rear panel) */
13016         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13017         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13018         /* port-H for side (rear panel) */
13019         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13020         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
13021         /* CD-in */
13022         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13023         /* route front mic to ADC1*/
13024         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13025         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13026
13027         /* Unmute DAC0~3 & spdif out*/
13028         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13029         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13030         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13031         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13032         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13033
13034         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13035         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13036         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13037         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13038         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13039
13040         /* Unmute Stereo Mixer 15 */
13041         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13042         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13043         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13044         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13045
13046         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13047         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13048         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13049         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13050         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13051         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13052         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13053         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13054         /* hp used DAC 3 (Front) */
13055         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13056         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13057
13058         { }
13059 };
13060
13061 static struct hda_verb alc861_threestack_init_verbs[] = {
13062         /*
13063          * Unmute ADC0 and set the default input to mic-in
13064          */
13065         /* port-A for surround (rear panel) */
13066         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13067         /* port-B for mic-in (rear panel) with vref */
13068         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13069         /* port-C for line-in (rear panel) */
13070         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13071         /* port-D for Front */
13072         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13073         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13074         /* port-E for HP out (front panel) */
13075         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13076         /* route front PCM to HP */
13077         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13078         /* port-F for mic-in (front panel) with vref */
13079         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13080         /* port-G for CLFE (rear panel) */
13081         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13082         /* port-H for side (rear panel) */
13083         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13084         /* CD-in */
13085         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13086         /* route front mic to ADC1*/
13087         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13088         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13089         /* Unmute DAC0~3 & spdif out*/
13090         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13091         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13092         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13093         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13094         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13095
13096         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13097         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13098         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13099         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13100         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13101
13102         /* Unmute Stereo Mixer 15 */
13103         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13104         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13105         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13106         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13107
13108         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13109         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13110         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13111         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13112         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13113         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13114         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13115         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13116         /* hp used DAC 3 (Front) */
13117         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13118         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13119         { }
13120 };
13121
13122 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
13123         /*
13124          * Unmute ADC0 and set the default input to mic-in
13125          */
13126         /* port-A for surround (rear panel) */
13127         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13128         /* port-B for mic-in (rear panel) with vref */
13129         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13130         /* port-C for line-in (rear panel) */
13131         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13132         /* port-D for Front */
13133         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13134         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13135         /* port-E for HP out (front panel) */
13136         /* this has to be set to VREF80 */
13137         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13138         /* route front PCM to HP */
13139         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13140         /* port-F for mic-in (front panel) with vref */
13141         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13142         /* port-G for CLFE (rear panel) */
13143         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13144         /* port-H for side (rear panel) */
13145         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13146         /* CD-in */
13147         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13148         /* route front mic to ADC1*/
13149         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13150         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13151         /* Unmute DAC0~3 & spdif out*/
13152         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13153         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13154         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13155         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13156         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13157
13158         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13159         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13160         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13161         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13162         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13163
13164         /* Unmute Stereo Mixer 15 */
13165         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13166         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13167         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13168         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13169
13170         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13171         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13172         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13173         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13174         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13175         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13176         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13177         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13178         /* hp used DAC 3 (Front) */
13179         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13180         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13181         { }
13182 };
13183
13184 static struct hda_verb alc861_asus_init_verbs[] = {
13185         /*
13186          * Unmute ADC0 and set the default input to mic-in
13187          */
13188         /* port-A for surround (rear panel)
13189          * according to codec#0 this is the HP jack
13190          */
13191         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
13192         /* route front PCM to HP */
13193         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
13194         /* port-B for mic-in (rear panel) with vref */
13195         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13196         /* port-C for line-in (rear panel) */
13197         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13198         /* port-D for Front */
13199         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13200         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13201         /* port-E for HP out (front panel) */
13202         /* this has to be set to VREF80 */
13203         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13204         /* route front PCM to HP */
13205         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13206         /* port-F for mic-in (front panel) with vref */
13207         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13208         /* port-G for CLFE (rear panel) */
13209         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13210         /* port-H for side (rear panel) */
13211         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13212         /* CD-in */
13213         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13214         /* route front mic to ADC1*/
13215         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13216         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13217         /* Unmute DAC0~3 & spdif out*/
13218         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13219         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13220         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13221         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13222         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13223         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13224         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13225         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13226         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13227         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13228
13229         /* Unmute Stereo Mixer 15 */
13230         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13231         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13232         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13233         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13234
13235         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13236         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13237         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13238         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13239         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13240         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13241         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13242         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13243         /* hp used DAC 3 (Front) */
13244         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13245         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13246         { }
13247 };
13248
13249 /* additional init verbs for ASUS laptops */
13250 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
13251         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
13252         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
13253         { }
13254 };
13255
13256 /*
13257  * generic initialization of ADC, input mixers and output mixers
13258  */
13259 static struct hda_verb alc861_auto_init_verbs[] = {
13260         /*
13261          * Unmute ADC0 and set the default input to mic-in
13262          */
13263         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
13264         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13265
13266         /* Unmute DAC0~3 & spdif out*/
13267         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13268         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13269         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13270         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13271         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13272
13273         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13274         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13275         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13276         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13277         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13278
13279         /* Unmute Stereo Mixer 15 */
13280         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13281         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13282         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13283         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
13284
13285         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13286         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13287         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13288         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13289         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13290         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13291         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13292         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13293
13294         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13295         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13296         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13297         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13298         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13299         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13300         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13301         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13302
13303         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
13304
13305         { }
13306 };
13307
13308 static struct hda_verb alc861_toshiba_init_verbs[] = {
13309         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13310
13311         { }
13312 };
13313
13314 /* toggle speaker-output according to the hp-jack state */
13315 static void alc861_toshiba_automute(struct hda_codec *codec)
13316 {
13317         unsigned int present;
13318
13319         present = snd_hda_codec_read(codec, 0x0f, 0,
13320                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13321         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
13322                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
13323         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
13324                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
13325 }
13326
13327 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
13328                                        unsigned int res)
13329 {
13330         if ((res >> 26) == ALC880_HP_EVENT)
13331                 alc861_toshiba_automute(codec);
13332 }
13333
13334 /* pcm configuration: identiacal with ALC880 */
13335 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
13336 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
13337 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
13338 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
13339
13340
13341 #define ALC861_DIGOUT_NID       0x07
13342
13343 static struct hda_channel_mode alc861_8ch_modes[1] = {
13344         { 8, NULL }
13345 };
13346
13347 static hda_nid_t alc861_dac_nids[4] = {
13348         /* front, surround, clfe, side */
13349         0x03, 0x06, 0x05, 0x04
13350 };
13351
13352 static hda_nid_t alc660_dac_nids[3] = {
13353         /* front, clfe, surround */
13354         0x03, 0x05, 0x06
13355 };
13356
13357 static hda_nid_t alc861_adc_nids[1] = {
13358         /* ADC0-2 */
13359         0x08,
13360 };
13361
13362 static struct hda_input_mux alc861_capture_source = {
13363         .num_items = 5,
13364         .items = {
13365                 { "Mic", 0x0 },
13366                 { "Front Mic", 0x3 },
13367                 { "Line", 0x1 },
13368                 { "CD", 0x4 },
13369                 { "Mixer", 0x5 },
13370         },
13371 };
13372
13373 /* fill in the dac_nids table from the parsed pin configuration */
13374 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
13375                                      const struct auto_pin_cfg *cfg)
13376 {
13377         int i;
13378         hda_nid_t nid;
13379
13380         spec->multiout.dac_nids = spec->private_dac_nids;
13381         for (i = 0; i < cfg->line_outs; i++) {
13382                 nid = cfg->line_out_pins[i];
13383                 if (nid) {
13384                         if (i >= ARRAY_SIZE(alc861_dac_nids))
13385                                 continue;
13386                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
13387                 }
13388         }
13389         spec->multiout.num_dacs = cfg->line_outs;
13390         return 0;
13391 }
13392
13393 /* add playback controls from the parsed DAC table */
13394 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
13395                                              const struct auto_pin_cfg *cfg)
13396 {
13397         char name[32];
13398         static const char *chname[4] = {
13399                 "Front", "Surround", NULL /*CLFE*/, "Side"
13400         };
13401         hda_nid_t nid;
13402         int i, idx, err;
13403
13404         for (i = 0; i < cfg->line_outs; i++) {
13405                 nid = spec->multiout.dac_nids[i];
13406                 if (!nid)
13407                         continue;
13408                 if (nid == 0x05) {
13409                         /* Center/LFE */
13410                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13411                                           "Center Playback Switch",
13412                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
13413                                                               HDA_OUTPUT));
13414                         if (err < 0)
13415                                 return err;
13416                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13417                                           "LFE Playback Switch",
13418                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13419                                                               HDA_OUTPUT));
13420                         if (err < 0)
13421                                 return err;
13422                 } else {
13423                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
13424                              idx++)
13425                                 if (nid == alc861_dac_nids[idx])
13426                                         break;
13427                         sprintf(name, "%s Playback Switch", chname[idx]);
13428                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13429                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13430                                                               HDA_OUTPUT));
13431                         if (err < 0)
13432                                 return err;
13433                 }
13434         }
13435         return 0;
13436 }
13437
13438 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
13439 {
13440         int err;
13441         hda_nid_t nid;
13442
13443         if (!pin)
13444                 return 0;
13445
13446         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
13447                 nid = 0x03;
13448                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13449                                   "Headphone Playback Switch",
13450                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13451                 if (err < 0)
13452                         return err;
13453                 spec->multiout.hp_nid = nid;
13454         }
13455         return 0;
13456 }
13457
13458 /* create playback/capture controls for input pins */
13459 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
13460                                                 const struct auto_pin_cfg *cfg)
13461 {
13462         struct hda_input_mux *imux = &spec->private_imux;
13463         int i, err, idx, idx1;
13464
13465         for (i = 0; i < AUTO_PIN_LAST; i++) {
13466                 switch (cfg->input_pins[i]) {
13467                 case 0x0c:
13468                         idx1 = 1;
13469                         idx = 2;        /* Line In */
13470                         break;
13471                 case 0x0f:
13472                         idx1 = 2;
13473                         idx = 2;        /* Line In */
13474                         break;
13475                 case 0x0d:
13476                         idx1 = 0;
13477                         idx = 1;        /* Mic In */
13478                         break;
13479                 case 0x10:
13480                         idx1 = 3;
13481                         idx = 1;        /* Mic In */
13482                         break;
13483                 case 0x11:
13484                         idx1 = 4;
13485                         idx = 0;        /* CD */
13486                         break;
13487                 default:
13488                         continue;
13489                 }
13490
13491                 err = new_analog_input(spec, cfg->input_pins[i],
13492                                        auto_pin_cfg_labels[i], idx, 0x15);
13493                 if (err < 0)
13494                         return err;
13495
13496                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
13497                 imux->items[imux->num_items].index = idx1;
13498                 imux->num_items++;
13499         }
13500         return 0;
13501 }
13502
13503 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
13504                                               hda_nid_t nid,
13505                                               int pin_type, int dac_idx)
13506 {
13507         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
13508                             pin_type);
13509         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13510                             AMP_OUT_UNMUTE);
13511 }
13512
13513 static void alc861_auto_init_multi_out(struct hda_codec *codec)
13514 {
13515         struct alc_spec *spec = codec->spec;
13516         int i;
13517
13518         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
13519         for (i = 0; i < spec->autocfg.line_outs; i++) {
13520                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13521                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13522                 if (nid)
13523                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
13524                                                           spec->multiout.dac_nids[i]);
13525         }
13526 }
13527
13528 static void alc861_auto_init_hp_out(struct hda_codec *codec)
13529 {
13530         struct alc_spec *spec = codec->spec;
13531         hda_nid_t pin;
13532
13533         pin = spec->autocfg.hp_pins[0];
13534         if (pin) /* connect to front */
13535                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
13536                                                   spec->multiout.dac_nids[0]);
13537         pin = spec->autocfg.speaker_pins[0];
13538         if (pin)
13539                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13540 }
13541
13542 static void alc861_auto_init_analog_input(struct hda_codec *codec)
13543 {
13544         struct alc_spec *spec = codec->spec;
13545         int i;
13546
13547         for (i = 0; i < AUTO_PIN_LAST; i++) {
13548                 hda_nid_t nid = spec->autocfg.input_pins[i];
13549                 if (nid >= 0x0c && nid <= 0x11) {
13550                         snd_hda_codec_write(codec, nid, 0,
13551                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
13552                                             i <= AUTO_PIN_FRONT_MIC ?
13553                                             PIN_VREF80 : PIN_IN);
13554                 }
13555         }
13556 }
13557
13558 /* parse the BIOS configuration and set up the alc_spec */
13559 /* return 1 if successful, 0 if the proper config is not found,
13560  * or a negative error code
13561  */
13562 static int alc861_parse_auto_config(struct hda_codec *codec)
13563 {
13564         struct alc_spec *spec = codec->spec;
13565         int err;
13566         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
13567
13568         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13569                                            alc861_ignore);
13570         if (err < 0)
13571                 return err;
13572         if (!spec->autocfg.line_outs)
13573                 return 0; /* can't find valid BIOS pin config */
13574
13575         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
13576         if (err < 0)
13577                 return err;
13578         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
13579         if (err < 0)
13580                 return err;
13581         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
13582         if (err < 0)
13583                 return err;
13584         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
13585         if (err < 0)
13586                 return err;
13587
13588         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13589
13590         if (spec->autocfg.dig_out_pin)
13591                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
13592
13593         if (spec->kctls.list)
13594                 add_mixer(spec, spec->kctls.list);
13595
13596         add_verb(spec, alc861_auto_init_verbs);
13597
13598         spec->num_mux_defs = 1;
13599         spec->input_mux = &spec->private_imux;
13600
13601         spec->adc_nids = alc861_adc_nids;
13602         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
13603         set_capture_mixer(spec);
13604
13605         store_pin_configs(codec);
13606         return 1;
13607 }
13608
13609 /* additional initialization for auto-configuration model */
13610 static void alc861_auto_init(struct hda_codec *codec)
13611 {
13612         struct alc_spec *spec = codec->spec;
13613         alc861_auto_init_multi_out(codec);
13614         alc861_auto_init_hp_out(codec);
13615         alc861_auto_init_analog_input(codec);
13616         if (spec->unsol_event)
13617                 alc_inithook(codec);
13618 }
13619
13620 #ifdef CONFIG_SND_HDA_POWER_SAVE
13621 static struct hda_amp_list alc861_loopbacks[] = {
13622         { 0x15, HDA_INPUT, 0 },
13623         { 0x15, HDA_INPUT, 1 },
13624         { 0x15, HDA_INPUT, 2 },
13625         { 0x15, HDA_INPUT, 3 },
13626         { } /* end */
13627 };
13628 #endif
13629
13630
13631 /*
13632  * configuration and preset
13633  */
13634 static const char *alc861_models[ALC861_MODEL_LAST] = {
13635         [ALC861_3ST]            = "3stack",
13636         [ALC660_3ST]            = "3stack-660",
13637         [ALC861_3ST_DIG]        = "3stack-dig",
13638         [ALC861_6ST_DIG]        = "6stack-dig",
13639         [ALC861_UNIWILL_M31]    = "uniwill-m31",
13640         [ALC861_TOSHIBA]        = "toshiba",
13641         [ALC861_ASUS]           = "asus",
13642         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
13643         [ALC861_AUTO]           = "auto",
13644 };
13645
13646 static struct snd_pci_quirk alc861_cfg_tbl[] = {
13647         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
13648         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13649         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13650         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
13651         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
13652         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
13653         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
13654         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
13655          *        Any other models that need this preset?
13656          */
13657         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
13658         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
13659         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
13660         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
13661         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
13662         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
13663         /* FIXME: the below seems conflict */
13664         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
13665         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
13666         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
13667         {}
13668 };
13669
13670 static struct alc_config_preset alc861_presets[] = {
13671         [ALC861_3ST] = {
13672                 .mixers = { alc861_3ST_mixer },
13673                 .init_verbs = { alc861_threestack_init_verbs },
13674                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13675                 .dac_nids = alc861_dac_nids,
13676                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13677                 .channel_mode = alc861_threestack_modes,
13678                 .need_dac_fix = 1,
13679                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13680                 .adc_nids = alc861_adc_nids,
13681                 .input_mux = &alc861_capture_source,
13682         },
13683         [ALC861_3ST_DIG] = {
13684                 .mixers = { alc861_base_mixer },
13685                 .init_verbs = { alc861_threestack_init_verbs },
13686                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13687                 .dac_nids = alc861_dac_nids,
13688                 .dig_out_nid = ALC861_DIGOUT_NID,
13689                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13690                 .channel_mode = alc861_threestack_modes,
13691                 .need_dac_fix = 1,
13692                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13693                 .adc_nids = alc861_adc_nids,
13694                 .input_mux = &alc861_capture_source,
13695         },
13696         [ALC861_6ST_DIG] = {
13697                 .mixers = { alc861_base_mixer },
13698                 .init_verbs = { alc861_base_init_verbs },
13699                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13700                 .dac_nids = alc861_dac_nids,
13701                 .dig_out_nid = ALC861_DIGOUT_NID,
13702                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
13703                 .channel_mode = alc861_8ch_modes,
13704                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13705                 .adc_nids = alc861_adc_nids,
13706                 .input_mux = &alc861_capture_source,
13707         },
13708         [ALC660_3ST] = {
13709                 .mixers = { alc861_3ST_mixer },
13710                 .init_verbs = { alc861_threestack_init_verbs },
13711                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
13712                 .dac_nids = alc660_dac_nids,
13713                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13714                 .channel_mode = alc861_threestack_modes,
13715                 .need_dac_fix = 1,
13716                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13717                 .adc_nids = alc861_adc_nids,
13718                 .input_mux = &alc861_capture_source,
13719         },
13720         [ALC861_UNIWILL_M31] = {
13721                 .mixers = { alc861_uniwill_m31_mixer },
13722                 .init_verbs = { alc861_uniwill_m31_init_verbs },
13723                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13724                 .dac_nids = alc861_dac_nids,
13725                 .dig_out_nid = ALC861_DIGOUT_NID,
13726                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
13727                 .channel_mode = alc861_uniwill_m31_modes,
13728                 .need_dac_fix = 1,
13729                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13730                 .adc_nids = alc861_adc_nids,
13731                 .input_mux = &alc861_capture_source,
13732         },
13733         [ALC861_TOSHIBA] = {
13734                 .mixers = { alc861_toshiba_mixer },
13735                 .init_verbs = { alc861_base_init_verbs,
13736                                 alc861_toshiba_init_verbs },
13737                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13738                 .dac_nids = alc861_dac_nids,
13739                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13740                 .channel_mode = alc883_3ST_2ch_modes,
13741                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13742                 .adc_nids = alc861_adc_nids,
13743                 .input_mux = &alc861_capture_source,
13744                 .unsol_event = alc861_toshiba_unsol_event,
13745                 .init_hook = alc861_toshiba_automute,
13746         },
13747         [ALC861_ASUS] = {
13748                 .mixers = { alc861_asus_mixer },
13749                 .init_verbs = { alc861_asus_init_verbs },
13750                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13751                 .dac_nids = alc861_dac_nids,
13752                 .dig_out_nid = ALC861_DIGOUT_NID,
13753                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
13754                 .channel_mode = alc861_asus_modes,
13755                 .need_dac_fix = 1,
13756                 .hp_nid = 0x06,
13757                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13758                 .adc_nids = alc861_adc_nids,
13759                 .input_mux = &alc861_capture_source,
13760         },
13761         [ALC861_ASUS_LAPTOP] = {
13762                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
13763                 .init_verbs = { alc861_asus_init_verbs,
13764                                 alc861_asus_laptop_init_verbs },
13765                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13766                 .dac_nids = alc861_dac_nids,
13767                 .dig_out_nid = ALC861_DIGOUT_NID,
13768                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13769                 .channel_mode = alc883_3ST_2ch_modes,
13770                 .need_dac_fix = 1,
13771                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13772                 .adc_nids = alc861_adc_nids,
13773                 .input_mux = &alc861_capture_source,
13774         },
13775 };
13776
13777
13778 static int patch_alc861(struct hda_codec *codec)
13779 {
13780         struct alc_spec *spec;
13781         int board_config;
13782         int err;
13783
13784         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13785         if (spec == NULL)
13786                 return -ENOMEM;
13787
13788         codec->spec = spec;
13789
13790         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
13791                                                   alc861_models,
13792                                                   alc861_cfg_tbl);
13793
13794         if (board_config < 0) {
13795                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
13796                        "trying auto-probe from BIOS...\n");
13797                 board_config = ALC861_AUTO;
13798         }
13799
13800         if (board_config == ALC861_AUTO) {
13801                 /* automatic parse from the BIOS config */
13802                 err = alc861_parse_auto_config(codec);
13803                 if (err < 0) {
13804                         alc_free(codec);
13805                         return err;
13806                 } else if (!err) {
13807                         printk(KERN_INFO
13808                                "hda_codec: Cannot set up configuration "
13809                                "from BIOS.  Using base mode...\n");
13810                    board_config = ALC861_3ST_DIG;
13811                 }
13812         }
13813
13814         if (board_config != ALC861_AUTO)
13815                 setup_preset(spec, &alc861_presets[board_config]);
13816
13817         spec->stream_name_analog = "ALC861 Analog";
13818         spec->stream_analog_playback = &alc861_pcm_analog_playback;
13819         spec->stream_analog_capture = &alc861_pcm_analog_capture;
13820
13821         spec->stream_name_digital = "ALC861 Digital";
13822         spec->stream_digital_playback = &alc861_pcm_digital_playback;
13823         spec->stream_digital_capture = &alc861_pcm_digital_capture;
13824
13825         spec->vmaster_nid = 0x03;
13826
13827         codec->patch_ops = alc_patch_ops;
13828         if (board_config == ALC861_AUTO)
13829                 spec->init_hook = alc861_auto_init;
13830 #ifdef CONFIG_SND_HDA_POWER_SAVE
13831         if (!spec->loopback.amplist)
13832                 spec->loopback.amplist = alc861_loopbacks;
13833 #endif
13834         codec->proc_widget_hook = print_realtek_coef;
13835
13836         return 0;
13837 }
13838
13839 /*
13840  * ALC861-VD support
13841  *
13842  * Based on ALC882
13843  *
13844  * In addition, an independent DAC
13845  */
13846 #define ALC861VD_DIGOUT_NID     0x06
13847
13848 static hda_nid_t alc861vd_dac_nids[4] = {
13849         /* front, surr, clfe, side surr */
13850         0x02, 0x03, 0x04, 0x05
13851 };
13852
13853 /* dac_nids for ALC660vd are in a different order - according to
13854  * Realtek's driver.
13855  * This should probably tesult in a different mixer for 6stack models
13856  * of ALC660vd codecs, but for now there is only 3stack mixer
13857  * - and it is the same as in 861vd.
13858  * adc_nids in ALC660vd are (is) the same as in 861vd
13859  */
13860 static hda_nid_t alc660vd_dac_nids[3] = {
13861         /* front, rear, clfe, rear_surr */
13862         0x02, 0x04, 0x03
13863 };
13864
13865 static hda_nid_t alc861vd_adc_nids[1] = {
13866         /* ADC0 */
13867         0x09,
13868 };
13869
13870 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
13871
13872 /* input MUX */
13873 /* FIXME: should be a matrix-type input source selection */
13874 static struct hda_input_mux alc861vd_capture_source = {
13875         .num_items = 4,
13876         .items = {
13877                 { "Mic", 0x0 },
13878                 { "Front Mic", 0x1 },
13879                 { "Line", 0x2 },
13880                 { "CD", 0x4 },
13881         },
13882 };
13883
13884 static struct hda_input_mux alc861vd_dallas_capture_source = {
13885         .num_items = 2,
13886         .items = {
13887                 { "Ext Mic", 0x0 },
13888                 { "Int Mic", 0x1 },
13889         },
13890 };
13891
13892 static struct hda_input_mux alc861vd_hp_capture_source = {
13893         .num_items = 2,
13894         .items = {
13895                 { "Front Mic", 0x0 },
13896                 { "ATAPI Mic", 0x1 },
13897         },
13898 };
13899
13900 /*
13901  * 2ch mode
13902  */
13903 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
13904         { 2, NULL }
13905 };
13906
13907 /*
13908  * 6ch mode
13909  */
13910 static struct hda_verb alc861vd_6stack_ch6_init[] = {
13911         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13912         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13913         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13914         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13915         { } /* end */
13916 };
13917
13918 /*
13919  * 8ch mode
13920  */
13921 static struct hda_verb alc861vd_6stack_ch8_init[] = {
13922         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13923         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13924         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13925         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13926         { } /* end */
13927 };
13928
13929 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
13930         { 6, alc861vd_6stack_ch6_init },
13931         { 8, alc861vd_6stack_ch8_init },
13932 };
13933
13934 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
13935         {
13936                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13937                 .name = "Channel Mode",
13938                 .info = alc_ch_mode_info,
13939                 .get = alc_ch_mode_get,
13940                 .put = alc_ch_mode_put,
13941         },
13942         { } /* end */
13943 };
13944
13945 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
13946  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
13947  */
13948 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
13949         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13950         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13951
13952         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13953         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
13954
13955         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
13956                                 HDA_OUTPUT),
13957         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
13958                                 HDA_OUTPUT),
13959         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
13960         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
13961
13962         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
13963         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
13964
13965         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13966
13967         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13968         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13969         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13970
13971         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13972         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13973         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13974
13975         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13976         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13977
13978         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13979         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13980
13981         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13982         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13983
13984         { } /* end */
13985 };
13986
13987 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
13988         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13989         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13990
13991         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13992
13993         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13994         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13995         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13996
13997         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13998         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13999         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14000
14001         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14002         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14003
14004         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14005         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14006
14007         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14008         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14009
14010         { } /* end */
14011 };
14012
14013 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
14014         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14015         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
14016         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14017
14018         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14019
14020         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14021         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14022         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14023
14024         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14025         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14026         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14027
14028         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14029         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14030
14031         { } /* end */
14032 };
14033
14034 /* Pin assignment: Speaker=0x14, HP = 0x15,
14035  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
14036  */
14037 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
14038         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14039         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
14040         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14041         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14042         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
14043         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14044         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14045         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
14046         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14047         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14048         HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
14049         HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
14050         { } /* end */
14051 };
14052
14053 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
14054  *                 Front Mic=0x18, ATAPI Mic = 0x19,
14055  */
14056 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
14057         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14058         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14059         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14060         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14061         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14062         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14063         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14064         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14065
14066         { } /* end */
14067 };
14068
14069 /*
14070  * generic initialization of ADC, input mixers and output mixers
14071  */
14072 static struct hda_verb alc861vd_volume_init_verbs[] = {
14073         /*
14074          * Unmute ADC0 and set the default input to mic-in
14075          */
14076         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14077         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14078
14079         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
14080          * the analog-loopback mixer widget
14081          */
14082         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14083         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14084         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14085         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14086         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14087         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14088
14089         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
14090         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14091         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14092         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14093         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14094
14095         /*
14096          * Set up output mixers (0x02 - 0x05)
14097          */
14098         /* set vol=0 to output mixers */
14099         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14100         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14101         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14102         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14103
14104         /* set up input amps for analog loopback */
14105         /* Amp Indices: DAC = 0, mixer = 1 */
14106         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14107         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14108         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14109         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14110         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14111         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14112         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14113         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14114
14115         { }
14116 };
14117
14118 /*
14119  * 3-stack pin configuration:
14120  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
14121  */
14122 static struct hda_verb alc861vd_3stack_init_verbs[] = {
14123         /*
14124          * Set pin mode and muting
14125          */
14126         /* set front pin widgets 0x14 for output */
14127         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14128         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14129         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14130
14131         /* Mic (rear) pin: input vref at 80% */
14132         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14133         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14134         /* Front Mic pin: input vref at 80% */
14135         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14136         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14137         /* Line In pin: input */
14138         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14139         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14140         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14141         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14142         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14143         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14144         /* CD pin widget for input */
14145         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14146
14147         { }
14148 };
14149
14150 /*
14151  * 6-stack pin configuration:
14152  */
14153 static struct hda_verb alc861vd_6stack_init_verbs[] = {
14154         /*
14155          * Set pin mode and muting
14156          */
14157         /* set front pin widgets 0x14 for output */
14158         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14159         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14160         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14161
14162         /* Rear Pin: output 1 (0x0d) */
14163         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14164         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14165         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14166         /* CLFE Pin: output 2 (0x0e) */
14167         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14168         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14169         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
14170         /* Side Pin: output 3 (0x0f) */
14171         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14172         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14173         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
14174
14175         /* Mic (rear) pin: input vref at 80% */
14176         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14177         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14178         /* Front Mic pin: input vref at 80% */
14179         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14180         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14181         /* Line In pin: input */
14182         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14183         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14184         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14185         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14186         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14187         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14188         /* CD pin widget for input */
14189         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14190
14191         { }
14192 };
14193
14194 static struct hda_verb alc861vd_eapd_verbs[] = {
14195         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14196         { }
14197 };
14198
14199 static struct hda_verb alc660vd_eapd_verbs[] = {
14200         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14201         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
14202         { }
14203 };
14204
14205 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
14206         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14207         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14208         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
14209         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14210         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14211         {}
14212 };
14213
14214 /* toggle speaker-output according to the hp-jack state */
14215 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
14216 {
14217         unsigned int present;
14218         unsigned char bits;
14219
14220         present = snd_hda_codec_read(codec, 0x1b, 0,
14221                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14222         bits = present ? HDA_AMP_MUTE : 0;
14223         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14224                                  HDA_AMP_MUTE, bits);
14225 }
14226
14227 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
14228 {
14229         unsigned int present;
14230         unsigned char bits;
14231
14232         present = snd_hda_codec_read(codec, 0x18, 0,
14233                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14234         bits = present ? HDA_AMP_MUTE : 0;
14235         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
14236                                  HDA_AMP_MUTE, bits);
14237 }
14238
14239 static void alc861vd_lenovo_automute(struct hda_codec *codec)
14240 {
14241         alc861vd_lenovo_hp_automute(codec);
14242         alc861vd_lenovo_mic_automute(codec);
14243 }
14244
14245 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
14246                                         unsigned int res)
14247 {
14248         switch (res >> 26) {
14249         case ALC880_HP_EVENT:
14250                 alc861vd_lenovo_hp_automute(codec);
14251                 break;
14252         case ALC880_MIC_EVENT:
14253                 alc861vd_lenovo_mic_automute(codec);
14254                 break;
14255         }
14256 }
14257
14258 static struct hda_verb alc861vd_dallas_verbs[] = {
14259         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14260         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14261         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14262         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14263
14264         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14265         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14266         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14267         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14268         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14269         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14270         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14271         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14272
14273         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14274         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14275         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14276         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14277         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14278         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14279         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14280         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14281
14282         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14283         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14284         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14285         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14286         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14287         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14288         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14289         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14290
14291         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14292         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14293         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14294         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14295
14296         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14297         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14298         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14299
14300         { } /* end */
14301 };
14302
14303 /* toggle speaker-output according to the hp-jack state */
14304 static void alc861vd_dallas_automute(struct hda_codec *codec)
14305 {
14306         unsigned int present;
14307
14308         present = snd_hda_codec_read(codec, 0x15, 0,
14309                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14310         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14311                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14312 }
14313
14314 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
14315 {
14316         if ((res >> 26) == ALC880_HP_EVENT)
14317                 alc861vd_dallas_automute(codec);
14318 }
14319
14320 #ifdef CONFIG_SND_HDA_POWER_SAVE
14321 #define alc861vd_loopbacks      alc880_loopbacks
14322 #endif
14323
14324 /* pcm configuration: identiacal with ALC880 */
14325 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
14326 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
14327 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
14328 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
14329
14330 /*
14331  * configuration and preset
14332  */
14333 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
14334         [ALC660VD_3ST]          = "3stack-660",
14335         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
14336         [ALC660VD_ASUS_V1S]     = "asus-v1s",
14337         [ALC861VD_3ST]          = "3stack",
14338         [ALC861VD_3ST_DIG]      = "3stack-digout",
14339         [ALC861VD_6ST_DIG]      = "6stack-digout",
14340         [ALC861VD_LENOVO]       = "lenovo",
14341         [ALC861VD_DALLAS]       = "dallas",
14342         [ALC861VD_HP]           = "hp",
14343         [ALC861VD_AUTO]         = "auto",
14344 };
14345
14346 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
14347         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
14348         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
14349         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
14350         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
14351         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
14352         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
14353         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
14354         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
14355         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
14356         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
14357         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
14358         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
14359         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
14360         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
14361         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
14362         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 N200", ALC861VD_LENOVO),
14363         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
14364         {}
14365 };
14366
14367 static struct alc_config_preset alc861vd_presets[] = {
14368         [ALC660VD_3ST] = {
14369                 .mixers = { alc861vd_3st_mixer },
14370                 .init_verbs = { alc861vd_volume_init_verbs,
14371                                  alc861vd_3stack_init_verbs },
14372                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14373                 .dac_nids = alc660vd_dac_nids,
14374                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14375                 .channel_mode = alc861vd_3stack_2ch_modes,
14376                 .input_mux = &alc861vd_capture_source,
14377         },
14378         [ALC660VD_3ST_DIG] = {
14379                 .mixers = { alc861vd_3st_mixer },
14380                 .init_verbs = { alc861vd_volume_init_verbs,
14381                                  alc861vd_3stack_init_verbs },
14382                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14383                 .dac_nids = alc660vd_dac_nids,
14384                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14385                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14386                 .channel_mode = alc861vd_3stack_2ch_modes,
14387                 .input_mux = &alc861vd_capture_source,
14388         },
14389         [ALC861VD_3ST] = {
14390                 .mixers = { alc861vd_3st_mixer },
14391                 .init_verbs = { alc861vd_volume_init_verbs,
14392                                  alc861vd_3stack_init_verbs },
14393                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14394                 .dac_nids = alc861vd_dac_nids,
14395                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14396                 .channel_mode = alc861vd_3stack_2ch_modes,
14397                 .input_mux = &alc861vd_capture_source,
14398         },
14399         [ALC861VD_3ST_DIG] = {
14400                 .mixers = { alc861vd_3st_mixer },
14401                 .init_verbs = { alc861vd_volume_init_verbs,
14402                                  alc861vd_3stack_init_verbs },
14403                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14404                 .dac_nids = alc861vd_dac_nids,
14405                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14406                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14407                 .channel_mode = alc861vd_3stack_2ch_modes,
14408                 .input_mux = &alc861vd_capture_source,
14409         },
14410         [ALC861VD_6ST_DIG] = {
14411                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
14412                 .init_verbs = { alc861vd_volume_init_verbs,
14413                                 alc861vd_6stack_init_verbs },
14414                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14415                 .dac_nids = alc861vd_dac_nids,
14416                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14417                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
14418                 .channel_mode = alc861vd_6stack_modes,
14419                 .input_mux = &alc861vd_capture_source,
14420         },
14421         [ALC861VD_LENOVO] = {
14422                 .mixers = { alc861vd_lenovo_mixer },
14423                 .init_verbs = { alc861vd_volume_init_verbs,
14424                                 alc861vd_3stack_init_verbs,
14425                                 alc861vd_eapd_verbs,
14426                                 alc861vd_lenovo_unsol_verbs },
14427                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14428                 .dac_nids = alc660vd_dac_nids,
14429                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14430                 .channel_mode = alc861vd_3stack_2ch_modes,
14431                 .input_mux = &alc861vd_capture_source,
14432                 .unsol_event = alc861vd_lenovo_unsol_event,
14433                 .init_hook = alc861vd_lenovo_automute,
14434         },
14435         [ALC861VD_DALLAS] = {
14436                 .mixers = { alc861vd_dallas_mixer },
14437                 .init_verbs = { alc861vd_dallas_verbs },
14438                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14439                 .dac_nids = alc861vd_dac_nids,
14440                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14441                 .channel_mode = alc861vd_3stack_2ch_modes,
14442                 .input_mux = &alc861vd_dallas_capture_source,
14443                 .unsol_event = alc861vd_dallas_unsol_event,
14444                 .init_hook = alc861vd_dallas_automute,
14445         },
14446         [ALC861VD_HP] = {
14447                 .mixers = { alc861vd_hp_mixer },
14448                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
14449                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14450                 .dac_nids = alc861vd_dac_nids,
14451                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14452                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14453                 .channel_mode = alc861vd_3stack_2ch_modes,
14454                 .input_mux = &alc861vd_hp_capture_source,
14455                 .unsol_event = alc861vd_dallas_unsol_event,
14456                 .init_hook = alc861vd_dallas_automute,
14457         },
14458         [ALC660VD_ASUS_V1S] = {
14459                 .mixers = { alc861vd_lenovo_mixer },
14460                 .init_verbs = { alc861vd_volume_init_verbs,
14461                                 alc861vd_3stack_init_verbs,
14462                                 alc861vd_eapd_verbs,
14463                                 alc861vd_lenovo_unsol_verbs },
14464                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14465                 .dac_nids = alc660vd_dac_nids,
14466                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14467                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14468                 .channel_mode = alc861vd_3stack_2ch_modes,
14469                 .input_mux = &alc861vd_capture_source,
14470                 .unsol_event = alc861vd_lenovo_unsol_event,
14471                 .init_hook = alc861vd_lenovo_automute,
14472         },
14473 };
14474
14475 /*
14476  * BIOS auto configuration
14477  */
14478 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
14479                                 hda_nid_t nid, int pin_type, int dac_idx)
14480 {
14481         alc_set_pin_output(codec, nid, pin_type);
14482 }
14483
14484 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
14485 {
14486         struct alc_spec *spec = codec->spec;
14487         int i;
14488
14489         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
14490         for (i = 0; i <= HDA_SIDE; i++) {
14491                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14492                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14493                 if (nid)
14494                         alc861vd_auto_set_output_and_unmute(codec, nid,
14495                                                             pin_type, i);
14496         }
14497 }
14498
14499
14500 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
14501 {
14502         struct alc_spec *spec = codec->spec;
14503         hda_nid_t pin;
14504
14505         pin = spec->autocfg.hp_pins[0];
14506         if (pin) /* connect to front and  use dac 0 */
14507                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
14508         pin = spec->autocfg.speaker_pins[0];
14509         if (pin)
14510                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14511 }
14512
14513 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
14514 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
14515
14516 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
14517 {
14518         struct alc_spec *spec = codec->spec;
14519         int i;
14520
14521         for (i = 0; i < AUTO_PIN_LAST; i++) {
14522                 hda_nid_t nid = spec->autocfg.input_pins[i];
14523                 if (alc861vd_is_input_pin(nid)) {
14524                         snd_hda_codec_write(codec, nid, 0,
14525                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
14526                                         i <= AUTO_PIN_FRONT_MIC ?
14527                                                         PIN_VREF80 : PIN_IN);
14528                         if (nid != ALC861VD_PIN_CD_NID)
14529                                 snd_hda_codec_write(codec, nid, 0,
14530                                                 AC_VERB_SET_AMP_GAIN_MUTE,
14531                                                 AMP_OUT_MUTE);
14532                 }
14533         }
14534 }
14535
14536 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
14537
14538 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
14539 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
14540
14541 /* add playback controls from the parsed DAC table */
14542 /* Based on ALC880 version. But ALC861VD has separate,
14543  * different NIDs for mute/unmute switch and volume control */
14544 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
14545                                              const struct auto_pin_cfg *cfg)
14546 {
14547         char name[32];
14548         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
14549         hda_nid_t nid_v, nid_s;
14550         int i, err;
14551
14552         for (i = 0; i < cfg->line_outs; i++) {
14553                 if (!spec->multiout.dac_nids[i])
14554                         continue;
14555                 nid_v = alc861vd_idx_to_mixer_vol(
14556                                 alc880_dac_to_idx(
14557                                         spec->multiout.dac_nids[i]));
14558                 nid_s = alc861vd_idx_to_mixer_switch(
14559                                 alc880_dac_to_idx(
14560                                         spec->multiout.dac_nids[i]));
14561
14562                 if (i == 2) {
14563                         /* Center/LFE */
14564                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14565                                           "Center Playback Volume",
14566                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
14567                                                               HDA_OUTPUT));
14568                         if (err < 0)
14569                                 return err;
14570                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14571                                           "LFE Playback Volume",
14572                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
14573                                                               HDA_OUTPUT));
14574                         if (err < 0)
14575                                 return err;
14576                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14577                                           "Center Playback Switch",
14578                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
14579                                                               HDA_INPUT));
14580                         if (err < 0)
14581                                 return err;
14582                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14583                                           "LFE Playback Switch",
14584                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
14585                                                               HDA_INPUT));
14586                         if (err < 0)
14587                                 return err;
14588                 } else {
14589                         sprintf(name, "%s Playback Volume", chname[i]);
14590                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14591                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
14592                                                               HDA_OUTPUT));
14593                         if (err < 0)
14594                                 return err;
14595                         sprintf(name, "%s Playback Switch", chname[i]);
14596                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14597                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
14598                                                               HDA_INPUT));
14599                         if (err < 0)
14600                                 return err;
14601                 }
14602         }
14603         return 0;
14604 }
14605
14606 /* add playback controls for speaker and HP outputs */
14607 /* Based on ALC880 version. But ALC861VD has separate,
14608  * different NIDs for mute/unmute switch and volume control */
14609 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
14610                                         hda_nid_t pin, const char *pfx)
14611 {
14612         hda_nid_t nid_v, nid_s;
14613         int err;
14614         char name[32];
14615
14616         if (!pin)
14617                 return 0;
14618
14619         if (alc880_is_fixed_pin(pin)) {
14620                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14621                 /* specify the DAC as the extra output */
14622                 if (!spec->multiout.hp_nid)
14623                         spec->multiout.hp_nid = nid_v;
14624                 else
14625                         spec->multiout.extra_out_nid[0] = nid_v;
14626                 /* control HP volume/switch on the output mixer amp */
14627                 nid_v = alc861vd_idx_to_mixer_vol(
14628                                 alc880_fixed_pin_idx(pin));
14629                 nid_s = alc861vd_idx_to_mixer_switch(
14630                                 alc880_fixed_pin_idx(pin));
14631
14632                 sprintf(name, "%s Playback Volume", pfx);
14633                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14634                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
14635                 if (err < 0)
14636                         return err;
14637                 sprintf(name, "%s Playback Switch", pfx);
14638                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14639                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
14640                 if (err < 0)
14641                         return err;
14642         } else if (alc880_is_multi_pin(pin)) {
14643                 /* set manual connection */
14644                 /* we have only a switch on HP-out PIN */
14645                 sprintf(name, "%s Playback Switch", pfx);
14646                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14647                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
14648                 if (err < 0)
14649                         return err;
14650         }
14651         return 0;
14652 }
14653
14654 /* parse the BIOS configuration and set up the alc_spec
14655  * return 1 if successful, 0 if the proper config is not found,
14656  * or a negative error code
14657  * Based on ALC880 version - had to change it to override
14658  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
14659 static int alc861vd_parse_auto_config(struct hda_codec *codec)
14660 {
14661         struct alc_spec *spec = codec->spec;
14662         int err;
14663         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
14664
14665         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14666                                            alc861vd_ignore);
14667         if (err < 0)
14668                 return err;
14669         if (!spec->autocfg.line_outs)
14670                 return 0; /* can't find valid BIOS pin config */
14671
14672         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
14673         if (err < 0)
14674                 return err;
14675         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
14676         if (err < 0)
14677                 return err;
14678         err = alc861vd_auto_create_extra_out(spec,
14679                                              spec->autocfg.speaker_pins[0],
14680                                              "Speaker");
14681         if (err < 0)
14682                 return err;
14683         err = alc861vd_auto_create_extra_out(spec,
14684                                              spec->autocfg.hp_pins[0],
14685                                              "Headphone");
14686         if (err < 0)
14687                 return err;
14688         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
14689         if (err < 0)
14690                 return err;
14691
14692         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14693
14694         if (spec->autocfg.dig_out_pin)
14695                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
14696
14697         if (spec->kctls.list)
14698                 add_mixer(spec, spec->kctls.list);
14699
14700         add_verb(spec, alc861vd_volume_init_verbs);
14701
14702         spec->num_mux_defs = 1;
14703         spec->input_mux = &spec->private_imux;
14704
14705         err = alc_auto_add_mic_boost(codec);
14706         if (err < 0)
14707                 return err;
14708
14709         store_pin_configs(codec);
14710         return 1;
14711 }
14712
14713 /* additional initialization for auto-configuration model */
14714 static void alc861vd_auto_init(struct hda_codec *codec)
14715 {
14716         struct alc_spec *spec = codec->spec;
14717         alc861vd_auto_init_multi_out(codec);
14718         alc861vd_auto_init_hp_out(codec);
14719         alc861vd_auto_init_analog_input(codec);
14720         alc861vd_auto_init_input_src(codec);
14721         if (spec->unsol_event)
14722                 alc_inithook(codec);
14723 }
14724
14725 static int patch_alc861vd(struct hda_codec *codec)
14726 {
14727         struct alc_spec *spec;
14728         int err, board_config;
14729
14730         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14731         if (spec == NULL)
14732                 return -ENOMEM;
14733
14734         codec->spec = spec;
14735
14736         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
14737                                                   alc861vd_models,
14738                                                   alc861vd_cfg_tbl);
14739
14740         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
14741                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
14742                         "ALC861VD, trying auto-probe from BIOS...\n");
14743                 board_config = ALC861VD_AUTO;
14744         }
14745
14746         if (board_config == ALC861VD_AUTO) {
14747                 /* automatic parse from the BIOS config */
14748                 err = alc861vd_parse_auto_config(codec);
14749                 if (err < 0) {
14750                         alc_free(codec);
14751                         return err;
14752                 } else if (!err) {
14753                         printk(KERN_INFO
14754                                "hda_codec: Cannot set up configuration "
14755                                "from BIOS.  Using base mode...\n");
14756                         board_config = ALC861VD_3ST;
14757                 }
14758         }
14759
14760         if (board_config != ALC861VD_AUTO)
14761                 setup_preset(spec, &alc861vd_presets[board_config]);
14762
14763         if (codec->vendor_id == 0x10ec0660) {
14764                 spec->stream_name_analog = "ALC660-VD Analog";
14765                 spec->stream_name_digital = "ALC660-VD Digital";
14766                 /* always turn on EAPD */
14767                 add_verb(spec, alc660vd_eapd_verbs);
14768         } else {
14769                 spec->stream_name_analog = "ALC861VD Analog";
14770                 spec->stream_name_digital = "ALC861VD Digital";
14771         }
14772
14773         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
14774         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
14775
14776         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
14777         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
14778
14779         spec->adc_nids = alc861vd_adc_nids;
14780         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
14781         spec->capsrc_nids = alc861vd_capsrc_nids;
14782         spec->is_mix_capture = 1;
14783
14784         set_capture_mixer(spec);
14785
14786         spec->vmaster_nid = 0x02;
14787
14788         codec->patch_ops = alc_patch_ops;
14789
14790         if (board_config == ALC861VD_AUTO)
14791                 spec->init_hook = alc861vd_auto_init;
14792 #ifdef CONFIG_SND_HDA_POWER_SAVE
14793         if (!spec->loopback.amplist)
14794                 spec->loopback.amplist = alc861vd_loopbacks;
14795 #endif
14796         codec->proc_widget_hook = print_realtek_coef;
14797
14798         return 0;
14799 }
14800
14801 /*
14802  * ALC662 support
14803  *
14804  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
14805  * configuration.  Each pin widget can choose any input DACs and a mixer.
14806  * Each ADC is connected from a mixer of all inputs.  This makes possible
14807  * 6-channel independent captures.
14808  *
14809  * In addition, an independent DAC for the multi-playback (not used in this
14810  * driver yet).
14811  */
14812 #define ALC662_DIGOUT_NID       0x06
14813 #define ALC662_DIGIN_NID        0x0a
14814
14815 static hda_nid_t alc662_dac_nids[4] = {
14816         /* front, rear, clfe, rear_surr */
14817         0x02, 0x03, 0x04
14818 };
14819
14820 static hda_nid_t alc662_adc_nids[1] = {
14821         /* ADC1-2 */
14822         0x09,
14823 };
14824
14825 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
14826
14827 /* input MUX */
14828 /* FIXME: should be a matrix-type input source selection */
14829 static struct hda_input_mux alc662_capture_source = {
14830         .num_items = 4,
14831         .items = {
14832                 { "Mic", 0x0 },
14833                 { "Front Mic", 0x1 },
14834                 { "Line", 0x2 },
14835                 { "CD", 0x4 },
14836         },
14837 };
14838
14839 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
14840         .num_items = 2,
14841         .items = {
14842                 { "Mic", 0x1 },
14843                 { "Line", 0x2 },
14844         },
14845 };
14846
14847 static struct hda_input_mux alc662_eeepc_capture_source = {
14848         .num_items = 2,
14849         .items = {
14850                 { "i-Mic", 0x1 },
14851                 { "e-Mic", 0x0 },
14852         },
14853 };
14854
14855 static struct hda_input_mux alc663_capture_source = {
14856         .num_items = 3,
14857         .items = {
14858                 { "Mic", 0x0 },
14859                 { "Front Mic", 0x1 },
14860                 { "Line", 0x2 },
14861         },
14862 };
14863
14864 static struct hda_input_mux alc663_m51va_capture_source = {
14865         .num_items = 2,
14866         .items = {
14867                 { "Ext-Mic", 0x0 },
14868                 { "D-Mic", 0x9 },
14869         },
14870 };
14871
14872 /*
14873  * 2ch mode
14874  */
14875 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
14876         { 2, NULL }
14877 };
14878
14879 /*
14880  * 2ch mode
14881  */
14882 static struct hda_verb alc662_3ST_ch2_init[] = {
14883         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
14884         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14885         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
14886         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14887         { } /* end */
14888 };
14889
14890 /*
14891  * 6ch mode
14892  */
14893 static struct hda_verb alc662_3ST_ch6_init[] = {
14894         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14895         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14896         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
14897         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14898         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14899         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
14900         { } /* end */
14901 };
14902
14903 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
14904         { 2, alc662_3ST_ch2_init },
14905         { 6, alc662_3ST_ch6_init },
14906 };
14907
14908 /*
14909  * 2ch mode
14910  */
14911 static struct hda_verb alc662_sixstack_ch6_init[] = {
14912         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14913         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14914         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14915         { } /* end */
14916 };
14917
14918 /*
14919  * 6ch mode
14920  */
14921 static struct hda_verb alc662_sixstack_ch8_init[] = {
14922         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14923         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14924         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14925         { } /* end */
14926 };
14927
14928 static struct hda_channel_mode alc662_5stack_modes[2] = {
14929         { 2, alc662_sixstack_ch6_init },
14930         { 6, alc662_sixstack_ch8_init },
14931 };
14932
14933 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14934  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14935  */
14936
14937 static struct snd_kcontrol_new alc662_base_mixer[] = {
14938         /* output mixer control */
14939         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
14940         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14941         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
14942         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
14943         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14944         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14945         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
14946         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
14947         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14948
14949         /*Input mixer control */
14950         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
14951         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
14952         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
14953         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
14954         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
14955         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
14956         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
14957         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
14958         { } /* end */
14959 };
14960
14961 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
14962         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14963         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14964         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14965         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14966         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14967         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14968         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14969         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14970         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14971         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14972         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14973         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14974         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14975         { } /* end */
14976 };
14977
14978 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
14979         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14980         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14981         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14982         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
14983         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14984         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14985         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
14986         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
14987         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14988         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14989         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14990         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14991         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14992         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14993         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14994         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14995         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14996         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14997         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14998         { } /* end */
14999 };
15000
15001 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
15002         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15003         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
15004         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15005         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
15006         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15007         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15008         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15009         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15010         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15011         { } /* end */
15012 };
15013
15014 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
15015         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15016
15017         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15018         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15019
15020         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
15021         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15022         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15023
15024         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15025         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15026         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15027         { } /* end */
15028 };
15029
15030 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
15031         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15032         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15033         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15034         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
15035         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15036         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15037         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
15038         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
15039         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15040         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
15041         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15042         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15043         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15044         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15045         { } /* end */
15046 };
15047
15048 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
15049         .ops = &snd_hda_bind_vol,
15050         .values = {
15051                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15052                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
15053                 0
15054         },
15055 };
15056
15057 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
15058         .ops = &snd_hda_bind_sw,
15059         .values = {
15060                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15061                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15062                 0
15063         },
15064 };
15065
15066 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
15067         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15068         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
15069         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15070         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15071         { } /* end */
15072 };
15073
15074 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
15075         .ops = &snd_hda_bind_sw,
15076         .values = {
15077                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15078                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15079                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15080                 0
15081         },
15082 };
15083
15084 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
15085         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15086         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
15087         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15088         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15089         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15090         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15091
15092         { } /* end */
15093 };
15094
15095 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
15096         .ops = &snd_hda_bind_sw,
15097         .values = {
15098                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15099                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15100                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15101                 0
15102         },
15103 };
15104
15105 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
15106         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15107         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
15108         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15109         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15110         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15111         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15112         { } /* end */
15113 };
15114
15115 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
15116         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15117         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15118         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15119         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15120         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15121         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15122         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15123         { } /* end */
15124 };
15125
15126 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
15127         .ops = &snd_hda_bind_vol,
15128         .values = {
15129                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15130                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
15131                 0
15132         },
15133 };
15134
15135 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
15136         .ops = &snd_hda_bind_sw,
15137         .values = {
15138                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15139                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
15140                 0
15141         },
15142 };
15143
15144 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
15145         HDA_BIND_VOL("Master Playback Volume",
15146                                 &alc663_asus_two_bind_master_vol),
15147         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15148         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15149         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15150         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15151         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15152         { } /* end */
15153 };
15154
15155 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
15156         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15157         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15158         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15159         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15160         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15161         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15162         { } /* end */
15163 };
15164
15165 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
15166         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15167         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15168         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15169         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15170         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15171
15172         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15173         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15174         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15175         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15176         { } /* end */
15177 };
15178
15179 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
15180         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15181         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15182         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15183
15184         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15185         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15186         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15187         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15188         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15189         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15190         { } /* end */
15191 };
15192
15193 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
15194         {
15195                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15196                 .name = "Channel Mode",
15197                 .info = alc_ch_mode_info,
15198                 .get = alc_ch_mode_get,
15199                 .put = alc_ch_mode_put,
15200         },
15201         { } /* end */
15202 };
15203
15204 static struct hda_verb alc662_init_verbs[] = {
15205         /* ADC: mute amp left and right */
15206         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15207         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15208         /* Front mixer: unmute input/output amp left and right (volume = 0) */
15209
15210         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15211         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15212         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15213         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15214         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15215
15216         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15217         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15218         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15219         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15220         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15221         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15222
15223         /* Front Pin: output 0 (0x0c) */
15224         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15225         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15226
15227         /* Rear Pin: output 1 (0x0d) */
15228         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15229         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15230
15231         /* CLFE Pin: output 2 (0x0e) */
15232         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15233         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15234
15235         /* Mic (rear) pin: input vref at 80% */
15236         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15237         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15238         /* Front Mic pin: input vref at 80% */
15239         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15240         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15241         /* Line In pin: input */
15242         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15243         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15244         /* Line-2 In: Headphone output (output 0 - 0x0c) */
15245         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15246         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15247         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
15248         /* CD pin widget for input */
15249         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15250
15251         /* FIXME: use matrix-type input source selection */
15252         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15253         /* Input mixer */
15254         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15255         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15256         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15257         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15258
15259         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15260         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15261         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15262         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15263
15264         /* always trun on EAPD */
15265         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15266         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
15267
15268         { }
15269 };
15270
15271 static struct hda_verb alc662_sue_init_verbs[] = {
15272         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15273         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15274         {}
15275 };
15276
15277 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
15278         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15279         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15280         {}
15281 };
15282
15283 /* Set Unsolicited Event*/
15284 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
15285         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15286         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15287         {}
15288 };
15289
15290 /*
15291  * generic initialization of ADC, input mixers and output mixers
15292  */
15293 static struct hda_verb alc662_auto_init_verbs[] = {
15294         /*
15295          * Unmute ADC and set the default input to mic-in
15296          */
15297         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15298         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15299
15300         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
15301          * mixer widget
15302          * Note: PASD motherboards uses the Line In 2 as the input for front
15303          * panel mic (mic 2)
15304          */
15305         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
15306         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15307         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15308         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15309         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15310         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15311
15312         /*
15313          * Set up output mixers (0x0c - 0x0f)
15314          */
15315         /* set vol=0 to output mixers */
15316         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15317         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15318         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15319
15320         /* set up input amps for analog loopback */
15321         /* Amp Indices: DAC = 0, mixer = 1 */
15322         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15323         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15324         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15325         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15326         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15327         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15328
15329
15330         /* FIXME: use matrix-type input source selection */
15331         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15332         /* Input mixer */
15333         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15334         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15335         { }
15336 };
15337
15338 /* additional verbs for ALC663 */
15339 static struct hda_verb alc663_auto_init_verbs[] = {
15340         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15341         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15342         { }
15343 };
15344
15345 static struct hda_verb alc663_m51va_init_verbs[] = {
15346         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15347         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15348         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15349         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15350         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15351         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15352         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
15353         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15354         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15355         {}
15356 };
15357
15358 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
15359         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15360         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15361         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15362         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15363         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15364         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15365         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15366         {}
15367 };
15368
15369 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
15370         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15371         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15372         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15373         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15374         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15375         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15376         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15377         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15378         {}
15379 };
15380
15381 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
15382         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15383         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15384         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15385         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15386         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15387         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15388         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15389         {}
15390 };
15391
15392 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
15393         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15394         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15395         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15396         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15397         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15398         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15399         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15400         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15401         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15402         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15403         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15404         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15405         {}
15406 };
15407
15408 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
15409         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15410         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15411         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15412         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15413         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15414         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15415         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15416         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15417         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15418         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15419         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15420         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15421         {}
15422 };
15423
15424 static struct hda_verb alc663_g71v_init_verbs[] = {
15425         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15426         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
15427         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
15428
15429         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15430         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15431         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15432
15433         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15434         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
15435         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15436         {}
15437 };
15438
15439 static struct hda_verb alc663_g50v_init_verbs[] = {
15440         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15441         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15442         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15443
15444         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15445         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15446         {}
15447 };
15448
15449 static struct hda_verb alc662_ecs_init_verbs[] = {
15450         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
15451         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15452         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15453         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15454         {}
15455 };
15456
15457 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
15458         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
15459         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
15460         { } /* end */
15461 };
15462
15463 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
15464 {
15465         unsigned int present;
15466         unsigned char bits;
15467
15468         present = snd_hda_codec_read(codec, 0x14, 0,
15469                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15470         bits = present ? HDA_AMP_MUTE : 0;
15471         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15472                                  HDA_AMP_MUTE, bits);
15473 }
15474
15475 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
15476 {
15477         unsigned int present;
15478         unsigned char bits;
15479
15480         present = snd_hda_codec_read(codec, 0x1b, 0,
15481                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15482         bits = present ? HDA_AMP_MUTE : 0;
15483         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15484                                  HDA_AMP_MUTE, bits);
15485         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15486                                  HDA_AMP_MUTE, bits);
15487 }
15488
15489 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
15490                                            unsigned int res)
15491 {
15492         if ((res >> 26) == ALC880_HP_EVENT)
15493                 alc662_lenovo_101e_all_automute(codec);
15494         if ((res >> 26) == ALC880_FRONT_EVENT)
15495                 alc662_lenovo_101e_ispeaker_automute(codec);
15496 }
15497
15498 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
15499 {
15500         unsigned int present;
15501
15502         present = snd_hda_codec_read(codec, 0x18, 0,
15503                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15504         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15505                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15506         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15507                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15508         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15509                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15510         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15511                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15512 }
15513
15514 /* unsolicited event for HP jack sensing */
15515 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
15516                                      unsigned int res)
15517 {
15518         if ((res >> 26) == ALC880_HP_EVENT)
15519                 alc262_hippo1_automute( codec );
15520
15521         if ((res >> 26) == ALC880_MIC_EVENT)
15522                 alc662_eeepc_mic_automute(codec);
15523 }
15524
15525 static void alc662_eeepc_inithook(struct hda_codec *codec)
15526 {
15527         alc262_hippo1_automute( codec );
15528         alc662_eeepc_mic_automute(codec);
15529 }
15530
15531 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
15532 {
15533         unsigned int mute;
15534         unsigned int present;
15535
15536         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
15537         present = snd_hda_codec_read(codec, 0x14, 0,
15538                                      AC_VERB_GET_PIN_SENSE, 0);
15539         present = (present & 0x80000000) != 0;
15540         if (present) {
15541                 /* mute internal speaker */
15542                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15543                                         HDA_AMP_MUTE, HDA_AMP_MUTE);
15544         } else {
15545                 /* unmute internal speaker if necessary */
15546                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
15547                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15548                                         HDA_AMP_MUTE, mute);
15549         }
15550 }
15551
15552 /* unsolicited event for HP jack sensing */
15553 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
15554                                           unsigned int res)
15555 {
15556         if ((res >> 26) == ALC880_HP_EVENT)
15557                 alc662_eeepc_ep20_automute(codec);
15558 }
15559
15560 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
15561 {
15562         alc662_eeepc_ep20_automute(codec);
15563 }
15564
15565 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
15566 {
15567         unsigned int present;
15568         unsigned char bits;
15569
15570         present = snd_hda_codec_read(codec, 0x21, 0,
15571                         AC_VERB_GET_PIN_SENSE, 0)
15572                         & AC_PINSENSE_PRESENCE;
15573         bits = present ? HDA_AMP_MUTE : 0;
15574         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15575                                 AMP_IN_MUTE(0), bits);
15576         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15577                                 AMP_IN_MUTE(0), bits);
15578 }
15579
15580 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
15581 {
15582         unsigned int present;
15583         unsigned char bits;
15584
15585         present = snd_hda_codec_read(codec, 0x21, 0,
15586                         AC_VERB_GET_PIN_SENSE, 0)
15587                         & AC_PINSENSE_PRESENCE;
15588         bits = present ? HDA_AMP_MUTE : 0;
15589         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15590                                 AMP_IN_MUTE(0), bits);
15591         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15592                                 AMP_IN_MUTE(0), bits);
15593         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15594                                 AMP_IN_MUTE(0), bits);
15595         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15596                                 AMP_IN_MUTE(0), bits);
15597 }
15598
15599 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
15600 {
15601         unsigned int present;
15602         unsigned char bits;
15603
15604         present = snd_hda_codec_read(codec, 0x15, 0,
15605                         AC_VERB_GET_PIN_SENSE, 0)
15606                         & AC_PINSENSE_PRESENCE;
15607         bits = present ? HDA_AMP_MUTE : 0;
15608         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15609                                 AMP_IN_MUTE(0), bits);
15610         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15611                                 AMP_IN_MUTE(0), bits);
15612         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15613                                 AMP_IN_MUTE(0), bits);
15614         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15615                                 AMP_IN_MUTE(0), bits);
15616 }
15617
15618 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
15619 {
15620         unsigned int present;
15621         unsigned char bits;
15622
15623         present = snd_hda_codec_read(codec, 0x1b, 0,
15624                         AC_VERB_GET_PIN_SENSE, 0)
15625                         & AC_PINSENSE_PRESENCE;
15626         bits = present ? 0 : PIN_OUT;
15627         snd_hda_codec_write(codec, 0x14, 0,
15628                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
15629 }
15630
15631 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
15632 {
15633         unsigned int present1, present2;
15634
15635         present1 = snd_hda_codec_read(codec, 0x21, 0,
15636                         AC_VERB_GET_PIN_SENSE, 0)
15637                         & AC_PINSENSE_PRESENCE;
15638         present2 = snd_hda_codec_read(codec, 0x15, 0,
15639                         AC_VERB_GET_PIN_SENSE, 0)
15640                         & AC_PINSENSE_PRESENCE;
15641
15642         if (present1 || present2) {
15643                 snd_hda_codec_write_cache(codec, 0x14, 0,
15644                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
15645         } else {
15646                 snd_hda_codec_write_cache(codec, 0x14, 0,
15647                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
15648         }
15649 }
15650
15651 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
15652 {
15653         unsigned int present1, present2;
15654
15655         present1 = snd_hda_codec_read(codec, 0x1b, 0,
15656                                 AC_VERB_GET_PIN_SENSE, 0)
15657                                 & AC_PINSENSE_PRESENCE;
15658         present2 = snd_hda_codec_read(codec, 0x15, 0,
15659                                 AC_VERB_GET_PIN_SENSE, 0)
15660                                 & AC_PINSENSE_PRESENCE;
15661
15662         if (present1 || present2) {
15663                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15664                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15665                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15666                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15667         } else {
15668                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15669                                 AMP_IN_MUTE(0), 0);
15670                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15671                                 AMP_IN_MUTE(0), 0);
15672         }
15673 }
15674
15675 static void alc663_m51va_mic_automute(struct hda_codec *codec)
15676 {
15677         unsigned int present;
15678
15679         present = snd_hda_codec_read(codec, 0x18, 0,
15680                         AC_VERB_GET_PIN_SENSE, 0)
15681                         & AC_PINSENSE_PRESENCE;
15682         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15683                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15684         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15685                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15686         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15687                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15688         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15689                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15690 }
15691
15692 static void alc663_m51va_unsol_event(struct hda_codec *codec,
15693                                            unsigned int res)
15694 {
15695         switch (res >> 26) {
15696         case ALC880_HP_EVENT:
15697                 alc663_m51va_speaker_automute(codec);
15698                 break;
15699         case ALC880_MIC_EVENT:
15700                 alc663_m51va_mic_automute(codec);
15701                 break;
15702         }
15703 }
15704
15705 static void alc663_m51va_inithook(struct hda_codec *codec)
15706 {
15707         alc663_m51va_speaker_automute(codec);
15708         alc663_m51va_mic_automute(codec);
15709 }
15710
15711 /* ***************** Mode1 ******************************/
15712 static void alc663_mode1_unsol_event(struct hda_codec *codec,
15713                                            unsigned int res)
15714 {
15715         switch (res >> 26) {
15716         case ALC880_HP_EVENT:
15717                 alc663_m51va_speaker_automute(codec);
15718                 break;
15719         case ALC880_MIC_EVENT:
15720                 alc662_eeepc_mic_automute(codec);
15721                 break;
15722         }
15723 }
15724
15725 static void alc663_mode1_inithook(struct hda_codec *codec)
15726 {
15727         alc663_m51va_speaker_automute(codec);
15728         alc662_eeepc_mic_automute(codec);
15729 }
15730 /* ***************** Mode2 ******************************/
15731 static void alc662_mode2_unsol_event(struct hda_codec *codec,
15732                                            unsigned int res)
15733 {
15734         switch (res >> 26) {
15735         case ALC880_HP_EVENT:
15736                 alc662_f5z_speaker_automute(codec);
15737                 break;
15738         case ALC880_MIC_EVENT:
15739                 alc662_eeepc_mic_automute(codec);
15740                 break;
15741         }
15742 }
15743
15744 static void alc662_mode2_inithook(struct hda_codec *codec)
15745 {
15746         alc662_f5z_speaker_automute(codec);
15747         alc662_eeepc_mic_automute(codec);
15748 }
15749 /* ***************** Mode3 ******************************/
15750 static void alc663_mode3_unsol_event(struct hda_codec *codec,
15751                                            unsigned int res)
15752 {
15753         switch (res >> 26) {
15754         case ALC880_HP_EVENT:
15755                 alc663_two_hp_m1_speaker_automute(codec);
15756                 break;
15757         case ALC880_MIC_EVENT:
15758                 alc662_eeepc_mic_automute(codec);
15759                 break;
15760         }
15761 }
15762
15763 static void alc663_mode3_inithook(struct hda_codec *codec)
15764 {
15765         alc663_two_hp_m1_speaker_automute(codec);
15766         alc662_eeepc_mic_automute(codec);
15767 }
15768 /* ***************** Mode4 ******************************/
15769 static void alc663_mode4_unsol_event(struct hda_codec *codec,
15770                                            unsigned int res)
15771 {
15772         switch (res >> 26) {
15773         case ALC880_HP_EVENT:
15774                 alc663_21jd_two_speaker_automute(codec);
15775                 break;
15776         case ALC880_MIC_EVENT:
15777                 alc662_eeepc_mic_automute(codec);
15778                 break;
15779         }
15780 }
15781
15782 static void alc663_mode4_inithook(struct hda_codec *codec)
15783 {
15784         alc663_21jd_two_speaker_automute(codec);
15785         alc662_eeepc_mic_automute(codec);
15786 }
15787 /* ***************** Mode5 ******************************/
15788 static void alc663_mode5_unsol_event(struct hda_codec *codec,
15789                                            unsigned int res)
15790 {
15791         switch (res >> 26) {
15792         case ALC880_HP_EVENT:
15793                 alc663_15jd_two_speaker_automute(codec);
15794                 break;
15795         case ALC880_MIC_EVENT:
15796                 alc662_eeepc_mic_automute(codec);
15797                 break;
15798         }
15799 }
15800
15801 static void alc663_mode5_inithook(struct hda_codec *codec)
15802 {
15803         alc663_15jd_two_speaker_automute(codec);
15804         alc662_eeepc_mic_automute(codec);
15805 }
15806 /* ***************** Mode6 ******************************/
15807 static void alc663_mode6_unsol_event(struct hda_codec *codec,
15808                                            unsigned int res)
15809 {
15810         switch (res >> 26) {
15811         case ALC880_HP_EVENT:
15812                 alc663_two_hp_m2_speaker_automute(codec);
15813                 break;
15814         case ALC880_MIC_EVENT:
15815                 alc662_eeepc_mic_automute(codec);
15816                 break;
15817         }
15818 }
15819
15820 static void alc663_mode6_inithook(struct hda_codec *codec)
15821 {
15822         alc663_two_hp_m2_speaker_automute(codec);
15823         alc662_eeepc_mic_automute(codec);
15824 }
15825
15826 static void alc663_g71v_hp_automute(struct hda_codec *codec)
15827 {
15828         unsigned int present;
15829         unsigned char bits;
15830
15831         present = snd_hda_codec_read(codec, 0x21, 0,
15832                                      AC_VERB_GET_PIN_SENSE, 0)
15833                 & AC_PINSENSE_PRESENCE;
15834         bits = present ? HDA_AMP_MUTE : 0;
15835         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15836                                  HDA_AMP_MUTE, bits);
15837         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15838                                  HDA_AMP_MUTE, bits);
15839 }
15840
15841 static void alc663_g71v_front_automute(struct hda_codec *codec)
15842 {
15843         unsigned int present;
15844         unsigned char bits;
15845
15846         present = snd_hda_codec_read(codec, 0x15, 0,
15847                                      AC_VERB_GET_PIN_SENSE, 0)
15848                 & AC_PINSENSE_PRESENCE;
15849         bits = present ? HDA_AMP_MUTE : 0;
15850         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15851                                  HDA_AMP_MUTE, bits);
15852 }
15853
15854 static void alc663_g71v_unsol_event(struct hda_codec *codec,
15855                                            unsigned int res)
15856 {
15857         switch (res >> 26) {
15858         case ALC880_HP_EVENT:
15859                 alc663_g71v_hp_automute(codec);
15860                 break;
15861         case ALC880_FRONT_EVENT:
15862                 alc663_g71v_front_automute(codec);
15863                 break;
15864         case ALC880_MIC_EVENT:
15865                 alc662_eeepc_mic_automute(codec);
15866                 break;
15867         }
15868 }
15869
15870 static void alc663_g71v_inithook(struct hda_codec *codec)
15871 {
15872         alc663_g71v_front_automute(codec);
15873         alc663_g71v_hp_automute(codec);
15874         alc662_eeepc_mic_automute(codec);
15875 }
15876
15877 static void alc663_g50v_unsol_event(struct hda_codec *codec,
15878                                            unsigned int res)
15879 {
15880         switch (res >> 26) {
15881         case ALC880_HP_EVENT:
15882                 alc663_m51va_speaker_automute(codec);
15883                 break;
15884         case ALC880_MIC_EVENT:
15885                 alc662_eeepc_mic_automute(codec);
15886                 break;
15887         }
15888 }
15889
15890 static void alc663_g50v_inithook(struct hda_codec *codec)
15891 {
15892         alc663_m51va_speaker_automute(codec);
15893         alc662_eeepc_mic_automute(codec);
15894 }
15895
15896 /* bind hp and internal speaker mute (with plug check) */
15897 static int alc662_ecs_master_sw_put(struct snd_kcontrol *kcontrol,
15898                                      struct snd_ctl_elem_value *ucontrol)
15899 {
15900         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
15901         long *valp = ucontrol->value.integer.value;
15902         int change;
15903
15904         change = snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
15905                                           HDA_AMP_MUTE,
15906                                           valp[0] ? 0 : HDA_AMP_MUTE);
15907         change |= snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
15908                                            HDA_AMP_MUTE,
15909                                            valp[1] ? 0 : HDA_AMP_MUTE);
15910         if (change)
15911                 alc262_hippo1_automute(codec);
15912         return change;
15913 }
15914
15915 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
15916         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15917         {
15918                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15919                 .name = "Master Playback Switch",
15920                 .info = snd_hda_mixer_amp_switch_info,
15921                 .get = snd_hda_mixer_amp_switch_get,
15922                 .put = alc662_ecs_master_sw_put,
15923                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15924         },
15925
15926         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
15927         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
15928         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
15929
15930         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15931         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15932         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15933         { } /* end */
15934 };
15935
15936 #ifdef CONFIG_SND_HDA_POWER_SAVE
15937 #define alc662_loopbacks        alc880_loopbacks
15938 #endif
15939
15940
15941 /* pcm configuration: identiacal with ALC880 */
15942 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
15943 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
15944 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
15945 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
15946
15947 /*
15948  * configuration and preset
15949  */
15950 static const char *alc662_models[ALC662_MODEL_LAST] = {
15951         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
15952         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
15953         [ALC662_3ST_6ch]        = "3stack-6ch",
15954         [ALC662_5ST_DIG]        = "6stack-dig",
15955         [ALC662_LENOVO_101E]    = "lenovo-101e",
15956         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
15957         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
15958         [ALC662_ECS] = "ecs",
15959         [ALC663_ASUS_M51VA] = "m51va",
15960         [ALC663_ASUS_G71V] = "g71v",
15961         [ALC663_ASUS_H13] = "h13",
15962         [ALC663_ASUS_G50V] = "g50v",
15963         [ALC663_ASUS_MODE1] = "asus-mode1",
15964         [ALC662_ASUS_MODE2] = "asus-mode2",
15965         [ALC663_ASUS_MODE3] = "asus-mode3",
15966         [ALC663_ASUS_MODE4] = "asus-mode4",
15967         [ALC663_ASUS_MODE5] = "asus-mode5",
15968         [ALC663_ASUS_MODE6] = "asus-mode6",
15969         [ALC662_AUTO]           = "auto",
15970 };
15971
15972 static struct snd_pci_quirk alc662_cfg_tbl[] = {
15973         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
15974         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
15975         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
15976         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
15977         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
15978         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
15979         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),
15980         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
15981         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
15982         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
15983         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),
15984         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
15985         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
15986         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
15987         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
15988         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
15989         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
15990         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
15991         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
15992         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
15993         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
15994         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
15995         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
15996         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
15997         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
15998         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
15999         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
16000         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
16001         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
16002         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
16003         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
16004         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
16005         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
16006         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
16007         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
16008         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
16009         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
16010         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
16011                       ALC662_3ST_6ch_DIG),
16012         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
16013         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
16014         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
16015         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
16016                       ALC662_3ST_6ch_DIG),
16017         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
16018         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
16019                                         ALC662_3ST_6ch_DIG),
16020         SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13),
16021         SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13),
16022         SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13),
16023         {}
16024 };
16025
16026 static struct alc_config_preset alc662_presets[] = {
16027         [ALC662_3ST_2ch_DIG] = {
16028                 .mixers = { alc662_3ST_2ch_mixer },
16029                 .init_verbs = { alc662_init_verbs },
16030                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16031                 .dac_nids = alc662_dac_nids,
16032                 .dig_out_nid = ALC662_DIGOUT_NID,
16033                 .dig_in_nid = ALC662_DIGIN_NID,
16034                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16035                 .channel_mode = alc662_3ST_2ch_modes,
16036                 .input_mux = &alc662_capture_source,
16037         },
16038         [ALC662_3ST_6ch_DIG] = {
16039                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16040                 .init_verbs = { alc662_init_verbs },
16041                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16042                 .dac_nids = alc662_dac_nids,
16043                 .dig_out_nid = ALC662_DIGOUT_NID,
16044                 .dig_in_nid = ALC662_DIGIN_NID,
16045                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16046                 .channel_mode = alc662_3ST_6ch_modes,
16047                 .need_dac_fix = 1,
16048                 .input_mux = &alc662_capture_source,
16049         },
16050         [ALC662_3ST_6ch] = {
16051                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16052                 .init_verbs = { alc662_init_verbs },
16053                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16054                 .dac_nids = alc662_dac_nids,
16055                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16056                 .channel_mode = alc662_3ST_6ch_modes,
16057                 .need_dac_fix = 1,
16058                 .input_mux = &alc662_capture_source,
16059         },
16060         [ALC662_5ST_DIG] = {
16061                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
16062                 .init_verbs = { alc662_init_verbs },
16063                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16064                 .dac_nids = alc662_dac_nids,
16065                 .dig_out_nid = ALC662_DIGOUT_NID,
16066                 .dig_in_nid = ALC662_DIGIN_NID,
16067                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
16068                 .channel_mode = alc662_5stack_modes,
16069                 .input_mux = &alc662_capture_source,
16070         },
16071         [ALC662_LENOVO_101E] = {
16072                 .mixers = { alc662_lenovo_101e_mixer },
16073                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
16074                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16075                 .dac_nids = alc662_dac_nids,
16076                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16077                 .channel_mode = alc662_3ST_2ch_modes,
16078                 .input_mux = &alc662_lenovo_101e_capture_source,
16079                 .unsol_event = alc662_lenovo_101e_unsol_event,
16080                 .init_hook = alc662_lenovo_101e_all_automute,
16081         },
16082         [ALC662_ASUS_EEEPC_P701] = {
16083                 .mixers = { alc662_eeepc_p701_mixer },
16084                 .init_verbs = { alc662_init_verbs,
16085                                 alc662_eeepc_sue_init_verbs },
16086                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16087                 .dac_nids = alc662_dac_nids,
16088                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16089                 .channel_mode = alc662_3ST_2ch_modes,
16090                 .input_mux = &alc662_eeepc_capture_source,
16091                 .unsol_event = alc662_eeepc_unsol_event,
16092                 .init_hook = alc662_eeepc_inithook,
16093         },
16094         [ALC662_ASUS_EEEPC_EP20] = {
16095                 .mixers = { alc662_eeepc_ep20_mixer,
16096                             alc662_chmode_mixer },
16097                 .init_verbs = { alc662_init_verbs,
16098                                 alc662_eeepc_ep20_sue_init_verbs },
16099                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16100                 .dac_nids = alc662_dac_nids,
16101                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16102                 .channel_mode = alc662_3ST_6ch_modes,
16103                 .input_mux = &alc662_lenovo_101e_capture_source,
16104                 .unsol_event = alc662_eeepc_ep20_unsol_event,
16105                 .init_hook = alc662_eeepc_ep20_inithook,
16106         },
16107         [ALC662_ECS] = {
16108                 .mixers = { alc662_ecs_mixer },
16109                 .init_verbs = { alc662_init_verbs,
16110                                 alc662_ecs_init_verbs },
16111                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16112                 .dac_nids = alc662_dac_nids,
16113                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16114                 .channel_mode = alc662_3ST_2ch_modes,
16115                 .input_mux = &alc662_eeepc_capture_source,
16116                 .unsol_event = alc662_eeepc_unsol_event,
16117                 .init_hook = alc662_eeepc_inithook,
16118         },
16119         [ALC663_ASUS_M51VA] = {
16120                 .mixers = { alc663_m51va_mixer },
16121                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16122                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16123                 .dac_nids = alc662_dac_nids,
16124                 .dig_out_nid = ALC662_DIGOUT_NID,
16125                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16126                 .channel_mode = alc662_3ST_2ch_modes,
16127                 .input_mux = &alc663_m51va_capture_source,
16128                 .unsol_event = alc663_m51va_unsol_event,
16129                 .init_hook = alc663_m51va_inithook,
16130         },
16131         [ALC663_ASUS_G71V] = {
16132                 .mixers = { alc663_g71v_mixer },
16133                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
16134                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16135                 .dac_nids = alc662_dac_nids,
16136                 .dig_out_nid = ALC662_DIGOUT_NID,
16137                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16138                 .channel_mode = alc662_3ST_2ch_modes,
16139                 .input_mux = &alc662_eeepc_capture_source,
16140                 .unsol_event = alc663_g71v_unsol_event,
16141                 .init_hook = alc663_g71v_inithook,
16142         },
16143         [ALC663_ASUS_H13] = {
16144                 .mixers = { alc663_m51va_mixer },
16145                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16146                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16147                 .dac_nids = alc662_dac_nids,
16148                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16149                 .channel_mode = alc662_3ST_2ch_modes,
16150                 .input_mux = &alc663_m51va_capture_source,
16151                 .unsol_event = alc663_m51va_unsol_event,
16152                 .init_hook = alc663_m51va_inithook,
16153         },
16154         [ALC663_ASUS_G50V] = {
16155                 .mixers = { alc663_g50v_mixer },
16156                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
16157                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16158                 .dac_nids = alc662_dac_nids,
16159                 .dig_out_nid = ALC662_DIGOUT_NID,
16160                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16161                 .channel_mode = alc662_3ST_6ch_modes,
16162                 .input_mux = &alc663_capture_source,
16163                 .unsol_event = alc663_g50v_unsol_event,
16164                 .init_hook = alc663_g50v_inithook,
16165         },
16166         [ALC663_ASUS_MODE1] = {
16167                 .mixers = { alc663_m51va_mixer },
16168                 .cap_mixer = alc662_auto_capture_mixer,
16169                 .init_verbs = { alc662_init_verbs,
16170                                 alc663_21jd_amic_init_verbs },
16171                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16172                 .hp_nid = 0x03,
16173                 .dac_nids = alc662_dac_nids,
16174                 .dig_out_nid = ALC662_DIGOUT_NID,
16175                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16176                 .channel_mode = alc662_3ST_2ch_modes,
16177                 .input_mux = &alc662_eeepc_capture_source,
16178                 .unsol_event = alc663_mode1_unsol_event,
16179                 .init_hook = alc663_mode1_inithook,
16180         },
16181         [ALC662_ASUS_MODE2] = {
16182                 .mixers = { alc662_1bjd_mixer },
16183                 .cap_mixer = alc662_auto_capture_mixer,
16184                 .init_verbs = { alc662_init_verbs,
16185                                 alc662_1bjd_amic_init_verbs },
16186                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16187                 .dac_nids = alc662_dac_nids,
16188                 .dig_out_nid = ALC662_DIGOUT_NID,
16189                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16190                 .channel_mode = alc662_3ST_2ch_modes,
16191                 .input_mux = &alc662_eeepc_capture_source,
16192                 .unsol_event = alc662_mode2_unsol_event,
16193                 .init_hook = alc662_mode2_inithook,
16194         },
16195         [ALC663_ASUS_MODE3] = {
16196                 .mixers = { alc663_two_hp_m1_mixer },
16197                 .cap_mixer = alc662_auto_capture_mixer,
16198                 .init_verbs = { alc662_init_verbs,
16199                                 alc663_two_hp_amic_m1_init_verbs },
16200                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16201                 .hp_nid = 0x03,
16202                 .dac_nids = alc662_dac_nids,
16203                 .dig_out_nid = ALC662_DIGOUT_NID,
16204                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16205                 .channel_mode = alc662_3ST_2ch_modes,
16206                 .input_mux = &alc662_eeepc_capture_source,
16207                 .unsol_event = alc663_mode3_unsol_event,
16208                 .init_hook = alc663_mode3_inithook,
16209         },
16210         [ALC663_ASUS_MODE4] = {
16211                 .mixers = { alc663_asus_21jd_clfe_mixer },
16212                 .cap_mixer = alc662_auto_capture_mixer,
16213                 .init_verbs = { alc662_init_verbs,
16214                                 alc663_21jd_amic_init_verbs},
16215                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16216                 .hp_nid = 0x03,
16217                 .dac_nids = alc662_dac_nids,
16218                 .dig_out_nid = ALC662_DIGOUT_NID,
16219                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16220                 .channel_mode = alc662_3ST_2ch_modes,
16221                 .input_mux = &alc662_eeepc_capture_source,
16222                 .unsol_event = alc663_mode4_unsol_event,
16223                 .init_hook = alc663_mode4_inithook,
16224         },
16225         [ALC663_ASUS_MODE5] = {
16226                 .mixers = { alc663_asus_15jd_clfe_mixer },
16227                 .cap_mixer = alc662_auto_capture_mixer,
16228                 .init_verbs = { alc662_init_verbs,
16229                                 alc663_15jd_amic_init_verbs },
16230                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16231                 .hp_nid = 0x03,
16232                 .dac_nids = alc662_dac_nids,
16233                 .dig_out_nid = ALC662_DIGOUT_NID,
16234                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16235                 .channel_mode = alc662_3ST_2ch_modes,
16236                 .input_mux = &alc662_eeepc_capture_source,
16237                 .unsol_event = alc663_mode5_unsol_event,
16238                 .init_hook = alc663_mode5_inithook,
16239         },
16240         [ALC663_ASUS_MODE6] = {
16241                 .mixers = { alc663_two_hp_m2_mixer },
16242                 .cap_mixer = alc662_auto_capture_mixer,
16243                 .init_verbs = { alc662_init_verbs,
16244                                 alc663_two_hp_amic_m2_init_verbs },
16245                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16246                 .hp_nid = 0x03,
16247                 .dac_nids = alc662_dac_nids,
16248                 .dig_out_nid = ALC662_DIGOUT_NID,
16249                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16250                 .channel_mode = alc662_3ST_2ch_modes,
16251                 .input_mux = &alc662_eeepc_capture_source,
16252                 .unsol_event = alc663_mode6_unsol_event,
16253                 .init_hook = alc663_mode6_inithook,
16254         },
16255 };
16256
16257
16258 /*
16259  * BIOS auto configuration
16260  */
16261
16262 /* add playback controls from the parsed DAC table */
16263 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
16264                                              const struct auto_pin_cfg *cfg)
16265 {
16266         char name[32];
16267         static const char *chname[4] = {
16268                 "Front", "Surround", NULL /*CLFE*/, "Side"
16269         };
16270         hda_nid_t nid;
16271         int i, err;
16272
16273         for (i = 0; i < cfg->line_outs; i++) {
16274                 if (!spec->multiout.dac_nids[i])
16275                         continue;
16276                 nid = alc880_idx_to_dac(i);
16277                 if (i == 2) {
16278                         /* Center/LFE */
16279                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16280                                           "Center Playback Volume",
16281                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
16282                                                               HDA_OUTPUT));
16283                         if (err < 0)
16284                                 return err;
16285                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16286                                           "LFE Playback Volume",
16287                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
16288                                                               HDA_OUTPUT));
16289                         if (err < 0)
16290                                 return err;
16291                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16292                                           "Center Playback Switch",
16293                                           HDA_COMPOSE_AMP_VAL(0x0e, 1, 0,
16294                                                               HDA_INPUT));
16295                         if (err < 0)
16296                                 return err;
16297                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16298                                           "LFE Playback Switch",
16299                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
16300                                                               HDA_INPUT));
16301                         if (err < 0)
16302                                 return err;
16303                 } else {
16304                         sprintf(name, "%s Playback Volume", chname[i]);
16305                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16306                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
16307                                                               HDA_OUTPUT));
16308                         if (err < 0)
16309                                 return err;
16310                         sprintf(name, "%s Playback Switch", chname[i]);
16311                         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16312                                 HDA_COMPOSE_AMP_VAL(alc880_idx_to_mixer(i),
16313                                                     3, 0, HDA_INPUT));
16314                         if (err < 0)
16315                                 return err;
16316                 }
16317         }
16318         return 0;
16319 }
16320
16321 /* add playback controls for speaker and HP outputs */
16322 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
16323                                         const char *pfx)
16324 {
16325         hda_nid_t nid;
16326         int err;
16327         char name[32];
16328
16329         if (!pin)
16330                 return 0;
16331
16332         if (pin == 0x17) {
16333                 /* ALC663 has a mono output pin on 0x17 */
16334                 sprintf(name, "%s Playback Switch", pfx);
16335                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16336                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
16337                 return err;
16338         }
16339
16340         if (alc880_is_fixed_pin(pin)) {
16341                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16342                 /* printk("DAC nid=%x\n",nid); */
16343                 /* specify the DAC as the extra output */
16344                 if (!spec->multiout.hp_nid)
16345                         spec->multiout.hp_nid = nid;
16346                 else
16347                         spec->multiout.extra_out_nid[0] = nid;
16348                 /* control HP volume/switch on the output mixer amp */
16349                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16350                 sprintf(name, "%s Playback Volume", pfx);
16351                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16352                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
16353                 if (err < 0)
16354                         return err;
16355                 sprintf(name, "%s Playback Switch", pfx);
16356                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
16357                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
16358                 if (err < 0)
16359                         return err;
16360         } else if (alc880_is_multi_pin(pin)) {
16361                 /* set manual connection */
16362                 /* we have only a switch on HP-out PIN */
16363                 sprintf(name, "%s Playback Switch", pfx);
16364                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16365                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
16366                 if (err < 0)
16367                         return err;
16368         }
16369         return 0;
16370 }
16371
16372 /* create playback/capture controls for input pins */
16373 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
16374                                                 const struct auto_pin_cfg *cfg)
16375 {
16376         struct hda_input_mux *imux = &spec->private_imux;
16377         int i, err, idx;
16378
16379         for (i = 0; i < AUTO_PIN_LAST; i++) {
16380                 if (alc880_is_input_pin(cfg->input_pins[i])) {
16381                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
16382                         err = new_analog_input(spec, cfg->input_pins[i],
16383                                                auto_pin_cfg_labels[i],
16384                                                idx, 0x0b);
16385                         if (err < 0)
16386                                 return err;
16387                         imux->items[imux->num_items].label =
16388                                 auto_pin_cfg_labels[i];
16389                         imux->items[imux->num_items].index =
16390                                 alc880_input_pin_idx(cfg->input_pins[i]);
16391                         imux->num_items++;
16392                 }
16393         }
16394         return 0;
16395 }
16396
16397 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
16398                                               hda_nid_t nid, int pin_type,
16399                                               int dac_idx)
16400 {
16401         alc_set_pin_output(codec, nid, pin_type);
16402         /* need the manual connection? */
16403         if (alc880_is_multi_pin(nid)) {
16404                 struct alc_spec *spec = codec->spec;
16405                 int idx = alc880_multi_pin_idx(nid);
16406                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
16407                                     AC_VERB_SET_CONNECT_SEL,
16408                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
16409         }
16410 }
16411
16412 static void alc662_auto_init_multi_out(struct hda_codec *codec)
16413 {
16414         struct alc_spec *spec = codec->spec;
16415         int i;
16416
16417         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
16418         for (i = 0; i <= HDA_SIDE; i++) {
16419                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
16420                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
16421                 if (nid)
16422                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
16423                                                           i);
16424         }
16425 }
16426
16427 static void alc662_auto_init_hp_out(struct hda_codec *codec)
16428 {
16429         struct alc_spec *spec = codec->spec;
16430         hda_nid_t pin;
16431
16432         pin = spec->autocfg.hp_pins[0];
16433         if (pin) /* connect to front */
16434                 /* use dac 0 */
16435                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
16436         pin = spec->autocfg.speaker_pins[0];
16437         if (pin)
16438                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
16439 }
16440
16441 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
16442 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
16443
16444 static void alc662_auto_init_analog_input(struct hda_codec *codec)
16445 {
16446         struct alc_spec *spec = codec->spec;
16447         int i;
16448
16449         for (i = 0; i < AUTO_PIN_LAST; i++) {
16450                 hda_nid_t nid = spec->autocfg.input_pins[i];
16451                 if (alc662_is_input_pin(nid)) {
16452                         snd_hda_codec_write(codec, nid, 0,
16453                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
16454                                             (i <= AUTO_PIN_FRONT_MIC ?
16455                                              PIN_VREF80 : PIN_IN));
16456                         if (nid != ALC662_PIN_CD_NID)
16457                                 snd_hda_codec_write(codec, nid, 0,
16458                                                     AC_VERB_SET_AMP_GAIN_MUTE,
16459                                                     AMP_OUT_MUTE);
16460                 }
16461         }
16462 }
16463
16464 #define alc662_auto_init_input_src      alc882_auto_init_input_src
16465
16466 static int alc662_parse_auto_config(struct hda_codec *codec)
16467 {
16468         struct alc_spec *spec = codec->spec;
16469         int err;
16470         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
16471
16472         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
16473                                            alc662_ignore);
16474         if (err < 0)
16475                 return err;
16476         if (!spec->autocfg.line_outs)
16477                 return 0; /* can't find valid BIOS pin config */
16478
16479         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
16480         if (err < 0)
16481                 return err;
16482         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
16483         if (err < 0)
16484                 return err;
16485         err = alc662_auto_create_extra_out(spec,
16486                                            spec->autocfg.speaker_pins[0],
16487                                            "Speaker");
16488         if (err < 0)
16489                 return err;
16490         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
16491                                            "Headphone");
16492         if (err < 0)
16493                 return err;
16494         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
16495         if (err < 0)
16496                 return err;
16497
16498         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
16499
16500         if (spec->autocfg.dig_out_pin)
16501                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
16502
16503         if (spec->kctls.list)
16504                 add_mixer(spec, spec->kctls.list);
16505
16506         spec->num_mux_defs = 1;
16507         spec->input_mux = &spec->private_imux;
16508
16509         add_verb(spec, alc662_auto_init_verbs);
16510         if (codec->vendor_id == 0x10ec0663)
16511                 add_verb(spec, alc663_auto_init_verbs);
16512
16513         err = alc_auto_add_mic_boost(codec);
16514         if (err < 0)
16515                 return err;
16516
16517         store_pin_configs(codec);
16518         return 1;
16519 }
16520
16521 /* additional initialization for auto-configuration model */
16522 static void alc662_auto_init(struct hda_codec *codec)
16523 {
16524         struct alc_spec *spec = codec->spec;
16525         alc662_auto_init_multi_out(codec);
16526         alc662_auto_init_hp_out(codec);
16527         alc662_auto_init_analog_input(codec);
16528         alc662_auto_init_input_src(codec);
16529         if (spec->unsol_event)
16530                 alc_inithook(codec);
16531 }
16532
16533 static int patch_alc662(struct hda_codec *codec)
16534 {
16535         struct alc_spec *spec;
16536         int err, board_config;
16537
16538         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
16539         if (!spec)
16540                 return -ENOMEM;
16541
16542         codec->spec = spec;
16543
16544         alc_fix_pll_init(codec, 0x20, 0x04, 15);
16545
16546         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
16547                                                   alc662_models,
16548                                                   alc662_cfg_tbl);
16549         if (board_config < 0) {
16550                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
16551                        "trying auto-probe from BIOS...\n");
16552                 board_config = ALC662_AUTO;
16553         }
16554
16555         if (board_config == ALC662_AUTO) {
16556                 /* automatic parse from the BIOS config */
16557                 err = alc662_parse_auto_config(codec);
16558                 if (err < 0) {
16559                         alc_free(codec);
16560                         return err;
16561                 } else if (!err) {
16562                         printk(KERN_INFO
16563                                "hda_codec: Cannot set up configuration "
16564                                "from BIOS.  Using base mode...\n");
16565                         board_config = ALC662_3ST_2ch_DIG;
16566                 }
16567         }
16568
16569         if (board_config != ALC662_AUTO)
16570                 setup_preset(spec, &alc662_presets[board_config]);
16571
16572         if (codec->vendor_id == 0x10ec0663) {
16573                 spec->stream_name_analog = "ALC663 Analog";
16574                 spec->stream_name_digital = "ALC663 Digital";
16575         } else if (codec->vendor_id == 0x10ec0272) {
16576                 spec->stream_name_analog = "ALC272 Analog";
16577                 spec->stream_name_digital = "ALC272 Digital";
16578         } else {
16579                 spec->stream_name_analog = "ALC662 Analog";
16580                 spec->stream_name_digital = "ALC662 Digital";
16581         }
16582
16583         spec->stream_analog_playback = &alc662_pcm_analog_playback;
16584         spec->stream_analog_capture = &alc662_pcm_analog_capture;
16585
16586         spec->stream_digital_playback = &alc662_pcm_digital_playback;
16587         spec->stream_digital_capture = &alc662_pcm_digital_capture;
16588
16589         spec->adc_nids = alc662_adc_nids;
16590         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
16591         spec->capsrc_nids = alc662_capsrc_nids;
16592         spec->is_mix_capture = 1;
16593
16594         if (!spec->cap_mixer)
16595                 set_capture_mixer(spec);
16596
16597         spec->vmaster_nid = 0x02;
16598
16599         codec->patch_ops = alc_patch_ops;
16600         if (board_config == ALC662_AUTO)
16601                 spec->init_hook = alc662_auto_init;
16602 #ifdef CONFIG_SND_HDA_POWER_SAVE
16603         if (!spec->loopback.amplist)
16604                 spec->loopback.amplist = alc662_loopbacks;
16605 #endif
16606         codec->proc_widget_hook = print_realtek_coef;
16607
16608         return 0;
16609 }
16610
16611 /*
16612  * patch entries
16613  */
16614 struct hda_codec_preset snd_hda_preset_realtek[] = {
16615         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
16616         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
16617         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
16618         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
16619         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
16620         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
16621         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
16622           .patch = patch_alc861 },
16623         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
16624         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
16625         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
16626         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
16627           .patch = patch_alc883 },
16628         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
16629           .patch = patch_alc662 },
16630         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
16631         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
16632         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
16633         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
16634         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
16635           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16636         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
16637           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16638         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
16639         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc883 },
16640         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
16641         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
16642           .patch = patch_alc883 },
16643         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
16644         {} /* terminator */
16645 };