Merge git://git.kernel.org/pub/scm/linux/kernel/git/wim/linux-2.6-nvram
[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
34 #define ALC880_FRONT_EVENT              0x01
35 #define ALC880_DCVOL_EVENT              0x02
36 #define ALC880_HP_EVENT                 0x04
37 #define ALC880_MIC_EVENT                0x08
38
39 /* ALC880 board config type */
40 enum {
41         ALC880_3ST,
42         ALC880_3ST_DIG,
43         ALC880_5ST,
44         ALC880_5ST_DIG,
45         ALC880_W810,
46         ALC880_Z71V,
47         ALC880_6ST,
48         ALC880_6ST_DIG,
49         ALC880_F1734,
50         ALC880_ASUS,
51         ALC880_ASUS_DIG,
52         ALC880_ASUS_W1V,
53         ALC880_ASUS_DIG2,
54         ALC880_FUJITSU,
55         ALC880_UNIWILL_DIG,
56         ALC880_UNIWILL,
57         ALC880_UNIWILL_P53,
58         ALC880_CLEVO,
59         ALC880_TCL_S700,
60         ALC880_LG,
61         ALC880_LG_LW,
62         ALC880_MEDION_RIM,
63 #ifdef CONFIG_SND_DEBUG
64         ALC880_TEST,
65 #endif
66         ALC880_AUTO,
67         ALC880_MODEL_LAST /* last tag */
68 };
69
70 /* ALC260 models */
71 enum {
72         ALC260_BASIC,
73         ALC260_HP,
74         ALC260_HP_DC7600,
75         ALC260_HP_3013,
76         ALC260_FUJITSU_S702X,
77         ALC260_ACER,
78         ALC260_WILL,
79         ALC260_REPLACER_672V,
80 #ifdef CONFIG_SND_DEBUG
81         ALC260_TEST,
82 #endif
83         ALC260_AUTO,
84         ALC260_MODEL_LAST /* last tag */
85 };
86
87 /* ALC262 models */
88 enum {
89         ALC262_BASIC,
90         ALC262_HIPPO,
91         ALC262_HIPPO_1,
92         ALC262_FUJITSU,
93         ALC262_HP_BPC,
94         ALC262_HP_BPC_D7000_WL,
95         ALC262_HP_BPC_D7000_WF,
96         ALC262_HP_TC_T5735,
97         ALC262_HP_RP5700,
98         ALC262_BENQ_ED8,
99         ALC262_SONY_ASSAMD,
100         ALC262_BENQ_T31,
101         ALC262_ULTRA,
102         ALC262_LENOVO_3000,
103         ALC262_NEC,
104         ALC262_TOSHIBA_S06,
105         ALC262_TOSHIBA_RX1,
106         ALC262_AUTO,
107         ALC262_MODEL_LAST /* last tag */
108 };
109
110 /* ALC268 models */
111 enum {
112         ALC267_QUANTA_IL1,
113         ALC268_3ST,
114         ALC268_TOSHIBA,
115         ALC268_ACER,
116         ALC268_ACER_DMIC,
117         ALC268_ACER_ASPIRE_ONE,
118         ALC268_DELL,
119         ALC268_ZEPTO,
120 #ifdef CONFIG_SND_DEBUG
121         ALC268_TEST,
122 #endif
123         ALC268_AUTO,
124         ALC268_MODEL_LAST /* last tag */
125 };
126
127 /* ALC269 models */
128 enum {
129         ALC269_BASIC,
130         ALC269_QUANTA_FL1,
131         ALC269_ASUS_EEEPC_P703,
132         ALC269_ASUS_EEEPC_P901,
133         ALC269_FUJITSU,
134         ALC269_LIFEBOOK,
135         ALC269_AUTO,
136         ALC269_MODEL_LAST /* last tag */
137 };
138
139 /* ALC861 models */
140 enum {
141         ALC861_3ST,
142         ALC660_3ST,
143         ALC861_3ST_DIG,
144         ALC861_6ST_DIG,
145         ALC861_UNIWILL_M31,
146         ALC861_TOSHIBA,
147         ALC861_ASUS,
148         ALC861_ASUS_LAPTOP,
149         ALC861_AUTO,
150         ALC861_MODEL_LAST,
151 };
152
153 /* ALC861-VD models */
154 enum {
155         ALC660VD_3ST,
156         ALC660VD_3ST_DIG,
157         ALC660VD_ASUS_V1S,
158         ALC861VD_3ST,
159         ALC861VD_3ST_DIG,
160         ALC861VD_6ST_DIG,
161         ALC861VD_LENOVO,
162         ALC861VD_DALLAS,
163         ALC861VD_HP,
164         ALC861VD_AUTO,
165         ALC861VD_MODEL_LAST,
166 };
167
168 /* ALC662 models */
169 enum {
170         ALC662_3ST_2ch_DIG,
171         ALC662_3ST_6ch_DIG,
172         ALC662_3ST_6ch,
173         ALC662_5ST_DIG,
174         ALC662_LENOVO_101E,
175         ALC662_ASUS_EEEPC_P701,
176         ALC662_ASUS_EEEPC_EP20,
177         ALC663_ASUS_M51VA,
178         ALC663_ASUS_G71V,
179         ALC663_ASUS_H13,
180         ALC663_ASUS_G50V,
181         ALC662_ECS,
182         ALC663_ASUS_MODE1,
183         ALC662_ASUS_MODE2,
184         ALC663_ASUS_MODE3,
185         ALC663_ASUS_MODE4,
186         ALC663_ASUS_MODE5,
187         ALC663_ASUS_MODE6,
188         ALC662_AUTO,
189         ALC662_MODEL_LAST,
190 };
191
192 /* ALC882 models */
193 enum {
194         ALC882_3ST_DIG,
195         ALC882_6ST_DIG,
196         ALC882_ARIMA,
197         ALC882_W2JC,
198         ALC882_TARGA,
199         ALC882_ASUS_A7J,
200         ALC882_ASUS_A7M,
201         ALC885_MACPRO,
202         ALC885_MBP3,
203         ALC885_IMAC24,
204         ALC882_AUTO,
205         ALC882_MODEL_LAST,
206 };
207
208 /* ALC883 models */
209 enum {
210         ALC883_3ST_2ch_DIG,
211         ALC883_3ST_6ch_DIG,
212         ALC883_3ST_6ch,
213         ALC883_6ST_DIG,
214         ALC883_TARGA_DIG,
215         ALC883_TARGA_2ch_DIG,
216         ALC883_ACER,
217         ALC883_ACER_ASPIRE,
218         ALC888_ACER_ASPIRE_4930G,
219         ALC883_MEDION,
220         ALC883_MEDION_MD2,
221         ALC883_LAPTOP_EAPD,
222         ALC883_LENOVO_101E_2ch,
223         ALC883_LENOVO_NB0763,
224         ALC888_LENOVO_MS7195_DIG,
225         ALC888_LENOVO_SKY,
226         ALC883_HAIER_W66,
227         ALC888_3ST_HP,
228         ALC888_6ST_DELL,
229         ALC883_MITAC,
230         ALC883_CLEVO_M720,
231         ALC883_FUJITSU_PI2515,
232         ALC888_FUJITSU_XA3530,
233         ALC883_3ST_6ch_INTEL,
234         ALC888_ASUS_M90V,
235         ALC888_ASUS_EEE1601,
236         ALC1200_ASUS_P5Q,
237         ALC883_AUTO,
238         ALC883_MODEL_LAST,
239 };
240
241 /* for GPIO Poll */
242 #define GPIO_MASK       0x03
243
244 struct alc_spec {
245         /* codec parameterization */
246         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
247         unsigned int num_mixers;
248         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
249
250         const struct hda_verb *init_verbs[5];   /* initialization verbs
251                                                  * don't forget NULL
252                                                  * termination!
253                                                  */
254         unsigned int num_init_verbs;
255
256         char *stream_name_analog;       /* analog PCM stream */
257         struct hda_pcm_stream *stream_analog_playback;
258         struct hda_pcm_stream *stream_analog_capture;
259         struct hda_pcm_stream *stream_analog_alt_playback;
260         struct hda_pcm_stream *stream_analog_alt_capture;
261
262         char *stream_name_digital;      /* digital PCM stream */
263         struct hda_pcm_stream *stream_digital_playback;
264         struct hda_pcm_stream *stream_digital_capture;
265
266         /* playback */
267         struct hda_multi_out multiout;  /* playback set-up
268                                          * max_channels, dacs must be set
269                                          * dig_out_nid and hp_nid are optional
270                                          */
271         hda_nid_t alt_dac_nid;
272
273         /* capture */
274         unsigned int num_adc_nids;
275         hda_nid_t *adc_nids;
276         hda_nid_t *capsrc_nids;
277         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
278         unsigned char is_mix_capture;   /* matrix-style capture (non-mux) */
279
280         /* capture source */
281         unsigned int num_mux_defs;
282         const struct hda_input_mux *input_mux;
283         unsigned int cur_mux[3];
284
285         /* channel model */
286         const struct hda_channel_mode *channel_mode;
287         int num_channel_mode;
288         int need_dac_fix;
289
290         /* PCM information */
291         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
292
293         /* dynamic controls, init_verbs and input_mux */
294         struct auto_pin_cfg autocfg;
295         struct snd_array kctls;
296         struct hda_input_mux private_imux;
297         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
298
299         /* hooks */
300         void (*init_hook)(struct hda_codec *codec);
301         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
302
303         /* for pin sensing */
304         unsigned int sense_updated: 1;
305         unsigned int jack_present: 1;
306         unsigned int master_sw: 1;
307
308         /* for virtual master */
309         hda_nid_t vmaster_nid;
310 #ifdef CONFIG_SND_HDA_POWER_SAVE
311         struct hda_loopback_check loopback;
312 #endif
313
314         /* for PLL fix */
315         hda_nid_t pll_nid;
316         unsigned int pll_coef_idx, pll_coef_bit;
317
318 #ifdef SND_HDA_NEEDS_RESUME
319 #define ALC_MAX_PINS    16
320         unsigned int num_pins;
321         hda_nid_t pin_nids[ALC_MAX_PINS];
322         unsigned int pin_cfgs[ALC_MAX_PINS];
323 #endif
324 };
325
326 /*
327  * configuration template - to be copied to the spec instance
328  */
329 struct alc_config_preset {
330         struct snd_kcontrol_new *mixers[5]; /* should be identical size
331                                              * with spec
332                                              */
333         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
334         const struct hda_verb *init_verbs[5];
335         unsigned int num_dacs;
336         hda_nid_t *dac_nids;
337         hda_nid_t dig_out_nid;          /* optional */
338         hda_nid_t hp_nid;               /* optional */
339         unsigned int num_adc_nids;
340         hda_nid_t *adc_nids;
341         hda_nid_t *capsrc_nids;
342         hda_nid_t dig_in_nid;
343         unsigned int num_channel_mode;
344         const struct hda_channel_mode *channel_mode;
345         int need_dac_fix;
346         unsigned int num_mux_defs;
347         const struct hda_input_mux *input_mux;
348         void (*unsol_event)(struct hda_codec *, unsigned int);
349         void (*init_hook)(struct hda_codec *);
350 #ifdef CONFIG_SND_HDA_POWER_SAVE
351         struct hda_amp_list *loopbacks;
352 #endif
353 };
354
355
356 /*
357  * input MUX handling
358  */
359 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
360                              struct snd_ctl_elem_info *uinfo)
361 {
362         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
363         struct alc_spec *spec = codec->spec;
364         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
365         if (mux_idx >= spec->num_mux_defs)
366                 mux_idx = 0;
367         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
368 }
369
370 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
371                             struct snd_ctl_elem_value *ucontrol)
372 {
373         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
374         struct alc_spec *spec = codec->spec;
375         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
376
377         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
378         return 0;
379 }
380
381 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
382                             struct snd_ctl_elem_value *ucontrol)
383 {
384         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
385         struct alc_spec *spec = codec->spec;
386         const struct hda_input_mux *imux;
387         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
388         unsigned int mux_idx;
389         hda_nid_t nid = spec->capsrc_nids ?
390                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
391
392         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
393         imux = &spec->input_mux[mux_idx];
394
395         if (spec->is_mix_capture) {
396                 /* Matrix-mixer style (e.g. ALC882) */
397                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
398                 unsigned int i, idx;
399
400                 idx = ucontrol->value.enumerated.item[0];
401                 if (idx >= imux->num_items)
402                         idx = imux->num_items - 1;
403                 if (*cur_val == idx)
404                         return 0;
405                 for (i = 0; i < imux->num_items; i++) {
406                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
407                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
408                                                  imux->items[i].index,
409                                                  HDA_AMP_MUTE, v);
410                 }
411                 *cur_val = idx;
412                 return 1;
413         } else {
414                 /* MUX style (e.g. ALC880) */
415                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
416                                              &spec->cur_mux[adc_idx]);
417         }
418 }
419
420 /*
421  * channel mode setting
422  */
423 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
424                             struct snd_ctl_elem_info *uinfo)
425 {
426         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
427         struct alc_spec *spec = codec->spec;
428         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
429                                     spec->num_channel_mode);
430 }
431
432 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
433                            struct snd_ctl_elem_value *ucontrol)
434 {
435         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
436         struct alc_spec *spec = codec->spec;
437         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
438                                    spec->num_channel_mode,
439                                    spec->multiout.max_channels);
440 }
441
442 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
443                            struct snd_ctl_elem_value *ucontrol)
444 {
445         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
446         struct alc_spec *spec = codec->spec;
447         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
448                                       spec->num_channel_mode,
449                                       &spec->multiout.max_channels);
450         if (err >= 0 && spec->need_dac_fix)
451                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
452         return err;
453 }
454
455 /*
456  * Control the mode of pin widget settings via the mixer.  "pc" is used
457  * instead of "%" to avoid consequences of accidently treating the % as
458  * being part of a format specifier.  Maximum allowed length of a value is
459  * 63 characters plus NULL terminator.
460  *
461  * Note: some retasking pin complexes seem to ignore requests for input
462  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
463  * are requested.  Therefore order this list so that this behaviour will not
464  * cause problems when mixer clients move through the enum sequentially.
465  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
466  * March 2006.
467  */
468 static char *alc_pin_mode_names[] = {
469         "Mic 50pc bias", "Mic 80pc bias",
470         "Line in", "Line out", "Headphone out",
471 };
472 static unsigned char alc_pin_mode_values[] = {
473         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
474 };
475 /* The control can present all 5 options, or it can limit the options based
476  * in the pin being assumed to be exclusively an input or an output pin.  In
477  * addition, "input" pins may or may not process the mic bias option
478  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
479  * accept requests for bias as of chip versions up to March 2006) and/or
480  * wiring in the computer.
481  */
482 #define ALC_PIN_DIR_IN              0x00
483 #define ALC_PIN_DIR_OUT             0x01
484 #define ALC_PIN_DIR_INOUT           0x02
485 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
486 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
487
488 /* Info about the pin modes supported by the different pin direction modes.
489  * For each direction the minimum and maximum values are given.
490  */
491 static signed char alc_pin_mode_dir_info[5][2] = {
492         { 0, 2 },    /* ALC_PIN_DIR_IN */
493         { 3, 4 },    /* ALC_PIN_DIR_OUT */
494         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
495         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
496         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
497 };
498 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
499 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
500 #define alc_pin_mode_n_items(_dir) \
501         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
502
503 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
504                              struct snd_ctl_elem_info *uinfo)
505 {
506         unsigned int item_num = uinfo->value.enumerated.item;
507         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
508
509         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
510         uinfo->count = 1;
511         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
512
513         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
514                 item_num = alc_pin_mode_min(dir);
515         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
516         return 0;
517 }
518
519 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
520                             struct snd_ctl_elem_value *ucontrol)
521 {
522         unsigned int i;
523         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
524         hda_nid_t nid = kcontrol->private_value & 0xffff;
525         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
526         long *valp = ucontrol->value.integer.value;
527         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
528                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
529                                                  0x00);
530
531         /* Find enumerated value for current pinctl setting */
532         i = alc_pin_mode_min(dir);
533         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
534                 i++;
535         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
536         return 0;
537 }
538
539 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
540                             struct snd_ctl_elem_value *ucontrol)
541 {
542         signed int change;
543         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
544         hda_nid_t nid = kcontrol->private_value & 0xffff;
545         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
546         long val = *ucontrol->value.integer.value;
547         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
548                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
549                                                  0x00);
550
551         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
552                 val = alc_pin_mode_min(dir);
553
554         change = pinctl != alc_pin_mode_values[val];
555         if (change) {
556                 /* Set pin mode to that requested */
557                 snd_hda_codec_write_cache(codec, nid, 0,
558                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
559                                           alc_pin_mode_values[val]);
560
561                 /* Also enable the retasking pin's input/output as required
562                  * for the requested pin mode.  Enum values of 2 or less are
563                  * input modes.
564                  *
565                  * Dynamically switching the input/output buffers probably
566                  * reduces noise slightly (particularly on input) so we'll
567                  * do it.  However, having both input and output buffers
568                  * enabled simultaneously doesn't seem to be problematic if
569                  * this turns out to be necessary in the future.
570                  */
571                 if (val <= 2) {
572                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
573                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
574                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
575                                                  HDA_AMP_MUTE, 0);
576                 } else {
577                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
578                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
579                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
580                                                  HDA_AMP_MUTE, 0);
581                 }
582         }
583         return change;
584 }
585
586 #define ALC_PIN_MODE(xname, nid, dir) \
587         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
588           .info = alc_pin_mode_info, \
589           .get = alc_pin_mode_get, \
590           .put = alc_pin_mode_put, \
591           .private_value = nid | (dir<<16) }
592
593 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
594  * together using a mask with more than one bit set.  This control is
595  * currently used only by the ALC260 test model.  At this stage they are not
596  * needed for any "production" models.
597  */
598 #ifdef CONFIG_SND_DEBUG
599 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
600
601 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
602                              struct snd_ctl_elem_value *ucontrol)
603 {
604         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
605         hda_nid_t nid = kcontrol->private_value & 0xffff;
606         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
607         long *valp = ucontrol->value.integer.value;
608         unsigned int val = snd_hda_codec_read(codec, nid, 0,
609                                               AC_VERB_GET_GPIO_DATA, 0x00);
610
611         *valp = (val & mask) != 0;
612         return 0;
613 }
614 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
615                              struct snd_ctl_elem_value *ucontrol)
616 {
617         signed int change;
618         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
619         hda_nid_t nid = kcontrol->private_value & 0xffff;
620         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
621         long val = *ucontrol->value.integer.value;
622         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
623                                                     AC_VERB_GET_GPIO_DATA,
624                                                     0x00);
625
626         /* Set/unset the masked GPIO bit(s) as needed */
627         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
628         if (val == 0)
629                 gpio_data &= ~mask;
630         else
631                 gpio_data |= mask;
632         snd_hda_codec_write_cache(codec, nid, 0,
633                                   AC_VERB_SET_GPIO_DATA, gpio_data);
634
635         return change;
636 }
637 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
638         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
639           .info = alc_gpio_data_info, \
640           .get = alc_gpio_data_get, \
641           .put = alc_gpio_data_put, \
642           .private_value = nid | (mask<<16) }
643 #endif   /* CONFIG_SND_DEBUG */
644
645 /* A switch control to allow the enabling of the digital IO pins on the
646  * ALC260.  This is incredibly simplistic; the intention of this control is
647  * to provide something in the test model allowing digital outputs to be
648  * identified if present.  If models are found which can utilise these
649  * outputs a more complete mixer control can be devised for those models if
650  * necessary.
651  */
652 #ifdef CONFIG_SND_DEBUG
653 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
654
655 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
656                               struct snd_ctl_elem_value *ucontrol)
657 {
658         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
659         hda_nid_t nid = kcontrol->private_value & 0xffff;
660         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
661         long *valp = ucontrol->value.integer.value;
662         unsigned int val = snd_hda_codec_read(codec, nid, 0,
663                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
664
665         *valp = (val & mask) != 0;
666         return 0;
667 }
668 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
669                               struct snd_ctl_elem_value *ucontrol)
670 {
671         signed int change;
672         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
673         hda_nid_t nid = kcontrol->private_value & 0xffff;
674         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
675         long val = *ucontrol->value.integer.value;
676         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
677                                                     AC_VERB_GET_DIGI_CONVERT_1,
678                                                     0x00);
679
680         /* Set/unset the masked control bit(s) as needed */
681         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
682         if (val==0)
683                 ctrl_data &= ~mask;
684         else
685                 ctrl_data |= mask;
686         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
687                                   ctrl_data);
688
689         return change;
690 }
691 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
692         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
693           .info = alc_spdif_ctrl_info, \
694           .get = alc_spdif_ctrl_get, \
695           .put = alc_spdif_ctrl_put, \
696           .private_value = nid | (mask<<16) }
697 #endif   /* CONFIG_SND_DEBUG */
698
699 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
700  * Again, this is only used in the ALC26x test models to help identify when
701  * the EAPD line must be asserted for features to work.
702  */
703 #ifdef CONFIG_SND_DEBUG
704 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
705
706 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
707                               struct snd_ctl_elem_value *ucontrol)
708 {
709         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
710         hda_nid_t nid = kcontrol->private_value & 0xffff;
711         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
712         long *valp = ucontrol->value.integer.value;
713         unsigned int val = snd_hda_codec_read(codec, nid, 0,
714                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
715
716         *valp = (val & mask) != 0;
717         return 0;
718 }
719
720 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
721                               struct snd_ctl_elem_value *ucontrol)
722 {
723         int change;
724         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
725         hda_nid_t nid = kcontrol->private_value & 0xffff;
726         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
727         long val = *ucontrol->value.integer.value;
728         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
729                                                     AC_VERB_GET_EAPD_BTLENABLE,
730                                                     0x00);
731
732         /* Set/unset the masked control bit(s) as needed */
733         change = (!val ? 0 : mask) != (ctrl_data & mask);
734         if (!val)
735                 ctrl_data &= ~mask;
736         else
737                 ctrl_data |= mask;
738         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
739                                   ctrl_data);
740
741         return change;
742 }
743
744 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
745         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
746           .info = alc_eapd_ctrl_info, \
747           .get = alc_eapd_ctrl_get, \
748           .put = alc_eapd_ctrl_put, \
749           .private_value = nid | (mask<<16) }
750 #endif   /* CONFIG_SND_DEBUG */
751
752 /*
753  */
754 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
755 {
756         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
757                 return;
758         spec->mixers[spec->num_mixers++] = mix;
759 }
760
761 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
762 {
763         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
764                 return;
765         spec->init_verbs[spec->num_init_verbs++] = verb;
766 }
767
768 #ifdef CONFIG_PROC_FS
769 /*
770  * hook for proc
771  */
772 static void print_realtek_coef(struct snd_info_buffer *buffer,
773                                struct hda_codec *codec, hda_nid_t nid)
774 {
775         int coeff;
776
777         if (nid != 0x20)
778                 return;
779         coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
780         snd_iprintf(buffer, "  Processing Coefficient: 0x%02x\n", coeff);
781         coeff = snd_hda_codec_read(codec, nid, 0,
782                                    AC_VERB_GET_COEF_INDEX, 0);
783         snd_iprintf(buffer, "  Coefficient Index: 0x%02x\n", coeff);
784 }
785 #else
786 #define print_realtek_coef      NULL
787 #endif
788
789 /*
790  * set up from the preset table
791  */
792 static void setup_preset(struct alc_spec *spec,
793                          const struct alc_config_preset *preset)
794 {
795         int i;
796
797         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
798                 add_mixer(spec, preset->mixers[i]);
799         spec->cap_mixer = preset->cap_mixer;
800         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
801              i++)
802                 add_verb(spec, preset->init_verbs[i]);
803
804         spec->channel_mode = preset->channel_mode;
805         spec->num_channel_mode = preset->num_channel_mode;
806         spec->need_dac_fix = preset->need_dac_fix;
807
808         spec->multiout.max_channels = spec->channel_mode[0].channels;
809
810         spec->multiout.num_dacs = preset->num_dacs;
811         spec->multiout.dac_nids = preset->dac_nids;
812         spec->multiout.dig_out_nid = preset->dig_out_nid;
813         spec->multiout.hp_nid = preset->hp_nid;
814
815         spec->num_mux_defs = preset->num_mux_defs;
816         if (!spec->num_mux_defs)
817                 spec->num_mux_defs = 1;
818         spec->input_mux = preset->input_mux;
819
820         spec->num_adc_nids = preset->num_adc_nids;
821         spec->adc_nids = preset->adc_nids;
822         spec->capsrc_nids = preset->capsrc_nids;
823         spec->dig_in_nid = preset->dig_in_nid;
824
825         spec->unsol_event = preset->unsol_event;
826         spec->init_hook = preset->init_hook;
827 #ifdef CONFIG_SND_HDA_POWER_SAVE
828         spec->loopback.amplist = preset->loopbacks;
829 #endif
830 }
831
832 /* Enable GPIO mask and set output */
833 static struct hda_verb alc_gpio1_init_verbs[] = {
834         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
835         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
836         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
837         { }
838 };
839
840 static struct hda_verb alc_gpio2_init_verbs[] = {
841         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
842         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
843         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
844         { }
845 };
846
847 static struct hda_verb alc_gpio3_init_verbs[] = {
848         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
849         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
850         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
851         { }
852 };
853
854 /*
855  * Fix hardware PLL issue
856  * On some codecs, the analog PLL gating control must be off while
857  * the default value is 1.
858  */
859 static void alc_fix_pll(struct hda_codec *codec)
860 {
861         struct alc_spec *spec = codec->spec;
862         unsigned int val;
863
864         if (!spec->pll_nid)
865                 return;
866         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
867                             spec->pll_coef_idx);
868         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
869                                  AC_VERB_GET_PROC_COEF, 0);
870         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
871                             spec->pll_coef_idx);
872         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
873                             val & ~(1 << spec->pll_coef_bit));
874 }
875
876 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
877                              unsigned int coef_idx, unsigned int coef_bit)
878 {
879         struct alc_spec *spec = codec->spec;
880         spec->pll_nid = nid;
881         spec->pll_coef_idx = coef_idx;
882         spec->pll_coef_bit = coef_bit;
883         alc_fix_pll(codec);
884 }
885
886 static void alc_sku_automute(struct hda_codec *codec)
887 {
888         struct alc_spec *spec = codec->spec;
889         unsigned int present;
890         unsigned int hp_nid = spec->autocfg.hp_pins[0];
891         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
892
893         /* need to execute and sync at first */
894         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
895         present = snd_hda_codec_read(codec, hp_nid, 0,
896                                      AC_VERB_GET_PIN_SENSE, 0);
897         spec->jack_present = (present & 0x80000000) != 0;
898         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
899                             spec->jack_present ? 0 : PIN_OUT);
900 }
901
902 #if 0 /* it's broken in some acses -- temporarily disabled */
903 static void alc_mic_automute(struct hda_codec *codec)
904 {
905         struct alc_spec *spec = codec->spec;
906         unsigned int present;
907         unsigned int mic_nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
908         unsigned int fmic_nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
909         unsigned int mix_nid = spec->capsrc_nids[0];
910         unsigned int capsrc_idx_mic, capsrc_idx_fmic;
911
912         capsrc_idx_mic = mic_nid - 0x18;
913         capsrc_idx_fmic = fmic_nid - 0x18;
914         present = snd_hda_codec_read(codec, mic_nid, 0,
915                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
916         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
917                     0x7000 | (capsrc_idx_mic << 8) | (present ? 0 : 0x80));
918         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
919                     0x7000 | (capsrc_idx_fmic << 8) | (present ? 0x80 : 0));
920         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, capsrc_idx_fmic,
921                          HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
922 }
923 #else
924 #define alc_mic_automute(codec) /* NOP */
925 #endif /* disabled */
926
927 /* unsolicited event for HP jack sensing */
928 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
929 {
930         if (codec->vendor_id == 0x10ec0880)
931                 res >>= 28;
932         else
933                 res >>= 26;
934         if (res == ALC880_HP_EVENT)
935                 alc_sku_automute(codec);
936
937         if (res == ALC880_MIC_EVENT)
938                 alc_mic_automute(codec);
939 }
940
941 static void alc_inithook(struct hda_codec *codec)
942 {
943         alc_sku_automute(codec);
944         alc_mic_automute(codec);
945 }
946
947 /* additional initialization for ALC888 variants */
948 static void alc888_coef_init(struct hda_codec *codec)
949 {
950         unsigned int tmp;
951
952         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
953         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
954         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
955         if ((tmp & 0xf0) == 2)
956                 /* alc888S-VC */
957                 snd_hda_codec_read(codec, 0x20, 0,
958                                    AC_VERB_SET_PROC_COEF, 0x830);
959          else
960                  /* alc888-VB */
961                  snd_hda_codec_read(codec, 0x20, 0,
962                                     AC_VERB_SET_PROC_COEF, 0x3030);
963 }
964
965 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
966  *      31 ~ 16 :       Manufacture ID
967  *      15 ~ 8  :       SKU ID
968  *      7  ~ 0  :       Assembly ID
969  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
970  */
971 static void alc_subsystem_id(struct hda_codec *codec,
972                              unsigned int porta, unsigned int porte,
973                              unsigned int portd)
974 {
975         unsigned int ass, tmp, i;
976         unsigned nid;
977         struct alc_spec *spec = codec->spec;
978
979         ass = codec->subsystem_id & 0xffff;
980         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
981                 goto do_sku;
982
983         /*
984          * 31~30        : port conetcivity
985          * 29~21        : reserve
986          * 20           : PCBEEP input
987          * 19~16        : Check sum (15:1)
988          * 15~1         : Custom
989          * 0            : override
990         */
991         nid = 0x1d;
992         if (codec->vendor_id == 0x10ec0260)
993                 nid = 0x17;
994         ass = snd_hda_codec_read(codec, nid, 0,
995                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
996         if (!(ass & 1) && !(ass & 0x100000))
997                 return;
998         if ((ass >> 30) != 1)   /* no physical connection */
999                 return;
1000
1001         /* check sum */
1002         tmp = 0;
1003         for (i = 1; i < 16; i++) {
1004                 if ((ass >> i) & 1)
1005                         tmp++;
1006         }
1007         if (((ass >> 16) & 0xf) != tmp)
1008                 return;
1009 do_sku:
1010         /*
1011          * 0 : override
1012          * 1 :  Swap Jack
1013          * 2 : 0 --> Desktop, 1 --> Laptop
1014          * 3~5 : External Amplifier control
1015          * 7~6 : Reserved
1016         */
1017         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1018         switch (tmp) {
1019         case 1:
1020                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1021                 break;
1022         case 3:
1023                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1024                 break;
1025         case 7:
1026                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1027                 break;
1028         case 5: /* set EAPD output high */
1029                 switch (codec->vendor_id) {
1030                 case 0x10ec0260:
1031                         snd_hda_codec_write(codec, 0x0f, 0,
1032                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1033                         snd_hda_codec_write(codec, 0x10, 0,
1034                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1035                         break;
1036                 case 0x10ec0262:
1037                 case 0x10ec0267:
1038                 case 0x10ec0268:
1039                 case 0x10ec0269:
1040                 case 0x10ec0660:
1041                 case 0x10ec0662:
1042                 case 0x10ec0663:
1043                 case 0x10ec0862:
1044                 case 0x10ec0889:
1045                         snd_hda_codec_write(codec, 0x14, 0,
1046                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1047                         snd_hda_codec_write(codec, 0x15, 0,
1048                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1049                         break;
1050                 }
1051                 switch (codec->vendor_id) {
1052                 case 0x10ec0260:
1053                         snd_hda_codec_write(codec, 0x1a, 0,
1054                                             AC_VERB_SET_COEF_INDEX, 7);
1055                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1056                                                  AC_VERB_GET_PROC_COEF, 0);
1057                         snd_hda_codec_write(codec, 0x1a, 0,
1058                                             AC_VERB_SET_COEF_INDEX, 7);
1059                         snd_hda_codec_write(codec, 0x1a, 0,
1060                                             AC_VERB_SET_PROC_COEF,
1061                                             tmp | 0x2010);
1062                         break;
1063                 case 0x10ec0262:
1064                 case 0x10ec0880:
1065                 case 0x10ec0882:
1066                 case 0x10ec0883:
1067                 case 0x10ec0885:
1068                 case 0x10ec0889:
1069                         snd_hda_codec_write(codec, 0x20, 0,
1070                                             AC_VERB_SET_COEF_INDEX, 7);
1071                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1072                                                  AC_VERB_GET_PROC_COEF, 0);
1073                         snd_hda_codec_write(codec, 0x20, 0,
1074                                             AC_VERB_SET_COEF_INDEX, 7);
1075                         snd_hda_codec_write(codec, 0x20, 0,
1076                                             AC_VERB_SET_PROC_COEF,
1077                                             tmp | 0x2010);
1078                         break;
1079                 case 0x10ec0888:
1080                         /*alc888_coef_init(codec);*/ /* called in alc_init() */
1081                         break;
1082                 case 0x10ec0267:
1083                 case 0x10ec0268:
1084                         snd_hda_codec_write(codec, 0x20, 0,
1085                                             AC_VERB_SET_COEF_INDEX, 7);
1086                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1087                                                  AC_VERB_GET_PROC_COEF, 0);
1088                         snd_hda_codec_write(codec, 0x20, 0,
1089                                             AC_VERB_SET_COEF_INDEX, 7);
1090                         snd_hda_codec_write(codec, 0x20, 0,
1091                                             AC_VERB_SET_PROC_COEF,
1092                                             tmp | 0x3000);
1093                         break;
1094                 }
1095         default:
1096                 break;
1097         }
1098
1099         /* is laptop or Desktop and enable the function "Mute internal speaker
1100          * when the external headphone out jack is plugged"
1101          */
1102         if (!(ass & 0x8000))
1103                 return;
1104         /*
1105          * 10~8 : Jack location
1106          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1107          * 14~13: Resvered
1108          * 15   : 1 --> enable the function "Mute internal speaker
1109          *              when the external headphone out jack is plugged"
1110          */
1111         if (!spec->autocfg.speaker_pins[0]) {
1112                 if (spec->autocfg.line_out_pins[0])
1113                         spec->autocfg.speaker_pins[0] =
1114                                 spec->autocfg.line_out_pins[0];
1115                 else
1116                         return;
1117         }
1118
1119         if (!spec->autocfg.hp_pins[0]) {
1120                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1121                 if (tmp == 0)
1122                         spec->autocfg.hp_pins[0] = porta;
1123                 else if (tmp == 1)
1124                         spec->autocfg.hp_pins[0] = porte;
1125                 else if (tmp == 2)
1126                         spec->autocfg.hp_pins[0] = portd;
1127                 else
1128                         return;
1129         }
1130         if (spec->autocfg.hp_pins[0])
1131                 snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1132                         AC_VERB_SET_UNSOLICITED_ENABLE,
1133                         AC_USRSP_EN | ALC880_HP_EVENT);
1134
1135 #if 0 /* it's broken in some acses -- temporarily disabled */
1136         if (spec->autocfg.input_pins[AUTO_PIN_MIC] &&
1137                 spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC])
1138                 snd_hda_codec_write(codec,
1139                         spec->autocfg.input_pins[AUTO_PIN_MIC], 0,
1140                         AC_VERB_SET_UNSOLICITED_ENABLE,
1141                         AC_USRSP_EN | ALC880_MIC_EVENT);
1142 #endif /* disabled */
1143
1144         spec->unsol_event = alc_sku_unsol_event;
1145 }
1146
1147 /*
1148  * Fix-up pin default configurations
1149  */
1150
1151 struct alc_pincfg {
1152         hda_nid_t nid;
1153         u32 val;
1154 };
1155
1156 static void alc_fix_pincfg(struct hda_codec *codec,
1157                            const struct snd_pci_quirk *quirk,
1158                            const struct alc_pincfg **pinfix)
1159 {
1160         const struct alc_pincfg *cfg;
1161
1162         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1163         if (!quirk)
1164                 return;
1165
1166         cfg = pinfix[quirk->value];
1167         for (; cfg->nid; cfg++) {
1168                 int i;
1169                 u32 val = cfg->val;
1170                 for (i = 0; i < 4; i++) {
1171                         snd_hda_codec_write(codec, cfg->nid, 0,
1172                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
1173                                     val & 0xff);
1174                         val >>= 8;
1175                 }
1176         }
1177 }
1178
1179 /*
1180  * ALC888
1181  */
1182
1183 /*
1184  * 2ch mode
1185  */
1186 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1187 /* Mic-in jack as mic in */
1188         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1189         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1190 /* Line-in jack as Line in */
1191         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1192         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1193 /* Line-Out as Front */
1194         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1195         { } /* end */
1196 };
1197
1198 /*
1199  * 4ch mode
1200  */
1201 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1202 /* Mic-in jack as mic in */
1203         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1204         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1205 /* Line-in jack as Surround */
1206         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1207         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1208 /* Line-Out as Front */
1209         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1210         { } /* end */
1211 };
1212
1213 /*
1214  * 6ch mode
1215  */
1216 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1217 /* Mic-in jack as CLFE */
1218         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1219         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1220 /* Line-in jack as Surround */
1221         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1222         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1223 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1224         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1225         { } /* end */
1226 };
1227
1228 /*
1229  * 8ch mode
1230  */
1231 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1232 /* Mic-in jack as CLFE */
1233         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1234         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1235 /* Line-in jack as Surround */
1236         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1237         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1238 /* Line-Out as Side */
1239         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1240         { } /* end */
1241 };
1242
1243 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1244         { 2, alc888_4ST_ch2_intel_init },
1245         { 4, alc888_4ST_ch4_intel_init },
1246         { 6, alc888_4ST_ch6_intel_init },
1247         { 8, alc888_4ST_ch8_intel_init },
1248 };
1249
1250 /*
1251  * ALC888 Fujitsu Siemens Amillo xa3530
1252  */
1253
1254 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1255 /* Front Mic: set to PIN_IN (empty by default) */
1256         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1257 /* Connect Internal HP to Front */
1258         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1259         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1260         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1261 /* Connect Bass HP to Front */
1262         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1263         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1264         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1265 /* Connect Line-Out side jack (SPDIF) to Side */
1266         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1267         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1268         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1269 /* Connect Mic jack to CLFE */
1270         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1271         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1272         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1273 /* Connect Line-in jack to Surround */
1274         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1275         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1276         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1277 /* Connect HP out jack to Front */
1278         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1279         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1280         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1281 /* Enable unsolicited event for HP jack and Line-out jack */
1282         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1283         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1284         {}
1285 };
1286
1287 static void alc888_fujitsu_xa3530_automute(struct hda_codec *codec)
1288 {
1289         unsigned int present;
1290         unsigned int bits;
1291         /* Line out presence */
1292         present = snd_hda_codec_read(codec, 0x17, 0,
1293                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1294         /* HP out presence */
1295         present = present || snd_hda_codec_read(codec, 0x1b, 0,
1296                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1297         bits = present ? HDA_AMP_MUTE : 0;
1298         /* Toggle internal speakers muting */
1299         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1300                                  HDA_AMP_MUTE, bits);
1301         /* Toggle internal bass muting */
1302         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1303                                  HDA_AMP_MUTE, bits);
1304 }
1305
1306 static void alc888_fujitsu_xa3530_unsol_event(struct hda_codec *codec,
1307                 unsigned int res)
1308 {
1309         if (res >> 26 == ALC880_HP_EVENT)
1310                 alc888_fujitsu_xa3530_automute(codec);
1311 }
1312
1313
1314 /*
1315  * ALC888 Acer Aspire 4930G model
1316  */
1317
1318 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1319 /* Front Mic: set to PIN_IN (empty by default) */
1320         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1321 /* Unselect Front Mic by default in input mixer 3 */
1322         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1323 /* Enable unsolicited event for HP jack */
1324         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1325 /* Connect Internal HP to front */
1326         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1327         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1328         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1329 /* Connect HP out to front */
1330         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1331         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1332         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1333         { }
1334 };
1335
1336 static struct hda_input_mux alc888_2_capture_sources[2] = {
1337         /* Front mic only available on one ADC */
1338         {
1339                 .num_items = 4,
1340                 .items = {
1341                         { "Mic", 0x0 },
1342                         { "Line", 0x2 },
1343                         { "CD", 0x4 },
1344                         { "Front Mic", 0xb },
1345                 },
1346         },
1347         {
1348                 .num_items = 3,
1349                 .items = {
1350                         { "Mic", 0x0 },
1351                         { "Line", 0x2 },
1352                         { "CD", 0x4 },
1353                 },
1354         }
1355 };
1356
1357 static struct snd_kcontrol_new alc888_base_mixer[] = {
1358         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1359         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1360         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1361         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1362         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1363                 HDA_OUTPUT),
1364         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1365         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1366         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1367         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1368         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1369         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1370         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1371         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1372         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1373         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1374         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1375         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1376         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1377         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1378         { } /* end */
1379 };
1380
1381 static void alc888_acer_aspire_4930g_automute(struct hda_codec *codec)
1382 {
1383         unsigned int present;
1384         unsigned int bits;
1385         present = snd_hda_codec_read(codec, 0x15, 0,
1386                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1387         bits = present ? HDA_AMP_MUTE : 0;
1388         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1389                                  HDA_AMP_MUTE, bits);
1390 }
1391
1392 static void alc888_acer_aspire_4930g_unsol_event(struct hda_codec *codec,
1393                 unsigned int res)
1394 {
1395         if (res >> 26 == ALC880_HP_EVENT)
1396                 alc888_acer_aspire_4930g_automute(codec);
1397 }
1398
1399 /*
1400  * ALC880 3-stack model
1401  *
1402  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1403  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1404  *                 F-Mic = 0x1b, HP = 0x19
1405  */
1406
1407 static hda_nid_t alc880_dac_nids[4] = {
1408         /* front, rear, clfe, rear_surr */
1409         0x02, 0x05, 0x04, 0x03
1410 };
1411
1412 static hda_nid_t alc880_adc_nids[3] = {
1413         /* ADC0-2 */
1414         0x07, 0x08, 0x09,
1415 };
1416
1417 /* The datasheet says the node 0x07 is connected from inputs,
1418  * but it shows zero connection in the real implementation on some devices.
1419  * Note: this is a 915GAV bug, fixed on 915GLV
1420  */
1421 static hda_nid_t alc880_adc_nids_alt[2] = {
1422         /* ADC1-2 */
1423         0x08, 0x09,
1424 };
1425
1426 #define ALC880_DIGOUT_NID       0x06
1427 #define ALC880_DIGIN_NID        0x0a
1428
1429 static struct hda_input_mux alc880_capture_source = {
1430         .num_items = 4,
1431         .items = {
1432                 { "Mic", 0x0 },
1433                 { "Front Mic", 0x3 },
1434                 { "Line", 0x2 },
1435                 { "CD", 0x4 },
1436         },
1437 };
1438
1439 /* channel source setting (2/6 channel selection for 3-stack) */
1440 /* 2ch mode */
1441 static struct hda_verb alc880_threestack_ch2_init[] = {
1442         /* set line-in to input, mute it */
1443         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1444         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1445         /* set mic-in to input vref 80%, mute it */
1446         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1447         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1448         { } /* end */
1449 };
1450
1451 /* 6ch mode */
1452 static struct hda_verb alc880_threestack_ch6_init[] = {
1453         /* set line-in to output, unmute it */
1454         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1455         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1456         /* set mic-in to output, unmute it */
1457         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1458         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1459         { } /* end */
1460 };
1461
1462 static struct hda_channel_mode alc880_threestack_modes[2] = {
1463         { 2, alc880_threestack_ch2_init },
1464         { 6, alc880_threestack_ch6_init },
1465 };
1466
1467 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1468         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1469         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1470         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1471         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1472         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1473         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1474         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1475         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1476         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1477         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1478         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1479         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1480         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1481         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1482         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1483         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1484         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1485         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1486         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1487         {
1488                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1489                 .name = "Channel Mode",
1490                 .info = alc_ch_mode_info,
1491                 .get = alc_ch_mode_get,
1492                 .put = alc_ch_mode_put,
1493         },
1494         { } /* end */
1495 };
1496
1497 /* capture mixer elements */
1498 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1499                             struct snd_ctl_elem_info *uinfo)
1500 {
1501         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1502         struct alc_spec *spec = codec->spec;
1503         int err;
1504
1505         mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1506         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1507                                                       HDA_INPUT);
1508         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1509         mutex_unlock(&codec->spdif_mutex); /* reuse spdif_mutex */
1510         return err;
1511 }
1512
1513 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1514                            unsigned int size, unsigned int __user *tlv)
1515 {
1516         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1517         struct alc_spec *spec = codec->spec;
1518         int err;
1519
1520         mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1521         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1522                                                       HDA_INPUT);
1523         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1524         mutex_unlock(&codec->spdif_mutex); /* reuse spdif_mutex */
1525         return err;
1526 }
1527
1528 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1529                              struct snd_ctl_elem_value *ucontrol);
1530
1531 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1532                                  struct snd_ctl_elem_value *ucontrol,
1533                                  getput_call_t func)
1534 {
1535         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1536         struct alc_spec *spec = codec->spec;
1537         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1538         int err;
1539
1540         mutex_lock(&codec->spdif_mutex); /* reuse spdif_mutex */
1541         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1542                                                       3, 0, HDA_INPUT);
1543         err = func(kcontrol, ucontrol);
1544         mutex_unlock(&codec->spdif_mutex); /* reuse spdif_mutex */
1545         return err;
1546 }
1547
1548 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1549                            struct snd_ctl_elem_value *ucontrol)
1550 {
1551         return alc_cap_getput_caller(kcontrol, ucontrol,
1552                                      snd_hda_mixer_amp_volume_get);
1553 }
1554
1555 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1556                            struct snd_ctl_elem_value *ucontrol)
1557 {
1558         return alc_cap_getput_caller(kcontrol, ucontrol,
1559                                      snd_hda_mixer_amp_volume_put);
1560 }
1561
1562 /* capture mixer elements */
1563 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1564
1565 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1566                           struct snd_ctl_elem_value *ucontrol)
1567 {
1568         return alc_cap_getput_caller(kcontrol, ucontrol,
1569                                      snd_hda_mixer_amp_switch_get);
1570 }
1571
1572 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1573                           struct snd_ctl_elem_value *ucontrol)
1574 {
1575         return alc_cap_getput_caller(kcontrol, ucontrol,
1576                                      snd_hda_mixer_amp_switch_put);
1577 }
1578
1579 #define DEFINE_CAPMIX(num) \
1580 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1581         { \
1582                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1583                 .name = "Capture Switch", \
1584                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1585                 .count = num, \
1586                 .info = alc_cap_sw_info, \
1587                 .get = alc_cap_sw_get, \
1588                 .put = alc_cap_sw_put, \
1589         }, \
1590         { \
1591                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1592                 .name = "Capture Volume", \
1593                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1594                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1595                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1596                 .count = num, \
1597                 .info = alc_cap_vol_info, \
1598                 .get = alc_cap_vol_get, \
1599                 .put = alc_cap_vol_put, \
1600                 .tlv = { .c = alc_cap_vol_tlv }, \
1601         }, \
1602         { \
1603                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1604                 /* .name = "Capture Source", */ \
1605                 .name = "Input Source", \
1606                 .count = num, \
1607                 .info = alc_mux_enum_info, \
1608                 .get = alc_mux_enum_get, \
1609                 .put = alc_mux_enum_put, \
1610         }, \
1611         { } /* end */ \
1612 }
1613
1614 /* up to three ADCs */
1615 DEFINE_CAPMIX(1);
1616 DEFINE_CAPMIX(2);
1617 DEFINE_CAPMIX(3);
1618
1619
1620 /*
1621  * ALC880 5-stack model
1622  *
1623  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1624  *      Side = 0x02 (0xd)
1625  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1626  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1627  */
1628
1629 /* additional mixers to alc880_three_stack_mixer */
1630 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1631         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1632         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1633         { } /* end */
1634 };
1635
1636 /* channel source setting (6/8 channel selection for 5-stack) */
1637 /* 6ch mode */
1638 static struct hda_verb alc880_fivestack_ch6_init[] = {
1639         /* set line-in to input, mute it */
1640         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1641         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1642         { } /* end */
1643 };
1644
1645 /* 8ch mode */
1646 static struct hda_verb alc880_fivestack_ch8_init[] = {
1647         /* set line-in to output, unmute it */
1648         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1649         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1650         { } /* end */
1651 };
1652
1653 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1654         { 6, alc880_fivestack_ch6_init },
1655         { 8, alc880_fivestack_ch8_init },
1656 };
1657
1658
1659 /*
1660  * ALC880 6-stack model
1661  *
1662  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1663  *      Side = 0x05 (0x0f)
1664  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1665  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1666  */
1667
1668 static hda_nid_t alc880_6st_dac_nids[4] = {
1669         /* front, rear, clfe, rear_surr */
1670         0x02, 0x03, 0x04, 0x05
1671 };
1672
1673 static struct hda_input_mux alc880_6stack_capture_source = {
1674         .num_items = 4,
1675         .items = {
1676                 { "Mic", 0x0 },
1677                 { "Front Mic", 0x1 },
1678                 { "Line", 0x2 },
1679                 { "CD", 0x4 },
1680         },
1681 };
1682
1683 /* fixed 8-channels */
1684 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1685         { 8, NULL },
1686 };
1687
1688 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1689         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1690         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1691         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1692         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1693         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1694         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1695         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1696         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1697         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1698         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1699         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1700         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1701         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1702         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1703         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1704         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1705         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1706         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1707         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1708         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1709         {
1710                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1711                 .name = "Channel Mode",
1712                 .info = alc_ch_mode_info,
1713                 .get = alc_ch_mode_get,
1714                 .put = alc_ch_mode_put,
1715         },
1716         { } /* end */
1717 };
1718
1719
1720 /*
1721  * ALC880 W810 model
1722  *
1723  * W810 has rear IO for:
1724  * Front (DAC 02)
1725  * Surround (DAC 03)
1726  * Center/LFE (DAC 04)
1727  * Digital out (06)
1728  *
1729  * The system also has a pair of internal speakers, and a headphone jack.
1730  * These are both connected to Line2 on the codec, hence to DAC 02.
1731  *
1732  * There is a variable resistor to control the speaker or headphone
1733  * volume. This is a hardware-only device without a software API.
1734  *
1735  * Plugging headphones in will disable the internal speakers. This is
1736  * implemented in hardware, not via the driver using jack sense. In
1737  * a similar fashion, plugging into the rear socket marked "front" will
1738  * disable both the speakers and headphones.
1739  *
1740  * For input, there's a microphone jack, and an "audio in" jack.
1741  * These may not do anything useful with this driver yet, because I
1742  * haven't setup any initialization verbs for these yet...
1743  */
1744
1745 static hda_nid_t alc880_w810_dac_nids[3] = {
1746         /* front, rear/surround, clfe */
1747         0x02, 0x03, 0x04
1748 };
1749
1750 /* fixed 6 channels */
1751 static struct hda_channel_mode alc880_w810_modes[1] = {
1752         { 6, NULL }
1753 };
1754
1755 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1756 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1757         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1758         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1759         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1760         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1761         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1762         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1763         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1764         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1765         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1766         { } /* end */
1767 };
1768
1769
1770 /*
1771  * Z710V model
1772  *
1773  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1774  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1775  *                 Line = 0x1a
1776  */
1777
1778 static hda_nid_t alc880_z71v_dac_nids[1] = {
1779         0x02
1780 };
1781 #define ALC880_Z71V_HP_DAC      0x03
1782
1783 /* fixed 2 channels */
1784 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1785         { 2, NULL }
1786 };
1787
1788 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1789         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1790         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1791         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1792         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1793         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1794         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1795         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1796         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1797         { } /* end */
1798 };
1799
1800
1801 /*
1802  * ALC880 F1734 model
1803  *
1804  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1805  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1806  */
1807
1808 static hda_nid_t alc880_f1734_dac_nids[1] = {
1809         0x03
1810 };
1811 #define ALC880_F1734_HP_DAC     0x02
1812
1813 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1814         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1815         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1816         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1817         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1818         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1819         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1820         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1821         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1822         { } /* end */
1823 };
1824
1825 static struct hda_input_mux alc880_f1734_capture_source = {
1826         .num_items = 2,
1827         .items = {
1828                 { "Mic", 0x1 },
1829                 { "CD", 0x4 },
1830         },
1831 };
1832
1833
1834 /*
1835  * ALC880 ASUS model
1836  *
1837  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1838  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1839  *  Mic = 0x18, Line = 0x1a
1840  */
1841
1842 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1843 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1844
1845 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1846         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1847         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1848         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1849         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1850         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1851         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1852         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1853         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1854         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1855         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1856         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1857         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1858         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1859         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1860         {
1861                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1862                 .name = "Channel Mode",
1863                 .info = alc_ch_mode_info,
1864                 .get = alc_ch_mode_get,
1865                 .put = alc_ch_mode_put,
1866         },
1867         { } /* end */
1868 };
1869
1870 /*
1871  * ALC880 ASUS W1V model
1872  *
1873  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1874  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1875  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1876  */
1877
1878 /* additional mixers to alc880_asus_mixer */
1879 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1880         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1881         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1882         { } /* end */
1883 };
1884
1885 /* additional mixers to alc880_asus_mixer */
1886 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1887         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1888         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1889         { } /* end */
1890 };
1891
1892 /* TCL S700 */
1893 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1894         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1895         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1896         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1897         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1898         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1899         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1900         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1901         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1902         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1903         { } /* end */
1904 };
1905
1906 /* Uniwill */
1907 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1908         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1909         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1910         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1911         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1912         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1913         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1914         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1915         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1916         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1917         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1918         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1919         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1920         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1921         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1922         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1923         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1924         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1925         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1926         {
1927                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1928                 .name = "Channel Mode",
1929                 .info = alc_ch_mode_info,
1930                 .get = alc_ch_mode_get,
1931                 .put = alc_ch_mode_put,
1932         },
1933         { } /* end */
1934 };
1935
1936 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1937         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1938         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1939         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1940         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1941         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1942         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1943         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1944         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1945         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1946         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1947         { } /* end */
1948 };
1949
1950 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1951         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1952         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1953         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1954         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1955         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1956         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1957         { } /* end */
1958 };
1959
1960 /*
1961  * virtual master controls
1962  */
1963
1964 /*
1965  * slave controls for virtual master
1966  */
1967 static const char *alc_slave_vols[] = {
1968         "Front Playback Volume",
1969         "Surround Playback Volume",
1970         "Center Playback Volume",
1971         "LFE Playback Volume",
1972         "Side Playback Volume",
1973         "Headphone Playback Volume",
1974         "Speaker Playback Volume",
1975         "Mono Playback Volume",
1976         "Line-Out Playback Volume",
1977         "PCM Playback Volume",
1978         NULL,
1979 };
1980
1981 static const char *alc_slave_sws[] = {
1982         "Front Playback Switch",
1983         "Surround Playback Switch",
1984         "Center Playback Switch",
1985         "LFE Playback Switch",
1986         "Side Playback Switch",
1987         "Headphone Playback Switch",
1988         "Speaker Playback Switch",
1989         "Mono Playback Switch",
1990         "IEC958 Playback Switch",
1991         NULL,
1992 };
1993
1994 /*
1995  * build control elements
1996  */
1997
1998 static void alc_free_kctls(struct hda_codec *codec);
1999
2000 static int alc_build_controls(struct hda_codec *codec)
2001 {
2002         struct alc_spec *spec = codec->spec;
2003         int err;
2004         int i;
2005
2006         for (i = 0; i < spec->num_mixers; i++) {
2007                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2008                 if (err < 0)
2009                         return err;
2010         }
2011         if (spec->cap_mixer) {
2012                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2013                 if (err < 0)
2014                         return err;
2015         }
2016         if (spec->multiout.dig_out_nid) {
2017                 err = snd_hda_create_spdif_out_ctls(codec,
2018                                                     spec->multiout.dig_out_nid);
2019                 if (err < 0)
2020                         return err;
2021                 err = snd_hda_create_spdif_share_sw(codec,
2022                                                     &spec->multiout);
2023                 if (err < 0)
2024                         return err;
2025                 spec->multiout.share_spdif = 1;
2026         }
2027         if (spec->dig_in_nid) {
2028                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2029                 if (err < 0)
2030                         return err;
2031         }
2032
2033         /* if we have no master control, let's create it */
2034         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2035                 unsigned int vmaster_tlv[4];
2036                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2037                                         HDA_OUTPUT, vmaster_tlv);
2038                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2039                                           vmaster_tlv, alc_slave_vols);
2040                 if (err < 0)
2041                         return err;
2042         }
2043         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2044                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2045                                           NULL, alc_slave_sws);
2046                 if (err < 0)
2047                         return err;
2048         }
2049
2050         alc_free_kctls(codec); /* no longer needed */
2051         return 0;
2052 }
2053
2054
2055 /*
2056  * initialize the codec volumes, etc
2057  */
2058
2059 /*
2060  * generic initialization of ADC, input mixers and output mixers
2061  */
2062 static struct hda_verb alc880_volume_init_verbs[] = {
2063         /*
2064          * Unmute ADC0-2 and set the default input to mic-in
2065          */
2066         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2067         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2068         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2069         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2070         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2071         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2072
2073         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2074          * mixer widget
2075          * Note: PASD motherboards uses the Line In 2 as the input for front
2076          * panel mic (mic 2)
2077          */
2078         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2079         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2080         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2081         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2082         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2083         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2084         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2085         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2086
2087         /*
2088          * Set up output mixers (0x0c - 0x0f)
2089          */
2090         /* set vol=0 to output mixers */
2091         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2092         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2093         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2094         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2095         /* set up input amps for analog loopback */
2096         /* Amp Indices: DAC = 0, mixer = 1 */
2097         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2098         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2099         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2100         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2101         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2102         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2103         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2104         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2105
2106         { }
2107 };
2108
2109 /*
2110  * 3-stack pin configuration:
2111  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2112  */
2113 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2114         /*
2115          * preset connection lists of input pins
2116          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2117          */
2118         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2119         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2120         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2121
2122         /*
2123          * Set pin mode and muting
2124          */
2125         /* set front pin widgets 0x14 for output */
2126         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2127         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2128         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2129         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2130         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2131         /* Mic2 (as headphone out) for HP output */
2132         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2133         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2134         /* Line In pin widget for input */
2135         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2136         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2137         /* Line2 (as front mic) pin widget for input and vref at 80% */
2138         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2139         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2140         /* CD pin widget for input */
2141         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2142
2143         { }
2144 };
2145
2146 /*
2147  * 5-stack pin configuration:
2148  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2149  * line-in/side = 0x1a, f-mic = 0x1b
2150  */
2151 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2152         /*
2153          * preset connection lists of input pins
2154          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2155          */
2156         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2157         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2158
2159         /*
2160          * Set pin mode and muting
2161          */
2162         /* set pin widgets 0x14-0x17 for output */
2163         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2164         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2165         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2166         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2167         /* unmute pins for output (no gain on this amp) */
2168         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2169         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2170         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2171         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2172
2173         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2174         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2175         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2176         /* Mic2 (as headphone out) for HP output */
2177         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2178         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2179         /* Line In pin widget for input */
2180         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2181         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2182         /* Line2 (as front mic) pin widget for input and vref at 80% */
2183         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2184         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2185         /* CD pin widget for input */
2186         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2187
2188         { }
2189 };
2190
2191 /*
2192  * W810 pin configuration:
2193  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2194  */
2195 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2196         /* hphone/speaker input selector: front DAC */
2197         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2198
2199         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2200         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2201         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2202         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2203         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2204         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2205
2206         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2207         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2208
2209         { }
2210 };
2211
2212 /*
2213  * Z71V pin configuration:
2214  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2215  */
2216 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2217         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2218         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2219         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2220         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2221
2222         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2223         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2224         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2225         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2226
2227         { }
2228 };
2229
2230 /*
2231  * 6-stack pin configuration:
2232  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2233  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2234  */
2235 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2236         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2237
2238         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2239         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2240         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2241         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2242         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2243         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2244         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2245         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2246
2247         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2248         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2249         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2250         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2251         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2252         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2253         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2254         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2255         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2256
2257         { }
2258 };
2259
2260 /*
2261  * Uniwill pin configuration:
2262  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2263  * line = 0x1a
2264  */
2265 static struct hda_verb alc880_uniwill_init_verbs[] = {
2266         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2267
2268         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2269         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2270         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2271         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2272         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2273         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2274         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2275         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2276         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2277         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2278         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2279         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2280         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2281         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2282
2283         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2284         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2285         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2286         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2287         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2288         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2289         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2290         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2291         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2292
2293         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2294         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2295
2296         { }
2297 };
2298
2299 /*
2300 * Uniwill P53
2301 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2302  */
2303 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2304         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2305
2306         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2307         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2308         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2309         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2310         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2311         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2312         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2313         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2314         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2315         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2316         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2317         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2318
2319         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2320         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2321         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2322         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2323         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2324         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2325
2326         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2327         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2328
2329         { }
2330 };
2331
2332 static struct hda_verb alc880_beep_init_verbs[] = {
2333         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2334         { }
2335 };
2336
2337 /* toggle speaker-output according to the hp-jack state */
2338 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
2339 {
2340         unsigned int present;
2341         unsigned char bits;
2342
2343         present = snd_hda_codec_read(codec, 0x14, 0,
2344                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2345         bits = present ? HDA_AMP_MUTE : 0;
2346         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
2347                                  HDA_AMP_MUTE, bits);
2348         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
2349                                  HDA_AMP_MUTE, bits);
2350 }
2351
2352 /* auto-toggle front mic */
2353 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2354 {
2355         unsigned int present;
2356         unsigned char bits;
2357
2358         present = snd_hda_codec_read(codec, 0x18, 0,
2359                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2360         bits = present ? HDA_AMP_MUTE : 0;
2361         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2362 }
2363
2364 static void alc880_uniwill_automute(struct hda_codec *codec)
2365 {
2366         alc880_uniwill_hp_automute(codec);
2367         alc880_uniwill_mic_automute(codec);
2368 }
2369
2370 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2371                                        unsigned int res)
2372 {
2373         /* Looks like the unsol event is incompatible with the standard
2374          * definition.  4bit tag is placed at 28 bit!
2375          */
2376         switch (res >> 28) {
2377         case ALC880_HP_EVENT:
2378                 alc880_uniwill_hp_automute(codec);
2379                 break;
2380         case ALC880_MIC_EVENT:
2381                 alc880_uniwill_mic_automute(codec);
2382                 break;
2383         }
2384 }
2385
2386 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
2387 {
2388         unsigned int present;
2389         unsigned char bits;
2390
2391         present = snd_hda_codec_read(codec, 0x14, 0,
2392                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2393         bits = present ? HDA_AMP_MUTE : 0;
2394         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
2395 }
2396
2397 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2398 {
2399         unsigned int present;
2400
2401         present = snd_hda_codec_read(codec, 0x21, 0,
2402                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2403         present &= HDA_AMP_VOLMASK;
2404         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2405                                  HDA_AMP_VOLMASK, present);
2406         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2407                                  HDA_AMP_VOLMASK, present);
2408 }
2409
2410 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2411                                            unsigned int res)
2412 {
2413         /* Looks like the unsol event is incompatible with the standard
2414          * definition.  4bit tag is placed at 28 bit!
2415          */
2416         if ((res >> 28) == ALC880_HP_EVENT)
2417                 alc880_uniwill_p53_hp_automute(codec);
2418         if ((res >> 28) == ALC880_DCVOL_EVENT)
2419                 alc880_uniwill_p53_dcvol_automute(codec);
2420 }
2421
2422 /*
2423  * F1734 pin configuration:
2424  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2425  */
2426 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2427         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2428         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2429         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2430         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2431         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2432
2433         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2434         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2435         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2436         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2437
2438         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2439         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2440         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2441         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2442         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2443         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2444         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2445         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2446         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2447
2448         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2449         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2450
2451         { }
2452 };
2453
2454 /*
2455  * ASUS pin configuration:
2456  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2457  */
2458 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2459         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2460         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2461         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2462         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2463
2464         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2465         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2466         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2467         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2468         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2469         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2470         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2471         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2472
2473         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2474         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2475         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2476         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2477         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2478         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2479         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2480         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2481         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2482
2483         { }
2484 };
2485
2486 /* Enable GPIO mask and set output */
2487 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2488 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2489
2490 /* Clevo m520g init */
2491 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2492         /* headphone output */
2493         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2494         /* line-out */
2495         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2496         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2497         /* Line-in */
2498         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2499         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2500         /* CD */
2501         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2502         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2503         /* Mic1 (rear panel) */
2504         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2505         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2506         /* Mic2 (front panel) */
2507         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2508         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2509         /* headphone */
2510         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2511         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2512         /* change to EAPD mode */
2513         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2514         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2515
2516         { }
2517 };
2518
2519 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2520         /* change to EAPD mode */
2521         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2522         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2523
2524         /* Headphone output */
2525         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2526         /* Front output*/
2527         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2528         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2529
2530         /* Line In pin widget for input */
2531         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2532         /* CD pin widget for input */
2533         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2534         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2535         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2536
2537         /* change to EAPD mode */
2538         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2539         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2540
2541         { }
2542 };
2543
2544 /*
2545  * LG m1 express dual
2546  *
2547  * Pin assignment:
2548  *   Rear Line-In/Out (blue): 0x14
2549  *   Build-in Mic-In: 0x15
2550  *   Speaker-out: 0x17
2551  *   HP-Out (green): 0x1b
2552  *   Mic-In/Out (red): 0x19
2553  *   SPDIF-Out: 0x1e
2554  */
2555
2556 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2557 static hda_nid_t alc880_lg_dac_nids[3] = {
2558         0x05, 0x02, 0x03
2559 };
2560
2561 /* seems analog CD is not working */
2562 static struct hda_input_mux alc880_lg_capture_source = {
2563         .num_items = 3,
2564         .items = {
2565                 { "Mic", 0x1 },
2566                 { "Line", 0x5 },
2567                 { "Internal Mic", 0x6 },
2568         },
2569 };
2570
2571 /* 2,4,6 channel modes */
2572 static struct hda_verb alc880_lg_ch2_init[] = {
2573         /* set line-in and mic-in to input */
2574         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2575         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2576         { }
2577 };
2578
2579 static struct hda_verb alc880_lg_ch4_init[] = {
2580         /* set line-in to out and mic-in to input */
2581         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2582         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2583         { }
2584 };
2585
2586 static struct hda_verb alc880_lg_ch6_init[] = {
2587         /* set line-in and mic-in to output */
2588         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2589         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2590         { }
2591 };
2592
2593 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2594         { 2, alc880_lg_ch2_init },
2595         { 4, alc880_lg_ch4_init },
2596         { 6, alc880_lg_ch6_init },
2597 };
2598
2599 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2600         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2601         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2602         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2603         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2604         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2605         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2606         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2607         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2608         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2609         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2610         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2611         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2612         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2613         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2614         {
2615                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2616                 .name = "Channel Mode",
2617                 .info = alc_ch_mode_info,
2618                 .get = alc_ch_mode_get,
2619                 .put = alc_ch_mode_put,
2620         },
2621         { } /* end */
2622 };
2623
2624 static struct hda_verb alc880_lg_init_verbs[] = {
2625         /* set capture source to mic-in */
2626         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2627         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2628         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2629         /* mute all amp mixer inputs */
2630         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2631         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2632         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2633         /* line-in to input */
2634         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2635         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2636         /* built-in mic */
2637         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2638         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2639         /* speaker-out */
2640         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2641         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2642         /* mic-in to input */
2643         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2644         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2645         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2646         /* HP-out */
2647         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2648         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2649         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2650         /* jack sense */
2651         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2652         { }
2653 };
2654
2655 /* toggle speaker-output according to the hp-jack state */
2656 static void alc880_lg_automute(struct hda_codec *codec)
2657 {
2658         unsigned int present;
2659         unsigned char bits;
2660
2661         present = snd_hda_codec_read(codec, 0x1b, 0,
2662                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2663         bits = present ? HDA_AMP_MUTE : 0;
2664         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2665                                  HDA_AMP_MUTE, bits);
2666 }
2667
2668 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2669 {
2670         /* Looks like the unsol event is incompatible with the standard
2671          * definition.  4bit tag is placed at 28 bit!
2672          */
2673         if ((res >> 28) == 0x01)
2674                 alc880_lg_automute(codec);
2675 }
2676
2677 /*
2678  * LG LW20
2679  *
2680  * Pin assignment:
2681  *   Speaker-out: 0x14
2682  *   Mic-In: 0x18
2683  *   Built-in Mic-In: 0x19
2684  *   Line-In: 0x1b
2685  *   HP-Out: 0x1a
2686  *   SPDIF-Out: 0x1e
2687  */
2688
2689 static struct hda_input_mux alc880_lg_lw_capture_source = {
2690         .num_items = 3,
2691         .items = {
2692                 { "Mic", 0x0 },
2693                 { "Internal Mic", 0x1 },
2694                 { "Line In", 0x2 },
2695         },
2696 };
2697
2698 #define alc880_lg_lw_modes alc880_threestack_modes
2699
2700 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2701         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2702         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2703         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2704         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2705         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2706         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2707         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2708         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2709         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2710         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2711         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2712         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2713         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2714         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2715         {
2716                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2717                 .name = "Channel Mode",
2718                 .info = alc_ch_mode_info,
2719                 .get = alc_ch_mode_get,
2720                 .put = alc_ch_mode_put,
2721         },
2722         { } /* end */
2723 };
2724
2725 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2726         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2727         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2728         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2729
2730         /* set capture source to mic-in */
2731         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2732         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2733         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2734         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2735         /* speaker-out */
2736         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2737         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2738         /* HP-out */
2739         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2740         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2741         /* mic-in to input */
2742         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2743         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2744         /* built-in mic */
2745         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2746         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2747         /* jack sense */
2748         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2749         { }
2750 };
2751
2752 /* toggle speaker-output according to the hp-jack state */
2753 static void alc880_lg_lw_automute(struct hda_codec *codec)
2754 {
2755         unsigned int present;
2756         unsigned char bits;
2757
2758         present = snd_hda_codec_read(codec, 0x1b, 0,
2759                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2760         bits = present ? HDA_AMP_MUTE : 0;
2761         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2762                                  HDA_AMP_MUTE, bits);
2763 }
2764
2765 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2766 {
2767         /* Looks like the unsol event is incompatible with the standard
2768          * definition.  4bit tag is placed at 28 bit!
2769          */
2770         if ((res >> 28) == 0x01)
2771                 alc880_lg_lw_automute(codec);
2772 }
2773
2774 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2775         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2776         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2777         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2778         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2779         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2780         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2781         { } /* end */
2782 };
2783
2784 static struct hda_input_mux alc880_medion_rim_capture_source = {
2785         .num_items = 2,
2786         .items = {
2787                 { "Mic", 0x0 },
2788                 { "Internal Mic", 0x1 },
2789         },
2790 };
2791
2792 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2793         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2794
2795         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2796         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2797
2798         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2799         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2800         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2801         /* Mic2 (as headphone out) for HP output */
2802         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2803         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2804         /* Internal Speaker */
2805         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2806         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2807
2808         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2809         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2810
2811         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2812         { }
2813 };
2814
2815 /* toggle speaker-output according to the hp-jack state */
2816 static void alc880_medion_rim_automute(struct hda_codec *codec)
2817 {
2818         unsigned int present;
2819         unsigned char bits;
2820
2821         present = snd_hda_codec_read(codec, 0x14, 0,
2822                                      AC_VERB_GET_PIN_SENSE, 0)
2823                 & AC_PINSENSE_PRESENCE;
2824         bits = present ? HDA_AMP_MUTE : 0;
2825         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2826                                  HDA_AMP_MUTE, bits);
2827         if (present)
2828                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2829         else
2830                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2831 }
2832
2833 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2834                                           unsigned int res)
2835 {
2836         /* Looks like the unsol event is incompatible with the standard
2837          * definition.  4bit tag is placed at 28 bit!
2838          */
2839         if ((res >> 28) == ALC880_HP_EVENT)
2840                 alc880_medion_rim_automute(codec);
2841 }
2842
2843 #ifdef CONFIG_SND_HDA_POWER_SAVE
2844 static struct hda_amp_list alc880_loopbacks[] = {
2845         { 0x0b, HDA_INPUT, 0 },
2846         { 0x0b, HDA_INPUT, 1 },
2847         { 0x0b, HDA_INPUT, 2 },
2848         { 0x0b, HDA_INPUT, 3 },
2849         { 0x0b, HDA_INPUT, 4 },
2850         { } /* end */
2851 };
2852
2853 static struct hda_amp_list alc880_lg_loopbacks[] = {
2854         { 0x0b, HDA_INPUT, 1 },
2855         { 0x0b, HDA_INPUT, 6 },
2856         { 0x0b, HDA_INPUT, 7 },
2857         { } /* end */
2858 };
2859 #endif
2860
2861 /*
2862  * Common callbacks
2863  */
2864
2865 static int alc_init(struct hda_codec *codec)
2866 {
2867         struct alc_spec *spec = codec->spec;
2868         unsigned int i;
2869
2870         alc_fix_pll(codec);
2871         if (codec->vendor_id == 0x10ec0888)
2872                 alc888_coef_init(codec);
2873
2874         for (i = 0; i < spec->num_init_verbs; i++)
2875                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2876
2877         if (spec->init_hook)
2878                 spec->init_hook(codec);
2879
2880         return 0;
2881 }
2882
2883 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2884 {
2885         struct alc_spec *spec = codec->spec;
2886
2887         if (spec->unsol_event)
2888                 spec->unsol_event(codec, res);
2889 }
2890
2891 #ifdef CONFIG_SND_HDA_POWER_SAVE
2892 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2893 {
2894         struct alc_spec *spec = codec->spec;
2895         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2896 }
2897 #endif
2898
2899 /*
2900  * Analog playback callbacks
2901  */
2902 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2903                                     struct hda_codec *codec,
2904                                     struct snd_pcm_substream *substream)
2905 {
2906         struct alc_spec *spec = codec->spec;
2907         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2908                                              hinfo);
2909 }
2910
2911 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2912                                        struct hda_codec *codec,
2913                                        unsigned int stream_tag,
2914                                        unsigned int format,
2915                                        struct snd_pcm_substream *substream)
2916 {
2917         struct alc_spec *spec = codec->spec;
2918         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2919                                                 stream_tag, format, substream);
2920 }
2921
2922 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2923                                        struct hda_codec *codec,
2924                                        struct snd_pcm_substream *substream)
2925 {
2926         struct alc_spec *spec = codec->spec;
2927         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2928 }
2929
2930 /*
2931  * Digital out
2932  */
2933 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2934                                         struct hda_codec *codec,
2935                                         struct snd_pcm_substream *substream)
2936 {
2937         struct alc_spec *spec = codec->spec;
2938         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2939 }
2940
2941 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2942                                            struct hda_codec *codec,
2943                                            unsigned int stream_tag,
2944                                            unsigned int format,
2945                                            struct snd_pcm_substream *substream)
2946 {
2947         struct alc_spec *spec = codec->spec;
2948         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2949                                              stream_tag, format, substream);
2950 }
2951
2952 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2953                                          struct hda_codec *codec,
2954                                          struct snd_pcm_substream *substream)
2955 {
2956         struct alc_spec *spec = codec->spec;
2957         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2958 }
2959
2960 /*
2961  * Analog capture
2962  */
2963 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2964                                       struct hda_codec *codec,
2965                                       unsigned int stream_tag,
2966                                       unsigned int format,
2967                                       struct snd_pcm_substream *substream)
2968 {
2969         struct alc_spec *spec = codec->spec;
2970
2971         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2972                                    stream_tag, 0, format);
2973         return 0;
2974 }
2975
2976 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2977                                       struct hda_codec *codec,
2978                                       struct snd_pcm_substream *substream)
2979 {
2980         struct alc_spec *spec = codec->spec;
2981
2982         snd_hda_codec_cleanup_stream(codec,
2983                                      spec->adc_nids[substream->number + 1]);
2984         return 0;
2985 }
2986
2987
2988 /*
2989  */
2990 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2991         .substreams = 1,
2992         .channels_min = 2,
2993         .channels_max = 8,
2994         /* NID is set in alc_build_pcms */
2995         .ops = {
2996                 .open = alc880_playback_pcm_open,
2997                 .prepare = alc880_playback_pcm_prepare,
2998                 .cleanup = alc880_playback_pcm_cleanup
2999         },
3000 };
3001
3002 static struct hda_pcm_stream alc880_pcm_analog_capture = {
3003         .substreams = 1,
3004         .channels_min = 2,
3005         .channels_max = 2,
3006         /* NID is set in alc_build_pcms */
3007 };
3008
3009 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
3010         .substreams = 1,
3011         .channels_min = 2,
3012         .channels_max = 2,
3013         /* NID is set in alc_build_pcms */
3014 };
3015
3016 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
3017         .substreams = 2, /* can be overridden */
3018         .channels_min = 2,
3019         .channels_max = 2,
3020         /* NID is set in alc_build_pcms */
3021         .ops = {
3022                 .prepare = alc880_alt_capture_pcm_prepare,
3023                 .cleanup = alc880_alt_capture_pcm_cleanup
3024         },
3025 };
3026
3027 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3028         .substreams = 1,
3029         .channels_min = 2,
3030         .channels_max = 2,
3031         /* NID is set in alc_build_pcms */
3032         .ops = {
3033                 .open = alc880_dig_playback_pcm_open,
3034                 .close = alc880_dig_playback_pcm_close,
3035                 .prepare = alc880_dig_playback_pcm_prepare
3036         },
3037 };
3038
3039 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3040         .substreams = 1,
3041         .channels_min = 2,
3042         .channels_max = 2,
3043         /* NID is set in alc_build_pcms */
3044 };
3045
3046 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3047 static struct hda_pcm_stream alc_pcm_null_stream = {
3048         .substreams = 0,
3049         .channels_min = 0,
3050         .channels_max = 0,
3051 };
3052
3053 static int alc_build_pcms(struct hda_codec *codec)
3054 {
3055         struct alc_spec *spec = codec->spec;
3056         struct hda_pcm *info = spec->pcm_rec;
3057         int i;
3058
3059         codec->num_pcms = 1;
3060         codec->pcm_info = info;
3061
3062         info->name = spec->stream_name_analog;
3063         if (spec->stream_analog_playback) {
3064                 if (snd_BUG_ON(!spec->multiout.dac_nids))
3065                         return -EINVAL;
3066                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
3067                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
3068         }
3069         if (spec->stream_analog_capture) {
3070                 if (snd_BUG_ON(!spec->adc_nids))
3071                         return -EINVAL;
3072                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
3073                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
3074         }
3075
3076         if (spec->channel_mode) {
3077                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
3078                 for (i = 0; i < spec->num_channel_mode; i++) {
3079                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
3080                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
3081                         }
3082                 }
3083         }
3084
3085         /* SPDIF for stream index #1 */
3086         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3087                 codec->num_pcms = 2;
3088                 info = spec->pcm_rec + 1;
3089                 info->name = spec->stream_name_digital;
3090                 info->pcm_type = HDA_PCM_TYPE_SPDIF;
3091                 if (spec->multiout.dig_out_nid &&
3092                     spec->stream_digital_playback) {
3093                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
3094                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
3095                 }
3096                 if (spec->dig_in_nid &&
3097                     spec->stream_digital_capture) {
3098                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
3099                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
3100                 }
3101                 /* FIXME: do we need this for all Realtek codec models? */
3102                 codec->spdif_status_reset = 1;
3103         }
3104
3105         /* If the use of more than one ADC is requested for the current
3106          * model, configure a second analog capture-only PCM.
3107          */
3108         /* Additional Analaog capture for index #2 */
3109         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
3110             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3111                 codec->num_pcms = 3;
3112                 info = spec->pcm_rec + 2;
3113                 info->name = spec->stream_name_analog;
3114                 if (spec->alt_dac_nid) {
3115                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3116                                 *spec->stream_analog_alt_playback;
3117                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
3118                                 spec->alt_dac_nid;
3119                 } else {
3120                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3121                                 alc_pcm_null_stream;
3122                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
3123                 }
3124                 if (spec->num_adc_nids > 1) {
3125                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3126                                 *spec->stream_analog_alt_capture;
3127                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
3128                                 spec->adc_nids[1];
3129                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3130                                 spec->num_adc_nids - 1;
3131                 } else {
3132                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3133                                 alc_pcm_null_stream;
3134                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3135                 }
3136         }
3137
3138         return 0;
3139 }
3140
3141 static void alc_free_kctls(struct hda_codec *codec)
3142 {
3143         struct alc_spec *spec = codec->spec;
3144
3145         if (spec->kctls.list) {
3146                 struct snd_kcontrol_new *kctl = spec->kctls.list;
3147                 int i;
3148                 for (i = 0; i < spec->kctls.used; i++)
3149                         kfree(kctl[i].name);
3150         }
3151         snd_array_free(&spec->kctls);
3152 }
3153
3154 static void alc_free(struct hda_codec *codec)
3155 {
3156         struct alc_spec *spec = codec->spec;
3157
3158         if (!spec)
3159                 return;
3160
3161         alc_free_kctls(codec);
3162         kfree(spec);
3163         codec->spec = NULL; /* to be sure */
3164 }
3165
3166 #ifdef SND_HDA_NEEDS_RESUME
3167 static void store_pin_configs(struct hda_codec *codec)
3168 {
3169         struct alc_spec *spec = codec->spec;
3170         hda_nid_t nid, end_nid;
3171
3172         end_nid = codec->start_nid + codec->num_nodes;
3173         for (nid = codec->start_nid; nid < end_nid; nid++) {
3174                 unsigned int wid_caps = get_wcaps(codec, nid);
3175                 unsigned int wid_type =
3176                         (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3177                 if (wid_type != AC_WID_PIN)
3178                         continue;
3179                 if (spec->num_pins >= ARRAY_SIZE(spec->pin_nids))
3180                         break;
3181                 spec->pin_nids[spec->num_pins] = nid;
3182                 spec->pin_cfgs[spec->num_pins] =
3183                         snd_hda_codec_read(codec, nid, 0,
3184                                            AC_VERB_GET_CONFIG_DEFAULT, 0);
3185                 spec->num_pins++;
3186         }
3187 }
3188
3189 static void resume_pin_configs(struct hda_codec *codec)
3190 {
3191         struct alc_spec *spec = codec->spec;
3192         int i;
3193
3194         for (i = 0; i < spec->num_pins; i++) {
3195                 hda_nid_t pin_nid = spec->pin_nids[i];
3196                 unsigned int pin_config = spec->pin_cfgs[i];
3197                 snd_hda_codec_write(codec, pin_nid, 0,
3198                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
3199                                     pin_config & 0x000000ff);
3200                 snd_hda_codec_write(codec, pin_nid, 0,
3201                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
3202                                     (pin_config & 0x0000ff00) >> 8);
3203                 snd_hda_codec_write(codec, pin_nid, 0,
3204                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
3205                                     (pin_config & 0x00ff0000) >> 16);
3206                 snd_hda_codec_write(codec, pin_nid, 0,
3207                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
3208                                     pin_config >> 24);
3209         }
3210 }
3211
3212 static int alc_resume(struct hda_codec *codec)
3213 {
3214         resume_pin_configs(codec);
3215         codec->patch_ops.init(codec);
3216         snd_hda_codec_resume_amp(codec);
3217         snd_hda_codec_resume_cache(codec);
3218         return 0;
3219 }
3220 #else
3221 #define store_pin_configs(codec)
3222 #endif
3223
3224 /*
3225  */
3226 static struct hda_codec_ops alc_patch_ops = {
3227         .build_controls = alc_build_controls,
3228         .build_pcms = alc_build_pcms,
3229         .init = alc_init,
3230         .free = alc_free,
3231         .unsol_event = alc_unsol_event,
3232 #ifdef SND_HDA_NEEDS_RESUME
3233         .resume = alc_resume,
3234 #endif
3235 #ifdef CONFIG_SND_HDA_POWER_SAVE
3236         .check_power_status = alc_check_power_status,
3237 #endif
3238 };
3239
3240
3241 /*
3242  * Test configuration for debugging
3243  *
3244  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3245  * enum controls.
3246  */
3247 #ifdef CONFIG_SND_DEBUG
3248 static hda_nid_t alc880_test_dac_nids[4] = {
3249         0x02, 0x03, 0x04, 0x05
3250 };
3251
3252 static struct hda_input_mux alc880_test_capture_source = {
3253         .num_items = 7,
3254         .items = {
3255                 { "In-1", 0x0 },
3256                 { "In-2", 0x1 },
3257                 { "In-3", 0x2 },
3258                 { "In-4", 0x3 },
3259                 { "CD", 0x4 },
3260                 { "Front", 0x5 },
3261                 { "Surround", 0x6 },
3262         },
3263 };
3264
3265 static struct hda_channel_mode alc880_test_modes[4] = {
3266         { 2, NULL },
3267         { 4, NULL },
3268         { 6, NULL },
3269         { 8, NULL },
3270 };
3271
3272 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3273                                  struct snd_ctl_elem_info *uinfo)
3274 {
3275         static char *texts[] = {
3276                 "N/A", "Line Out", "HP Out",
3277                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3278         };
3279         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3280         uinfo->count = 1;
3281         uinfo->value.enumerated.items = 8;
3282         if (uinfo->value.enumerated.item >= 8)
3283                 uinfo->value.enumerated.item = 7;
3284         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3285         return 0;
3286 }
3287
3288 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3289                                 struct snd_ctl_elem_value *ucontrol)
3290 {
3291         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3292         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3293         unsigned int pin_ctl, item = 0;
3294
3295         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3296                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3297         if (pin_ctl & AC_PINCTL_OUT_EN) {
3298                 if (pin_ctl & AC_PINCTL_HP_EN)
3299                         item = 2;
3300                 else
3301                         item = 1;
3302         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3303                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3304                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3305                 case AC_PINCTL_VREF_50:  item = 4; break;
3306                 case AC_PINCTL_VREF_GRD: item = 5; break;
3307                 case AC_PINCTL_VREF_80:  item = 6; break;
3308                 case AC_PINCTL_VREF_100: item = 7; break;
3309                 }
3310         }
3311         ucontrol->value.enumerated.item[0] = item;
3312         return 0;
3313 }
3314
3315 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3316                                 struct snd_ctl_elem_value *ucontrol)
3317 {
3318         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3319         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3320         static unsigned int ctls[] = {
3321                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3322                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3323                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3324                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3325                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3326                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3327         };
3328         unsigned int old_ctl, new_ctl;
3329
3330         old_ctl = snd_hda_codec_read(codec, nid, 0,
3331                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3332         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3333         if (old_ctl != new_ctl) {
3334                 int val;
3335                 snd_hda_codec_write_cache(codec, nid, 0,
3336                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3337                                           new_ctl);
3338                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3339                         HDA_AMP_MUTE : 0;
3340                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3341                                          HDA_AMP_MUTE, val);
3342                 return 1;
3343         }
3344         return 0;
3345 }
3346
3347 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3348                                  struct snd_ctl_elem_info *uinfo)
3349 {
3350         static char *texts[] = {
3351                 "Front", "Surround", "CLFE", "Side"
3352         };
3353         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3354         uinfo->count = 1;
3355         uinfo->value.enumerated.items = 4;
3356         if (uinfo->value.enumerated.item >= 4)
3357                 uinfo->value.enumerated.item = 3;
3358         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3359         return 0;
3360 }
3361
3362 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3363                                 struct snd_ctl_elem_value *ucontrol)
3364 {
3365         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3366         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3367         unsigned int sel;
3368
3369         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3370         ucontrol->value.enumerated.item[0] = sel & 3;
3371         return 0;
3372 }
3373
3374 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3375                                 struct snd_ctl_elem_value *ucontrol)
3376 {
3377         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3378         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3379         unsigned int sel;
3380
3381         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3382         if (ucontrol->value.enumerated.item[0] != sel) {
3383                 sel = ucontrol->value.enumerated.item[0] & 3;
3384                 snd_hda_codec_write_cache(codec, nid, 0,
3385                                           AC_VERB_SET_CONNECT_SEL, sel);
3386                 return 1;
3387         }
3388         return 0;
3389 }
3390
3391 #define PIN_CTL_TEST(xname,nid) {                       \
3392                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3393                         .name = xname,                 \
3394                         .info = alc_test_pin_ctl_info, \
3395                         .get = alc_test_pin_ctl_get,   \
3396                         .put = alc_test_pin_ctl_put,   \
3397                         .private_value = nid           \
3398                         }
3399
3400 #define PIN_SRC_TEST(xname,nid) {                       \
3401                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3402                         .name = xname,                 \
3403                         .info = alc_test_pin_src_info, \
3404                         .get = alc_test_pin_src_get,   \
3405                         .put = alc_test_pin_src_put,   \
3406                         .private_value = nid           \
3407                         }
3408
3409 static struct snd_kcontrol_new alc880_test_mixer[] = {
3410         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3411         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3412         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3413         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3414         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3415         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3416         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3417         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3418         PIN_CTL_TEST("Front Pin Mode", 0x14),
3419         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3420         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3421         PIN_CTL_TEST("Side Pin Mode", 0x17),
3422         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3423         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3424         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3425         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3426         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3427         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3428         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3429         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3430         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3431         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3432         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3433         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3434         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3435         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3436         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3437         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3438         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3439         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3440         {
3441                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3442                 .name = "Channel Mode",
3443                 .info = alc_ch_mode_info,
3444                 .get = alc_ch_mode_get,
3445                 .put = alc_ch_mode_put,
3446         },
3447         { } /* end */
3448 };
3449
3450 static struct hda_verb alc880_test_init_verbs[] = {
3451         /* Unmute inputs of 0x0c - 0x0f */
3452         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3453         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3454         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3455         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3456         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3457         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3458         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3459         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3460         /* Vol output for 0x0c-0x0f */
3461         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3462         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3463         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3464         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3465         /* Set output pins 0x14-0x17 */
3466         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3467         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3468         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3469         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3470         /* Unmute output pins 0x14-0x17 */
3471         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3472         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3473         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3474         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3475         /* Set input pins 0x18-0x1c */
3476         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3477         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3478         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3479         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3480         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3481         /* Mute input pins 0x18-0x1b */
3482         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3483         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3484         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3485         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3486         /* ADC set up */
3487         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3488         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3489         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3490         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3491         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3492         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3493         /* Analog input/passthru */
3494         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3495         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3496         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3497         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3498         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3499         { }
3500 };
3501 #endif
3502
3503 /*
3504  */
3505
3506 static const char *alc880_models[ALC880_MODEL_LAST] = {
3507         [ALC880_3ST]            = "3stack",
3508         [ALC880_TCL_S700]       = "tcl",
3509         [ALC880_3ST_DIG]        = "3stack-digout",
3510         [ALC880_CLEVO]          = "clevo",
3511         [ALC880_5ST]            = "5stack",
3512         [ALC880_5ST_DIG]        = "5stack-digout",
3513         [ALC880_W810]           = "w810",
3514         [ALC880_Z71V]           = "z71v",
3515         [ALC880_6ST]            = "6stack",
3516         [ALC880_6ST_DIG]        = "6stack-digout",
3517         [ALC880_ASUS]           = "asus",
3518         [ALC880_ASUS_W1V]       = "asus-w1v",
3519         [ALC880_ASUS_DIG]       = "asus-dig",
3520         [ALC880_ASUS_DIG2]      = "asus-dig2",
3521         [ALC880_UNIWILL_DIG]    = "uniwill",
3522         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3523         [ALC880_FUJITSU]        = "fujitsu",
3524         [ALC880_F1734]          = "F1734",
3525         [ALC880_LG]             = "lg",
3526         [ALC880_LG_LW]          = "lg-lw",
3527         [ALC880_MEDION_RIM]     = "medion",
3528 #ifdef CONFIG_SND_DEBUG
3529         [ALC880_TEST]           = "test",
3530 #endif
3531         [ALC880_AUTO]           = "auto",
3532 };
3533
3534 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3535         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3536         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3537         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3538         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3539         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3540         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3541         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3542         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3543         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3544         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3545         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3546         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3547         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3548         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3549         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3550         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3551         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3552         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3553         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3554         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3555         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3556         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3557         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3558         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3559         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3560         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
3561         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3562         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3563         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3564         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3565         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3566         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3567         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3568         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3569         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3570         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3571         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3572         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3573         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3574         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3575         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3576         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3577         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3578         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3579         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3580         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3581         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3582         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3583         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3584         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3585         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3586         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3587         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3588         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3589         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3590         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3591         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3592         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3593         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3594         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3595         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3596         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3597         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3598         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3599         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3600         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3601         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3602         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3603         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
3604         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3605         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3606         {}
3607 };
3608
3609 /*
3610  * ALC880 codec presets
3611  */
3612 static struct alc_config_preset alc880_presets[] = {
3613         [ALC880_3ST] = {
3614                 .mixers = { alc880_three_stack_mixer },
3615                 .init_verbs = { alc880_volume_init_verbs,
3616                                 alc880_pin_3stack_init_verbs },
3617                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3618                 .dac_nids = alc880_dac_nids,
3619                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3620                 .channel_mode = alc880_threestack_modes,
3621                 .need_dac_fix = 1,
3622                 .input_mux = &alc880_capture_source,
3623         },
3624         [ALC880_3ST_DIG] = {
3625                 .mixers = { alc880_three_stack_mixer },
3626                 .init_verbs = { alc880_volume_init_verbs,
3627                                 alc880_pin_3stack_init_verbs },
3628                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3629                 .dac_nids = alc880_dac_nids,
3630                 .dig_out_nid = ALC880_DIGOUT_NID,
3631                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3632                 .channel_mode = alc880_threestack_modes,
3633                 .need_dac_fix = 1,
3634                 .input_mux = &alc880_capture_source,
3635         },
3636         [ALC880_TCL_S700] = {
3637                 .mixers = { alc880_tcl_s700_mixer },
3638                 .init_verbs = { alc880_volume_init_verbs,
3639                                 alc880_pin_tcl_S700_init_verbs,
3640                                 alc880_gpio2_init_verbs },
3641                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3642                 .dac_nids = alc880_dac_nids,
3643                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
3644                 .num_adc_nids = 1, /* single ADC */
3645                 .hp_nid = 0x03,
3646                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3647                 .channel_mode = alc880_2_jack_modes,
3648                 .input_mux = &alc880_capture_source,
3649         },
3650         [ALC880_5ST] = {
3651                 .mixers = { alc880_three_stack_mixer,
3652                             alc880_five_stack_mixer},
3653                 .init_verbs = { alc880_volume_init_verbs,
3654                                 alc880_pin_5stack_init_verbs },
3655                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3656                 .dac_nids = alc880_dac_nids,
3657                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3658                 .channel_mode = alc880_fivestack_modes,
3659                 .input_mux = &alc880_capture_source,
3660         },
3661         [ALC880_5ST_DIG] = {
3662                 .mixers = { alc880_three_stack_mixer,
3663                             alc880_five_stack_mixer },
3664                 .init_verbs = { alc880_volume_init_verbs,
3665                                 alc880_pin_5stack_init_verbs },
3666                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3667                 .dac_nids = alc880_dac_nids,
3668                 .dig_out_nid = ALC880_DIGOUT_NID,
3669                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3670                 .channel_mode = alc880_fivestack_modes,
3671                 .input_mux = &alc880_capture_source,
3672         },
3673         [ALC880_6ST] = {
3674                 .mixers = { alc880_six_stack_mixer },
3675                 .init_verbs = { alc880_volume_init_verbs,
3676                                 alc880_pin_6stack_init_verbs },
3677                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3678                 .dac_nids = alc880_6st_dac_nids,
3679                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3680                 .channel_mode = alc880_sixstack_modes,
3681                 .input_mux = &alc880_6stack_capture_source,
3682         },
3683         [ALC880_6ST_DIG] = {
3684                 .mixers = { alc880_six_stack_mixer },
3685                 .init_verbs = { alc880_volume_init_verbs,
3686                                 alc880_pin_6stack_init_verbs },
3687                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3688                 .dac_nids = alc880_6st_dac_nids,
3689                 .dig_out_nid = ALC880_DIGOUT_NID,
3690                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3691                 .channel_mode = alc880_sixstack_modes,
3692                 .input_mux = &alc880_6stack_capture_source,
3693         },
3694         [ALC880_W810] = {
3695                 .mixers = { alc880_w810_base_mixer },
3696                 .init_verbs = { alc880_volume_init_verbs,
3697                                 alc880_pin_w810_init_verbs,
3698                                 alc880_gpio2_init_verbs },
3699                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3700                 .dac_nids = alc880_w810_dac_nids,
3701                 .dig_out_nid = ALC880_DIGOUT_NID,
3702                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3703                 .channel_mode = alc880_w810_modes,
3704                 .input_mux = &alc880_capture_source,
3705         },
3706         [ALC880_Z71V] = {
3707                 .mixers = { alc880_z71v_mixer },
3708                 .init_verbs = { alc880_volume_init_verbs,
3709                                 alc880_pin_z71v_init_verbs },
3710                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3711                 .dac_nids = alc880_z71v_dac_nids,
3712                 .dig_out_nid = ALC880_DIGOUT_NID,
3713                 .hp_nid = 0x03,
3714                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3715                 .channel_mode = alc880_2_jack_modes,
3716                 .input_mux = &alc880_capture_source,
3717         },
3718         [ALC880_F1734] = {
3719                 .mixers = { alc880_f1734_mixer },
3720                 .init_verbs = { alc880_volume_init_verbs,
3721                                 alc880_pin_f1734_init_verbs },
3722                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3723                 .dac_nids = alc880_f1734_dac_nids,
3724                 .hp_nid = 0x02,
3725                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3726                 .channel_mode = alc880_2_jack_modes,
3727                 .input_mux = &alc880_f1734_capture_source,
3728                 .unsol_event = alc880_uniwill_p53_unsol_event,
3729                 .init_hook = alc880_uniwill_p53_hp_automute,
3730         },
3731         [ALC880_ASUS] = {
3732                 .mixers = { alc880_asus_mixer },
3733                 .init_verbs = { alc880_volume_init_verbs,
3734                                 alc880_pin_asus_init_verbs,
3735                                 alc880_gpio1_init_verbs },
3736                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3737                 .dac_nids = alc880_asus_dac_nids,
3738                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3739                 .channel_mode = alc880_asus_modes,
3740                 .need_dac_fix = 1,
3741                 .input_mux = &alc880_capture_source,
3742         },
3743         [ALC880_ASUS_DIG] = {
3744                 .mixers = { alc880_asus_mixer },
3745                 .init_verbs = { alc880_volume_init_verbs,
3746                                 alc880_pin_asus_init_verbs,
3747                                 alc880_gpio1_init_verbs },
3748                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3749                 .dac_nids = alc880_asus_dac_nids,
3750                 .dig_out_nid = ALC880_DIGOUT_NID,
3751                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3752                 .channel_mode = alc880_asus_modes,
3753                 .need_dac_fix = 1,
3754                 .input_mux = &alc880_capture_source,
3755         },
3756         [ALC880_ASUS_DIG2] = {
3757                 .mixers = { alc880_asus_mixer },
3758                 .init_verbs = { alc880_volume_init_verbs,
3759                                 alc880_pin_asus_init_verbs,
3760                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3761                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3762                 .dac_nids = alc880_asus_dac_nids,
3763                 .dig_out_nid = ALC880_DIGOUT_NID,
3764                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3765                 .channel_mode = alc880_asus_modes,
3766                 .need_dac_fix = 1,
3767                 .input_mux = &alc880_capture_source,
3768         },
3769         [ALC880_ASUS_W1V] = {
3770                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3771                 .init_verbs = { alc880_volume_init_verbs,
3772                                 alc880_pin_asus_init_verbs,
3773                                 alc880_gpio1_init_verbs },
3774                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3775                 .dac_nids = alc880_asus_dac_nids,
3776                 .dig_out_nid = ALC880_DIGOUT_NID,
3777                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3778                 .channel_mode = alc880_asus_modes,
3779                 .need_dac_fix = 1,
3780                 .input_mux = &alc880_capture_source,
3781         },
3782         [ALC880_UNIWILL_DIG] = {
3783                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3784                 .init_verbs = { alc880_volume_init_verbs,
3785                                 alc880_pin_asus_init_verbs },
3786                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3787                 .dac_nids = alc880_asus_dac_nids,
3788                 .dig_out_nid = ALC880_DIGOUT_NID,
3789                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3790                 .channel_mode = alc880_asus_modes,
3791                 .need_dac_fix = 1,
3792                 .input_mux = &alc880_capture_source,
3793         },
3794         [ALC880_UNIWILL] = {
3795                 .mixers = { alc880_uniwill_mixer },
3796                 .init_verbs = { alc880_volume_init_verbs,
3797                                 alc880_uniwill_init_verbs },
3798                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3799                 .dac_nids = alc880_asus_dac_nids,
3800                 .dig_out_nid = ALC880_DIGOUT_NID,
3801                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3802                 .channel_mode = alc880_threestack_modes,
3803                 .need_dac_fix = 1,
3804                 .input_mux = &alc880_capture_source,
3805                 .unsol_event = alc880_uniwill_unsol_event,
3806                 .init_hook = alc880_uniwill_automute,
3807         },
3808         [ALC880_UNIWILL_P53] = {
3809                 .mixers = { alc880_uniwill_p53_mixer },
3810                 .init_verbs = { alc880_volume_init_verbs,
3811                                 alc880_uniwill_p53_init_verbs },
3812                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3813                 .dac_nids = alc880_asus_dac_nids,
3814                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3815                 .channel_mode = alc880_threestack_modes,
3816                 .input_mux = &alc880_capture_source,
3817                 .unsol_event = alc880_uniwill_p53_unsol_event,
3818                 .init_hook = alc880_uniwill_p53_hp_automute,
3819         },
3820         [ALC880_FUJITSU] = {
3821                 .mixers = { alc880_fujitsu_mixer,
3822                             alc880_pcbeep_mixer, },
3823                 .init_verbs = { alc880_volume_init_verbs,
3824                                 alc880_uniwill_p53_init_verbs,
3825                                 alc880_beep_init_verbs },
3826                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3827                 .dac_nids = alc880_dac_nids,
3828                 .dig_out_nid = ALC880_DIGOUT_NID,
3829                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3830                 .channel_mode = alc880_2_jack_modes,
3831                 .input_mux = &alc880_capture_source,
3832                 .unsol_event = alc880_uniwill_p53_unsol_event,
3833                 .init_hook = alc880_uniwill_p53_hp_automute,
3834         },
3835         [ALC880_CLEVO] = {
3836                 .mixers = { alc880_three_stack_mixer },
3837                 .init_verbs = { alc880_volume_init_verbs,
3838                                 alc880_pin_clevo_init_verbs },
3839                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3840                 .dac_nids = alc880_dac_nids,
3841                 .hp_nid = 0x03,
3842                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3843                 .channel_mode = alc880_threestack_modes,
3844                 .need_dac_fix = 1,
3845                 .input_mux = &alc880_capture_source,
3846         },
3847         [ALC880_LG] = {
3848                 .mixers = { alc880_lg_mixer },
3849                 .init_verbs = { alc880_volume_init_verbs,
3850                                 alc880_lg_init_verbs },
3851                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3852                 .dac_nids = alc880_lg_dac_nids,
3853                 .dig_out_nid = ALC880_DIGOUT_NID,
3854                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3855                 .channel_mode = alc880_lg_ch_modes,
3856                 .need_dac_fix = 1,
3857                 .input_mux = &alc880_lg_capture_source,
3858                 .unsol_event = alc880_lg_unsol_event,
3859                 .init_hook = alc880_lg_automute,
3860 #ifdef CONFIG_SND_HDA_POWER_SAVE
3861                 .loopbacks = alc880_lg_loopbacks,
3862 #endif
3863         },
3864         [ALC880_LG_LW] = {
3865                 .mixers = { alc880_lg_lw_mixer },
3866                 .init_verbs = { alc880_volume_init_verbs,
3867                                 alc880_lg_lw_init_verbs },
3868                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3869                 .dac_nids = alc880_dac_nids,
3870                 .dig_out_nid = ALC880_DIGOUT_NID,
3871                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3872                 .channel_mode = alc880_lg_lw_modes,
3873                 .input_mux = &alc880_lg_lw_capture_source,
3874                 .unsol_event = alc880_lg_lw_unsol_event,
3875                 .init_hook = alc880_lg_lw_automute,
3876         },
3877         [ALC880_MEDION_RIM] = {
3878                 .mixers = { alc880_medion_rim_mixer },
3879                 .init_verbs = { alc880_volume_init_verbs,
3880                                 alc880_medion_rim_init_verbs,
3881                                 alc_gpio2_init_verbs },
3882                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3883                 .dac_nids = alc880_dac_nids,
3884                 .dig_out_nid = ALC880_DIGOUT_NID,
3885                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3886                 .channel_mode = alc880_2_jack_modes,
3887                 .input_mux = &alc880_medion_rim_capture_source,
3888                 .unsol_event = alc880_medion_rim_unsol_event,
3889                 .init_hook = alc880_medion_rim_automute,
3890         },
3891 #ifdef CONFIG_SND_DEBUG
3892         [ALC880_TEST] = {
3893                 .mixers = { alc880_test_mixer },
3894                 .init_verbs = { alc880_test_init_verbs },
3895                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3896                 .dac_nids = alc880_test_dac_nids,
3897                 .dig_out_nid = ALC880_DIGOUT_NID,
3898                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3899                 .channel_mode = alc880_test_modes,
3900                 .input_mux = &alc880_test_capture_source,
3901         },
3902 #endif
3903 };
3904
3905 /*
3906  * Automatic parse of I/O pins from the BIOS configuration
3907  */
3908
3909 enum {
3910         ALC_CTL_WIDGET_VOL,
3911         ALC_CTL_WIDGET_MUTE,
3912         ALC_CTL_BIND_MUTE,
3913 };
3914 static struct snd_kcontrol_new alc880_control_templates[] = {
3915         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3916         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3917         HDA_BIND_MUTE(NULL, 0, 0, 0),
3918 };
3919
3920 /* add dynamic controls */
3921 static int add_control(struct alc_spec *spec, int type, const char *name,
3922                        unsigned long val)
3923 {
3924         struct snd_kcontrol_new *knew;
3925
3926         snd_array_init(&spec->kctls, sizeof(*knew), 32);
3927         knew = snd_array_new(&spec->kctls);
3928         if (!knew)
3929                 return -ENOMEM;
3930         *knew = alc880_control_templates[type];
3931         knew->name = kstrdup(name, GFP_KERNEL);
3932         if (!knew->name)
3933                 return -ENOMEM;
3934         knew->private_value = val;
3935         return 0;
3936 }
3937
3938 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3939 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3940 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3941 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3942 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3943 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3944 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3945 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3946 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3947 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3948 #define ALC880_PIN_CD_NID               0x1c
3949
3950 /* fill in the dac_nids table from the parsed pin configuration */
3951 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3952                                      const struct auto_pin_cfg *cfg)
3953 {
3954         hda_nid_t nid;
3955         int assigned[4];
3956         int i, j;
3957
3958         memset(assigned, 0, sizeof(assigned));
3959         spec->multiout.dac_nids = spec->private_dac_nids;
3960
3961         /* check the pins hardwired to audio widget */
3962         for (i = 0; i < cfg->line_outs; i++) {
3963                 nid = cfg->line_out_pins[i];
3964                 if (alc880_is_fixed_pin(nid)) {
3965                         int idx = alc880_fixed_pin_idx(nid);
3966                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3967                         assigned[idx] = 1;
3968                 }
3969         }
3970         /* left pins can be connect to any audio widget */
3971         for (i = 0; i < cfg->line_outs; i++) {
3972                 nid = cfg->line_out_pins[i];
3973                 if (alc880_is_fixed_pin(nid))
3974                         continue;
3975                 /* search for an empty channel */
3976                 for (j = 0; j < cfg->line_outs; j++) {
3977                         if (!assigned[j]) {
3978                                 spec->multiout.dac_nids[i] =
3979                                         alc880_idx_to_dac(j);
3980                                 assigned[j] = 1;
3981                                 break;
3982                         }
3983                 }
3984         }
3985         spec->multiout.num_dacs = cfg->line_outs;
3986         return 0;
3987 }
3988
3989 /* add playback controls from the parsed DAC table */
3990 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3991                                              const struct auto_pin_cfg *cfg)
3992 {
3993         char name[32];
3994         static const char *chname[4] = {
3995                 "Front", "Surround", NULL /*CLFE*/, "Side"
3996         };
3997         hda_nid_t nid;
3998         int i, err;
3999
4000         for (i = 0; i < cfg->line_outs; i++) {
4001                 if (!spec->multiout.dac_nids[i])
4002                         continue;
4003                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
4004                 if (i == 2) {
4005                         /* Center/LFE */
4006                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4007                                           "Center Playback Volume",
4008                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
4009                                                               HDA_OUTPUT));
4010                         if (err < 0)
4011                                 return err;
4012                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4013                                           "LFE Playback Volume",
4014                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
4015                                                               HDA_OUTPUT));
4016                         if (err < 0)
4017                                 return err;
4018                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4019                                           "Center Playback Switch",
4020                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4021                                                               HDA_INPUT));
4022                         if (err < 0)
4023                                 return err;
4024                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4025                                           "LFE Playback Switch",
4026                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4027                                                               HDA_INPUT));
4028                         if (err < 0)
4029                                 return err;
4030                 } else {
4031                         sprintf(name, "%s Playback Volume", chname[i]);
4032                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4033                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4034                                                               HDA_OUTPUT));
4035                         if (err < 0)
4036                                 return err;
4037                         sprintf(name, "%s Playback Switch", chname[i]);
4038                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4039                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4040                                                               HDA_INPUT));
4041                         if (err < 0)
4042                                 return err;
4043                 }
4044         }
4045         return 0;
4046 }
4047
4048 /* add playback controls for speaker and HP outputs */
4049 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4050                                         const char *pfx)
4051 {
4052         hda_nid_t nid;
4053         int err;
4054         char name[32];
4055
4056         if (!pin)
4057                 return 0;
4058
4059         if (alc880_is_fixed_pin(pin)) {
4060                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
4061                 /* specify the DAC as the extra output */
4062                 if (!spec->multiout.hp_nid)
4063                         spec->multiout.hp_nid = nid;
4064                 else
4065                         spec->multiout.extra_out_nid[0] = nid;
4066                 /* control HP volume/switch on the output mixer amp */
4067                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4068                 sprintf(name, "%s Playback Volume", pfx);
4069                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4070                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4071                 if (err < 0)
4072                         return err;
4073                 sprintf(name, "%s Playback Switch", pfx);
4074                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4075                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4076                 if (err < 0)
4077                         return err;
4078         } else if (alc880_is_multi_pin(pin)) {
4079                 /* set manual connection */
4080                 /* we have only a switch on HP-out PIN */
4081                 sprintf(name, "%s Playback Switch", pfx);
4082                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4083                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4084                 if (err < 0)
4085                         return err;
4086         }
4087         return 0;
4088 }
4089
4090 /* create input playback/capture controls for the given pin */
4091 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4092                             const char *ctlname,
4093                             int idx, hda_nid_t mix_nid)
4094 {
4095         char name[32];
4096         int err;
4097
4098         sprintf(name, "%s Playback Volume", ctlname);
4099         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4100                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4101         if (err < 0)
4102                 return err;
4103         sprintf(name, "%s Playback Switch", ctlname);
4104         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4105                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4106         if (err < 0)
4107                 return err;
4108         return 0;
4109 }
4110
4111 /* create playback/capture controls for input pins */
4112 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
4113                                                 const struct auto_pin_cfg *cfg)
4114 {
4115         struct hda_input_mux *imux = &spec->private_imux;
4116         int i, err, idx;
4117
4118         for (i = 0; i < AUTO_PIN_LAST; i++) {
4119                 if (alc880_is_input_pin(cfg->input_pins[i])) {
4120                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
4121                         err = new_analog_input(spec, cfg->input_pins[i],
4122                                                auto_pin_cfg_labels[i],
4123                                                idx, 0x0b);
4124                         if (err < 0)
4125                                 return err;
4126                         imux->items[imux->num_items].label =
4127                                 auto_pin_cfg_labels[i];
4128                         imux->items[imux->num_items].index =
4129                                 alc880_input_pin_idx(cfg->input_pins[i]);
4130                         imux->num_items++;
4131                 }
4132         }
4133         return 0;
4134 }
4135
4136 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
4137                                unsigned int pin_type)
4138 {
4139         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4140                             pin_type);
4141         /* unmute pin */
4142         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4143                             AMP_OUT_UNMUTE);
4144 }
4145
4146 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
4147                                               hda_nid_t nid, int pin_type,
4148                                               int dac_idx)
4149 {
4150         alc_set_pin_output(codec, nid, pin_type);
4151         /* need the manual connection? */
4152         if (alc880_is_multi_pin(nid)) {
4153                 struct alc_spec *spec = codec->spec;
4154                 int idx = alc880_multi_pin_idx(nid);
4155                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
4156                                     AC_VERB_SET_CONNECT_SEL,
4157                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
4158         }
4159 }
4160
4161 static int get_pin_type(int line_out_type)
4162 {
4163         if (line_out_type == AUTO_PIN_HP_OUT)
4164                 return PIN_HP;
4165         else
4166                 return PIN_OUT;
4167 }
4168
4169 static void alc880_auto_init_multi_out(struct hda_codec *codec)
4170 {
4171         struct alc_spec *spec = codec->spec;
4172         int i;
4173
4174         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
4175         for (i = 0; i < spec->autocfg.line_outs; i++) {
4176                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4177                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4178                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
4179         }
4180 }
4181
4182 static void alc880_auto_init_extra_out(struct hda_codec *codec)
4183 {
4184         struct alc_spec *spec = codec->spec;
4185         hda_nid_t pin;
4186
4187         pin = spec->autocfg.speaker_pins[0];
4188         if (pin) /* connect to front */
4189                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
4190         pin = spec->autocfg.hp_pins[0];
4191         if (pin) /* connect to front */
4192                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
4193 }
4194
4195 static void alc880_auto_init_analog_input(struct hda_codec *codec)
4196 {
4197         struct alc_spec *spec = codec->spec;
4198         int i;
4199
4200         for (i = 0; i < AUTO_PIN_LAST; i++) {
4201                 hda_nid_t nid = spec->autocfg.input_pins[i];
4202                 if (alc880_is_input_pin(nid)) {
4203                         snd_hda_codec_write(codec, nid, 0,
4204                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
4205                                             i <= AUTO_PIN_FRONT_MIC ?
4206                                             PIN_VREF80 : PIN_IN);
4207                         if (nid != ALC880_PIN_CD_NID)
4208                                 snd_hda_codec_write(codec, nid, 0,
4209                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4210                                                     AMP_OUT_MUTE);
4211                 }
4212         }
4213 }
4214
4215 /* parse the BIOS configuration and set up the alc_spec */
4216 /* return 1 if successful, 0 if the proper config is not found,
4217  * or a negative error code
4218  */
4219 static int alc880_parse_auto_config(struct hda_codec *codec)
4220 {
4221         struct alc_spec *spec = codec->spec;
4222         int err;
4223         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4224
4225         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4226                                            alc880_ignore);
4227         if (err < 0)
4228                 return err;
4229         if (!spec->autocfg.line_outs)
4230                 return 0; /* can't find valid BIOS pin config */
4231
4232         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
4233         if (err < 0)
4234                 return err;
4235         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
4236         if (err < 0)
4237                 return err;
4238         err = alc880_auto_create_extra_out(spec,
4239                                            spec->autocfg.speaker_pins[0],
4240                                            "Speaker");
4241         if (err < 0)
4242                 return err;
4243         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
4244                                            "Headphone");
4245         if (err < 0)
4246                 return err;
4247         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
4248         if (err < 0)
4249                 return err;
4250
4251         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4252
4253         if (spec->autocfg.dig_out_pin)
4254                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
4255         if (spec->autocfg.dig_in_pin)
4256                 spec->dig_in_nid = ALC880_DIGIN_NID;
4257
4258         if (spec->kctls.list)
4259                 add_mixer(spec, spec->kctls.list);
4260
4261         add_verb(spec, alc880_volume_init_verbs);
4262
4263         spec->num_mux_defs = 1;
4264         spec->input_mux = &spec->private_imux;
4265
4266         store_pin_configs(codec);
4267         return 1;
4268 }
4269
4270 /* additional initialization for auto-configuration model */
4271 static void alc880_auto_init(struct hda_codec *codec)
4272 {
4273         struct alc_spec *spec = codec->spec;
4274         alc880_auto_init_multi_out(codec);
4275         alc880_auto_init_extra_out(codec);
4276         alc880_auto_init_analog_input(codec);
4277         if (spec->unsol_event)
4278                 alc_inithook(codec);
4279 }
4280
4281 /*
4282  * OK, here we have finally the patch for ALC880
4283  */
4284
4285 static void set_capture_mixer(struct alc_spec *spec)
4286 {
4287         static struct snd_kcontrol_new *caps[3] = {
4288                 alc_capture_mixer1,
4289                 alc_capture_mixer2,
4290                 alc_capture_mixer3,
4291         };
4292         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3)
4293                 spec->cap_mixer = caps[spec->num_adc_nids - 1];
4294 }
4295
4296 static int patch_alc880(struct hda_codec *codec)
4297 {
4298         struct alc_spec *spec;
4299         int board_config;
4300         int err;
4301
4302         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4303         if (spec == NULL)
4304                 return -ENOMEM;
4305
4306         codec->spec = spec;
4307
4308         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4309                                                   alc880_models,
4310                                                   alc880_cfg_tbl);
4311         if (board_config < 0) {
4312                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
4313                        "trying auto-probe from BIOS...\n");
4314                 board_config = ALC880_AUTO;
4315         }
4316
4317         if (board_config == ALC880_AUTO) {
4318                 /* automatic parse from the BIOS config */
4319                 err = alc880_parse_auto_config(codec);
4320                 if (err < 0) {
4321                         alc_free(codec);
4322                         return err;
4323                 } else if (!err) {
4324                         printk(KERN_INFO
4325                                "hda_codec: Cannot set up configuration "
4326                                "from BIOS.  Using 3-stack mode...\n");
4327                         board_config = ALC880_3ST;
4328                 }
4329         }
4330
4331         if (board_config != ALC880_AUTO)
4332                 setup_preset(spec, &alc880_presets[board_config]);
4333
4334         spec->stream_name_analog = "ALC880 Analog";
4335         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4336         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4337         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4338
4339         spec->stream_name_digital = "ALC880 Digital";
4340         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4341         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4342
4343         if (!spec->adc_nids && spec->input_mux) {
4344                 /* check whether NID 0x07 is valid */
4345                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4346                 /* get type */
4347                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
4348                 if (wcap != AC_WID_AUD_IN) {
4349                         spec->adc_nids = alc880_adc_nids_alt;
4350                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4351                 } else {
4352                         spec->adc_nids = alc880_adc_nids;
4353                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4354                 }
4355         }
4356         set_capture_mixer(spec);
4357
4358         spec->vmaster_nid = 0x0c;
4359
4360         codec->patch_ops = alc_patch_ops;
4361         if (board_config == ALC880_AUTO)
4362                 spec->init_hook = alc880_auto_init;
4363 #ifdef CONFIG_SND_HDA_POWER_SAVE
4364         if (!spec->loopback.amplist)
4365                 spec->loopback.amplist = alc880_loopbacks;
4366 #endif
4367         codec->proc_widget_hook = print_realtek_coef;
4368
4369         return 0;
4370 }
4371
4372
4373 /*
4374  * ALC260 support
4375  */
4376
4377 static hda_nid_t alc260_dac_nids[1] = {
4378         /* front */
4379         0x02,
4380 };
4381
4382 static hda_nid_t alc260_adc_nids[1] = {
4383         /* ADC0 */
4384         0x04,
4385 };
4386
4387 static hda_nid_t alc260_adc_nids_alt[1] = {
4388         /* ADC1 */
4389         0x05,
4390 };
4391
4392 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4393  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4394  */
4395 static hda_nid_t alc260_dual_adc_nids[2] = {
4396         /* ADC0, ADC1 */
4397         0x04, 0x05
4398 };
4399
4400 #define ALC260_DIGOUT_NID       0x03
4401 #define ALC260_DIGIN_NID        0x06
4402
4403 static struct hda_input_mux alc260_capture_source = {
4404         .num_items = 4,
4405         .items = {
4406                 { "Mic", 0x0 },
4407                 { "Front Mic", 0x1 },
4408                 { "Line", 0x2 },
4409                 { "CD", 0x4 },
4410         },
4411 };
4412
4413 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4414  * headphone jack and the internal CD lines since these are the only pins at
4415  * which audio can appear.  For flexibility, also allow the option of
4416  * recording the mixer output on the second ADC (ADC0 doesn't have a
4417  * connection to the mixer output).
4418  */
4419 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4420         {
4421                 .num_items = 3,
4422                 .items = {
4423                         { "Mic/Line", 0x0 },
4424                         { "CD", 0x4 },
4425                         { "Headphone", 0x2 },
4426                 },
4427         },
4428         {
4429                 .num_items = 4,
4430                 .items = {
4431                         { "Mic/Line", 0x0 },
4432                         { "CD", 0x4 },
4433                         { "Headphone", 0x2 },
4434                         { "Mixer", 0x5 },
4435                 },
4436         },
4437
4438 };
4439
4440 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4441  * the Fujitsu S702x, but jacks are marked differently.
4442  */
4443 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4444         {
4445                 .num_items = 4,
4446                 .items = {
4447                         { "Mic", 0x0 },
4448                         { "Line", 0x2 },
4449                         { "CD", 0x4 },
4450                         { "Headphone", 0x5 },
4451                 },
4452         },
4453         {
4454                 .num_items = 5,
4455                 .items = {
4456                         { "Mic", 0x0 },
4457                         { "Line", 0x2 },
4458                         { "CD", 0x4 },
4459                         { "Headphone", 0x6 },
4460                         { "Mixer", 0x5 },
4461                 },
4462         },
4463 };
4464 /*
4465  * This is just place-holder, so there's something for alc_build_pcms to look
4466  * at when it calculates the maximum number of channels. ALC260 has no mixer
4467  * element which allows changing the channel mode, so the verb list is
4468  * never used.
4469  */
4470 static struct hda_channel_mode alc260_modes[1] = {
4471         { 2, NULL },
4472 };
4473
4474
4475 /* Mixer combinations
4476  *
4477  * basic: base_output + input + pc_beep + capture
4478  * HP: base_output + input + capture_alt
4479  * HP_3013: hp_3013 + input + capture
4480  * fujitsu: fujitsu + capture
4481  * acer: acer + capture
4482  */
4483
4484 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
4485         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4486         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4487         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4488         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4489         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4490         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4491         { } /* end */
4492 };
4493
4494 static struct snd_kcontrol_new alc260_input_mixer[] = {
4495         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4496         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4497         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4498         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4499         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4500         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4501         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4502         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4503         { } /* end */
4504 };
4505
4506 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
4507         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
4508         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
4509         { } /* end */
4510 };
4511
4512 /* update HP, line and mono out pins according to the master switch */
4513 static void alc260_hp_master_update(struct hda_codec *codec,
4514                                     hda_nid_t hp, hda_nid_t line,
4515                                     hda_nid_t mono)
4516 {
4517         struct alc_spec *spec = codec->spec;
4518         unsigned int val = spec->master_sw ? PIN_HP : 0;
4519         /* change HP and line-out pins */
4520         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4521                             val);
4522         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4523                             val);
4524         /* mono (speaker) depending on the HP jack sense */
4525         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4526         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4527                             val);
4528 }
4529
4530 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4531                                    struct snd_ctl_elem_value *ucontrol)
4532 {
4533         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4534         struct alc_spec *spec = codec->spec;
4535         *ucontrol->value.integer.value = spec->master_sw;
4536         return 0;
4537 }
4538
4539 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4540                                    struct snd_ctl_elem_value *ucontrol)
4541 {
4542         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4543         struct alc_spec *spec = codec->spec;
4544         int val = !!*ucontrol->value.integer.value;
4545         hda_nid_t hp, line, mono;
4546
4547         if (val == spec->master_sw)
4548                 return 0;
4549         spec->master_sw = val;
4550         hp = (kcontrol->private_value >> 16) & 0xff;
4551         line = (kcontrol->private_value >> 8) & 0xff;
4552         mono = kcontrol->private_value & 0xff;
4553         alc260_hp_master_update(codec, hp, line, mono);
4554         return 1;
4555 }
4556
4557 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4558         {
4559                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4560                 .name = "Master Playback Switch",
4561                 .info = snd_ctl_boolean_mono_info,
4562                 .get = alc260_hp_master_sw_get,
4563                 .put = alc260_hp_master_sw_put,
4564                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4565         },
4566         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4567         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4568         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4569         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4570         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4571                               HDA_OUTPUT),
4572         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4573         { } /* end */
4574 };
4575
4576 static struct hda_verb alc260_hp_unsol_verbs[] = {
4577         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4578         {},
4579 };
4580
4581 static void alc260_hp_automute(struct hda_codec *codec)
4582 {
4583         struct alc_spec *spec = codec->spec;
4584         unsigned int present;
4585
4586         present = snd_hda_codec_read(codec, 0x10, 0,
4587                                      AC_VERB_GET_PIN_SENSE, 0);
4588         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4589         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4590 }
4591
4592 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4593 {
4594         if ((res >> 26) == ALC880_HP_EVENT)
4595                 alc260_hp_automute(codec);
4596 }
4597
4598 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4599         {
4600                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4601                 .name = "Master Playback Switch",
4602                 .info = snd_ctl_boolean_mono_info,
4603                 .get = alc260_hp_master_sw_get,
4604                 .put = alc260_hp_master_sw_put,
4605                 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
4606         },
4607         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4608         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4609         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4610         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4611         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4612         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4613         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4614         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4615         { } /* end */
4616 };
4617
4618 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
4619         .ops = &snd_hda_bind_vol,
4620         .values = {
4621                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
4622                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
4623                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
4624                 0
4625         },
4626 };
4627
4628 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
4629         .ops = &snd_hda_bind_sw,
4630         .values = {
4631                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
4632                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
4633                 0
4634         },
4635 };
4636
4637 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
4638         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
4639         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
4640         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
4641         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4642         { } /* end */
4643 };
4644
4645 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4646         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4647         {},
4648 };
4649
4650 static void alc260_hp_3013_automute(struct hda_codec *codec)
4651 {
4652         struct alc_spec *spec = codec->spec;
4653         unsigned int present;
4654
4655         present = snd_hda_codec_read(codec, 0x15, 0,
4656                                      AC_VERB_GET_PIN_SENSE, 0);
4657         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4658         alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
4659 }
4660
4661 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4662                                        unsigned int res)
4663 {
4664         if ((res >> 26) == ALC880_HP_EVENT)
4665                 alc260_hp_3013_automute(codec);
4666 }
4667
4668 static void alc260_hp_3012_automute(struct hda_codec *codec)
4669 {
4670         unsigned int present, bits;
4671
4672         present = snd_hda_codec_read(codec, 0x10, 0,
4673                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
4674
4675         bits = present ? 0 : PIN_OUT;
4676         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4677                             bits);
4678         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4679                             bits);
4680         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4681                             bits);
4682 }
4683
4684 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
4685                                        unsigned int res)
4686 {
4687         if ((res >> 26) == ALC880_HP_EVENT)
4688                 alc260_hp_3012_automute(codec);
4689 }
4690
4691 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
4692  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4693  */
4694 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4695         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4696         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4697         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4698         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4699         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4700         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4701         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4702         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4703         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4704         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4705         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4706         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4707         { } /* end */
4708 };
4709
4710 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4711  * versions of the ALC260 don't act on requests to enable mic bias from NID
4712  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4713  * datasheet doesn't mention this restriction.  At this stage it's not clear
4714  * whether this behaviour is intentional or is a hardware bug in chip
4715  * revisions available in early 2006.  Therefore for now allow the
4716  * "Headphone Jack Mode" control to span all choices, but if it turns out
4717  * that the lack of mic bias for this NID is intentional we could change the
4718  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4719  *
4720  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4721  * don't appear to make the mic bias available from the "line" jack, even
4722  * though the NID used for this jack (0x14) can supply it.  The theory is
4723  * that perhaps Acer have included blocking capacitors between the ALC260
4724  * and the output jack.  If this turns out to be the case for all such
4725  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4726  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4727  *
4728  * The C20x Tablet series have a mono internal speaker which is controlled
4729  * via the chip's Mono sum widget and pin complex, so include the necessary
4730  * controls for such models.  On models without a "mono speaker" the control
4731  * won't do anything.
4732  */
4733 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4734         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4735         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4736         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4737         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4738                               HDA_OUTPUT),
4739         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4740                            HDA_INPUT),
4741         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4742         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4743         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4744         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4745         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4746         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4747         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4748         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4749         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4750         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4751         { } /* end */
4752 };
4753
4754 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4755  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4756  */
4757 static struct snd_kcontrol_new alc260_will_mixer[] = {
4758         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4759         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4760         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4761         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4762         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4763         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4764         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4765         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4766         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4767         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4768         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4769         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4770         { } /* end */
4771 };
4772
4773 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4774  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4775  */
4776 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4777         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4778         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4779         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4780         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4781         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4782         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4783         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4784         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4785         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4786         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4787         { } /* end */
4788 };
4789
4790 /*
4791  * initialization verbs
4792  */
4793 static struct hda_verb alc260_init_verbs[] = {
4794         /* Line In pin widget for input */
4795         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4796         /* CD pin widget for input */
4797         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4798         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4799         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4800         /* Mic2 (front panel) pin widget for input and vref at 80% */
4801         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4802         /* LINE-2 is used for line-out in rear */
4803         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4804         /* select line-out */
4805         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4806         /* LINE-OUT pin */
4807         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4808         /* enable HP */
4809         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4810         /* enable Mono */
4811         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4812         /* mute capture amp left and right */
4813         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4814         /* set connection select to line in (default select for this ADC) */
4815         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4816         /* mute capture amp left and right */
4817         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4818         /* set connection select to line in (default select for this ADC) */
4819         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4820         /* set vol=0 Line-Out mixer amp left and right */
4821         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4822         /* unmute pin widget amp left and right (no gain on this amp) */
4823         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4824         /* set vol=0 HP mixer amp left and right */
4825         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4826         /* unmute pin widget amp left and right (no gain on this amp) */
4827         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4828         /* set vol=0 Mono mixer amp left and right */
4829         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4830         /* unmute pin widget amp left and right (no gain on this amp) */
4831         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4832         /* unmute LINE-2 out pin */
4833         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4834         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4835          * Line In 2 = 0x03
4836          */
4837         /* mute analog inputs */
4838         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4839         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4840         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4841         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4842         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4843         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4844         /* mute Front out path */
4845         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4846         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4847         /* mute Headphone out path */
4848         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4849         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4850         /* mute Mono out path */
4851         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4852         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4853         { }
4854 };
4855
4856 #if 0 /* should be identical with alc260_init_verbs? */
4857 static struct hda_verb alc260_hp_init_verbs[] = {
4858         /* Headphone and output */
4859         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4860         /* mono output */
4861         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4862         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4863         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4864         /* Mic2 (front panel) pin widget for input and vref at 80% */
4865         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4866         /* Line In pin widget for input */
4867         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4868         /* Line-2 pin widget for output */
4869         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4870         /* CD pin widget for input */
4871         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4872         /* unmute amp left and right */
4873         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4874         /* set connection select to line in (default select for this ADC) */
4875         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4876         /* unmute Line-Out mixer amp left and right (volume = 0) */
4877         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4878         /* mute pin widget amp left and right (no gain on this amp) */
4879         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4880         /* unmute HP mixer amp left and right (volume = 0) */
4881         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4882         /* mute pin widget amp left and right (no gain on this amp) */
4883         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4884         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4885          * Line In 2 = 0x03
4886          */
4887         /* mute analog inputs */
4888         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4889         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4890         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4891         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4892         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4893         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4894         /* Unmute Front out path */
4895         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4896         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4897         /* Unmute Headphone out path */
4898         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4899         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4900         /* Unmute Mono out path */
4901         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4902         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4903         { }
4904 };
4905 #endif
4906
4907 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4908         /* Line out and output */
4909         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4910         /* mono output */
4911         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4912         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4913         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4914         /* Mic2 (front panel) pin widget for input and vref at 80% */
4915         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4916         /* Line In pin widget for input */
4917         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4918         /* Headphone pin widget for output */
4919         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4920         /* CD pin widget for input */
4921         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4922         /* unmute amp left and right */
4923         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4924         /* set connection select to line in (default select for this ADC) */
4925         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4926         /* unmute Line-Out mixer amp left and right (volume = 0) */
4927         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4928         /* mute pin widget amp left and right (no gain on this amp) */
4929         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4930         /* unmute HP mixer amp left and right (volume = 0) */
4931         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4932         /* mute pin widget amp left and right (no gain on this amp) */
4933         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4934         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4935          * Line In 2 = 0x03
4936          */
4937         /* mute analog inputs */
4938         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4939         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4940         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4941         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4942         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4943         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4944         /* Unmute Front out path */
4945         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4946         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4947         /* Unmute Headphone out path */
4948         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4949         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4950         /* Unmute Mono out path */
4951         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4952         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4953         { }
4954 };
4955
4956 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4957  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4958  * audio = 0x16, internal speaker = 0x10.
4959  */
4960 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4961         /* Disable all GPIOs */
4962         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4963         /* Internal speaker is connected to headphone pin */
4964         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4965         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4966         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4967         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4968         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4969         /* Ensure all other unused pins are disabled and muted. */
4970         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4971         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4972         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4973         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4974         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4975         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4976         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4977         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4978
4979         /* Disable digital (SPDIF) pins */
4980         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4981         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4982
4983         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
4984          * when acting as an output.
4985          */
4986         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4987
4988         /* Start with output sum widgets muted and their output gains at min */
4989         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4990         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4991         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4992         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4993         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4994         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4995         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4996         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4997         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4998
4999         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
5000         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5001         /* Unmute Line1 pin widget output buffer since it starts as an output.
5002          * If the pin mode is changed by the user the pin mode control will
5003          * take care of enabling the pin's input/output buffers as needed.
5004          * Therefore there's no need to enable the input buffer at this
5005          * stage.
5006          */
5007         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5008         /* Unmute input buffer of pin widget used for Line-in (no equiv
5009          * mixer ctrl)
5010          */
5011         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5012
5013         /* Mute capture amp left and right */
5014         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5015         /* Set ADC connection select to match default mixer setting - line
5016          * in (on mic1 pin)
5017          */
5018         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5019
5020         /* Do the same for the second ADC: mute capture input amp and
5021          * set ADC connection to line in (on mic1 pin)
5022          */
5023         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5024         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5025
5026         /* Mute all inputs to mixer widget (even unconnected ones) */
5027         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5028         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5029         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5030         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5031         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5032         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5033         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5034         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5035
5036         { }
5037 };
5038
5039 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
5040  * similar laptops (adapted from Fujitsu init verbs).
5041  */
5042 static struct hda_verb alc260_acer_init_verbs[] = {
5043         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
5044          * the headphone jack.  Turn this on and rely on the standard mute
5045          * methods whenever the user wants to turn these outputs off.
5046          */
5047         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5048         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5049         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5050         /* Internal speaker/Headphone jack is connected to Line-out pin */
5051         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5052         /* Internal microphone/Mic jack is connected to Mic1 pin */
5053         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5054         /* Line In jack is connected to Line1 pin */
5055         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5056         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
5057         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5058         /* Ensure all other unused pins are disabled and muted. */
5059         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5060         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5061         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5062         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5063         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5064         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5065         /* Disable digital (SPDIF) pins */
5066         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5067         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5068
5069         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5070          * bus when acting as outputs.
5071          */
5072         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5073         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5074
5075         /* Start with output sum widgets muted and their output gains at min */
5076         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5077         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5078         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5079         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5080         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5081         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5082         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5083         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5084         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5085
5086         /* Unmute Line-out pin widget amp left and right
5087          * (no equiv mixer ctrl)
5088          */
5089         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5090         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
5091         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5092         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5093          * inputs. If the pin mode is changed by the user the pin mode control
5094          * will take care of enabling the pin's input/output buffers as needed.
5095          * Therefore there's no need to enable the input buffer at this
5096          * stage.
5097          */
5098         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5099         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5100
5101         /* Mute capture amp left and right */
5102         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5103         /* Set ADC connection select to match default mixer setting - mic
5104          * (on mic1 pin)
5105          */
5106         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5107
5108         /* Do similar with the second ADC: mute capture input amp and
5109          * set ADC connection to mic to match ALSA's default state.
5110          */
5111         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5112         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5113
5114         /* Mute all inputs to mixer widget (even unconnected ones) */
5115         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5116         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5117         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5118         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5119         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5120         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5121         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5122         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5123
5124         { }
5125 };
5126
5127 static struct hda_verb alc260_will_verbs[] = {
5128         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5129         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
5130         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
5131         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5132         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5133         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
5134         {}
5135 };
5136
5137 static struct hda_verb alc260_replacer_672v_verbs[] = {
5138         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5139         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5140         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
5141
5142         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5143         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5144         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5145
5146         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5147         {}
5148 };
5149
5150 /* toggle speaker-output according to the hp-jack state */
5151 static void alc260_replacer_672v_automute(struct hda_codec *codec)
5152 {
5153         unsigned int present;
5154
5155         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5156         present = snd_hda_codec_read(codec, 0x0f, 0,
5157                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5158         if (present) {
5159                 snd_hda_codec_write_cache(codec, 0x01, 0,
5160                                           AC_VERB_SET_GPIO_DATA, 1);
5161                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5162                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5163                                           PIN_HP);
5164         } else {
5165                 snd_hda_codec_write_cache(codec, 0x01, 0,
5166                                           AC_VERB_SET_GPIO_DATA, 0);
5167                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5168                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5169                                           PIN_OUT);
5170         }
5171 }
5172
5173 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
5174                                        unsigned int res)
5175 {
5176         if ((res >> 26) == ALC880_HP_EVENT)
5177                 alc260_replacer_672v_automute(codec);
5178 }
5179
5180 static struct hda_verb alc260_hp_dc7600_verbs[] = {
5181         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
5182         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5183         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5184         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5185         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5186         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5187         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5188         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5189         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5190         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5191         {}
5192 };
5193
5194 /* Test configuration for debugging, modelled after the ALC880 test
5195  * configuration.
5196  */
5197 #ifdef CONFIG_SND_DEBUG
5198 static hda_nid_t alc260_test_dac_nids[1] = {
5199         0x02,
5200 };
5201 static hda_nid_t alc260_test_adc_nids[2] = {
5202         0x04, 0x05,
5203 };
5204 /* For testing the ALC260, each input MUX needs its own definition since
5205  * the signal assignments are different.  This assumes that the first ADC
5206  * is NID 0x04.
5207  */
5208 static struct hda_input_mux alc260_test_capture_sources[2] = {
5209         {
5210                 .num_items = 7,
5211                 .items = {
5212                         { "MIC1 pin", 0x0 },
5213                         { "MIC2 pin", 0x1 },
5214                         { "LINE1 pin", 0x2 },
5215                         { "LINE2 pin", 0x3 },
5216                         { "CD pin", 0x4 },
5217                         { "LINE-OUT pin", 0x5 },
5218                         { "HP-OUT pin", 0x6 },
5219                 },
5220         },
5221         {
5222                 .num_items = 8,
5223                 .items = {
5224                         { "MIC1 pin", 0x0 },
5225                         { "MIC2 pin", 0x1 },
5226                         { "LINE1 pin", 0x2 },
5227                         { "LINE2 pin", 0x3 },
5228                         { "CD pin", 0x4 },
5229                         { "Mixer", 0x5 },
5230                         { "LINE-OUT pin", 0x6 },
5231                         { "HP-OUT pin", 0x7 },
5232                 },
5233         },
5234 };
5235 static struct snd_kcontrol_new alc260_test_mixer[] = {
5236         /* Output driver widgets */
5237         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5238         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5239         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5240         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
5241         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5242         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
5243
5244         /* Modes for retasking pin widgets
5245          * Note: the ALC260 doesn't seem to act on requests to enable mic
5246          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
5247          * mention this restriction.  At this stage it's not clear whether
5248          * this behaviour is intentional or is a hardware bug in chip
5249          * revisions available at least up until early 2006.  Therefore for
5250          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
5251          * choices, but if it turns out that the lack of mic bias for these
5252          * NIDs is intentional we could change their modes from
5253          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5254          */
5255         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
5256         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
5257         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
5258         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5259         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5260         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5261
5262         /* Loopback mixer controls */
5263         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5264         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5265         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5266         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5267         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5268         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5269         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5270         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5271         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5272         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5273         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
5274         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
5275         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5276         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5277         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5278         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5279
5280         /* Controls for GPIO pins, assuming they are configured as outputs */
5281         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5282         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5283         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5284         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5285
5286         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5287          * is ambigious as to which NID is which; testing on laptops which
5288          * make this output available should provide clarification.
5289          */
5290         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5291         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5292
5293         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5294          * this output to turn on an external amplifier.
5295          */
5296         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5297         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5298
5299         { } /* end */
5300 };
5301 static struct hda_verb alc260_test_init_verbs[] = {
5302         /* Enable all GPIOs as outputs with an initial value of 0 */
5303         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5304         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5305         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5306
5307         /* Enable retasking pins as output, initially without power amp */
5308         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5309         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5310         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5311         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5312         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5313         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5314
5315         /* Disable digital (SPDIF) pins initially, but users can enable
5316          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5317          * payload also sets the generation to 0, output to be in "consumer"
5318          * PCM format, copyright asserted, no pre-emphasis and no validity
5319          * control.
5320          */
5321         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5322         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5323
5324         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5325          * OUT1 sum bus when acting as an output.
5326          */
5327         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5328         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5329         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5330         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5331
5332         /* Start with output sum widgets muted and their output gains at min */
5333         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5334         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5335         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5336         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5337         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5338         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5339         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5340         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5341         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5342
5343         /* Unmute retasking pin widget output buffers since the default
5344          * state appears to be output.  As the pin mode is changed by the
5345          * user the pin mode control will take care of enabling the pin's
5346          * input/output buffers as needed.
5347          */
5348         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5349         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5350         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5351         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5352         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5353         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5354         /* Also unmute the mono-out pin widget */
5355         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5356
5357         /* Mute capture amp left and right */
5358         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5359         /* Set ADC connection select to match default mixer setting (mic1
5360          * pin)
5361          */
5362         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5363
5364         /* Do the same for the second ADC: mute capture input amp and
5365          * set ADC connection to mic1 pin
5366          */
5367         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5368         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5369
5370         /* Mute all inputs to mixer widget (even unconnected ones) */
5371         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5372         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5373         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5374         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5375         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5376         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5377         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5378         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5379
5380         { }
5381 };
5382 #endif
5383
5384 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5385 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5386
5387 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5388 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5389
5390 /*
5391  * for BIOS auto-configuration
5392  */
5393
5394 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5395                                         const char *pfx, int *vol_bits)
5396 {
5397         hda_nid_t nid_vol;
5398         unsigned long vol_val, sw_val;
5399         char name[32];
5400         int err;
5401
5402         if (nid >= 0x0f && nid < 0x11) {
5403                 nid_vol = nid - 0x7;
5404                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5405                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5406         } else if (nid == 0x11) {
5407                 nid_vol = nid - 0x7;
5408                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
5409                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
5410         } else if (nid >= 0x12 && nid <= 0x15) {
5411                 nid_vol = 0x08;
5412                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5413                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5414         } else
5415                 return 0; /* N/A */
5416
5417         if (!(*vol_bits & (1 << nid_vol))) {
5418                 /* first control for the volume widget */
5419                 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
5420                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
5421                 if (err < 0)
5422                         return err;
5423                 *vol_bits |= (1 << nid_vol);
5424         }
5425         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
5426         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
5427         if (err < 0)
5428                 return err;
5429         return 1;
5430 }
5431
5432 /* add playback controls from the parsed DAC table */
5433 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5434                                              const struct auto_pin_cfg *cfg)
5435 {
5436         hda_nid_t nid;
5437         int err;
5438         int vols = 0;
5439
5440         spec->multiout.num_dacs = 1;
5441         spec->multiout.dac_nids = spec->private_dac_nids;
5442         spec->multiout.dac_nids[0] = 0x02;
5443
5444         nid = cfg->line_out_pins[0];
5445         if (nid) {
5446                 err = alc260_add_playback_controls(spec, nid, "Front", &vols);
5447                 if (err < 0)
5448                         return err;
5449         }
5450
5451         nid = cfg->speaker_pins[0];
5452         if (nid) {
5453                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
5454                 if (err < 0)
5455                         return err;
5456         }
5457
5458         nid = cfg->hp_pins[0];
5459         if (nid) {
5460                 err = alc260_add_playback_controls(spec, nid, "Headphone",
5461                                                    &vols);
5462                 if (err < 0)
5463                         return err;
5464         }
5465         return 0;
5466 }
5467
5468 /* create playback/capture controls for input pins */
5469 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
5470                                                 const struct auto_pin_cfg *cfg)
5471 {
5472         struct hda_input_mux *imux = &spec->private_imux;
5473         int i, err, idx;
5474
5475         for (i = 0; i < AUTO_PIN_LAST; i++) {
5476                 if (cfg->input_pins[i] >= 0x12) {
5477                         idx = cfg->input_pins[i] - 0x12;
5478                         err = new_analog_input(spec, cfg->input_pins[i],
5479                                                auto_pin_cfg_labels[i], idx,
5480                                                0x07);
5481                         if (err < 0)
5482                                 return err;
5483                         imux->items[imux->num_items].label =
5484                                 auto_pin_cfg_labels[i];
5485                         imux->items[imux->num_items].index = idx;
5486                         imux->num_items++;
5487                 }
5488                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
5489                         idx = cfg->input_pins[i] - 0x09;
5490                         err = new_analog_input(spec, cfg->input_pins[i],
5491                                                auto_pin_cfg_labels[i], idx,
5492                                                0x07);
5493                         if (err < 0)
5494                                 return err;
5495                         imux->items[imux->num_items].label =
5496                                 auto_pin_cfg_labels[i];
5497                         imux->items[imux->num_items].index = idx;
5498                         imux->num_items++;
5499                 }
5500         }
5501         return 0;
5502 }
5503
5504 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
5505                                               hda_nid_t nid, int pin_type,
5506                                               int sel_idx)
5507 {
5508         alc_set_pin_output(codec, nid, pin_type);
5509         /* need the manual connection? */
5510         if (nid >= 0x12) {
5511                 int idx = nid - 0x12;
5512                 snd_hda_codec_write(codec, idx + 0x0b, 0,
5513                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
5514         }
5515 }
5516
5517 static void alc260_auto_init_multi_out(struct hda_codec *codec)
5518 {
5519         struct alc_spec *spec = codec->spec;
5520         hda_nid_t nid;
5521
5522         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
5523         nid = spec->autocfg.line_out_pins[0];
5524         if (nid) {
5525                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5526                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5527         }
5528
5529         nid = spec->autocfg.speaker_pins[0];
5530         if (nid)
5531                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5532
5533         nid = spec->autocfg.hp_pins[0];
5534         if (nid)
5535                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5536 }
5537
5538 #define ALC260_PIN_CD_NID               0x16
5539 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5540 {
5541         struct alc_spec *spec = codec->spec;
5542         int i;
5543
5544         for (i = 0; i < AUTO_PIN_LAST; i++) {
5545                 hda_nid_t nid = spec->autocfg.input_pins[i];
5546                 if (nid >= 0x12) {
5547                         snd_hda_codec_write(codec, nid, 0,
5548                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5549                                             i <= AUTO_PIN_FRONT_MIC ?
5550                                             PIN_VREF80 : PIN_IN);
5551                         if (nid != ALC260_PIN_CD_NID)
5552                                 snd_hda_codec_write(codec, nid, 0,
5553                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5554                                                     AMP_OUT_MUTE);
5555                 }
5556         }
5557 }
5558
5559 /*
5560  * generic initialization of ADC, input mixers and output mixers
5561  */
5562 static struct hda_verb alc260_volume_init_verbs[] = {
5563         /*
5564          * Unmute ADC0-1 and set the default input to mic-in
5565          */
5566         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5567         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5568         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5569         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5570
5571         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5572          * mixer widget
5573          * Note: PASD motherboards uses the Line In 2 as the input for
5574          * front panel mic (mic 2)
5575          */
5576         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5577         /* mute analog inputs */
5578         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5579         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5580         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5581         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5582         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5583
5584         /*
5585          * Set up output mixers (0x08 - 0x0a)
5586          */
5587         /* set vol=0 to output mixers */
5588         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5589         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5590         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5591         /* set up input amps for analog loopback */
5592         /* Amp Indices: DAC = 0, mixer = 1 */
5593         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5594         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5595         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5596         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5597         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5598         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5599
5600         { }
5601 };
5602
5603 static int alc260_parse_auto_config(struct hda_codec *codec)
5604 {
5605         struct alc_spec *spec = codec->spec;
5606         int err;
5607         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5608
5609         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5610                                            alc260_ignore);
5611         if (err < 0)
5612                 return err;
5613         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5614         if (err < 0)
5615                 return err;
5616         if (!spec->kctls.list)
5617                 return 0; /* can't find valid BIOS pin config */
5618         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5619         if (err < 0)
5620                 return err;
5621
5622         spec->multiout.max_channels = 2;
5623
5624         if (spec->autocfg.dig_out_pin)
5625                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5626         if (spec->kctls.list)
5627                 add_mixer(spec, spec->kctls.list);
5628
5629         add_verb(spec, alc260_volume_init_verbs);
5630
5631         spec->num_mux_defs = 1;
5632         spec->input_mux = &spec->private_imux;
5633
5634         store_pin_configs(codec);
5635         return 1;
5636 }
5637
5638 /* additional initialization for auto-configuration model */
5639 static void alc260_auto_init(struct hda_codec *codec)
5640 {
5641         struct alc_spec *spec = codec->spec;
5642         alc260_auto_init_multi_out(codec);
5643         alc260_auto_init_analog_input(codec);
5644         if (spec->unsol_event)
5645                 alc_inithook(codec);
5646 }
5647
5648 #ifdef CONFIG_SND_HDA_POWER_SAVE
5649 static struct hda_amp_list alc260_loopbacks[] = {
5650         { 0x07, HDA_INPUT, 0 },
5651         { 0x07, HDA_INPUT, 1 },
5652         { 0x07, HDA_INPUT, 2 },
5653         { 0x07, HDA_INPUT, 3 },
5654         { 0x07, HDA_INPUT, 4 },
5655         { } /* end */
5656 };
5657 #endif
5658
5659 /*
5660  * ALC260 configurations
5661  */
5662 static const char *alc260_models[ALC260_MODEL_LAST] = {
5663         [ALC260_BASIC]          = "basic",
5664         [ALC260_HP]             = "hp",
5665         [ALC260_HP_3013]        = "hp-3013",
5666         [ALC260_HP_DC7600]      = "hp-dc7600",
5667         [ALC260_FUJITSU_S702X]  = "fujitsu",
5668         [ALC260_ACER]           = "acer",
5669         [ALC260_WILL]           = "will",
5670         [ALC260_REPLACER_672V]  = "replacer",
5671 #ifdef CONFIG_SND_DEBUG
5672         [ALC260_TEST]           = "test",
5673 #endif
5674         [ALC260_AUTO]           = "auto",
5675 };
5676
5677 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5678         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5679         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5680         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5681         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5682         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5683         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
5684         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
5685         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5686         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5687         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5688         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5689         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5690         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5691         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5692         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5693         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5694         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5695         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5696         {}
5697 };
5698
5699 static struct alc_config_preset alc260_presets[] = {
5700         [ALC260_BASIC] = {
5701                 .mixers = { alc260_base_output_mixer,
5702                             alc260_input_mixer,
5703                             alc260_pc_beep_mixer },
5704                 .init_verbs = { alc260_init_verbs },
5705                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5706                 .dac_nids = alc260_dac_nids,
5707                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5708                 .adc_nids = alc260_adc_nids,
5709                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5710                 .channel_mode = alc260_modes,
5711                 .input_mux = &alc260_capture_source,
5712         },
5713         [ALC260_HP] = {
5714                 .mixers = { alc260_hp_output_mixer,
5715                             alc260_input_mixer },
5716                 .init_verbs = { alc260_init_verbs,
5717                                 alc260_hp_unsol_verbs },
5718                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5719                 .dac_nids = alc260_dac_nids,
5720                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5721                 .adc_nids = alc260_adc_nids_alt,
5722                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5723                 .channel_mode = alc260_modes,
5724                 .input_mux = &alc260_capture_source,
5725                 .unsol_event = alc260_hp_unsol_event,
5726                 .init_hook = alc260_hp_automute,
5727         },
5728         [ALC260_HP_DC7600] = {
5729                 .mixers = { alc260_hp_dc7600_mixer,
5730                             alc260_input_mixer },
5731                 .init_verbs = { alc260_init_verbs,
5732                                 alc260_hp_dc7600_verbs },
5733                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5734                 .dac_nids = alc260_dac_nids,
5735                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5736                 .adc_nids = alc260_adc_nids_alt,
5737                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5738                 .channel_mode = alc260_modes,
5739                 .input_mux = &alc260_capture_source,
5740                 .unsol_event = alc260_hp_3012_unsol_event,
5741                 .init_hook = alc260_hp_3012_automute,
5742         },
5743         [ALC260_HP_3013] = {
5744                 .mixers = { alc260_hp_3013_mixer,
5745                             alc260_input_mixer },
5746                 .init_verbs = { alc260_hp_3013_init_verbs,
5747                                 alc260_hp_3013_unsol_verbs },
5748                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5749                 .dac_nids = alc260_dac_nids,
5750                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5751                 .adc_nids = alc260_adc_nids_alt,
5752                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5753                 .channel_mode = alc260_modes,
5754                 .input_mux = &alc260_capture_source,
5755                 .unsol_event = alc260_hp_3013_unsol_event,
5756                 .init_hook = alc260_hp_3013_automute,
5757         },
5758         [ALC260_FUJITSU_S702X] = {
5759                 .mixers = { alc260_fujitsu_mixer },
5760                 .init_verbs = { alc260_fujitsu_init_verbs },
5761                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5762                 .dac_nids = alc260_dac_nids,
5763                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5764                 .adc_nids = alc260_dual_adc_nids,
5765                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5766                 .channel_mode = alc260_modes,
5767                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5768                 .input_mux = alc260_fujitsu_capture_sources,
5769         },
5770         [ALC260_ACER] = {
5771                 .mixers = { alc260_acer_mixer },
5772                 .init_verbs = { alc260_acer_init_verbs },
5773                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5774                 .dac_nids = alc260_dac_nids,
5775                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5776                 .adc_nids = alc260_dual_adc_nids,
5777                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5778                 .channel_mode = alc260_modes,
5779                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5780                 .input_mux = alc260_acer_capture_sources,
5781         },
5782         [ALC260_WILL] = {
5783                 .mixers = { alc260_will_mixer },
5784                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5785                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5786                 .dac_nids = alc260_dac_nids,
5787                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5788                 .adc_nids = alc260_adc_nids,
5789                 .dig_out_nid = ALC260_DIGOUT_NID,
5790                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5791                 .channel_mode = alc260_modes,
5792                 .input_mux = &alc260_capture_source,
5793         },
5794         [ALC260_REPLACER_672V] = {
5795                 .mixers = { alc260_replacer_672v_mixer },
5796                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5797                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5798                 .dac_nids = alc260_dac_nids,
5799                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5800                 .adc_nids = alc260_adc_nids,
5801                 .dig_out_nid = ALC260_DIGOUT_NID,
5802                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5803                 .channel_mode = alc260_modes,
5804                 .input_mux = &alc260_capture_source,
5805                 .unsol_event = alc260_replacer_672v_unsol_event,
5806                 .init_hook = alc260_replacer_672v_automute,
5807         },
5808 #ifdef CONFIG_SND_DEBUG
5809         [ALC260_TEST] = {
5810                 .mixers = { alc260_test_mixer },
5811                 .init_verbs = { alc260_test_init_verbs },
5812                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5813                 .dac_nids = alc260_test_dac_nids,
5814                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5815                 .adc_nids = alc260_test_adc_nids,
5816                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5817                 .channel_mode = alc260_modes,
5818                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5819                 .input_mux = alc260_test_capture_sources,
5820         },
5821 #endif
5822 };
5823
5824 static int patch_alc260(struct hda_codec *codec)
5825 {
5826         struct alc_spec *spec;
5827         int err, board_config;
5828
5829         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5830         if (spec == NULL)
5831                 return -ENOMEM;
5832
5833         codec->spec = spec;
5834
5835         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
5836                                                   alc260_models,
5837                                                   alc260_cfg_tbl);
5838         if (board_config < 0) {
5839                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
5840                            "trying auto-probe from BIOS...\n");
5841                 board_config = ALC260_AUTO;
5842         }
5843
5844         if (board_config == ALC260_AUTO) {
5845                 /* automatic parse from the BIOS config */
5846                 err = alc260_parse_auto_config(codec);
5847                 if (err < 0) {
5848                         alc_free(codec);
5849                         return err;
5850                 } else if (!err) {
5851                         printk(KERN_INFO
5852                                "hda_codec: Cannot set up configuration "
5853                                "from BIOS.  Using base mode...\n");
5854                         board_config = ALC260_BASIC;
5855                 }
5856         }
5857
5858         if (board_config != ALC260_AUTO)
5859                 setup_preset(spec, &alc260_presets[board_config]);
5860
5861         spec->stream_name_analog = "ALC260 Analog";
5862         spec->stream_analog_playback = &alc260_pcm_analog_playback;
5863         spec->stream_analog_capture = &alc260_pcm_analog_capture;
5864
5865         spec->stream_name_digital = "ALC260 Digital";
5866         spec->stream_digital_playback = &alc260_pcm_digital_playback;
5867         spec->stream_digital_capture = &alc260_pcm_digital_capture;
5868
5869         if (!spec->adc_nids && spec->input_mux) {
5870                 /* check whether NID 0x04 is valid */
5871                 unsigned int wcap = get_wcaps(codec, 0x04);
5872                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
5873                 /* get type */
5874                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
5875                         spec->adc_nids = alc260_adc_nids_alt;
5876                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
5877                 } else {
5878                         spec->adc_nids = alc260_adc_nids;
5879                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
5880                 }
5881         }
5882         set_capture_mixer(spec);
5883
5884         spec->vmaster_nid = 0x08;
5885
5886         codec->patch_ops = alc_patch_ops;
5887         if (board_config == ALC260_AUTO)
5888                 spec->init_hook = alc260_auto_init;
5889 #ifdef CONFIG_SND_HDA_POWER_SAVE
5890         if (!spec->loopback.amplist)
5891                 spec->loopback.amplist = alc260_loopbacks;
5892 #endif
5893         codec->proc_widget_hook = print_realtek_coef;
5894
5895         return 0;
5896 }
5897
5898
5899 /*
5900  * ALC882 support
5901  *
5902  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5903  * configuration.  Each pin widget can choose any input DACs and a mixer.
5904  * Each ADC is connected from a mixer of all inputs.  This makes possible
5905  * 6-channel independent captures.
5906  *
5907  * In addition, an independent DAC for the multi-playback (not used in this
5908  * driver yet).
5909  */
5910 #define ALC882_DIGOUT_NID       0x06
5911 #define ALC882_DIGIN_NID        0x0a
5912
5913 static struct hda_channel_mode alc882_ch_modes[1] = {
5914         { 8, NULL }
5915 };
5916
5917 static hda_nid_t alc882_dac_nids[4] = {
5918         /* front, rear, clfe, rear_surr */
5919         0x02, 0x03, 0x04, 0x05
5920 };
5921
5922 /* identical with ALC880 */
5923 #define alc882_adc_nids         alc880_adc_nids
5924 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5925
5926 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5927 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5928
5929 /* input MUX */
5930 /* FIXME: should be a matrix-type input source selection */
5931
5932 static struct hda_input_mux alc882_capture_source = {
5933         .num_items = 4,
5934         .items = {
5935                 { "Mic", 0x0 },
5936                 { "Front Mic", 0x1 },
5937                 { "Line", 0x2 },
5938                 { "CD", 0x4 },
5939         },
5940 };
5941 /*
5942  * 2ch mode
5943  */
5944 static struct hda_verb alc882_3ST_ch2_init[] = {
5945         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5946         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5947         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5948         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5949         { } /* end */
5950 };
5951
5952 /*
5953  * 6ch mode
5954  */
5955 static struct hda_verb alc882_3ST_ch6_init[] = {
5956         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5957         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5958         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5959         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5960         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5961         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5962         { } /* end */
5963 };
5964
5965 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5966         { 2, alc882_3ST_ch2_init },
5967         { 6, alc882_3ST_ch6_init },
5968 };
5969
5970 /*
5971  * 6ch mode
5972  */
5973 static struct hda_verb alc882_sixstack_ch6_init[] = {
5974         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5975         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5976         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5977         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5978         { } /* end */
5979 };
5980
5981 /*
5982  * 8ch mode
5983  */
5984 static struct hda_verb alc882_sixstack_ch8_init[] = {
5985         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5986         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5987         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5988         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5989         { } /* end */
5990 };
5991
5992 static struct hda_channel_mode alc882_sixstack_modes[2] = {
5993         { 6, alc882_sixstack_ch6_init },
5994         { 8, alc882_sixstack_ch8_init },
5995 };
5996
5997 /*
5998  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
5999  */
6000
6001 /*
6002  * 2ch mode
6003  */
6004 static struct hda_verb alc885_mbp_ch2_init[] = {
6005         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6006         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6007         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6008         { } /* end */
6009 };
6010
6011 /*
6012  * 6ch mode
6013  */
6014 static struct hda_verb alc885_mbp_ch6_init[] = {
6015         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6016         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6017         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6018         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6019         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6020         { } /* end */
6021 };
6022
6023 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
6024         { 2, alc885_mbp_ch2_init },
6025         { 6, alc885_mbp_ch6_init },
6026 };
6027
6028
6029 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6030  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6031  */
6032 static struct snd_kcontrol_new alc882_base_mixer[] = {
6033         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6034         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6035         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6036         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6037         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6038         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6039         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6040         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6041         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6042         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6043         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6044         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6045         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6046         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6047         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6048         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6049         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6050         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6051         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6052         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6053         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6054         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6055         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6056         { } /* end */
6057 };
6058
6059 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
6060         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6061         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
6062         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
6063         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
6064         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6065         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6066         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
6067         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
6068         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
6069         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
6070         { } /* end */
6071 };
6072 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
6073         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6074         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6075         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6076         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6077         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6078         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6079         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6080         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6081         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6082         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6083         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6084         { } /* end */
6085 };
6086
6087 static struct snd_kcontrol_new alc882_targa_mixer[] = {
6088         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6089         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6090         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6091         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6092         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6093         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6094         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6095         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6096         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6097         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6098         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6099         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6100         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6101         { } /* end */
6102 };
6103
6104 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
6105  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
6106  */
6107 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
6108         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6109         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6110         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6111         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
6112         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6113         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6114         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6115         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6116         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
6117         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
6118         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6119         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6120         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6121         { } /* end */
6122 };
6123
6124 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
6125         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6126         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6127         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6128         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6129         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6130         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6131         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6132         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6133         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6134         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6135         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6136         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6137         { } /* end */
6138 };
6139
6140 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
6141         {
6142                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6143                 .name = "Channel Mode",
6144                 .info = alc_ch_mode_info,
6145                 .get = alc_ch_mode_get,
6146                 .put = alc_ch_mode_put,
6147         },
6148         { } /* end */
6149 };
6150
6151 static struct hda_verb alc882_init_verbs[] = {
6152         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6153         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6154         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6155         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6156         /* Rear mixer */
6157         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6158         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6159         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6160         /* CLFE mixer */
6161         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6162         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6163         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6164         /* Side mixer */
6165         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6166         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6167         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6168
6169         /* Front Pin: output 0 (0x0c) */
6170         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6171         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6172         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6173         /* Rear Pin: output 1 (0x0d) */
6174         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6175         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6176         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6177         /* CLFE Pin: output 2 (0x0e) */
6178         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6179         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6180         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
6181         /* Side Pin: output 3 (0x0f) */
6182         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6183         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6184         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
6185         /* Mic (rear) pin: input vref at 80% */
6186         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6187         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6188         /* Front Mic pin: input vref at 80% */
6189         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6190         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6191         /* Line In pin: input */
6192         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6193         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6194         /* Line-2 In: Headphone output (output 0 - 0x0c) */
6195         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6196         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6197         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6198         /* CD pin widget for input */
6199         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6200
6201         /* FIXME: use matrix-type input source selection */
6202         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6203         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6204         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6205         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6206         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6207         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6208         /* Input mixer2 */
6209         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6210         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6211         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6212         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6213         /* Input mixer3 */
6214         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6215         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6216         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6217         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6218         /* ADC1: mute amp left and right */
6219         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6220         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6221         /* ADC2: mute amp left and right */
6222         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6223         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6224         /* ADC3: mute amp left and right */
6225         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6226         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6227
6228         { }
6229 };
6230
6231 static struct hda_verb alc882_eapd_verbs[] = {
6232         /* change to EAPD mode */
6233         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6234         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
6235         { }
6236 };
6237
6238 /* Mac Pro test */
6239 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
6240         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6241         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6242         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
6243         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
6244         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
6245         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
6246         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
6247         { } /* end */
6248 };
6249
6250 static struct hda_verb alc882_macpro_init_verbs[] = {
6251         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6252         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6253         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6254         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6255         /* Front Pin: output 0 (0x0c) */
6256         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6257         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6258         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6259         /* Front Mic pin: input vref at 80% */
6260         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6261         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6262         /* Speaker:  output */
6263         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6264         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6265         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
6266         /* Headphone output (output 0 - 0x0c) */
6267         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6268         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6269         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6270
6271         /* FIXME: use matrix-type input source selection */
6272         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6273         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6274         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6275         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6276         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6277         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6278         /* Input mixer2 */
6279         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6280         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6281         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6282         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6283         /* Input mixer3 */
6284         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6285         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6286         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6287         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6288         /* ADC1: mute amp left and right */
6289         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6290         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6291         /* ADC2: mute amp left and right */
6292         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6293         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6294         /* ADC3: mute amp left and right */
6295         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6296         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6297
6298         { }
6299 };
6300
6301 /* Macbook Pro rev3 */
6302 static struct hda_verb alc885_mbp3_init_verbs[] = {
6303         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6304         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6305         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6306         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6307         /* Rear mixer */
6308         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6309         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6310         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6311         /* Front Pin: output 0 (0x0c) */
6312         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6313         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6314         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6315         /* HP Pin: output 0 (0x0d) */
6316         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
6317         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6318         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6319         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6320         /* Mic (rear) pin: input vref at 80% */
6321         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6322         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6323         /* Front Mic pin: input vref at 80% */
6324         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6325         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6326         /* Line In pin: use output 1 when in LineOut mode */
6327         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6328         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6329         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
6330
6331         /* FIXME: use matrix-type input source selection */
6332         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6333         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6334         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6335         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6336         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6337         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6338         /* Input mixer2 */
6339         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6340         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6341         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6342         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6343         /* Input mixer3 */
6344         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6345         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6346         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6347         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6348         /* ADC1: mute amp left and right */
6349         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6350         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6351         /* ADC2: mute amp left and right */
6352         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6353         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6354         /* ADC3: mute amp left and right */
6355         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6356         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6357
6358         { }
6359 };
6360
6361 /* iMac 24 mixer. */
6362 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
6363         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6364         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
6365         { } /* end */
6366 };
6367
6368 /* iMac 24 init verbs. */
6369 static struct hda_verb alc885_imac24_init_verbs[] = {
6370         /* Internal speakers: output 0 (0x0c) */
6371         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6372         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6373         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6374         /* Internal speakers: output 0 (0x0c) */
6375         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6376         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6377         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
6378         /* Headphone: output 0 (0x0c) */
6379         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6380         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6381         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6382         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6383         /* Front Mic: input vref at 80% */
6384         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6385         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6386         { }
6387 };
6388
6389 /* Toggle speaker-output according to the hp-jack state */
6390 static void alc885_imac24_automute(struct hda_codec *codec)
6391 {
6392         unsigned int present;
6393
6394         present = snd_hda_codec_read(codec, 0x14, 0,
6395                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6396         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
6397                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6398         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
6399                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6400 }
6401
6402 /* Processes unsolicited events. */
6403 static void alc885_imac24_unsol_event(struct hda_codec *codec,
6404                                       unsigned int res)
6405 {
6406         /* Headphone insertion or removal. */
6407         if ((res >> 26) == ALC880_HP_EVENT)
6408                 alc885_imac24_automute(codec);
6409 }
6410
6411 static void alc885_mbp3_automute(struct hda_codec *codec)
6412 {
6413         unsigned int present;
6414
6415         present = snd_hda_codec_read(codec, 0x15, 0,
6416                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6417         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
6418                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6419         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6420                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
6421
6422 }
6423 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
6424                                     unsigned int res)
6425 {
6426         /* Headphone insertion or removal. */
6427         if ((res >> 26) == ALC880_HP_EVENT)
6428                 alc885_mbp3_automute(codec);
6429 }
6430
6431
6432 static struct hda_verb alc882_targa_verbs[] = {
6433         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6434         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6435
6436         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6437         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6438
6439         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6440         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6441         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6442
6443         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6444         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6445         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6446         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6447         { } /* end */
6448 };
6449
6450 /* toggle speaker-output according to the hp-jack state */
6451 static void alc882_targa_automute(struct hda_codec *codec)
6452 {
6453         unsigned int present;
6454
6455         present = snd_hda_codec_read(codec, 0x14, 0,
6456                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6457         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
6458                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6459         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6460                                   present ? 1 : 3);
6461 }
6462
6463 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
6464 {
6465         /* Looks like the unsol event is incompatible with the standard
6466          * definition.  4bit tag is placed at 26 bit!
6467          */
6468         if (((res >> 26) == ALC880_HP_EVENT)) {
6469                 alc882_targa_automute(codec);
6470         }
6471 }
6472
6473 static struct hda_verb alc882_asus_a7j_verbs[] = {
6474         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6475         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6476
6477         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6478         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6479         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6480
6481         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6482         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6483         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6484
6485         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6486         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6487         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6488         { } /* end */
6489 };
6490
6491 static struct hda_verb alc882_asus_a7m_verbs[] = {
6492         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6493         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6494
6495         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6496         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6497         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6498
6499         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6500         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6501         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6502
6503         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6504         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6505         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6506         { } /* end */
6507 };
6508
6509 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6510 {
6511         unsigned int gpiostate, gpiomask, gpiodir;
6512
6513         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6514                                        AC_VERB_GET_GPIO_DATA, 0);
6515
6516         if (!muted)
6517                 gpiostate |= (1 << pin);
6518         else
6519                 gpiostate &= ~(1 << pin);
6520
6521         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
6522                                       AC_VERB_GET_GPIO_MASK, 0);
6523         gpiomask |= (1 << pin);
6524
6525         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
6526                                      AC_VERB_GET_GPIO_DIRECTION, 0);
6527         gpiodir |= (1 << pin);
6528
6529
6530         snd_hda_codec_write(codec, codec->afg, 0,
6531                             AC_VERB_SET_GPIO_MASK, gpiomask);
6532         snd_hda_codec_write(codec, codec->afg, 0,
6533                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
6534
6535         msleep(1);
6536
6537         snd_hda_codec_write(codec, codec->afg, 0,
6538                             AC_VERB_SET_GPIO_DATA, gpiostate);
6539 }
6540
6541 /* set up GPIO at initialization */
6542 static void alc885_macpro_init_hook(struct hda_codec *codec)
6543 {
6544         alc882_gpio_mute(codec, 0, 0);
6545         alc882_gpio_mute(codec, 1, 0);
6546 }
6547
6548 /* set up GPIO and update auto-muting at initialization */
6549 static void alc885_imac24_init_hook(struct hda_codec *codec)
6550 {
6551         alc885_macpro_init_hook(codec);
6552         alc885_imac24_automute(codec);
6553 }
6554
6555 /*
6556  * generic initialization of ADC, input mixers and output mixers
6557  */
6558 static struct hda_verb alc882_auto_init_verbs[] = {
6559         /*
6560          * Unmute ADC0-2 and set the default input to mic-in
6561          */
6562         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6563         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6564         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6565         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6566         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6567         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6568
6569         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6570          * mixer widget
6571          * Note: PASD motherboards uses the Line In 2 as the input for
6572          * front panel mic (mic 2)
6573          */
6574         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6575         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6576         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6577         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6578         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6579         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6580
6581         /*
6582          * Set up output mixers (0x0c - 0x0f)
6583          */
6584         /* set vol=0 to output mixers */
6585         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6586         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6587         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6588         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6589         /* set up input amps for analog loopback */
6590         /* Amp Indices: DAC = 0, mixer = 1 */
6591         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6592         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6593         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6594         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6595         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6596         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6597         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6598         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6599         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6600         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6601
6602         /* FIXME: use matrix-type input source selection */
6603         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6604         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6605         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6606         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6607         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6608         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6609         /* Input mixer2 */
6610         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6611         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6612         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6613         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6614         /* Input mixer3 */
6615         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6616         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6617         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6618         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6619
6620         { }
6621 };
6622
6623 #ifdef CONFIG_SND_HDA_POWER_SAVE
6624 #define alc882_loopbacks        alc880_loopbacks
6625 #endif
6626
6627 /* pcm configuration: identiacal with ALC880 */
6628 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6629 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6630 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6631 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6632
6633 /*
6634  * configuration and preset
6635  */
6636 static const char *alc882_models[ALC882_MODEL_LAST] = {
6637         [ALC882_3ST_DIG]        = "3stack-dig",
6638         [ALC882_6ST_DIG]        = "6stack-dig",
6639         [ALC882_ARIMA]          = "arima",
6640         [ALC882_W2JC]           = "w2jc",
6641         [ALC882_TARGA]          = "targa",
6642         [ALC882_ASUS_A7J]       = "asus-a7j",
6643         [ALC882_ASUS_A7M]       = "asus-a7m",
6644         [ALC885_MACPRO]         = "macpro",
6645         [ALC885_MBP3]           = "mbp3",
6646         [ALC885_IMAC24]         = "imac24",
6647         [ALC882_AUTO]           = "auto",
6648 };
6649
6650 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6651         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6652         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6653         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6654         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6655         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6656         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6657         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6658         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6659         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6660         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6661         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6662         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6663         {}
6664 };
6665
6666 static struct alc_config_preset alc882_presets[] = {
6667         [ALC882_3ST_DIG] = {
6668                 .mixers = { alc882_base_mixer },
6669                 .init_verbs = { alc882_init_verbs },
6670                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6671                 .dac_nids = alc882_dac_nids,
6672                 .dig_out_nid = ALC882_DIGOUT_NID,
6673                 .dig_in_nid = ALC882_DIGIN_NID,
6674                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6675                 .channel_mode = alc882_ch_modes,
6676                 .need_dac_fix = 1,
6677                 .input_mux = &alc882_capture_source,
6678         },
6679         [ALC882_6ST_DIG] = {
6680                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6681                 .init_verbs = { alc882_init_verbs },
6682                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6683                 .dac_nids = alc882_dac_nids,
6684                 .dig_out_nid = ALC882_DIGOUT_NID,
6685                 .dig_in_nid = ALC882_DIGIN_NID,
6686                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6687                 .channel_mode = alc882_sixstack_modes,
6688                 .input_mux = &alc882_capture_source,
6689         },
6690         [ALC882_ARIMA] = {
6691                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6692                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6693                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6694                 .dac_nids = alc882_dac_nids,
6695                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6696                 .channel_mode = alc882_sixstack_modes,
6697                 .input_mux = &alc882_capture_source,
6698         },
6699         [ALC882_W2JC] = {
6700                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6701                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6702                                 alc880_gpio1_init_verbs },
6703                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6704                 .dac_nids = alc882_dac_nids,
6705                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6706                 .channel_mode = alc880_threestack_modes,
6707                 .need_dac_fix = 1,
6708                 .input_mux = &alc882_capture_source,
6709                 .dig_out_nid = ALC882_DIGOUT_NID,
6710         },
6711         [ALC885_MBP3] = {
6712                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6713                 .init_verbs = { alc885_mbp3_init_verbs,
6714                                 alc880_gpio1_init_verbs },
6715                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6716                 .dac_nids = alc882_dac_nids,
6717                 .channel_mode = alc885_mbp_6ch_modes,
6718                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
6719                 .input_mux = &alc882_capture_source,
6720                 .dig_out_nid = ALC882_DIGOUT_NID,
6721                 .dig_in_nid = ALC882_DIGIN_NID,
6722                 .unsol_event = alc885_mbp3_unsol_event,
6723                 .init_hook = alc885_mbp3_automute,
6724         },
6725         [ALC885_MACPRO] = {
6726                 .mixers = { alc882_macpro_mixer },
6727                 .init_verbs = { alc882_macpro_init_verbs },
6728                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6729                 .dac_nids = alc882_dac_nids,
6730                 .dig_out_nid = ALC882_DIGOUT_NID,
6731                 .dig_in_nid = ALC882_DIGIN_NID,
6732                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6733                 .channel_mode = alc882_ch_modes,
6734                 .input_mux = &alc882_capture_source,
6735                 .init_hook = alc885_macpro_init_hook,
6736         },
6737         [ALC885_IMAC24] = {
6738                 .mixers = { alc885_imac24_mixer },
6739                 .init_verbs = { alc885_imac24_init_verbs },
6740                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6741                 .dac_nids = alc882_dac_nids,
6742                 .dig_out_nid = ALC882_DIGOUT_NID,
6743                 .dig_in_nid = ALC882_DIGIN_NID,
6744                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6745                 .channel_mode = alc882_ch_modes,
6746                 .input_mux = &alc882_capture_source,
6747                 .unsol_event = alc885_imac24_unsol_event,
6748                 .init_hook = alc885_imac24_init_hook,
6749         },
6750         [ALC882_TARGA] = {
6751                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
6752                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6753                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6754                 .dac_nids = alc882_dac_nids,
6755                 .dig_out_nid = ALC882_DIGOUT_NID,
6756                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6757                 .adc_nids = alc882_adc_nids,
6758                 .capsrc_nids = alc882_capsrc_nids,
6759                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6760                 .channel_mode = alc882_3ST_6ch_modes,
6761                 .need_dac_fix = 1,
6762                 .input_mux = &alc882_capture_source,
6763                 .unsol_event = alc882_targa_unsol_event,
6764                 .init_hook = alc882_targa_automute,
6765         },
6766         [ALC882_ASUS_A7J] = {
6767                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
6768                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6769                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6770                 .dac_nids = alc882_dac_nids,
6771                 .dig_out_nid = ALC882_DIGOUT_NID,
6772                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6773                 .adc_nids = alc882_adc_nids,
6774                 .capsrc_nids = alc882_capsrc_nids,
6775                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6776                 .channel_mode = alc882_3ST_6ch_modes,
6777                 .need_dac_fix = 1,
6778                 .input_mux = &alc882_capture_source,
6779         },
6780         [ALC882_ASUS_A7M] = {
6781                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6782                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6783                                 alc880_gpio1_init_verbs,
6784                                 alc882_asus_a7m_verbs },
6785                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6786                 .dac_nids = alc882_dac_nids,
6787                 .dig_out_nid = ALC882_DIGOUT_NID,
6788                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6789                 .channel_mode = alc880_threestack_modes,
6790                 .need_dac_fix = 1,
6791                 .input_mux = &alc882_capture_source,
6792         },
6793 };
6794
6795
6796 /*
6797  * Pin config fixes
6798  */
6799 enum {
6800         PINFIX_ABIT_AW9D_MAX
6801 };
6802
6803 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6804         { 0x15, 0x01080104 }, /* side */
6805         { 0x16, 0x01011012 }, /* rear */
6806         { 0x17, 0x01016011 }, /* clfe */
6807         { }
6808 };
6809
6810 static const struct alc_pincfg *alc882_pin_fixes[] = {
6811         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6812 };
6813
6814 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6815         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6816         {}
6817 };
6818
6819 /*
6820  * BIOS auto configuration
6821  */
6822 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6823                                               hda_nid_t nid, int pin_type,
6824                                               int dac_idx)
6825 {
6826         /* set as output */
6827         struct alc_spec *spec = codec->spec;
6828         int idx;
6829
6830         alc_set_pin_output(codec, nid, pin_type);
6831         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6832                 idx = 4;
6833         else
6834                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6835         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6836
6837 }
6838
6839 static void alc882_auto_init_multi_out(struct hda_codec *codec)
6840 {
6841         struct alc_spec *spec = codec->spec;
6842         int i;
6843
6844         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6845         for (i = 0; i <= HDA_SIDE; i++) {
6846                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6847                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6848                 if (nid)
6849                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6850                                                           i);
6851         }
6852 }
6853
6854 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6855 {
6856         struct alc_spec *spec = codec->spec;
6857         hda_nid_t pin;
6858
6859         pin = spec->autocfg.hp_pins[0];
6860         if (pin) /* connect to front */
6861                 /* use dac 0 */
6862                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6863         pin = spec->autocfg.speaker_pins[0];
6864         if (pin)
6865                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6866 }
6867
6868 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6869 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6870
6871 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6872 {
6873         struct alc_spec *spec = codec->spec;
6874         int i;
6875
6876         for (i = 0; i < AUTO_PIN_LAST; i++) {
6877                 hda_nid_t nid = spec->autocfg.input_pins[i];
6878                 unsigned int vref;
6879                 if (!nid)
6880                         continue;
6881                 vref = PIN_IN;
6882                 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6883                         unsigned int pincap;
6884                         pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
6885                         if ((pincap >> AC_PINCAP_VREF_SHIFT) &
6886                             AC_PINCAP_VREF_80)
6887                                 vref = PIN_VREF80;
6888                 }
6889                 snd_hda_codec_write(codec, nid, 0,
6890                                     AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6891                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6892                         snd_hda_codec_write(codec, nid, 0,
6893                                             AC_VERB_SET_AMP_GAIN_MUTE,
6894                                             AMP_OUT_MUTE);
6895         }
6896 }
6897
6898 static void alc882_auto_init_input_src(struct hda_codec *codec)
6899 {
6900         struct alc_spec *spec = codec->spec;
6901         const struct hda_input_mux *imux = spec->input_mux;
6902         int c;
6903
6904         for (c = 0; c < spec->num_adc_nids; c++) {
6905                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
6906                 hda_nid_t nid = spec->capsrc_nids[c];
6907                 int conns, mute, idx, item;
6908
6909                 conns = snd_hda_get_connections(codec, nid, conn_list,
6910                                                 ARRAY_SIZE(conn_list));
6911                 if (conns < 0)
6912                         continue;
6913                 for (idx = 0; idx < conns; idx++) {
6914                         /* if the current connection is the selected one,
6915                          * unmute it as default - otherwise mute it
6916                          */
6917                         mute = AMP_IN_MUTE(idx);
6918                         for (item = 0; item < imux->num_items; item++) {
6919                                 if (imux->items[item].index == idx) {
6920                                         if (spec->cur_mux[c] == item)
6921                                                 mute = AMP_IN_UNMUTE(idx);
6922                                         break;
6923                                 }
6924                         }
6925                         snd_hda_codec_write(codec, nid, 0,
6926                                             AC_VERB_SET_AMP_GAIN_MUTE, mute);
6927                 }
6928         }
6929 }
6930
6931 /* add mic boosts if needed */
6932 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6933 {
6934         struct alc_spec *spec = codec->spec;
6935         int err;
6936         hda_nid_t nid;
6937
6938         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6939         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6940                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6941                                   "Mic Boost",
6942                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6943                 if (err < 0)
6944                         return err;
6945         }
6946         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6947         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6948                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6949                                   "Front Mic Boost",
6950                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6951                 if (err < 0)
6952                         return err;
6953         }
6954         return 0;
6955 }
6956
6957 /* almost identical with ALC880 parser... */
6958 static int alc882_parse_auto_config(struct hda_codec *codec)
6959 {
6960         struct alc_spec *spec = codec->spec;
6961         int err = alc880_parse_auto_config(codec);
6962
6963         if (err < 0)
6964                 return err;
6965         else if (!err)
6966                 return 0; /* no config found */
6967
6968         err = alc_auto_add_mic_boost(codec);
6969         if (err < 0)
6970                 return err;
6971
6972         /* hack - override the init verbs */
6973         spec->init_verbs[0] = alc882_auto_init_verbs;
6974
6975         return 1; /* config found */
6976 }
6977
6978 /* additional initialization for auto-configuration model */
6979 static void alc882_auto_init(struct hda_codec *codec)
6980 {
6981         struct alc_spec *spec = codec->spec;
6982         alc882_auto_init_multi_out(codec);
6983         alc882_auto_init_hp_out(codec);
6984         alc882_auto_init_analog_input(codec);
6985         alc882_auto_init_input_src(codec);
6986         if (spec->unsol_event)
6987                 alc_inithook(codec);
6988 }
6989
6990 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
6991
6992 static int patch_alc882(struct hda_codec *codec)
6993 {
6994         struct alc_spec *spec;
6995         int err, board_config;
6996
6997         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6998         if (spec == NULL)
6999                 return -ENOMEM;
7000
7001         codec->spec = spec;
7002
7003         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
7004                                                   alc882_models,
7005                                                   alc882_cfg_tbl);
7006
7007         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
7008                 /* Pick up systems that don't supply PCI SSID */
7009                 switch (codec->subsystem_id) {
7010                 case 0x106b0c00: /* Mac Pro */
7011                         board_config = ALC885_MACPRO;
7012                         break;
7013                 case 0x106b1000: /* iMac 24 */
7014                 case 0x106b2800: /* AppleTV */
7015                         board_config = ALC885_IMAC24;
7016                         break;
7017                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
7018                 case 0x106b00a4: /* MacbookPro4,1 */
7019                 case 0x106b2c00: /* Macbook Pro rev3 */
7020                 case 0x106b3600: /* Macbook 3.1 */
7021                         board_config = ALC885_MBP3;
7022                         break;
7023                 default:
7024                         /* ALC889A is handled better as ALC888-compatible */
7025                         if (codec->revision_id == 0x100101 ||
7026                             codec->revision_id == 0x100103) {
7027                                 alc_free(codec);
7028                                 return patch_alc883(codec);
7029                         }
7030                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
7031                                          "trying auto-probe from BIOS...\n");
7032                         board_config = ALC882_AUTO;
7033                 }
7034         }
7035
7036         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
7037
7038         if (board_config == ALC882_AUTO) {
7039                 /* automatic parse from the BIOS config */
7040                 err = alc882_parse_auto_config(codec);
7041                 if (err < 0) {
7042                         alc_free(codec);
7043                         return err;
7044                 } else if (!err) {
7045                         printk(KERN_INFO
7046                                "hda_codec: Cannot set up configuration "
7047                                "from BIOS.  Using base mode...\n");
7048                         board_config = ALC882_3ST_DIG;
7049                 }
7050         }
7051
7052         if (board_config != ALC882_AUTO)
7053                 setup_preset(spec, &alc882_presets[board_config]);
7054
7055         if (codec->vendor_id == 0x10ec0885) {
7056                 spec->stream_name_analog = "ALC885 Analog";
7057                 spec->stream_name_digital = "ALC885 Digital";
7058         } else {
7059                 spec->stream_name_analog = "ALC882 Analog";
7060                 spec->stream_name_digital = "ALC882 Digital";
7061         }
7062
7063         spec->stream_analog_playback = &alc882_pcm_analog_playback;
7064         spec->stream_analog_capture = &alc882_pcm_analog_capture;
7065         /* FIXME: setup DAC5 */
7066         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
7067         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
7068
7069         spec->stream_digital_playback = &alc882_pcm_digital_playback;
7070         spec->stream_digital_capture = &alc882_pcm_digital_capture;
7071
7072         spec->is_mix_capture = 1; /* matrix-style capture */
7073         if (!spec->adc_nids && spec->input_mux) {
7074                 /* check whether NID 0x07 is valid */
7075                 unsigned int wcap = get_wcaps(codec, 0x07);
7076                 /* get type */
7077                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
7078                 if (wcap != AC_WID_AUD_IN) {
7079                         spec->adc_nids = alc882_adc_nids_alt;
7080                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
7081                         spec->capsrc_nids = alc882_capsrc_nids_alt;
7082                 } else {
7083                         spec->adc_nids = alc882_adc_nids;
7084                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
7085                         spec->capsrc_nids = alc882_capsrc_nids;
7086                 }
7087         }
7088         set_capture_mixer(spec);
7089
7090         spec->vmaster_nid = 0x0c;
7091
7092         codec->patch_ops = alc_patch_ops;
7093         if (board_config == ALC882_AUTO)
7094                 spec->init_hook = alc882_auto_init;
7095 #ifdef CONFIG_SND_HDA_POWER_SAVE
7096         if (!spec->loopback.amplist)
7097                 spec->loopback.amplist = alc882_loopbacks;
7098 #endif
7099         codec->proc_widget_hook = print_realtek_coef;
7100
7101         return 0;
7102 }
7103
7104 /*
7105  * ALC883 support
7106  *
7107  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
7108  * configuration.  Each pin widget can choose any input DACs and a mixer.
7109  * Each ADC is connected from a mixer of all inputs.  This makes possible
7110  * 6-channel independent captures.
7111  *
7112  * In addition, an independent DAC for the multi-playback (not used in this
7113  * driver yet).
7114  */
7115 #define ALC883_DIGOUT_NID       0x06
7116 #define ALC883_DIGIN_NID        0x0a
7117
7118 #define ALC1200_DIGOUT_NID      0x10
7119
7120 static hda_nid_t alc883_dac_nids[4] = {
7121         /* front, rear, clfe, rear_surr */
7122         0x02, 0x03, 0x04, 0x05
7123 };
7124
7125 static hda_nid_t alc883_adc_nids[2] = {
7126         /* ADC1-2 */
7127         0x08, 0x09,
7128 };
7129
7130 static hda_nid_t alc883_adc_nids_alt[1] = {
7131         /* ADC1 */
7132         0x08,
7133 };
7134
7135 static hda_nid_t alc883_adc_nids_rev[2] = {
7136         /* ADC2-1 */
7137         0x09, 0x08
7138 };
7139
7140 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
7141
7142 static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
7143
7144 /* input MUX */
7145 /* FIXME: should be a matrix-type input source selection */
7146
7147 static struct hda_input_mux alc883_capture_source = {
7148         .num_items = 4,
7149         .items = {
7150                 { "Mic", 0x0 },
7151                 { "Front Mic", 0x1 },
7152                 { "Line", 0x2 },
7153                 { "CD", 0x4 },
7154         },
7155 };
7156
7157 static struct hda_input_mux alc883_3stack_6ch_intel = {
7158         .num_items = 4,
7159         .items = {
7160                 { "Mic", 0x1 },
7161                 { "Front Mic", 0x0 },
7162                 { "Line", 0x2 },
7163                 { "CD", 0x4 },
7164         },
7165 };
7166
7167 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
7168         .num_items = 2,
7169         .items = {
7170                 { "Mic", 0x1 },
7171                 { "Line", 0x2 },
7172         },
7173 };
7174
7175 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
7176         .num_items = 4,
7177         .items = {
7178                 { "Mic", 0x0 },
7179                 { "iMic", 0x1 },
7180                 { "Line", 0x2 },
7181                 { "CD", 0x4 },
7182         },
7183 };
7184
7185 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
7186         .num_items = 2,
7187         .items = {
7188                 { "Mic", 0x0 },
7189                 { "Int Mic", 0x1 },
7190         },
7191 };
7192
7193 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
7194         .num_items = 3,
7195         .items = {
7196                 { "Mic", 0x0 },
7197                 { "Front Mic", 0x1 },
7198                 { "Line", 0x4 },
7199         },
7200 };
7201
7202 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
7203         .num_items = 2,
7204         .items = {
7205                 { "Mic", 0x0 },
7206                 { "Line", 0x2 },
7207         },
7208 };
7209
7210 /*
7211  * 2ch mode
7212  */
7213 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
7214         { 2, NULL }
7215 };
7216
7217 /*
7218  * 2ch mode
7219  */
7220 static struct hda_verb alc883_3ST_ch2_init[] = {
7221         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7222         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7223         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7224         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7225         { } /* end */
7226 };
7227
7228 /*
7229  * 4ch mode
7230  */
7231 static struct hda_verb alc883_3ST_ch4_init[] = {
7232         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7233         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7234         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7235         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7236         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7237         { } /* end */
7238 };
7239
7240 /*
7241  * 6ch mode
7242  */
7243 static struct hda_verb alc883_3ST_ch6_init[] = {
7244         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7245         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7246         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7247         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7248         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7249         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7250         { } /* end */
7251 };
7252
7253 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
7254         { 2, alc883_3ST_ch2_init },
7255         { 4, alc883_3ST_ch4_init },
7256         { 6, alc883_3ST_ch6_init },
7257 };
7258
7259 /*
7260  * 2ch mode
7261  */
7262 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
7263         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7264         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7265         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7266         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7267         { } /* end */
7268 };
7269
7270 /*
7271  * 4ch mode
7272  */
7273 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
7274         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7275         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7276         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7277         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7278         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7279         { } /* end */
7280 };
7281
7282 /*
7283  * 6ch mode
7284  */
7285 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
7286         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7287         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7288         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
7289         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7290         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7291         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7292         { } /* end */
7293 };
7294
7295 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
7296         { 2, alc883_3ST_ch2_intel_init },
7297         { 4, alc883_3ST_ch4_intel_init },
7298         { 6, alc883_3ST_ch6_intel_init },
7299 };
7300
7301 /*
7302  * 6ch mode
7303  */
7304 static struct hda_verb alc883_sixstack_ch6_init[] = {
7305         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7306         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7307         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7308         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7309         { } /* end */
7310 };
7311
7312 /*
7313  * 8ch mode
7314  */
7315 static struct hda_verb alc883_sixstack_ch8_init[] = {
7316         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7317         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7318         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7319         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7320         { } /* end */
7321 };
7322
7323 static struct hda_channel_mode alc883_sixstack_modes[2] = {
7324         { 6, alc883_sixstack_ch6_init },
7325         { 8, alc883_sixstack_ch8_init },
7326 };
7327
7328 static struct hda_verb alc883_medion_eapd_verbs[] = {
7329         /* eanable EAPD on medion laptop */
7330         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7331         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7332         { }
7333 };
7334
7335 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
7336  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
7337  */
7338
7339 static struct snd_kcontrol_new alc883_base_mixer[] = {
7340         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7341         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7342         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7343         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7344         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7345         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7346         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7347         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7348         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7349         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7350         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7351         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7352         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7353         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7354         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7355         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7356         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7357         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7358         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7359         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7360         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7361         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7362         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7363         { } /* end */
7364 };
7365
7366 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7367         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7368         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7369         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7370         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7371         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7372         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7373         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7374         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7375         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7376         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7377         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7378         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7379         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7380         { } /* end */
7381 };
7382
7383 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7384         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7385         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7386         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7387         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7388         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7389         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7390         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7391         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7392         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7393         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7394         { } /* end */
7395 };
7396
7397 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7398         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7399         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7400         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7401         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7402         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7403         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7404         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7405         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7406         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7407         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7408         { } /* end */
7409 };
7410
7411 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7412         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7413         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7414         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7415         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7416         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7417         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7418         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7419         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7420         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7421         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7422         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7423         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7424         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7425         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7426         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7427         { } /* end */
7428 };
7429
7430 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7431         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7432         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7433         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7434         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7435         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7436         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7437         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7438         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7439         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7440         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7441         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7442         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7443         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7444         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7445         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7446         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7447         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7448         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7449         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7450         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7451         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7452         { } /* end */
7453 };
7454
7455 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7456         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7457         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7458         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7459         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7460         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7461                               HDA_OUTPUT),
7462         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7463         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7464         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7465         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7466         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7467         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7468         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7469         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7470         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7471         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7472         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7473         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7474         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7475         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7476         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7477         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7478         { } /* end */
7479 };
7480
7481 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7482         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7483         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7484         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7485         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7486         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7487         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7488         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7489         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7490         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7491         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7492         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7493         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7494         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7495         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7496         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7497         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7498         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7499         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7500         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7501         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7502         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7503         { } /* end */
7504 };
7505
7506 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
7507         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7508         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7509         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7510         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7511         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7512         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7513         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7514         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7515         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7516         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7517         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7518         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7519         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7520         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7521         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7522         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7523         { } /* end */
7524 };
7525
7526 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
7527         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7528         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7529         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7530         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7531         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7532         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7533         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7534         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7535         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7536         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7537         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7538         { } /* end */
7539 };
7540
7541 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7542         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7543         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7544         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7545         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7546         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7547         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7548         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7549         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7550         { } /* end */
7551 };
7552
7553 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7554         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7555         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7556         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7557         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7558         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7559         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7560         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7561         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7562         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7563         { } /* end */
7564 };
7565
7566 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7567         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7568         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7569         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7570         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7571         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7572         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7573         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7574         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7575         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7576         { } /* end */
7577 };
7578
7579 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7580         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7581         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7582         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7583         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7584         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7585         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7586         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7587         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7588         { } /* end */
7589 };
7590
7591 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
7592         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7593         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7594         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
7595         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
7596         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
7597                                                 0x0d, 1, 0x0, HDA_OUTPUT),
7598         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
7599         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
7600         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
7601         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7602         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7603         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7604         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
7605         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7606         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7607         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7608         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7609         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7610         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7611         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7612         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7613         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7614         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7615         { } /* end */
7616 };
7617
7618 static struct hda_bind_ctls alc883_bind_cap_vol = {
7619         .ops = &snd_hda_bind_vol,
7620         .values = {
7621                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7622                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7623                 0
7624         },
7625 };
7626
7627 static struct hda_bind_ctls alc883_bind_cap_switch = {
7628         .ops = &snd_hda_bind_sw,
7629         .values = {
7630                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7631                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7632                 0
7633         },
7634 };
7635
7636 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
7637         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7638         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7639         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7640         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7641         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7642         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7643         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7644         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7645         { } /* end */
7646 };
7647
7648 static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
7649         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
7650         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
7651         {
7652                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7653                 /* .name = "Capture Source", */
7654                 .name = "Input Source",
7655                 .count = 1,
7656                 .info = alc_mux_enum_info,
7657                 .get = alc_mux_enum_get,
7658                 .put = alc_mux_enum_put,
7659         },
7660         { } /* end */
7661 };
7662
7663 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7664         {
7665                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7666                 .name = "Channel Mode",
7667                 .info = alc_ch_mode_info,
7668                 .get = alc_ch_mode_get,
7669                 .put = alc_ch_mode_put,
7670         },
7671         { } /* end */
7672 };
7673
7674 static struct hda_verb alc883_init_verbs[] = {
7675         /* ADC1: mute amp left and right */
7676         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7677         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7678         /* ADC2: mute amp left and right */
7679         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7680         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7681         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7682         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7683         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7684         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7685         /* Rear mixer */
7686         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7687         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7688         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7689         /* CLFE mixer */
7690         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7691         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7692         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7693         /* Side mixer */
7694         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7695         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7696         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7697
7698         /* mute analog input loopbacks */
7699         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7700         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7701         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7702         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7703         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7704
7705         /* Front Pin: output 0 (0x0c) */
7706         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7707         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7708         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7709         /* Rear Pin: output 1 (0x0d) */
7710         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7711         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7712         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7713         /* CLFE Pin: output 2 (0x0e) */
7714         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7715         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7716         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7717         /* Side Pin: output 3 (0x0f) */
7718         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7719         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7720         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7721         /* Mic (rear) pin: input vref at 80% */
7722         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7723         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7724         /* Front Mic pin: input vref at 80% */
7725         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7726         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7727         /* Line In pin: input */
7728         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7729         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7730         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7731         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7732         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7733         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7734         /* CD pin widget for input */
7735         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7736
7737         /* FIXME: use matrix-type input source selection */
7738         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7739         /* Input mixer2 */
7740         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7741         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7742         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7743         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7744         /* Input mixer3 */
7745         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7746         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7747         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7748         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7749         { }
7750 };
7751
7752 /* toggle speaker-output according to the hp-jack state */
7753 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7754 {
7755         unsigned int present;
7756
7757         present = snd_hda_codec_read(codec, 0x15, 0,
7758                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7759         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7760                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7761         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7762                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7763 }
7764
7765 /* auto-toggle front mic */
7766 /*
7767 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7768 {
7769         unsigned int present;
7770         unsigned char bits;
7771
7772         present = snd_hda_codec_read(codec, 0x18, 0,
7773                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7774         bits = present ? HDA_AMP_MUTE : 0;
7775         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7776 }
7777 */
7778
7779 static void alc883_mitac_automute(struct hda_codec *codec)
7780 {
7781         alc883_mitac_hp_automute(codec);
7782         /* alc883_mitac_mic_automute(codec); */
7783 }
7784
7785 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7786                                            unsigned int res)
7787 {
7788         switch (res >> 26) {
7789         case ALC880_HP_EVENT:
7790                 alc883_mitac_hp_automute(codec);
7791                 break;
7792         case ALC880_MIC_EVENT:
7793                 /* alc883_mitac_mic_automute(codec); */
7794                 break;
7795         }
7796 }
7797
7798 static struct hda_verb alc883_mitac_verbs[] = {
7799         /* HP */
7800         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7801         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7802         /* Subwoofer */
7803         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7804         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7805
7806         /* enable unsolicited event */
7807         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7808         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7809
7810         { } /* end */
7811 };
7812
7813 static struct hda_verb alc883_clevo_m720_verbs[] = {
7814         /* HP */
7815         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7816         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7817         /* Int speaker */
7818         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7819         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7820
7821         /* enable unsolicited event */
7822         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7823         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7824
7825         { } /* end */
7826 };
7827
7828 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7829         /* HP */
7830         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7831         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7832         /* Subwoofer */
7833         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7834         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7835
7836         /* enable unsolicited event */
7837         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7838
7839         { } /* end */
7840 };
7841
7842 static struct hda_verb alc883_tagra_verbs[] = {
7843         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7844         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7845
7846         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7847         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7848
7849         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7850         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7851         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7852
7853         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7854         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7855         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7856         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7857
7858         { } /* end */
7859 };
7860
7861 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7862         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7863         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7864         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7865         { } /* end */
7866 };
7867
7868 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7869         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7870         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7871         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7872         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7873         { } /* end */
7874 };
7875
7876 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7877         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7878         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7879         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7880         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7881         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7882         { } /* end */
7883 };
7884
7885 static struct hda_verb alc883_haier_w66_verbs[] = {
7886         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7887         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7888
7889         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7890
7891         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7892         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7893         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7894         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7895         { } /* end */
7896 };
7897
7898 static struct hda_verb alc888_lenovo_sky_verbs[] = {
7899         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7900         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7901         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7902         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7903         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7904         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7905         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7906         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7907         { } /* end */
7908 };
7909
7910 static struct hda_verb alc888_3st_hp_verbs[] = {
7911         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7912         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7913         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7914         { }
7915 };
7916
7917 static struct hda_verb alc888_6st_dell_verbs[] = {
7918         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7919         { }
7920 };
7921
7922 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7923         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7924         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7925         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7926         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7927         { }
7928 };
7929
7930 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7931         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7932         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7933         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7934         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7935         { }
7936 };
7937
7938 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7939         { 2, alc888_3st_hp_2ch_init },
7940         { 6, alc888_3st_hp_6ch_init },
7941 };
7942
7943 /* toggle front-jack and RCA according to the hp-jack state */
7944 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7945 {
7946         unsigned int present;
7947
7948         present = snd_hda_codec_read(codec, 0x1b, 0,
7949                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7950         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7951                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7952         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7953                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7954 }
7955
7956 /* toggle RCA according to the front-jack state */
7957 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7958 {
7959         unsigned int present;
7960
7961         present = snd_hda_codec_read(codec, 0x14, 0,
7962                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7963         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7964                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7965 }
7966
7967 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7968                                              unsigned int res)
7969 {
7970         if ((res >> 26) == ALC880_HP_EVENT)
7971                 alc888_lenovo_ms7195_front_automute(codec);
7972         if ((res >> 26) == ALC880_FRONT_EVENT)
7973                 alc888_lenovo_ms7195_rca_automute(codec);
7974 }
7975
7976 static struct hda_verb alc883_medion_md2_verbs[] = {
7977         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7978         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7979
7980         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7981
7982         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7983         { } /* end */
7984 };
7985
7986 /* toggle speaker-output according to the hp-jack state */
7987 static void alc883_medion_md2_automute(struct hda_codec *codec)
7988 {
7989         unsigned int present;
7990
7991         present = snd_hda_codec_read(codec, 0x14, 0,
7992                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7993         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7994                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7995 }
7996
7997 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
7998                                           unsigned int res)
7999 {
8000         if ((res >> 26) == ALC880_HP_EVENT)
8001                 alc883_medion_md2_automute(codec);
8002 }
8003
8004 /* toggle speaker-output according to the hp-jack state */
8005 static void alc883_tagra_automute(struct hda_codec *codec)
8006 {
8007         unsigned int present;
8008         unsigned char bits;
8009
8010         present = snd_hda_codec_read(codec, 0x14, 0,
8011                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8012         bits = present ? HDA_AMP_MUTE : 0;
8013         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
8014                                  HDA_AMP_MUTE, bits);
8015         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
8016                                   present ? 1 : 3);
8017 }
8018
8019 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
8020 {
8021         if ((res >> 26) == ALC880_HP_EVENT)
8022                 alc883_tagra_automute(codec);
8023 }
8024
8025 /* toggle speaker-output according to the hp-jack state */
8026 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
8027 {
8028         unsigned int present;
8029         unsigned char bits;
8030
8031         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
8032                 & AC_PINSENSE_PRESENCE;
8033         bits = present ? HDA_AMP_MUTE : 0;
8034         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8035                                  HDA_AMP_MUTE, bits);
8036 }
8037
8038 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8039 {
8040         unsigned int present;
8041
8042         present = snd_hda_codec_read(codec, 0x18, 0,
8043                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8044         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8045                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8046 }
8047
8048 static void alc883_clevo_m720_automute(struct hda_codec *codec)
8049 {
8050         alc883_clevo_m720_hp_automute(codec);
8051         alc883_clevo_m720_mic_automute(codec);
8052 }
8053
8054 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8055                                            unsigned int res)
8056 {
8057         switch (res >> 26) {
8058         case ALC880_HP_EVENT:
8059                 alc883_clevo_m720_hp_automute(codec);
8060                 break;
8061         case ALC880_MIC_EVENT:
8062                 alc883_clevo_m720_mic_automute(codec);
8063                 break;
8064         }
8065 }
8066
8067 /* toggle speaker-output according to the hp-jack state */
8068 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
8069 {
8070         unsigned int present;
8071         unsigned char bits;
8072
8073         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8074                 & AC_PINSENSE_PRESENCE;
8075         bits = present ? HDA_AMP_MUTE : 0;
8076         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8077                                  HDA_AMP_MUTE, bits);
8078 }
8079
8080 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
8081                                                   unsigned int res)
8082 {
8083         if ((res >> 26) == ALC880_HP_EVENT)
8084                 alc883_2ch_fujitsu_pi2515_automute(codec);
8085 }
8086
8087 static void alc883_haier_w66_automute(struct hda_codec *codec)
8088 {
8089         unsigned int present;
8090         unsigned char bits;
8091
8092         present = snd_hda_codec_read(codec, 0x1b, 0,
8093                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8094         bits = present ? 0x80 : 0;
8095         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8096                                  0x80, bits);
8097 }
8098
8099 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
8100                                          unsigned int res)
8101 {
8102         if ((res >> 26) == ALC880_HP_EVENT)
8103                 alc883_haier_w66_automute(codec);
8104 }
8105
8106 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8107 {
8108         unsigned int present;
8109         unsigned char bits;
8110
8111         present = snd_hda_codec_read(codec, 0x14, 0,
8112                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8113         bits = present ? HDA_AMP_MUTE : 0;
8114         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8115                                  HDA_AMP_MUTE, bits);
8116 }
8117
8118 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8119 {
8120         unsigned int present;
8121         unsigned char bits;
8122
8123         present = snd_hda_codec_read(codec, 0x1b, 0,
8124                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8125         bits = present ? HDA_AMP_MUTE : 0;
8126         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8127                                  HDA_AMP_MUTE, bits);
8128         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8129                                  HDA_AMP_MUTE, bits);
8130 }
8131
8132 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8133                                            unsigned int res)
8134 {
8135         if ((res >> 26) == ALC880_HP_EVENT)
8136                 alc883_lenovo_101e_all_automute(codec);
8137         if ((res >> 26) == ALC880_FRONT_EVENT)
8138                 alc883_lenovo_101e_ispeaker_automute(codec);
8139 }
8140
8141 /* toggle speaker-output according to the hp-jack state */
8142 static void alc883_acer_aspire_automute(struct hda_codec *codec)
8143 {
8144         unsigned int present;
8145
8146         present = snd_hda_codec_read(codec, 0x14, 0,
8147                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8148         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8149                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8150         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8151                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8152 }
8153
8154 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
8155                                            unsigned int res)
8156 {
8157         if ((res >> 26) == ALC880_HP_EVENT)
8158                 alc883_acer_aspire_automute(codec);
8159 }
8160
8161 static struct hda_verb alc883_acer_eapd_verbs[] = {
8162         /* HP Pin: output 0 (0x0c) */
8163         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8164         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8165         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8166         /* Front Pin: output 0 (0x0c) */
8167         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8168         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8169         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8170         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
8171         /* eanable EAPD on medion laptop */
8172         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8173         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8174         /* enable unsolicited event */
8175         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8176         { }
8177 };
8178
8179 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
8180 {
8181         unsigned int present;
8182
8183         present = snd_hda_codec_read(codec, 0x1b, 0,
8184                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8185         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8186                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8187         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8188                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8189         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8190                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8191         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8192                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8193 }
8194
8195 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
8196                                              unsigned int res)
8197 {
8198         switch (res >> 26) {
8199         case ALC880_HP_EVENT:
8200                 printk("hp_event\n");
8201                 alc888_6st_dell_front_automute(codec);
8202                 break;
8203         }
8204 }
8205
8206 static void alc888_lenovo_sky_front_automute(struct hda_codec *codec)
8207 {
8208         unsigned int mute;
8209         unsigned int present;
8210
8211         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8212         present = snd_hda_codec_read(codec, 0x1b, 0,
8213                                      AC_VERB_GET_PIN_SENSE, 0);
8214         present = (present & 0x80000000) != 0;
8215         if (present) {
8216                 /* mute internal speaker */
8217                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8218                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8219                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8220                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8221                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8222                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8223                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8224                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8225                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8226                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8227         } else {
8228                 /* unmute internal speaker if necessary */
8229                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8230                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8231                                          HDA_AMP_MUTE, mute);
8232                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8233                                          HDA_AMP_MUTE, mute);
8234                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8235                                          HDA_AMP_MUTE, mute);
8236                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8237                                          HDA_AMP_MUTE, mute);
8238                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8239                                          HDA_AMP_MUTE, mute);
8240         }
8241 }
8242
8243 static void alc883_lenovo_sky_unsol_event(struct hda_codec *codec,
8244                                              unsigned int res)
8245 {
8246         if ((res >> 26) == ALC880_HP_EVENT)
8247                 alc888_lenovo_sky_front_automute(codec);
8248 }
8249
8250 /*
8251  * generic initialization of ADC, input mixers and output mixers
8252  */
8253 static struct hda_verb alc883_auto_init_verbs[] = {
8254         /*
8255          * Unmute ADC0-2 and set the default input to mic-in
8256          */
8257         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8258         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8259         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8260         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8261
8262         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8263          * mixer widget
8264          * Note: PASD motherboards uses the Line In 2 as the input for
8265          * front panel mic (mic 2)
8266          */
8267         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8268         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8269         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8270         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8271         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8272         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8273
8274         /*
8275          * Set up output mixers (0x0c - 0x0f)
8276          */
8277         /* set vol=0 to output mixers */
8278         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8279         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8280         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8281         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8282         /* set up input amps for analog loopback */
8283         /* Amp Indices: DAC = 0, mixer = 1 */
8284         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8285         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8286         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8287         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8288         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8289         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8290         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8291         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8292         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8293         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8294
8295         /* FIXME: use matrix-type input source selection */
8296         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8297         /* Input mixer1 */
8298         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8299         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8300         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8301         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8302         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8303         /* Input mixer2 */
8304         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8305         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8306         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8307         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8308         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8309
8310         { }
8311 };
8312
8313 static struct hda_verb alc888_asus_m90v_verbs[] = {
8314         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8315         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8316         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8317         /* enable unsolicited event */
8318         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8319         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8320         { } /* end */
8321 };
8322
8323 static void alc883_nb_mic_automute(struct hda_codec *codec)
8324 {
8325         unsigned int present;
8326
8327         present = snd_hda_codec_read(codec, 0x18, 0,
8328                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8329         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8330                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
8331         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8332                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
8333 }
8334
8335 static void alc883_M90V_speaker_automute(struct hda_codec *codec)
8336 {
8337         unsigned int present;
8338         unsigned char bits;
8339
8340         present = snd_hda_codec_read(codec, 0x1b, 0,
8341                                      AC_VERB_GET_PIN_SENSE, 0)
8342                 & AC_PINSENSE_PRESENCE;
8343         bits = present ? 0 : PIN_OUT;
8344         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8345                             bits);
8346         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8347                             bits);
8348         snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8349                             bits);
8350 }
8351
8352 static void alc883_mode2_unsol_event(struct hda_codec *codec,
8353                                            unsigned int res)
8354 {
8355         switch (res >> 26) {
8356         case ALC880_HP_EVENT:
8357                 alc883_M90V_speaker_automute(codec);
8358                 break;
8359         case ALC880_MIC_EVENT:
8360                 alc883_nb_mic_automute(codec);
8361                 break;
8362         }
8363 }
8364
8365 static void alc883_mode2_inithook(struct hda_codec *codec)
8366 {
8367         alc883_M90V_speaker_automute(codec);
8368         alc883_nb_mic_automute(codec);
8369 }
8370
8371 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8372         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8373         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8374         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8375         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8376         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8377         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8378         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8379         /* enable unsolicited event */
8380         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8381         { } /* end */
8382 };
8383
8384 static void alc883_eee1601_speaker_automute(struct hda_codec *codec)
8385 {
8386         unsigned int present;
8387         unsigned char bits;
8388
8389         present = snd_hda_codec_read(codec, 0x14, 0,
8390                                      AC_VERB_GET_PIN_SENSE, 0)
8391                 & AC_PINSENSE_PRESENCE;
8392         bits = present ? 0 : PIN_OUT;
8393         snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8394                             bits);
8395 }
8396
8397 static void alc883_eee1601_unsol_event(struct hda_codec *codec,
8398                                            unsigned int res)
8399 {
8400         switch (res >> 26) {
8401         case ALC880_HP_EVENT:
8402                 alc883_eee1601_speaker_automute(codec);
8403                 break;
8404         }
8405 }
8406
8407 static void alc883_eee1601_inithook(struct hda_codec *codec)
8408 {
8409         alc883_eee1601_speaker_automute(codec);
8410 }
8411
8412 #ifdef CONFIG_SND_HDA_POWER_SAVE
8413 #define alc883_loopbacks        alc880_loopbacks
8414 #endif
8415
8416 /* pcm configuration: identiacal with ALC880 */
8417 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
8418 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
8419 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
8420 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
8421 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
8422
8423 /*
8424  * configuration and preset
8425  */
8426 static const char *alc883_models[ALC883_MODEL_LAST] = {
8427         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
8428         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8429         [ALC883_3ST_6ch]        = "3stack-6ch",
8430         [ALC883_6ST_DIG]        = "6stack-dig",
8431         [ALC883_TARGA_DIG]      = "targa-dig",
8432         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8433         [ALC883_ACER]           = "acer",
8434         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8435         [ALC888_ACER_ASPIRE_4930G]      = "acer-aspire-4930g",
8436         [ALC883_MEDION]         = "medion",
8437         [ALC883_MEDION_MD2]     = "medion-md2",
8438         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8439         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8440         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8441         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8442         [ALC888_LENOVO_SKY] = "lenovo-sky",
8443         [ALC883_HAIER_W66]      = "haier-w66",
8444         [ALC888_3ST_HP]         = "3stack-hp",
8445         [ALC888_6ST_DELL]       = "6stack-dell",
8446         [ALC883_MITAC]          = "mitac",
8447         [ALC883_CLEVO_M720]     = "clevo-m720",
8448         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8449         [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
8450         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8451         [ALC1200_ASUS_P5Q]      = "asus-p5q",
8452         [ALC883_AUTO]           = "auto",
8453 };
8454
8455 static struct snd_pci_quirk alc883_cfg_tbl[] = {
8456         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
8457         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8458         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
8459         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8460         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8461         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8462         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
8463                 ALC888_ACER_ASPIRE_4930G),
8464         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
8465         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8466         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8467         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8468         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8469         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8470         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8471         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8472         SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
8473         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8474         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8475         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
8476         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8477         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8478         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
8479         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8480         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
8481         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8482         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8483         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8484         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8485         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8486         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8487         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8488         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8489         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8490         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8491         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8492         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8493         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8494         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8495         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8496         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8497         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8498         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8499         SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
8500         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8501         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8502         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8503         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8504         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8505         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8506         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8507         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
8508         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8509         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8510         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
8511         SND_PCI_QUIRK(0x1734, 0x113d, "Fujitsu AMILO Xa3530",
8512                 ALC888_FUJITSU_XA3530),
8513         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8514         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8515         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8516         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8517         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
8518         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8519         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
8520         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8521         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8522         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8523         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8524         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8525         {}
8526 };
8527
8528 static struct alc_config_preset alc883_presets[] = {
8529         [ALC883_3ST_2ch_DIG] = {
8530                 .mixers = { alc883_3ST_2ch_mixer },
8531                 .init_verbs = { alc883_init_verbs },
8532                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8533                 .dac_nids = alc883_dac_nids,
8534                 .dig_out_nid = ALC883_DIGOUT_NID,
8535                 .dig_in_nid = ALC883_DIGIN_NID,
8536                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8537                 .channel_mode = alc883_3ST_2ch_modes,
8538                 .input_mux = &alc883_capture_source,
8539         },
8540         [ALC883_3ST_6ch_DIG] = {
8541                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8542                 .init_verbs = { alc883_init_verbs },
8543                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8544                 .dac_nids = alc883_dac_nids,
8545                 .dig_out_nid = ALC883_DIGOUT_NID,
8546                 .dig_in_nid = ALC883_DIGIN_NID,
8547                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8548                 .channel_mode = alc883_3ST_6ch_modes,
8549                 .need_dac_fix = 1,
8550                 .input_mux = &alc883_capture_source,
8551         },
8552         [ALC883_3ST_6ch] = {
8553                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8554                 .init_verbs = { alc883_init_verbs },
8555                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8556                 .dac_nids = alc883_dac_nids,
8557                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8558                 .channel_mode = alc883_3ST_6ch_modes,
8559                 .need_dac_fix = 1,
8560                 .input_mux = &alc883_capture_source,
8561         },
8562         [ALC883_3ST_6ch_INTEL] = {
8563                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
8564                 .init_verbs = { alc883_init_verbs },
8565                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8566                 .dac_nids = alc883_dac_nids,
8567                 .dig_out_nid = ALC883_DIGOUT_NID,
8568                 .dig_in_nid = ALC883_DIGIN_NID,
8569                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
8570                 .channel_mode = alc883_3ST_6ch_intel_modes,
8571                 .need_dac_fix = 1,
8572                 .input_mux = &alc883_3stack_6ch_intel,
8573         },
8574         [ALC883_6ST_DIG] = {
8575                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8576                 .init_verbs = { alc883_init_verbs },
8577                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8578                 .dac_nids = alc883_dac_nids,
8579                 .dig_out_nid = ALC883_DIGOUT_NID,
8580                 .dig_in_nid = ALC883_DIGIN_NID,
8581                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8582                 .channel_mode = alc883_sixstack_modes,
8583                 .input_mux = &alc883_capture_source,
8584         },
8585         [ALC883_TARGA_DIG] = {
8586                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
8587                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8588                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8589                 .dac_nids = alc883_dac_nids,
8590                 .dig_out_nid = ALC883_DIGOUT_NID,
8591                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8592                 .channel_mode = alc883_3ST_6ch_modes,
8593                 .need_dac_fix = 1,
8594                 .input_mux = &alc883_capture_source,
8595                 .unsol_event = alc883_tagra_unsol_event,
8596                 .init_hook = alc883_tagra_automute,
8597         },
8598         [ALC883_TARGA_2ch_DIG] = {
8599                 .mixers = { alc883_tagra_2ch_mixer},
8600                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8601                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8602                 .dac_nids = alc883_dac_nids,
8603                 .adc_nids = alc883_adc_nids_alt,
8604                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8605                 .dig_out_nid = ALC883_DIGOUT_NID,
8606                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8607                 .channel_mode = alc883_3ST_2ch_modes,
8608                 .input_mux = &alc883_capture_source,
8609                 .unsol_event = alc883_tagra_unsol_event,
8610                 .init_hook = alc883_tagra_automute,
8611         },
8612         [ALC883_ACER] = {
8613                 .mixers = { alc883_base_mixer },
8614                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
8615                  * and the headphone jack.  Turn this on and rely on the
8616                  * standard mute methods whenever the user wants to turn
8617                  * these outputs off.
8618                  */
8619                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
8620                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8621                 .dac_nids = alc883_dac_nids,
8622                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8623                 .channel_mode = alc883_3ST_2ch_modes,
8624                 .input_mux = &alc883_capture_source,
8625         },
8626         [ALC883_ACER_ASPIRE] = {
8627                 .mixers = { alc883_acer_aspire_mixer },
8628                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
8629                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8630                 .dac_nids = alc883_dac_nids,
8631                 .dig_out_nid = ALC883_DIGOUT_NID,
8632                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8633                 .channel_mode = alc883_3ST_2ch_modes,
8634                 .input_mux = &alc883_capture_source,
8635                 .unsol_event = alc883_acer_aspire_unsol_event,
8636                 .init_hook = alc883_acer_aspire_automute,
8637         },
8638         [ALC888_ACER_ASPIRE_4930G] = {
8639                 .mixers = { alc888_base_mixer,
8640                                 alc883_chmode_mixer },
8641                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
8642                                 alc888_acer_aspire_4930g_verbs },
8643                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8644                 .dac_nids = alc883_dac_nids,
8645                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
8646                 .adc_nids = alc883_adc_nids_rev,
8647                 .capsrc_nids = alc883_capsrc_nids_rev,
8648                 .dig_out_nid = ALC883_DIGOUT_NID,
8649                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8650                 .channel_mode = alc883_3ST_6ch_modes,
8651                 .need_dac_fix = 1,
8652                 .num_mux_defs =
8653                         ARRAY_SIZE(alc888_2_capture_sources),
8654                 .input_mux = alc888_2_capture_sources,
8655                 .unsol_event = alc888_acer_aspire_4930g_unsol_event,
8656                 .init_hook = alc888_acer_aspire_4930g_automute,
8657         },
8658         [ALC883_MEDION] = {
8659                 .mixers = { alc883_fivestack_mixer,
8660                             alc883_chmode_mixer },
8661                 .init_verbs = { alc883_init_verbs,
8662                                 alc883_medion_eapd_verbs },
8663                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8664                 .dac_nids = alc883_dac_nids,
8665                 .adc_nids = alc883_adc_nids_alt,
8666                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8667                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8668                 .channel_mode = alc883_sixstack_modes,
8669                 .input_mux = &alc883_capture_source,
8670         },
8671         [ALC883_MEDION_MD2] = {
8672                 .mixers = { alc883_medion_md2_mixer},
8673                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
8674                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8675                 .dac_nids = alc883_dac_nids,
8676                 .dig_out_nid = ALC883_DIGOUT_NID,
8677                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8678                 .channel_mode = alc883_3ST_2ch_modes,
8679                 .input_mux = &alc883_capture_source,
8680                 .unsol_event = alc883_medion_md2_unsol_event,
8681                 .init_hook = alc883_medion_md2_automute,
8682         },
8683         [ALC883_LAPTOP_EAPD] = {
8684                 .mixers = { alc883_base_mixer },
8685                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
8686                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8687                 .dac_nids = alc883_dac_nids,
8688                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8689                 .channel_mode = alc883_3ST_2ch_modes,
8690                 .input_mux = &alc883_capture_source,
8691         },
8692         [ALC883_CLEVO_M720] = {
8693                 .mixers = { alc883_clevo_m720_mixer },
8694                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
8695                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8696                 .dac_nids = alc883_dac_nids,
8697                 .dig_out_nid = ALC883_DIGOUT_NID,
8698                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8699                 .channel_mode = alc883_3ST_2ch_modes,
8700                 .input_mux = &alc883_capture_source,
8701                 .unsol_event = alc883_clevo_m720_unsol_event,
8702                 .init_hook = alc883_clevo_m720_automute,
8703         },
8704         [ALC883_LENOVO_101E_2ch] = {
8705                 .mixers = { alc883_lenovo_101e_2ch_mixer},
8706                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
8707                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8708                 .dac_nids = alc883_dac_nids,
8709                 .adc_nids = alc883_adc_nids_alt,
8710                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8711                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8712                 .channel_mode = alc883_3ST_2ch_modes,
8713                 .input_mux = &alc883_lenovo_101e_capture_source,
8714                 .unsol_event = alc883_lenovo_101e_unsol_event,
8715                 .init_hook = alc883_lenovo_101e_all_automute,
8716         },
8717         [ALC883_LENOVO_NB0763] = {
8718                 .mixers = { alc883_lenovo_nb0763_mixer },
8719                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
8720                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8721                 .dac_nids = alc883_dac_nids,
8722                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8723                 .channel_mode = alc883_3ST_2ch_modes,
8724                 .need_dac_fix = 1,
8725                 .input_mux = &alc883_lenovo_nb0763_capture_source,
8726                 .unsol_event = alc883_medion_md2_unsol_event,
8727                 .init_hook = alc883_medion_md2_automute,
8728         },
8729         [ALC888_LENOVO_MS7195_DIG] = {
8730                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8731                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
8732                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8733                 .dac_nids = alc883_dac_nids,
8734                 .dig_out_nid = ALC883_DIGOUT_NID,
8735                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8736                 .channel_mode = alc883_3ST_6ch_modes,
8737                 .need_dac_fix = 1,
8738                 .input_mux = &alc883_capture_source,
8739                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
8740                 .init_hook = alc888_lenovo_ms7195_front_automute,
8741         },
8742         [ALC883_HAIER_W66] = {
8743                 .mixers = { alc883_tagra_2ch_mixer},
8744                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
8745                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8746                 .dac_nids = alc883_dac_nids,
8747                 .dig_out_nid = ALC883_DIGOUT_NID,
8748                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8749                 .channel_mode = alc883_3ST_2ch_modes,
8750                 .input_mux = &alc883_capture_source,
8751                 .unsol_event = alc883_haier_w66_unsol_event,
8752                 .init_hook = alc883_haier_w66_automute,
8753         },
8754         [ALC888_3ST_HP] = {
8755                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8756                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
8757                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8758                 .dac_nids = alc883_dac_nids,
8759                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
8760                 .channel_mode = alc888_3st_hp_modes,
8761                 .need_dac_fix = 1,
8762                 .input_mux = &alc883_capture_source,
8763         },
8764         [ALC888_6ST_DELL] = {
8765                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8766                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
8767                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8768                 .dac_nids = alc883_dac_nids,
8769                 .dig_out_nid = ALC883_DIGOUT_NID,
8770                 .dig_in_nid = ALC883_DIGIN_NID,
8771                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8772                 .channel_mode = alc883_sixstack_modes,
8773                 .input_mux = &alc883_capture_source,
8774                 .unsol_event = alc888_6st_dell_unsol_event,
8775                 .init_hook = alc888_6st_dell_front_automute,
8776         },
8777         [ALC883_MITAC] = {
8778                 .mixers = { alc883_mitac_mixer },
8779                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
8780                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8781                 .dac_nids = alc883_dac_nids,
8782                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8783                 .channel_mode = alc883_3ST_2ch_modes,
8784                 .input_mux = &alc883_capture_source,
8785                 .unsol_event = alc883_mitac_unsol_event,
8786                 .init_hook = alc883_mitac_automute,
8787         },
8788         [ALC883_FUJITSU_PI2515] = {
8789                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
8790                 .init_verbs = { alc883_init_verbs,
8791                                 alc883_2ch_fujitsu_pi2515_verbs},
8792                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8793                 .dac_nids = alc883_dac_nids,
8794                 .dig_out_nid = ALC883_DIGOUT_NID,
8795                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8796                 .channel_mode = alc883_3ST_2ch_modes,
8797                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8798                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8799                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8800         },
8801         [ALC888_FUJITSU_XA3530] = {
8802                 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
8803                 .init_verbs = { alc883_init_verbs,
8804                         alc888_fujitsu_xa3530_verbs },
8805                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8806                 .dac_nids = alc883_dac_nids,
8807                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
8808                 .adc_nids = alc883_adc_nids_rev,
8809                 .capsrc_nids = alc883_capsrc_nids_rev,
8810                 .dig_out_nid = ALC883_DIGOUT_NID,
8811                 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
8812                 .channel_mode = alc888_4ST_8ch_intel_modes,
8813                 .num_mux_defs =
8814                         ARRAY_SIZE(alc888_2_capture_sources),
8815                 .input_mux = alc888_2_capture_sources,
8816                 .unsol_event = alc888_fujitsu_xa3530_unsol_event,
8817                 .init_hook = alc888_fujitsu_xa3530_automute,
8818         },
8819         [ALC888_LENOVO_SKY] = {
8820                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
8821                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
8822                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8823                 .dac_nids = alc883_dac_nids,
8824                 .dig_out_nid = ALC883_DIGOUT_NID,
8825                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8826                 .channel_mode = alc883_sixstack_modes,
8827                 .need_dac_fix = 1,
8828                 .input_mux = &alc883_lenovo_sky_capture_source,
8829                 .unsol_event = alc883_lenovo_sky_unsol_event,
8830                 .init_hook = alc888_lenovo_sky_front_automute,
8831         },
8832         [ALC888_ASUS_M90V] = {
8833                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8834                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
8835                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8836                 .dac_nids = alc883_dac_nids,
8837                 .dig_out_nid = ALC883_DIGOUT_NID,
8838                 .dig_in_nid = ALC883_DIGIN_NID,
8839                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8840                 .channel_mode = alc883_3ST_6ch_modes,
8841                 .need_dac_fix = 1,
8842                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8843                 .unsol_event = alc883_mode2_unsol_event,
8844                 .init_hook = alc883_mode2_inithook,
8845         },
8846         [ALC888_ASUS_EEE1601] = {
8847                 .mixers = { alc883_asus_eee1601_mixer },
8848                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
8849                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
8850                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8851                 .dac_nids = alc883_dac_nids,
8852                 .dig_out_nid = ALC883_DIGOUT_NID,
8853                 .dig_in_nid = ALC883_DIGIN_NID,
8854                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8855                 .channel_mode = alc883_3ST_2ch_modes,
8856                 .need_dac_fix = 1,
8857                 .input_mux = &alc883_asus_eee1601_capture_source,
8858                 .unsol_event = alc883_eee1601_unsol_event,
8859                 .init_hook = alc883_eee1601_inithook,
8860         },
8861         [ALC1200_ASUS_P5Q] = {
8862                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8863                 .init_verbs = { alc883_init_verbs },
8864                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8865                 .dac_nids = alc883_dac_nids,
8866                 .dig_out_nid = ALC1200_DIGOUT_NID,
8867                 .dig_in_nid = ALC883_DIGIN_NID,
8868                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8869                 .channel_mode = alc883_sixstack_modes,
8870                 .input_mux = &alc883_capture_source,
8871         },
8872 };
8873
8874
8875 /*
8876  * BIOS auto configuration
8877  */
8878 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
8879                                               hda_nid_t nid, int pin_type,
8880                                               int dac_idx)
8881 {
8882         /* set as output */
8883         struct alc_spec *spec = codec->spec;
8884         int idx;
8885
8886         alc_set_pin_output(codec, nid, pin_type);
8887         if (spec->multiout.dac_nids[dac_idx] == 0x25)
8888                 idx = 4;
8889         else
8890                 idx = spec->multiout.dac_nids[dac_idx] - 2;
8891         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
8892
8893 }
8894
8895 static void alc883_auto_init_multi_out(struct hda_codec *codec)
8896 {
8897         struct alc_spec *spec = codec->spec;
8898         int i;
8899
8900         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
8901         for (i = 0; i <= HDA_SIDE; i++) {
8902                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
8903                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
8904                 if (nid)
8905                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
8906                                                           i);
8907         }
8908 }
8909
8910 static void alc883_auto_init_hp_out(struct hda_codec *codec)
8911 {
8912         struct alc_spec *spec = codec->spec;
8913         hda_nid_t pin;
8914
8915         pin = spec->autocfg.hp_pins[0];
8916         if (pin) /* connect to front */
8917                 /* use dac 0 */
8918                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8919         pin = spec->autocfg.speaker_pins[0];
8920         if (pin)
8921                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
8922 }
8923
8924 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
8925 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
8926
8927 static void alc883_auto_init_analog_input(struct hda_codec *codec)
8928 {
8929         struct alc_spec *spec = codec->spec;
8930         int i;
8931
8932         for (i = 0; i < AUTO_PIN_LAST; i++) {
8933                 hda_nid_t nid = spec->autocfg.input_pins[i];
8934                 if (alc883_is_input_pin(nid)) {
8935                         snd_hda_codec_write(codec, nid, 0,
8936                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
8937                                             (i <= AUTO_PIN_FRONT_MIC ?
8938                                              PIN_VREF80 : PIN_IN));
8939                         if (nid != ALC883_PIN_CD_NID)
8940                                 snd_hda_codec_write(codec, nid, 0,
8941                                                     AC_VERB_SET_AMP_GAIN_MUTE,
8942                                                     AMP_OUT_MUTE);
8943                 }
8944         }
8945 }
8946
8947 #define alc883_auto_init_input_src      alc882_auto_init_input_src
8948
8949 /* almost identical with ALC880 parser... */
8950 static int alc883_parse_auto_config(struct hda_codec *codec)
8951 {
8952         struct alc_spec *spec = codec->spec;
8953         int err = alc880_parse_auto_config(codec);
8954
8955         if (err < 0)
8956                 return err;
8957         else if (!err)
8958                 return 0; /* no config found */
8959
8960         err = alc_auto_add_mic_boost(codec);
8961         if (err < 0)
8962                 return err;
8963
8964         /* hack - override the init verbs */
8965         spec->init_verbs[0] = alc883_auto_init_verbs;
8966
8967         return 1; /* config found */
8968 }
8969
8970 /* additional initialization for auto-configuration model */
8971 static void alc883_auto_init(struct hda_codec *codec)
8972 {
8973         struct alc_spec *spec = codec->spec;
8974         alc883_auto_init_multi_out(codec);
8975         alc883_auto_init_hp_out(codec);
8976         alc883_auto_init_analog_input(codec);
8977         alc883_auto_init_input_src(codec);
8978         if (spec->unsol_event)
8979                 alc_inithook(codec);
8980 }
8981
8982 static int patch_alc883(struct hda_codec *codec)
8983 {
8984         struct alc_spec *spec;
8985         int err, board_config;
8986
8987         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8988         if (spec == NULL)
8989                 return -ENOMEM;
8990
8991         codec->spec = spec;
8992
8993         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
8994
8995         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
8996                                                   alc883_models,
8997                                                   alc883_cfg_tbl);
8998         if (board_config < 0) {
8999                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
9000                        "trying auto-probe from BIOS...\n");
9001                 board_config = ALC883_AUTO;
9002         }
9003
9004         if (board_config == ALC883_AUTO) {
9005                 /* automatic parse from the BIOS config */
9006                 err = alc883_parse_auto_config(codec);
9007                 if (err < 0) {
9008                         alc_free(codec);
9009                         return err;
9010                 } else if (!err) {
9011                         printk(KERN_INFO
9012                                "hda_codec: Cannot set up configuration "
9013                                "from BIOS.  Using base mode...\n");
9014                         board_config = ALC883_3ST_2ch_DIG;
9015                 }
9016         }
9017
9018         if (board_config != ALC883_AUTO)
9019                 setup_preset(spec, &alc883_presets[board_config]);
9020
9021         switch (codec->vendor_id) {
9022         case 0x10ec0888:
9023                 if (codec->revision_id == 0x100101) {
9024                         spec->stream_name_analog = "ALC1200 Analog";
9025                         spec->stream_name_digital = "ALC1200 Digital";
9026                 } else {
9027                         spec->stream_name_analog = "ALC888 Analog";
9028                         spec->stream_name_digital = "ALC888 Digital";
9029                 }
9030                 break;
9031         case 0x10ec0889:
9032                 spec->stream_name_analog = "ALC889 Analog";
9033                 spec->stream_name_digital = "ALC889 Digital";
9034                 break;
9035         default:
9036                 spec->stream_name_analog = "ALC883 Analog";
9037                 spec->stream_name_digital = "ALC883 Digital";
9038                 break;
9039         }
9040
9041         spec->stream_analog_playback = &alc883_pcm_analog_playback;
9042         spec->stream_analog_capture = &alc883_pcm_analog_capture;
9043         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
9044
9045         spec->stream_digital_playback = &alc883_pcm_digital_playback;
9046         spec->stream_digital_capture = &alc883_pcm_digital_capture;
9047
9048         if (!spec->num_adc_nids) {
9049                 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9050                 spec->adc_nids = alc883_adc_nids;
9051         }
9052         if (!spec->capsrc_nids)
9053                 spec->capsrc_nids = alc883_capsrc_nids;
9054         spec->is_mix_capture = 1; /* matrix-style capture */
9055         if (!spec->cap_mixer)
9056                 set_capture_mixer(spec);
9057
9058         spec->vmaster_nid = 0x0c;
9059
9060         codec->patch_ops = alc_patch_ops;
9061         if (board_config == ALC883_AUTO)
9062                 spec->init_hook = alc883_auto_init;
9063
9064 #ifdef CONFIG_SND_HDA_POWER_SAVE
9065         if (!spec->loopback.amplist)
9066                 spec->loopback.amplist = alc883_loopbacks;
9067 #endif
9068         codec->proc_widget_hook = print_realtek_coef;
9069
9070         return 0;
9071 }
9072
9073 /*
9074  * ALC262 support
9075  */
9076
9077 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
9078 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
9079
9080 #define alc262_dac_nids         alc260_dac_nids
9081 #define alc262_adc_nids         alc882_adc_nids
9082 #define alc262_adc_nids_alt     alc882_adc_nids_alt
9083 #define alc262_capsrc_nids      alc882_capsrc_nids
9084 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
9085
9086 #define alc262_modes            alc260_modes
9087 #define alc262_capture_source   alc882_capture_source
9088
9089 static hda_nid_t alc262_dmic_adc_nids[1] = {
9090         /* ADC0 */
9091         0x09
9092 };
9093
9094 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
9095
9096 static struct snd_kcontrol_new alc262_base_mixer[] = {
9097         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9098         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9099         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9100         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9101         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9102         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9103         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9104         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9105         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9106         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9107         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9108         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9109         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9110            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
9111         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
9112         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9113         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9114         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
9115         { } /* end */
9116 };
9117
9118 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
9119         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9120         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9121         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9122         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9123         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9124         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9125         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9126         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9127         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9128         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9129         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9130         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9131         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9132            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
9133         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
9134         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9135         { } /* end */
9136 };
9137
9138 /* update HP, line and mono-out pins according to the master switch */
9139 static void alc262_hp_master_update(struct hda_codec *codec)
9140 {
9141         struct alc_spec *spec = codec->spec;
9142         int val = spec->master_sw;
9143
9144         /* HP & line-out */
9145         snd_hda_codec_write_cache(codec, 0x1b, 0,
9146                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9147                                   val ? PIN_HP : 0);
9148         snd_hda_codec_write_cache(codec, 0x15, 0,
9149                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9150                                   val ? PIN_HP : 0);
9151         /* mono (speaker) depending on the HP jack sense */
9152         val = val && !spec->jack_present;
9153         snd_hda_codec_write_cache(codec, 0x16, 0,
9154                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9155                                   val ? PIN_OUT : 0);
9156 }
9157
9158 static void alc262_hp_bpc_automute(struct hda_codec *codec)
9159 {
9160         struct alc_spec *spec = codec->spec;
9161         unsigned int presence;
9162         presence = snd_hda_codec_read(codec, 0x1b, 0,
9163                                       AC_VERB_GET_PIN_SENSE, 0);
9164         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9165         alc262_hp_master_update(codec);
9166 }
9167
9168 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
9169 {
9170         if ((res >> 26) != ALC880_HP_EVENT)
9171                 return;
9172         alc262_hp_bpc_automute(codec);
9173 }
9174
9175 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
9176 {
9177         struct alc_spec *spec = codec->spec;
9178         unsigned int presence;
9179         presence = snd_hda_codec_read(codec, 0x15, 0,
9180                                       AC_VERB_GET_PIN_SENSE, 0);
9181         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9182         alc262_hp_master_update(codec);
9183 }
9184
9185 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
9186                                            unsigned int res)
9187 {
9188         if ((res >> 26) != ALC880_HP_EVENT)
9189                 return;
9190         alc262_hp_wildwest_automute(codec);
9191 }
9192
9193 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
9194                                    struct snd_ctl_elem_value *ucontrol)
9195 {
9196         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9197         struct alc_spec *spec = codec->spec;
9198         *ucontrol->value.integer.value = spec->master_sw;
9199         return 0;
9200 }
9201
9202 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
9203                                    struct snd_ctl_elem_value *ucontrol)
9204 {
9205         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9206         struct alc_spec *spec = codec->spec;
9207         int val = !!*ucontrol->value.integer.value;
9208
9209         if (val == spec->master_sw)
9210                 return 0;
9211         spec->master_sw = val;
9212         alc262_hp_master_update(codec);
9213         return 1;
9214 }
9215
9216 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
9217         {
9218                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9219                 .name = "Master Playback Switch",
9220                 .info = snd_ctl_boolean_mono_info,
9221                 .get = alc262_hp_master_sw_get,
9222                 .put = alc262_hp_master_sw_put,
9223         },
9224         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9225         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9226         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9227         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9228                               HDA_OUTPUT),
9229         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9230                             HDA_OUTPUT),
9231         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9232         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9233         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9234         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9235         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9236         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9237         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9238         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9239         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9240         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9241         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9242         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9243         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
9244         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
9245         { } /* end */
9246 };
9247
9248 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
9249         {
9250                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9251                 .name = "Master Playback Switch",
9252                 .info = snd_ctl_boolean_mono_info,
9253                 .get = alc262_hp_master_sw_get,
9254                 .put = alc262_hp_master_sw_put,
9255         },
9256         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9257         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9258         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9259         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9260         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9261                               HDA_OUTPUT),
9262         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9263                             HDA_OUTPUT),
9264         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
9265         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
9266         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
9267         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9268         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9269         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9270         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9271         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9272         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9273         { } /* end */
9274 };
9275
9276 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
9277         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9278         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9279         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
9280         { } /* end */
9281 };
9282
9283 /* mute/unmute internal speaker according to the hp jack and mute state */
9284 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
9285 {
9286         struct alc_spec *spec = codec->spec;
9287
9288         if (force || !spec->sense_updated) {
9289                 unsigned int present;
9290                 present = snd_hda_codec_read(codec, 0x15, 0,
9291                                              AC_VERB_GET_PIN_SENSE, 0);
9292                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9293                 spec->sense_updated = 1;
9294         }
9295         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
9296                                  spec->jack_present ? HDA_AMP_MUTE : 0);
9297 }
9298
9299 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
9300                                         unsigned int res)
9301 {
9302         if ((res >> 26) != ALC880_HP_EVENT)
9303                 return;
9304         alc262_hp_t5735_automute(codec, 1);
9305 }
9306
9307 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
9308 {
9309         alc262_hp_t5735_automute(codec, 1);
9310 }
9311
9312 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
9313         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9314         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9315         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9316         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9317         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9318         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9319         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9320         { } /* end */
9321 };
9322
9323 static struct hda_verb alc262_hp_t5735_verbs[] = {
9324         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9325         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9326
9327         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9328         { }
9329 };
9330
9331 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
9332         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9333         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9334         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
9335         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
9336         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9337         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9338         { } /* end */
9339 };
9340
9341 static struct hda_verb alc262_hp_rp5700_verbs[] = {
9342         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9343         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9344         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9345         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9346         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9347         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9348         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9349         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9350         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9351         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9352         {}
9353 };
9354
9355 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
9356         .num_items = 1,
9357         .items = {
9358                 { "Line", 0x1 },
9359         },
9360 };
9361
9362 /* bind hp and internal speaker mute (with plug check) */
9363 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
9364                                      struct snd_ctl_elem_value *ucontrol)
9365 {
9366         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9367         long *valp = ucontrol->value.integer.value;
9368         int change;
9369
9370         /* change hp mute */
9371         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
9372                                           HDA_AMP_MUTE,
9373                                           valp[0] ? 0 : HDA_AMP_MUTE);
9374         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
9375                                            HDA_AMP_MUTE,
9376                                            valp[1] ? 0 : HDA_AMP_MUTE);
9377         if (change) {
9378                 /* change speaker according to HP jack state */
9379                 struct alc_spec *spec = codec->spec;
9380                 unsigned int mute;
9381                 if (spec->jack_present)
9382                         mute = HDA_AMP_MUTE;
9383                 else
9384                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
9385                                                       HDA_OUTPUT, 0);
9386                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9387                                          HDA_AMP_MUTE, mute);
9388         }
9389         return change;
9390 }
9391
9392 static struct snd_kcontrol_new alc262_sony_mixer[] = {
9393         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9394         {
9395                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9396                 .name = "Master Playback Switch",
9397                 .info = snd_hda_mixer_amp_switch_info,
9398                 .get = snd_hda_mixer_amp_switch_get,
9399                 .put = alc262_sony_master_sw_put,
9400                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9401         },
9402         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9403         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9404         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9405         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9406         { } /* end */
9407 };
9408
9409 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
9410         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9411         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9412         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9413         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9414         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9415         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9416         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9417         { } /* end */
9418 };
9419
9420 #define alc262_capture_mixer            alc882_capture_mixer
9421 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
9422
9423 /*
9424  * generic initialization of ADC, input mixers and output mixers
9425  */
9426 static struct hda_verb alc262_init_verbs[] = {
9427         /*
9428          * Unmute ADC0-2 and set the default input to mic-in
9429          */
9430         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9431         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9432         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9433         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9434         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9435         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9436
9437         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9438          * mixer widget
9439          * Note: PASD motherboards uses the Line In 2 as the input for
9440          * front panel mic (mic 2)
9441          */
9442         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9443         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9444         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9445         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9446         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9447         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9448
9449         /*
9450          * Set up output mixers (0x0c - 0x0e)
9451          */
9452         /* set vol=0 to output mixers */
9453         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9454         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9455         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9456         /* set up input amps for analog loopback */
9457         /* Amp Indices: DAC = 0, mixer = 1 */
9458         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9459         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9460         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9461         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9462         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9463         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9464
9465         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9466         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9467         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9468         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9469         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9470         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9471
9472         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9473         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9474         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9475         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9476         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9477
9478         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9479         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9480
9481         /* FIXME: use matrix-type input source selection */
9482         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9483         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9484         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9485         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9486         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9487         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9488         /* Input mixer2 */
9489         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9490         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9491         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9492         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9493         /* Input mixer3 */
9494         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9495         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9496         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9497         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9498
9499         { }
9500 };
9501
9502 static struct hda_verb alc262_eapd_verbs[] = {
9503         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9504         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9505         { }
9506 };
9507
9508 static struct hda_verb alc262_hippo_unsol_verbs[] = {
9509         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9510         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9511         {}
9512 };
9513
9514 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
9515         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9516         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9517         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9518
9519         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9520         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9521         {}
9522 };
9523
9524 static struct hda_verb alc262_sony_unsol_verbs[] = {
9525         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9526         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9527         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
9528
9529         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9530         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9531         {}
9532 };
9533
9534 static struct hda_input_mux alc262_dmic_capture_source = {
9535         .num_items = 2,
9536         .items = {
9537                 { "Int DMic", 0x9 },
9538                 { "Mic", 0x0 },
9539         },
9540 };
9541
9542 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
9543         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9544         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9545         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9546         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9547         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9548         { } /* end */
9549 };
9550
9551 static struct hda_verb alc262_toshiba_s06_verbs[] = {
9552         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9553         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9554         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9555         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9556         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
9557         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9558         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
9559         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9560         {}
9561 };
9562
9563 static void alc262_dmic_automute(struct hda_codec *codec)
9564 {
9565         unsigned int present;
9566
9567         present = snd_hda_codec_read(codec, 0x18, 0,
9568                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9569         snd_hda_codec_write(codec, 0x22, 0,
9570                                 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x09);
9571 }
9572
9573 /* toggle speaker-output according to the hp-jack state */
9574 static void alc262_toshiba_s06_speaker_automute(struct hda_codec *codec)
9575 {
9576         unsigned int present;
9577         unsigned char bits;
9578
9579         present = snd_hda_codec_read(codec, 0x15, 0,
9580                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9581         bits = present ? 0 : PIN_OUT;
9582         snd_hda_codec_write(codec, 0x14, 0,
9583                                         AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
9584 }
9585
9586
9587
9588 /* unsolicited event for HP jack sensing */
9589 static void alc262_toshiba_s06_unsol_event(struct hda_codec *codec,
9590                                        unsigned int res)
9591 {
9592         if ((res >> 26) == ALC880_HP_EVENT)
9593                 alc262_toshiba_s06_speaker_automute(codec);
9594         if ((res >> 26) == ALC880_MIC_EVENT)
9595                 alc262_dmic_automute(codec);
9596
9597 }
9598
9599 static void alc262_toshiba_s06_init_hook(struct hda_codec *codec)
9600 {
9601         alc262_toshiba_s06_speaker_automute(codec);
9602         alc262_dmic_automute(codec);
9603 }
9604
9605 /* mute/unmute internal speaker according to the hp jack and mute state */
9606 static void alc262_hippo_automute(struct hda_codec *codec)
9607 {
9608         struct alc_spec *spec = codec->spec;
9609         unsigned int mute;
9610         unsigned int present;
9611
9612         /* need to execute and sync at first */
9613         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9614         present = snd_hda_codec_read(codec, 0x15, 0,
9615                                      AC_VERB_GET_PIN_SENSE, 0);
9616         spec->jack_present = (present & 0x80000000) != 0;
9617         if (spec->jack_present) {
9618                 /* mute internal speaker */
9619                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9620                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9621         } else {
9622                 /* unmute internal speaker if necessary */
9623                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
9624                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9625                                          HDA_AMP_MUTE, mute);
9626         }
9627 }
9628
9629 /* unsolicited event for HP jack sensing */
9630 static void alc262_hippo_unsol_event(struct hda_codec *codec,
9631                                        unsigned int res)
9632 {
9633         if ((res >> 26) != ALC880_HP_EVENT)
9634                 return;
9635         alc262_hippo_automute(codec);
9636 }
9637
9638 static void alc262_hippo1_automute(struct hda_codec *codec)
9639 {
9640         unsigned int mute;
9641         unsigned int present;
9642
9643         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9644         present = snd_hda_codec_read(codec, 0x1b, 0,
9645                                      AC_VERB_GET_PIN_SENSE, 0);
9646         present = (present & 0x80000000) != 0;
9647         if (present) {
9648                 /* mute internal speaker */
9649                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9650                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9651         } else {
9652                 /* unmute internal speaker if necessary */
9653                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9654                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9655                                          HDA_AMP_MUTE, mute);
9656         }
9657 }
9658
9659 /* unsolicited event for HP jack sensing */
9660 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
9661                                        unsigned int res)
9662 {
9663         if ((res >> 26) != ALC880_HP_EVENT)
9664                 return;
9665         alc262_hippo1_automute(codec);
9666 }
9667
9668 /*
9669  * nec model
9670  *  0x15 = headphone
9671  *  0x16 = internal speaker
9672  *  0x18 = external mic
9673  */
9674
9675 static struct snd_kcontrol_new alc262_nec_mixer[] = {
9676         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9677         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
9678
9679         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9680         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9681         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9682
9683         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9684         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9685         { } /* end */
9686 };
9687
9688 static struct hda_verb alc262_nec_verbs[] = {
9689         /* Unmute Speaker */
9690         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9691
9692         /* Headphone */
9693         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9694         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9695
9696         /* External mic to headphone */
9697         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9698         /* External mic to speaker */
9699         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9700         {}
9701 };
9702
9703 /*
9704  * fujitsu model
9705  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
9706  *  0x1b = port replicator headphone out
9707  */
9708
9709 #define ALC_HP_EVENT    0x37
9710
9711 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
9712         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9713         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9714         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9715         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9716         {}
9717 };
9718
9719 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
9720         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9721         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9722         {}
9723 };
9724
9725 static struct hda_input_mux alc262_fujitsu_capture_source = {
9726         .num_items = 3,
9727         .items = {
9728                 { "Mic", 0x0 },
9729                 { "Int Mic", 0x1 },
9730                 { "CD", 0x4 },
9731         },
9732 };
9733
9734 static struct hda_input_mux alc262_HP_capture_source = {
9735         .num_items = 5,
9736         .items = {
9737                 { "Mic", 0x0 },
9738                 { "Front Mic", 0x1 },
9739                 { "Line", 0x2 },
9740                 { "CD", 0x4 },
9741                 { "AUX IN", 0x6 },
9742         },
9743 };
9744
9745 static struct hda_input_mux alc262_HP_D7000_capture_source = {
9746         .num_items = 4,
9747         .items = {
9748                 { "Mic", 0x0 },
9749                 { "Front Mic", 0x2 },
9750                 { "Line", 0x1 },
9751                 { "CD", 0x4 },
9752         },
9753 };
9754
9755 /* mute/unmute internal speaker according to the hp jacks and mute state */
9756 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
9757 {
9758         struct alc_spec *spec = codec->spec;
9759         unsigned int mute;
9760
9761         if (force || !spec->sense_updated) {
9762                 unsigned int present;
9763                 /* need to execute and sync at first */
9764                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
9765                 /* check laptop HP jack */
9766                 present = snd_hda_codec_read(codec, 0x14, 0,
9767                                              AC_VERB_GET_PIN_SENSE, 0);
9768                 /* need to execute and sync at first */
9769                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9770                 /* check docking HP jack */
9771                 present |= snd_hda_codec_read(codec, 0x1b, 0,
9772                                               AC_VERB_GET_PIN_SENSE, 0);
9773                 if (present & AC_PINSENSE_PRESENCE)
9774                         spec->jack_present = 1;
9775                 else
9776                         spec->jack_present = 0;
9777                 spec->sense_updated = 1;
9778         }
9779         /* unmute internal speaker only if both HPs are unplugged and
9780          * master switch is on
9781          */
9782         if (spec->jack_present)
9783                 mute = HDA_AMP_MUTE;
9784         else
9785                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9786         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9787                                  HDA_AMP_MUTE, mute);
9788 }
9789
9790 /* unsolicited event for HP jack sensing */
9791 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
9792                                        unsigned int res)
9793 {
9794         if ((res >> 26) != ALC_HP_EVENT)
9795                 return;
9796         alc262_fujitsu_automute(codec, 1);
9797 }
9798
9799 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
9800 {
9801         alc262_fujitsu_automute(codec, 1);
9802 }
9803
9804 /* bind volumes of both NID 0x0c and 0x0d */
9805 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
9806         .ops = &snd_hda_bind_vol,
9807         .values = {
9808                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
9809                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
9810                 0
9811         },
9812 };
9813
9814 /* mute/unmute internal speaker according to the hp jack and mute state */
9815 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
9816 {
9817         struct alc_spec *spec = codec->spec;
9818         unsigned int mute;
9819
9820         if (force || !spec->sense_updated) {
9821                 unsigned int present_int_hp;
9822                 /* need to execute and sync at first */
9823                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9824                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
9825                                         AC_VERB_GET_PIN_SENSE, 0);
9826                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
9827                 spec->sense_updated = 1;
9828         }
9829         if (spec->jack_present) {
9830                 /* mute internal speaker */
9831                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9832                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9833                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9834                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9835         } else {
9836                 /* unmute internal speaker if necessary */
9837                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9838                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9839                                          HDA_AMP_MUTE, mute);
9840                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9841                                          HDA_AMP_MUTE, mute);
9842         }
9843 }
9844
9845 /* unsolicited event for HP jack sensing */
9846 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
9847                                        unsigned int res)
9848 {
9849         if ((res >> 26) != ALC_HP_EVENT)
9850                 return;
9851         alc262_lenovo_3000_automute(codec, 1);
9852 }
9853
9854 /* bind hp and internal speaker mute (with plug check) */
9855 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
9856                                          struct snd_ctl_elem_value *ucontrol)
9857 {
9858         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9859         long *valp = ucontrol->value.integer.value;
9860         int change;
9861
9862         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9863                                                  HDA_AMP_MUTE,
9864                                                  valp ? 0 : HDA_AMP_MUTE);
9865         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9866                                                  HDA_AMP_MUTE,
9867                                                  valp ? 0 : HDA_AMP_MUTE);
9868
9869         if (change)
9870                 alc262_fujitsu_automute(codec, 0);
9871         return change;
9872 }
9873
9874 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
9875         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9876         {
9877                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9878                 .name = "Master Playback Switch",
9879                 .info = snd_hda_mixer_amp_switch_info,
9880                 .get = snd_hda_mixer_amp_switch_get,
9881                 .put = alc262_fujitsu_master_sw_put,
9882                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9883         },
9884         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9885         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9886         HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
9887         HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
9888         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9889         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9890         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9891         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9892         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9893         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9894         { } /* end */
9895 };
9896
9897 /* bind hp and internal speaker mute (with plug check) */
9898 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
9899                                          struct snd_ctl_elem_value *ucontrol)
9900 {
9901         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9902         long *valp = ucontrol->value.integer.value;
9903         int change;
9904
9905         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9906                                                  HDA_AMP_MUTE,
9907                                                  valp ? 0 : HDA_AMP_MUTE);
9908
9909         if (change)
9910                 alc262_lenovo_3000_automute(codec, 0);
9911         return change;
9912 }
9913
9914 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
9915         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9916         {
9917                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9918                 .name = "Master Playback Switch",
9919                 .info = snd_hda_mixer_amp_switch_info,
9920                 .get = snd_hda_mixer_amp_switch_get,
9921                 .put = alc262_lenovo_3000_master_sw_put,
9922                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
9923         },
9924         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9925         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9926         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9927         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9928         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9929         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9930         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9931         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9932         { } /* end */
9933 };
9934
9935 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
9936         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9937         {
9938                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9939                 .name = "Master Playback Switch",
9940                 .info = snd_hda_mixer_amp_switch_info,
9941                 .get = snd_hda_mixer_amp_switch_get,
9942                 .put = alc262_sony_master_sw_put,
9943                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9944         },
9945         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9946         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9947         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9948         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9949         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9950         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9951         { } /* end */
9952 };
9953
9954 /* additional init verbs for Benq laptops */
9955 static struct hda_verb alc262_EAPD_verbs[] = {
9956         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9957         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
9958         {}
9959 };
9960
9961 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
9962         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9963         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9964
9965         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9966         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
9967         {}
9968 };
9969
9970 /* Samsung Q1 Ultra Vista model setup */
9971 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
9972         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9973         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
9974         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9975         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9976         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
9977         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
9978         { } /* end */
9979 };
9980
9981 static struct hda_verb alc262_ultra_verbs[] = {
9982         /* output mixer */
9983         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9984         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9985         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9986         /* speaker */
9987         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9988         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9989         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9990         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9991         /* HP */
9992         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9993         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9994         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9995         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9996         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9997         /* internal mic */
9998         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9999         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10000         /* ADC, choose mic */
10001         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10002         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10003         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10004         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10005         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10006         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10007         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10008         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10009         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10010         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
10011         {}
10012 };
10013
10014 /* mute/unmute internal speaker according to the hp jack and mute state */
10015 static void alc262_ultra_automute(struct hda_codec *codec)
10016 {
10017         struct alc_spec *spec = codec->spec;
10018         unsigned int mute;
10019
10020         mute = 0;
10021         /* auto-mute only when HP is used as HP */
10022         if (!spec->cur_mux[0]) {
10023                 unsigned int present;
10024                 /* need to execute and sync at first */
10025                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10026                 present = snd_hda_codec_read(codec, 0x15, 0,
10027                                              AC_VERB_GET_PIN_SENSE, 0);
10028                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10029                 if (spec->jack_present)
10030                         mute = HDA_AMP_MUTE;
10031         }
10032         /* mute/unmute internal speaker */
10033         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10034                                  HDA_AMP_MUTE, mute);
10035         /* mute/unmute HP */
10036         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10037                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
10038 }
10039
10040 /* unsolicited event for HP jack sensing */
10041 static void alc262_ultra_unsol_event(struct hda_codec *codec,
10042                                        unsigned int res)
10043 {
10044         if ((res >> 26) != ALC880_HP_EVENT)
10045                 return;
10046         alc262_ultra_automute(codec);
10047 }
10048
10049 static struct hda_input_mux alc262_ultra_capture_source = {
10050         .num_items = 2,
10051         .items = {
10052                 { "Mic", 0x1 },
10053                 { "Headphone", 0x7 },
10054         },
10055 };
10056
10057 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
10058                                      struct snd_ctl_elem_value *ucontrol)
10059 {
10060         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10061         struct alc_spec *spec = codec->spec;
10062         int ret;
10063
10064         ret = alc_mux_enum_put(kcontrol, ucontrol);
10065         if (!ret)
10066                 return 0;
10067         /* reprogram the HP pin as mic or HP according to the input source */
10068         snd_hda_codec_write_cache(codec, 0x15, 0,
10069                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10070                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
10071         alc262_ultra_automute(codec); /* mute/unmute HP */
10072         return ret;
10073 }
10074
10075 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10076         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10077         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10078         {
10079                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10080                 .name = "Capture Source",
10081                 .info = alc_mux_enum_info,
10082                 .get = alc_mux_enum_get,
10083                 .put = alc262_ultra_mux_enum_put,
10084         },
10085         { } /* end */
10086 };
10087
10088 /* add playback controls from the parsed DAC table */
10089 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
10090                                              const struct auto_pin_cfg *cfg)
10091 {
10092         hda_nid_t nid;
10093         int err;
10094
10095         spec->multiout.num_dacs = 1;    /* only use one dac */
10096         spec->multiout.dac_nids = spec->private_dac_nids;
10097         spec->multiout.dac_nids[0] = 2;
10098
10099         nid = cfg->line_out_pins[0];
10100         if (nid) {
10101                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10102                                   "Front Playback Volume",
10103                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
10104                 if (err < 0)
10105                         return err;
10106                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10107                                   "Front Playback Switch",
10108                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
10109                 if (err < 0)
10110                         return err;
10111         }
10112
10113         nid = cfg->speaker_pins[0];
10114         if (nid) {
10115                 if (nid == 0x16) {
10116                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10117                                           "Speaker Playback Volume",
10118                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10119                                                               HDA_OUTPUT));
10120                         if (err < 0)
10121                                 return err;
10122                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10123                                           "Speaker Playback Switch",
10124                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10125                                                               HDA_OUTPUT));
10126                         if (err < 0)
10127                                 return err;
10128                 } else {
10129                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10130                                           "Speaker Playback Switch",
10131                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10132                                                               HDA_OUTPUT));
10133                         if (err < 0)
10134                                 return err;
10135                 }
10136         }
10137         nid = cfg->hp_pins[0];
10138         if (nid) {
10139                 /* spec->multiout.hp_nid = 2; */
10140                 if (nid == 0x16) {
10141                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10142                                           "Headphone Playback Volume",
10143                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10144                                                               HDA_OUTPUT));
10145                         if (err < 0)
10146                                 return err;
10147                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10148                                           "Headphone Playback Switch",
10149                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10150                                                               HDA_OUTPUT));
10151                         if (err < 0)
10152                                 return err;
10153                 } else {
10154                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10155                                           "Headphone Playback Switch",
10156                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10157                                                               HDA_OUTPUT));
10158                         if (err < 0)
10159                                 return err;
10160                 }
10161         }
10162         return 0;
10163 }
10164
10165 /* identical with ALC880 */
10166 #define alc262_auto_create_analog_input_ctls \
10167         alc880_auto_create_analog_input_ctls
10168
10169 /*
10170  * generic initialization of ADC, input mixers and output mixers
10171  */
10172 static struct hda_verb alc262_volume_init_verbs[] = {
10173         /*
10174          * Unmute ADC0-2 and set the default input to mic-in
10175          */
10176         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10177         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10178         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10179         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10180         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10181         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10182
10183         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10184          * mixer widget
10185          * Note: PASD motherboards uses the Line In 2 as the input for
10186          * front panel mic (mic 2)
10187          */
10188         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10189         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10190         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10191         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10192         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10193         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10194
10195         /*
10196          * Set up output mixers (0x0c - 0x0f)
10197          */
10198         /* set vol=0 to output mixers */
10199         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10200         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10201         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10202
10203         /* set up input amps for analog loopback */
10204         /* Amp Indices: DAC = 0, mixer = 1 */
10205         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10206         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10207         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10208         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10209         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10210         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10211
10212         /* FIXME: use matrix-type input source selection */
10213         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10214         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10215         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10216         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10217         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10218         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10219         /* Input mixer2 */
10220         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10221         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10222         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10223         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10224         /* Input mixer3 */
10225         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10226         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10227         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10228         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10229
10230         { }
10231 };
10232
10233 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
10234         /*
10235          * Unmute ADC0-2 and set the default input to mic-in
10236          */
10237         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10238         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10239         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10240         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10241         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10242         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10243
10244         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10245          * mixer widget
10246          * Note: PASD motherboards uses the Line In 2 as the input for
10247          * front panel mic (mic 2)
10248          */
10249         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10250         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10251         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10252         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10253         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10254         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10255         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10256         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10257
10258         /*
10259          * Set up output mixers (0x0c - 0x0e)
10260          */
10261         /* set vol=0 to output mixers */
10262         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10263         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10264         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10265
10266         /* set up input amps for analog loopback */
10267         /* Amp Indices: DAC = 0, mixer = 1 */
10268         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10269         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10270         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10271         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10272         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10273         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10274
10275         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10276         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10277         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10278
10279         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10280         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10281
10282         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10283         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10284
10285         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10286         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10287         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10288         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10289         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10290
10291         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10292         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10293         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10294         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10295         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10296         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10297
10298
10299         /* FIXME: use matrix-type input source selection */
10300         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10301         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10302         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10303         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10304         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10305         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10306         /* Input mixer2 */
10307         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10308         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10309         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10310         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10311         /* Input mixer3 */
10312         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10313         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10314         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10315         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10316
10317         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10318
10319         { }
10320 };
10321
10322 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
10323         /*
10324          * Unmute ADC0-2 and set the default input to mic-in
10325          */
10326         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10327         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10328         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10329         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10330         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10331         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10332
10333         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10334          * mixer widget
10335          * Note: PASD motherboards uses the Line In 2 as the input for front
10336          * panel mic (mic 2)
10337          */
10338         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10339         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10340         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10341         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10342         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10343         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10344         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10345         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10346         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10347         /*
10348          * Set up output mixers (0x0c - 0x0e)
10349          */
10350         /* set vol=0 to output mixers */
10351         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10352         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10353         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10354
10355         /* set up input amps for analog loopback */
10356         /* Amp Indices: DAC = 0, mixer = 1 */
10357         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10358         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10359         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10360         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10361         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10362         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10363
10364
10365         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
10366         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
10367         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
10368         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
10369         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10370         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
10371         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
10372
10373         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10374         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10375
10376         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10377         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10378
10379         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
10380         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10381         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10382         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10383         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10384         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10385
10386         /* FIXME: use matrix-type input source selection */
10387         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10388         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10389         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
10390         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
10391         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
10392         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
10393         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
10394         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
10395         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
10396         /* Input mixer2 */
10397         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10398         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10399         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10400         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10401         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10402         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10403         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10404         /* Input mixer3 */
10405         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10406         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10407         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10408         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10409         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10410         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10411         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10412
10413         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10414
10415         { }
10416 };
10417
10418 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
10419
10420         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
10421         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10422         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
10423
10424         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
10425         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10426         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10427         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10428
10429         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
10430         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10431         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10432         {}
10433 };
10434
10435
10436 #ifdef CONFIG_SND_HDA_POWER_SAVE
10437 #define alc262_loopbacks        alc880_loopbacks
10438 #endif
10439
10440 /* pcm configuration: identiacal with ALC880 */
10441 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
10442 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
10443 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
10444 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
10445
10446 /*
10447  * BIOS auto configuration
10448  */
10449 static int alc262_parse_auto_config(struct hda_codec *codec)
10450 {
10451         struct alc_spec *spec = codec->spec;
10452         int err;
10453         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
10454
10455         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10456                                            alc262_ignore);
10457         if (err < 0)
10458                 return err;
10459         if (!spec->autocfg.line_outs)
10460                 return 0; /* can't find valid BIOS pin config */
10461         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
10462         if (err < 0)
10463                 return err;
10464         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
10465         if (err < 0)
10466                 return err;
10467
10468         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10469
10470         if (spec->autocfg.dig_out_pin)
10471                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
10472         if (spec->autocfg.dig_in_pin)
10473                 spec->dig_in_nid = ALC262_DIGIN_NID;
10474
10475         if (spec->kctls.list)
10476                 add_mixer(spec, spec->kctls.list);
10477
10478         add_verb(spec, alc262_volume_init_verbs);
10479         spec->num_mux_defs = 1;
10480         spec->input_mux = &spec->private_imux;
10481
10482         err = alc_auto_add_mic_boost(codec);
10483         if (err < 0)
10484                 return err;
10485
10486         store_pin_configs(codec);
10487         return 1;
10488 }
10489
10490 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
10491 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
10492 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
10493 #define alc262_auto_init_input_src      alc882_auto_init_input_src
10494
10495
10496 /* init callback for auto-configuration model -- overriding the default init */
10497 static void alc262_auto_init(struct hda_codec *codec)
10498 {
10499         struct alc_spec *spec = codec->spec;
10500         alc262_auto_init_multi_out(codec);
10501         alc262_auto_init_hp_out(codec);
10502         alc262_auto_init_analog_input(codec);
10503         alc262_auto_init_input_src(codec);
10504         if (spec->unsol_event)
10505                 alc_inithook(codec);
10506 }
10507
10508 /*
10509  * configuration and preset
10510  */
10511 static const char *alc262_models[ALC262_MODEL_LAST] = {
10512         [ALC262_BASIC]          = "basic",
10513         [ALC262_HIPPO]          = "hippo",
10514         [ALC262_HIPPO_1]        = "hippo_1",
10515         [ALC262_FUJITSU]        = "fujitsu",
10516         [ALC262_HP_BPC]         = "hp-bpc",
10517         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
10518         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
10519         [ALC262_HP_RP5700]      = "hp-rp5700",
10520         [ALC262_BENQ_ED8]       = "benq",
10521         [ALC262_BENQ_T31]       = "benq-t31",
10522         [ALC262_SONY_ASSAMD]    = "sony-assamd",
10523         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
10524         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
10525         [ALC262_ULTRA]          = "ultra",
10526         [ALC262_LENOVO_3000]    = "lenovo-3000",
10527         [ALC262_NEC]            = "nec",
10528         [ALC262_AUTO]           = "auto",
10529 };
10530
10531 static struct snd_pci_quirk alc262_cfg_tbl[] = {
10532         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
10533         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
10534         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
10535         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
10536         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
10537         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
10538         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
10539         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
10540         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
10541         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
10542         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
10543         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
10544         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
10545         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
10546         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
10547         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
10548         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
10549         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
10550         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
10551         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
10552         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
10553         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
10554                       ALC262_HP_TC_T5735),
10555         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
10556         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10557         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
10558         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10559         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10560         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
10561         SND_PCI_QUIRK(0x104d, 0x9033, "Sony VAIO VGN-SR19XN",
10562                       ALC262_SONY_ASSAMD),
10563         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
10564                       ALC262_TOSHIBA_RX1),
10565         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
10566         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
10567         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
10568         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
10569         SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
10570         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
10571         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
10572         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
10573         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
10574         {}
10575 };
10576
10577 static struct alc_config_preset alc262_presets[] = {
10578         [ALC262_BASIC] = {
10579                 .mixers = { alc262_base_mixer },
10580                 .init_verbs = { alc262_init_verbs },
10581                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10582                 .dac_nids = alc262_dac_nids,
10583                 .hp_nid = 0x03,
10584                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10585                 .channel_mode = alc262_modes,
10586                 .input_mux = &alc262_capture_source,
10587         },
10588         [ALC262_HIPPO] = {
10589                 .mixers = { alc262_base_mixer },
10590                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
10591                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10592                 .dac_nids = alc262_dac_nids,
10593                 .hp_nid = 0x03,
10594                 .dig_out_nid = ALC262_DIGOUT_NID,
10595                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10596                 .channel_mode = alc262_modes,
10597                 .input_mux = &alc262_capture_source,
10598                 .unsol_event = alc262_hippo_unsol_event,
10599                 .init_hook = alc262_hippo_automute,
10600         },
10601         [ALC262_HIPPO_1] = {
10602                 .mixers = { alc262_hippo1_mixer },
10603                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
10604                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10605                 .dac_nids = alc262_dac_nids,
10606                 .hp_nid = 0x02,
10607                 .dig_out_nid = ALC262_DIGOUT_NID,
10608                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10609                 .channel_mode = alc262_modes,
10610                 .input_mux = &alc262_capture_source,
10611                 .unsol_event = alc262_hippo1_unsol_event,
10612                 .init_hook = alc262_hippo1_automute,
10613         },
10614         [ALC262_FUJITSU] = {
10615                 .mixers = { alc262_fujitsu_mixer },
10616                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10617                                 alc262_fujitsu_unsol_verbs },
10618                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10619                 .dac_nids = alc262_dac_nids,
10620                 .hp_nid = 0x03,
10621                 .dig_out_nid = ALC262_DIGOUT_NID,
10622                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10623                 .channel_mode = alc262_modes,
10624                 .input_mux = &alc262_fujitsu_capture_source,
10625                 .unsol_event = alc262_fujitsu_unsol_event,
10626                 .init_hook = alc262_fujitsu_init_hook,
10627         },
10628         [ALC262_HP_BPC] = {
10629                 .mixers = { alc262_HP_BPC_mixer },
10630                 .init_verbs = { alc262_HP_BPC_init_verbs },
10631                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10632                 .dac_nids = alc262_dac_nids,
10633                 .hp_nid = 0x03,
10634                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10635                 .channel_mode = alc262_modes,
10636                 .input_mux = &alc262_HP_capture_source,
10637                 .unsol_event = alc262_hp_bpc_unsol_event,
10638                 .init_hook = alc262_hp_bpc_automute,
10639         },
10640         [ALC262_HP_BPC_D7000_WF] = {
10641                 .mixers = { alc262_HP_BPC_WildWest_mixer },
10642                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10643                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10644                 .dac_nids = alc262_dac_nids,
10645                 .hp_nid = 0x03,
10646                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10647                 .channel_mode = alc262_modes,
10648                 .input_mux = &alc262_HP_D7000_capture_source,
10649                 .unsol_event = alc262_hp_wildwest_unsol_event,
10650                 .init_hook = alc262_hp_wildwest_automute,
10651         },
10652         [ALC262_HP_BPC_D7000_WL] = {
10653                 .mixers = { alc262_HP_BPC_WildWest_mixer,
10654                             alc262_HP_BPC_WildWest_option_mixer },
10655                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10656                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10657                 .dac_nids = alc262_dac_nids,
10658                 .hp_nid = 0x03,
10659                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10660                 .channel_mode = alc262_modes,
10661                 .input_mux = &alc262_HP_D7000_capture_source,
10662                 .unsol_event = alc262_hp_wildwest_unsol_event,
10663                 .init_hook = alc262_hp_wildwest_automute,
10664         },
10665         [ALC262_HP_TC_T5735] = {
10666                 .mixers = { alc262_hp_t5735_mixer },
10667                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
10668                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10669                 .dac_nids = alc262_dac_nids,
10670                 .hp_nid = 0x03,
10671                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10672                 .channel_mode = alc262_modes,
10673                 .input_mux = &alc262_capture_source,
10674                 .unsol_event = alc262_hp_t5735_unsol_event,
10675                 .init_hook = alc262_hp_t5735_init_hook,
10676         },
10677         [ALC262_HP_RP5700] = {
10678                 .mixers = { alc262_hp_rp5700_mixer },
10679                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
10680                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10681                 .dac_nids = alc262_dac_nids,
10682                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10683                 .channel_mode = alc262_modes,
10684                 .input_mux = &alc262_hp_rp5700_capture_source,
10685         },
10686         [ALC262_BENQ_ED8] = {
10687                 .mixers = { alc262_base_mixer },
10688                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
10689                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10690                 .dac_nids = alc262_dac_nids,
10691                 .hp_nid = 0x03,
10692                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10693                 .channel_mode = alc262_modes,
10694                 .input_mux = &alc262_capture_source,
10695         },
10696         [ALC262_SONY_ASSAMD] = {
10697                 .mixers = { alc262_sony_mixer },
10698                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
10699                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10700                 .dac_nids = alc262_dac_nids,
10701                 .hp_nid = 0x02,
10702                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10703                 .channel_mode = alc262_modes,
10704                 .input_mux = &alc262_capture_source,
10705                 .unsol_event = alc262_hippo_unsol_event,
10706                 .init_hook = alc262_hippo_automute,
10707         },
10708         [ALC262_BENQ_T31] = {
10709                 .mixers = { alc262_benq_t31_mixer },
10710                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
10711                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10712                 .dac_nids = alc262_dac_nids,
10713                 .hp_nid = 0x03,
10714                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10715                 .channel_mode = alc262_modes,
10716                 .input_mux = &alc262_capture_source,
10717                 .unsol_event = alc262_hippo_unsol_event,
10718                 .init_hook = alc262_hippo_automute,
10719         },
10720         [ALC262_ULTRA] = {
10721                 .mixers = { alc262_ultra_mixer },
10722                 .cap_mixer = alc262_ultra_capture_mixer,
10723                 .init_verbs = { alc262_ultra_verbs },
10724                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10725                 .dac_nids = alc262_dac_nids,
10726                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10727                 .channel_mode = alc262_modes,
10728                 .input_mux = &alc262_ultra_capture_source,
10729                 .adc_nids = alc262_adc_nids, /* ADC0 */
10730                 .capsrc_nids = alc262_capsrc_nids,
10731                 .num_adc_nids = 1, /* single ADC */
10732                 .unsol_event = alc262_ultra_unsol_event,
10733                 .init_hook = alc262_ultra_automute,
10734         },
10735         [ALC262_LENOVO_3000] = {
10736                 .mixers = { alc262_lenovo_3000_mixer },
10737                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10738                                 alc262_lenovo_3000_unsol_verbs },
10739                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10740                 .dac_nids = alc262_dac_nids,
10741                 .hp_nid = 0x03,
10742                 .dig_out_nid = ALC262_DIGOUT_NID,
10743                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10744                 .channel_mode = alc262_modes,
10745                 .input_mux = &alc262_fujitsu_capture_source,
10746                 .unsol_event = alc262_lenovo_3000_unsol_event,
10747         },
10748         [ALC262_NEC] = {
10749                 .mixers = { alc262_nec_mixer },
10750                 .init_verbs = { alc262_nec_verbs },
10751                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10752                 .dac_nids = alc262_dac_nids,
10753                 .hp_nid = 0x03,
10754                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10755                 .channel_mode = alc262_modes,
10756                 .input_mux = &alc262_capture_source,
10757         },
10758         [ALC262_TOSHIBA_S06] = {
10759                 .mixers = { alc262_toshiba_s06_mixer },
10760                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
10761                                                         alc262_eapd_verbs },
10762                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10763                 .capsrc_nids = alc262_dmic_capsrc_nids,
10764                 .dac_nids = alc262_dac_nids,
10765                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
10766                 .dig_out_nid = ALC262_DIGOUT_NID,
10767                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10768                 .channel_mode = alc262_modes,
10769                 .input_mux = &alc262_dmic_capture_source,
10770                 .unsol_event = alc262_toshiba_s06_unsol_event,
10771                 .init_hook = alc262_toshiba_s06_init_hook,
10772         },
10773         [ALC262_TOSHIBA_RX1] = {
10774                 .mixers = { alc262_toshiba_rx1_mixer },
10775                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
10776                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10777                 .dac_nids = alc262_dac_nids,
10778                 .hp_nid = 0x03,
10779                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10780                 .channel_mode = alc262_modes,
10781                 .input_mux = &alc262_capture_source,
10782                 .unsol_event = alc262_hippo_unsol_event,
10783                 .init_hook = alc262_hippo_automute,
10784         },
10785 };
10786
10787 static int patch_alc262(struct hda_codec *codec)
10788 {
10789         struct alc_spec *spec;
10790         int board_config;
10791         int err;
10792
10793         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10794         if (spec == NULL)
10795                 return -ENOMEM;
10796
10797         codec->spec = spec;
10798 #if 0
10799         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
10800          * under-run
10801          */
10802         {
10803         int tmp;
10804         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10805         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
10806         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10807         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
10808         }
10809 #endif
10810
10811         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
10812
10813         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
10814                                                   alc262_models,
10815                                                   alc262_cfg_tbl);
10816
10817         if (board_config < 0) {
10818                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
10819                        "trying auto-probe from BIOS...\n");
10820                 board_config = ALC262_AUTO;
10821         }
10822
10823         if (board_config == ALC262_AUTO) {
10824                 /* automatic parse from the BIOS config */
10825                 err = alc262_parse_auto_config(codec);
10826                 if (err < 0) {
10827                         alc_free(codec);
10828                         return err;
10829                 } else if (!err) {
10830                         printk(KERN_INFO
10831                                "hda_codec: Cannot set up configuration "
10832                                "from BIOS.  Using base mode...\n");
10833                         board_config = ALC262_BASIC;
10834                 }
10835         }
10836
10837         if (board_config != ALC262_AUTO)
10838                 setup_preset(spec, &alc262_presets[board_config]);
10839
10840         spec->stream_name_analog = "ALC262 Analog";
10841         spec->stream_analog_playback = &alc262_pcm_analog_playback;
10842         spec->stream_analog_capture = &alc262_pcm_analog_capture;
10843
10844         spec->stream_name_digital = "ALC262 Digital";
10845         spec->stream_digital_playback = &alc262_pcm_digital_playback;
10846         spec->stream_digital_capture = &alc262_pcm_digital_capture;
10847
10848         spec->is_mix_capture = 1;
10849         if (!spec->adc_nids && spec->input_mux) {
10850                 /* check whether NID 0x07 is valid */
10851                 unsigned int wcap = get_wcaps(codec, 0x07);
10852
10853                 /* get type */
10854                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10855                 if (wcap != AC_WID_AUD_IN) {
10856                         spec->adc_nids = alc262_adc_nids_alt;
10857                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
10858                         spec->capsrc_nids = alc262_capsrc_nids_alt;
10859                 } else {
10860                         spec->adc_nids = alc262_adc_nids;
10861                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
10862                         spec->capsrc_nids = alc262_capsrc_nids;
10863                 }
10864         }
10865         if (!spec->cap_mixer)
10866                 set_capture_mixer(spec);
10867
10868         spec->vmaster_nid = 0x0c;
10869
10870         codec->patch_ops = alc_patch_ops;
10871         if (board_config == ALC262_AUTO)
10872                 spec->init_hook = alc262_auto_init;
10873 #ifdef CONFIG_SND_HDA_POWER_SAVE
10874         if (!spec->loopback.amplist)
10875                 spec->loopback.amplist = alc262_loopbacks;
10876 #endif
10877         codec->proc_widget_hook = print_realtek_coef;
10878
10879         return 0;
10880 }
10881
10882 /*
10883  *  ALC268 channel source setting (2 channel)
10884  */
10885 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
10886 #define alc268_modes            alc260_modes
10887
10888 static hda_nid_t alc268_dac_nids[2] = {
10889         /* front, hp */
10890         0x02, 0x03
10891 };
10892
10893 static hda_nid_t alc268_adc_nids[2] = {
10894         /* ADC0-1 */
10895         0x08, 0x07
10896 };
10897
10898 static hda_nid_t alc268_adc_nids_alt[1] = {
10899         /* ADC0 */
10900         0x08
10901 };
10902
10903 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
10904
10905 static struct snd_kcontrol_new alc268_base_mixer[] = {
10906         /* output mixer control */
10907         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10908         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10909         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10910         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10911         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10912         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10913         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10914         { }
10915 };
10916
10917 /* bind Beep switches of both NID 0x0f and 0x10 */
10918 static struct hda_bind_ctls alc268_bind_beep_sw = {
10919         .ops = &snd_hda_bind_sw,
10920         .values = {
10921                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
10922                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
10923                 0
10924         },
10925 };
10926
10927 static struct snd_kcontrol_new alc268_beep_mixer[] = {
10928         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
10929         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
10930         { }
10931 };
10932
10933 static struct hda_verb alc268_eapd_verbs[] = {
10934         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10935         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10936         { }
10937 };
10938
10939 /* Toshiba specific */
10940 #define alc268_toshiba_automute alc262_hippo_automute
10941
10942 static struct hda_verb alc268_toshiba_verbs[] = {
10943         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10944         { } /* end */
10945 };
10946
10947 static struct hda_input_mux alc268_acer_lc_capture_source = {
10948         .num_items = 2,
10949         .items = {
10950                 { "i-Mic", 0x6 },
10951                 { "E-Mic", 0x0 },
10952         },
10953 };
10954
10955 /* Acer specific */
10956 /* bind volumes of both NID 0x02 and 0x03 */
10957 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
10958         .ops = &snd_hda_bind_vol,
10959         .values = {
10960                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
10961                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
10962                 0
10963         },
10964 };
10965
10966 /* mute/unmute internal speaker according to the hp jack and mute state */
10967 static void alc268_acer_automute(struct hda_codec *codec, int force)
10968 {
10969         struct alc_spec *spec = codec->spec;
10970         unsigned int mute;
10971
10972         if (force || !spec->sense_updated) {
10973                 unsigned int present;
10974                 present = snd_hda_codec_read(codec, 0x14, 0,
10975                                          AC_VERB_GET_PIN_SENSE, 0);
10976                 spec->jack_present = (present & 0x80000000) != 0;
10977                 spec->sense_updated = 1;
10978         }
10979         if (spec->jack_present)
10980                 mute = HDA_AMP_MUTE; /* mute internal speaker */
10981         else /* unmute internal speaker if necessary */
10982                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10983         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10984                                  HDA_AMP_MUTE, mute);
10985 }
10986
10987
10988 /* bind hp and internal speaker mute (with plug check) */
10989 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
10990                                      struct snd_ctl_elem_value *ucontrol)
10991 {
10992         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10993         long *valp = ucontrol->value.integer.value;
10994         int change;
10995
10996         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
10997                                           HDA_AMP_MUTE,
10998                                           valp[0] ? 0 : HDA_AMP_MUTE);
10999         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
11000                                            HDA_AMP_MUTE,
11001                                            valp[1] ? 0 : HDA_AMP_MUTE);
11002         if (change)
11003                 alc268_acer_automute(codec, 0);
11004         return change;
11005 }
11006
11007 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
11008         /* output mixer control */
11009         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11010         {
11011                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11012                 .name = "Master Playback Switch",
11013                 .info = snd_hda_mixer_amp_switch_info,
11014                 .get = snd_hda_mixer_amp_switch_get,
11015                 .put = alc268_acer_master_sw_put,
11016                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11017         },
11018         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
11019         { }
11020 };
11021
11022 static struct snd_kcontrol_new alc268_acer_mixer[] = {
11023         /* output mixer control */
11024         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11025         {
11026                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11027                 .name = "Master Playback Switch",
11028                 .info = snd_hda_mixer_amp_switch_info,
11029                 .get = snd_hda_mixer_amp_switch_get,
11030                 .put = alc268_acer_master_sw_put,
11031                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11032         },
11033         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11034         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11035         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11036         { }
11037 };
11038
11039 static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
11040         /* output mixer control */
11041         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11042         {
11043                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11044                 .name = "Master Playback Switch",
11045                 .info = snd_hda_mixer_amp_switch_info,
11046                 .get = snd_hda_mixer_amp_switch_get,
11047                 .put = alc268_acer_master_sw_put,
11048                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11049         },
11050         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11051         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11052         { }
11053 };
11054
11055 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
11056         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11057         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11058         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11059         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11060         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
11061         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
11062         { }
11063 };
11064
11065 static struct hda_verb alc268_acer_verbs[] = {
11066         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
11067         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11068         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11069         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11070         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11071         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11072         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11073         { }
11074 };
11075
11076 /* unsolicited event for HP jack sensing */
11077 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
11078                                        unsigned int res)
11079 {
11080         if ((res >> 26) != ALC880_HP_EVENT)
11081                 return;
11082         alc268_toshiba_automute(codec);
11083 }
11084
11085 static void alc268_acer_unsol_event(struct hda_codec *codec,
11086                                        unsigned int res)
11087 {
11088         if ((res >> 26) != ALC880_HP_EVENT)
11089                 return;
11090         alc268_acer_automute(codec, 1);
11091 }
11092
11093 static void alc268_acer_init_hook(struct hda_codec *codec)
11094 {
11095         alc268_acer_automute(codec, 1);
11096 }
11097
11098 /* toggle speaker-output according to the hp-jack state */
11099 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
11100 {
11101         unsigned int present;
11102         unsigned char bits;
11103
11104         present = snd_hda_codec_read(codec, 0x15, 0,
11105                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11106         bits = present ? AMP_IN_MUTE(0) : 0;
11107         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
11108                                 AMP_IN_MUTE(0), bits);
11109         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
11110                                 AMP_IN_MUTE(0), bits);
11111 }
11112
11113
11114 static void alc268_acer_mic_automute(struct hda_codec *codec)
11115 {
11116         unsigned int present;
11117
11118         present = snd_hda_codec_read(codec, 0x18, 0,
11119                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11120         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
11121                             present ? 0x0 : 0x6);
11122 }
11123
11124 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
11125                                     unsigned int res)
11126 {
11127         if ((res >> 26) == ALC880_HP_EVENT)
11128                 alc268_aspire_one_speaker_automute(codec);
11129         if ((res >> 26) == ALC880_MIC_EVENT)
11130                 alc268_acer_mic_automute(codec);
11131 }
11132
11133 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
11134 {
11135         alc268_aspire_one_speaker_automute(codec);
11136         alc268_acer_mic_automute(codec);
11137 }
11138
11139 static struct snd_kcontrol_new alc268_dell_mixer[] = {
11140         /* output mixer control */
11141         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11142         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11143         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11144         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11145         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11146         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11147         { }
11148 };
11149
11150 static struct hda_verb alc268_dell_verbs[] = {
11151         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11152         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11153         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11154         { }
11155 };
11156
11157 /* mute/unmute internal speaker according to the hp jack and mute state */
11158 static void alc268_dell_automute(struct hda_codec *codec)
11159 {
11160         unsigned int present;
11161         unsigned int mute;
11162
11163         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
11164         if (present & 0x80000000)
11165                 mute = HDA_AMP_MUTE;
11166         else
11167                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
11168         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
11169                                  HDA_AMP_MUTE, mute);
11170 }
11171
11172 static void alc268_dell_unsol_event(struct hda_codec *codec,
11173                                     unsigned int res)
11174 {
11175         if ((res >> 26) != ALC880_HP_EVENT)
11176                 return;
11177         alc268_dell_automute(codec);
11178 }
11179
11180 #define alc268_dell_init_hook   alc268_dell_automute
11181
11182 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
11183         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11184         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11185         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11186         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11187         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11188         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
11189         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
11190         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
11191         { }
11192 };
11193
11194 static struct hda_verb alc267_quanta_il1_verbs[] = {
11195         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11196         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
11197         { }
11198 };
11199
11200 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
11201 {
11202         unsigned int present;
11203
11204         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
11205                 & AC_PINSENSE_PRESENCE;
11206         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
11207                             present ? 0 : PIN_OUT);
11208 }
11209
11210 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
11211 {
11212         unsigned int present;
11213
11214         present = snd_hda_codec_read(codec, 0x18, 0,
11215                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11216         snd_hda_codec_write(codec, 0x23, 0,
11217                             AC_VERB_SET_CONNECT_SEL,
11218                             present ? 0x00 : 0x01);
11219 }
11220
11221 static void alc267_quanta_il1_automute(struct hda_codec *codec)
11222 {
11223         alc267_quanta_il1_hp_automute(codec);
11224         alc267_quanta_il1_mic_automute(codec);
11225 }
11226
11227 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
11228                                            unsigned int res)
11229 {
11230         switch (res >> 26) {
11231         case ALC880_HP_EVENT:
11232                 alc267_quanta_il1_hp_automute(codec);
11233                 break;
11234         case ALC880_MIC_EVENT:
11235                 alc267_quanta_il1_mic_automute(codec);
11236                 break;
11237         }
11238 }
11239
11240 /*
11241  * generic initialization of ADC, input mixers and output mixers
11242  */
11243 static struct hda_verb alc268_base_init_verbs[] = {
11244         /* Unmute DAC0-1 and set vol = 0 */
11245         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11246         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11247         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11248         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11249         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11250         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11251
11252         /*
11253          * Set up output mixers (0x0c - 0x0e)
11254          */
11255         /* set vol=0 to output mixers */
11256         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11257         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11258         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11259         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
11260
11261         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11262         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11263
11264         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11265         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
11266         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11267         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11268         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11269         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11270         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11271         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11272
11273         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11274         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11275         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11276         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11277         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11278         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11279         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11280
11281         /* set PCBEEP vol = 0, mute connections */
11282         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11283         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11284         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11285
11286         /* Unmute Selector 23h,24h and set the default input to mic-in */
11287
11288         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
11289         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11290         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
11291         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11292
11293         { }
11294 };
11295
11296 /*
11297  * generic initialization of ADC, input mixers and output mixers
11298  */
11299 static struct hda_verb alc268_volume_init_verbs[] = {
11300         /* set output DAC */
11301         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11302         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11303         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11304         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11305
11306         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11307         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11308         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11309         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11310         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11311
11312         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11313         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11314         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11315         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11316         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11317
11318         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11319         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11320         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11321         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11322
11323         /* set PCBEEP vol = 0, mute connections */
11324         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11325         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11326         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11327
11328         { }
11329 };
11330
11331 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
11332         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11333         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11334         {
11335                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11336                 /* The multiple "Capture Source" controls confuse alsamixer
11337                  * So call somewhat different..
11338                  */
11339                 /* .name = "Capture Source", */
11340                 .name = "Input Source",
11341                 .count = 1,
11342                 .info = alc_mux_enum_info,
11343                 .get = alc_mux_enum_get,
11344                 .put = alc_mux_enum_put,
11345         },
11346         { } /* end */
11347 };
11348
11349 static struct snd_kcontrol_new alc268_capture_mixer[] = {
11350         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11351         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11352         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
11353         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
11354         {
11355                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11356                 /* The multiple "Capture Source" controls confuse alsamixer
11357                  * So call somewhat different..
11358                  */
11359                 /* .name = "Capture Source", */
11360                 .name = "Input Source",
11361                 .count = 2,
11362                 .info = alc_mux_enum_info,
11363                 .get = alc_mux_enum_get,
11364                 .put = alc_mux_enum_put,
11365         },
11366         { } /* end */
11367 };
11368
11369 static struct hda_input_mux alc268_capture_source = {
11370         .num_items = 4,
11371         .items = {
11372                 { "Mic", 0x0 },
11373                 { "Front Mic", 0x1 },
11374                 { "Line", 0x2 },
11375                 { "CD", 0x3 },
11376         },
11377 };
11378
11379 static struct hda_input_mux alc268_acer_capture_source = {
11380         .num_items = 3,
11381         .items = {
11382                 { "Mic", 0x0 },
11383                 { "Internal Mic", 0x1 },
11384                 { "Line", 0x2 },
11385         },
11386 };
11387
11388 static struct hda_input_mux alc268_acer_dmic_capture_source = {
11389         .num_items = 3,
11390         .items = {
11391                 { "Mic", 0x0 },
11392                 { "Internal Mic", 0x6 },
11393                 { "Line", 0x2 },
11394         },
11395 };
11396
11397 #ifdef CONFIG_SND_DEBUG
11398 static struct snd_kcontrol_new alc268_test_mixer[] = {
11399         /* Volume widgets */
11400         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11401         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11402         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
11403         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
11404         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
11405         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
11406         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
11407         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
11408         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
11409         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
11410         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
11411         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
11412         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
11413         /* The below appears problematic on some hardwares */
11414         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
11415         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11416         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
11417         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
11418         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
11419
11420         /* Modes for retasking pin widgets */
11421         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
11422         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
11423         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
11424         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
11425
11426         /* Controls for GPIO pins, assuming they are configured as outputs */
11427         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
11428         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
11429         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
11430         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
11431
11432         /* Switches to allow the digital SPDIF output pin to be enabled.
11433          * The ALC268 does not have an SPDIF input.
11434          */
11435         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
11436
11437         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
11438          * this output to turn on an external amplifier.
11439          */
11440         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
11441         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
11442
11443         { } /* end */
11444 };
11445 #endif
11446
11447 /* create input playback/capture controls for the given pin */
11448 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
11449                                     const char *ctlname, int idx)
11450 {
11451         char name[32];
11452         int err;
11453
11454         sprintf(name, "%s Playback Volume", ctlname);
11455         if (nid == 0x14) {
11456                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11457                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
11458                                                       HDA_OUTPUT));
11459                 if (err < 0)
11460                         return err;
11461         } else if (nid == 0x15) {
11462                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11463                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
11464                                                       HDA_OUTPUT));
11465                 if (err < 0)
11466                         return err;
11467         } else
11468                 return -1;
11469         sprintf(name, "%s Playback Switch", ctlname);
11470         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11471                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
11472         if (err < 0)
11473                 return err;
11474         return 0;
11475 }
11476
11477 /* add playback controls from the parsed DAC table */
11478 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
11479                                              const struct auto_pin_cfg *cfg)
11480 {
11481         hda_nid_t nid;
11482         int err;
11483
11484         spec->multiout.num_dacs = 2;    /* only use one dac */
11485         spec->multiout.dac_nids = spec->private_dac_nids;
11486         spec->multiout.dac_nids[0] = 2;
11487         spec->multiout.dac_nids[1] = 3;
11488
11489         nid = cfg->line_out_pins[0];
11490         if (nid)
11491                 alc268_new_analog_output(spec, nid, "Front", 0);
11492
11493         nid = cfg->speaker_pins[0];
11494         if (nid == 0x1d) {
11495                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
11496                                   "Speaker Playback Volume",
11497                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
11498                 if (err < 0)
11499                         return err;
11500         }
11501         nid = cfg->hp_pins[0];
11502         if (nid)
11503                 alc268_new_analog_output(spec, nid, "Headphone", 0);
11504
11505         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
11506         if (nid == 0x16) {
11507                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11508                                   "Mono Playback Switch",
11509                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
11510                 if (err < 0)
11511                         return err;
11512         }
11513         return 0;
11514 }
11515
11516 /* create playback/capture controls for input pins */
11517 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
11518                                                 const struct auto_pin_cfg *cfg)
11519 {
11520         struct hda_input_mux *imux = &spec->private_imux;
11521         int i, idx1;
11522
11523         for (i = 0; i < AUTO_PIN_LAST; i++) {
11524                 switch(cfg->input_pins[i]) {
11525                 case 0x18:
11526                         idx1 = 0;       /* Mic 1 */
11527                         break;
11528                 case 0x19:
11529                         idx1 = 1;       /* Mic 2 */
11530                         break;
11531                 case 0x1a:
11532                         idx1 = 2;       /* Line In */
11533                         break;
11534                 case 0x1c:
11535                         idx1 = 3;       /* CD */
11536                         break;
11537                 case 0x12:
11538                 case 0x13:
11539                         idx1 = 6;       /* digital mics */
11540                         break;
11541                 default:
11542                         continue;
11543                 }
11544                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
11545                 imux->items[imux->num_items].index = idx1;
11546                 imux->num_items++;
11547         }
11548         return 0;
11549 }
11550
11551 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
11552 {
11553         struct alc_spec *spec = codec->spec;
11554         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
11555         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
11556         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
11557         unsigned int    dac_vol1, dac_vol2;
11558
11559         if (speaker_nid) {
11560                 snd_hda_codec_write(codec, speaker_nid, 0,
11561                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
11562                 snd_hda_codec_write(codec, 0x0f, 0,
11563                                     AC_VERB_SET_AMP_GAIN_MUTE,
11564                                     AMP_IN_UNMUTE(1));
11565                 snd_hda_codec_write(codec, 0x10, 0,
11566                                     AC_VERB_SET_AMP_GAIN_MUTE,
11567                                     AMP_IN_UNMUTE(1));
11568         } else {
11569                 snd_hda_codec_write(codec, 0x0f, 0,
11570                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11571                 snd_hda_codec_write(codec, 0x10, 0,
11572                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11573         }
11574
11575         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
11576         if (line_nid == 0x14)
11577                 dac_vol2 = AMP_OUT_ZERO;
11578         else if (line_nid == 0x15)
11579                 dac_vol1 = AMP_OUT_ZERO;
11580         if (hp_nid == 0x14)
11581                 dac_vol2 = AMP_OUT_ZERO;
11582         else if (hp_nid == 0x15)
11583                 dac_vol1 = AMP_OUT_ZERO;
11584         if (line_nid != 0x16 || hp_nid != 0x16 ||
11585             spec->autocfg.line_out_pins[1] != 0x16 ||
11586             spec->autocfg.line_out_pins[2] != 0x16)
11587                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
11588
11589         snd_hda_codec_write(codec, 0x02, 0,
11590                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
11591         snd_hda_codec_write(codec, 0x03, 0,
11592                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
11593 }
11594
11595 /* pcm configuration: identiacal with ALC880 */
11596 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
11597 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
11598 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
11599 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
11600
11601 /*
11602  * BIOS auto configuration
11603  */
11604 static int alc268_parse_auto_config(struct hda_codec *codec)
11605 {
11606         struct alc_spec *spec = codec->spec;
11607         int err;
11608         static hda_nid_t alc268_ignore[] = { 0 };
11609
11610         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11611                                            alc268_ignore);
11612         if (err < 0)
11613                 return err;
11614         if (!spec->autocfg.line_outs)
11615                 return 0; /* can't find valid BIOS pin config */
11616
11617         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
11618         if (err < 0)
11619                 return err;
11620         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
11621         if (err < 0)
11622                 return err;
11623
11624         spec->multiout.max_channels = 2;
11625
11626         /* digital only support output */
11627         if (spec->autocfg.dig_out_pin)
11628                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
11629
11630         if (spec->kctls.list)
11631                 add_mixer(spec, spec->kctls.list);
11632
11633         if (spec->autocfg.speaker_pins[0] != 0x1d)
11634                 add_mixer(spec, alc268_beep_mixer);
11635
11636         add_verb(spec, alc268_volume_init_verbs);
11637         spec->num_mux_defs = 1;
11638         spec->input_mux = &spec->private_imux;
11639
11640         err = alc_auto_add_mic_boost(codec);
11641         if (err < 0)
11642                 return err;
11643
11644         store_pin_configs(codec);
11645         return 1;
11646 }
11647
11648 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
11649 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
11650 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
11651
11652 /* init callback for auto-configuration model -- overriding the default init */
11653 static void alc268_auto_init(struct hda_codec *codec)
11654 {
11655         struct alc_spec *spec = codec->spec;
11656         alc268_auto_init_multi_out(codec);
11657         alc268_auto_init_hp_out(codec);
11658         alc268_auto_init_mono_speaker_out(codec);
11659         alc268_auto_init_analog_input(codec);
11660         if (spec->unsol_event)
11661                 alc_inithook(codec);
11662 }
11663
11664 /*
11665  * configuration and preset
11666  */
11667 static const char *alc268_models[ALC268_MODEL_LAST] = {
11668         [ALC267_QUANTA_IL1]     = "quanta-il1",
11669         [ALC268_3ST]            = "3stack",
11670         [ALC268_TOSHIBA]        = "toshiba",
11671         [ALC268_ACER]           = "acer",
11672         [ALC268_ACER_DMIC]      = "acer-dmic",
11673         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
11674         [ALC268_DELL]           = "dell",
11675         [ALC268_ZEPTO]          = "zepto",
11676 #ifdef CONFIG_SND_DEBUG
11677         [ALC268_TEST]           = "test",
11678 #endif
11679         [ALC268_AUTO]           = "auto",
11680 };
11681
11682 static struct snd_pci_quirk alc268_cfg_tbl[] = {
11683         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
11684         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
11685         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
11686         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
11687         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
11688         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
11689                                                 ALC268_ACER_ASPIRE_ONE),
11690         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
11691         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
11692         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
11693         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
11694         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
11695         SND_PCI_QUIRK(0x1179, 0xff64, "TOSHIBA L305", ALC268_TOSHIBA),
11696         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
11697         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
11698         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
11699         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
11700         {}
11701 };
11702
11703 static struct alc_config_preset alc268_presets[] = {
11704         [ALC267_QUANTA_IL1] = {
11705                 .mixers = { alc267_quanta_il1_mixer },
11706                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11707                                 alc267_quanta_il1_verbs },
11708                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11709                 .dac_nids = alc268_dac_nids,
11710                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11711                 .adc_nids = alc268_adc_nids_alt,
11712                 .hp_nid = 0x03,
11713                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11714                 .channel_mode = alc268_modes,
11715                 .input_mux = &alc268_capture_source,
11716                 .unsol_event = alc267_quanta_il1_unsol_event,
11717                 .init_hook = alc267_quanta_il1_automute,
11718         },
11719         [ALC268_3ST] = {
11720                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11721                             alc268_beep_mixer },
11722                 .init_verbs = { alc268_base_init_verbs },
11723                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11724                 .dac_nids = alc268_dac_nids,
11725                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11726                 .adc_nids = alc268_adc_nids_alt,
11727                 .capsrc_nids = alc268_capsrc_nids,
11728                 .hp_nid = 0x03,
11729                 .dig_out_nid = ALC268_DIGOUT_NID,
11730                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11731                 .channel_mode = alc268_modes,
11732                 .input_mux = &alc268_capture_source,
11733         },
11734         [ALC268_TOSHIBA] = {
11735                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11736                             alc268_beep_mixer },
11737                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11738                                 alc268_toshiba_verbs },
11739                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11740                 .dac_nids = alc268_dac_nids,
11741                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11742                 .adc_nids = alc268_adc_nids_alt,
11743                 .capsrc_nids = alc268_capsrc_nids,
11744                 .hp_nid = 0x03,
11745                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11746                 .channel_mode = alc268_modes,
11747                 .input_mux = &alc268_capture_source,
11748                 .unsol_event = alc268_toshiba_unsol_event,
11749                 .init_hook = alc268_toshiba_automute,
11750         },
11751         [ALC268_ACER] = {
11752                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
11753                             alc268_beep_mixer },
11754                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11755                                 alc268_acer_verbs },
11756                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11757                 .dac_nids = alc268_dac_nids,
11758                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11759                 .adc_nids = alc268_adc_nids_alt,
11760                 .capsrc_nids = alc268_capsrc_nids,
11761                 .hp_nid = 0x02,
11762                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11763                 .channel_mode = alc268_modes,
11764                 .input_mux = &alc268_acer_capture_source,
11765                 .unsol_event = alc268_acer_unsol_event,
11766                 .init_hook = alc268_acer_init_hook,
11767         },
11768         [ALC268_ACER_DMIC] = {
11769                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
11770                             alc268_beep_mixer },
11771                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11772                                 alc268_acer_verbs },
11773                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11774                 .dac_nids = alc268_dac_nids,
11775                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11776                 .adc_nids = alc268_adc_nids_alt,
11777                 .capsrc_nids = alc268_capsrc_nids,
11778                 .hp_nid = 0x02,
11779                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11780                 .channel_mode = alc268_modes,
11781                 .input_mux = &alc268_acer_dmic_capture_source,
11782                 .unsol_event = alc268_acer_unsol_event,
11783                 .init_hook = alc268_acer_init_hook,
11784         },
11785         [ALC268_ACER_ASPIRE_ONE] = {
11786                 .mixers = { alc268_acer_aspire_one_mixer,
11787                                 alc268_capture_alt_mixer },
11788                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11789                                 alc268_acer_aspire_one_verbs },
11790                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11791                 .dac_nids = alc268_dac_nids,
11792                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11793                 .adc_nids = alc268_adc_nids_alt,
11794                 .capsrc_nids = alc268_capsrc_nids,
11795                 .hp_nid = 0x03,
11796                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11797                 .channel_mode = alc268_modes,
11798                 .input_mux = &alc268_acer_lc_capture_source,
11799                 .unsol_event = alc268_acer_lc_unsol_event,
11800                 .init_hook = alc268_acer_lc_init_hook,
11801         },
11802         [ALC268_DELL] = {
11803                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
11804                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11805                                 alc268_dell_verbs },
11806                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11807                 .dac_nids = alc268_dac_nids,
11808                 .hp_nid = 0x02,
11809                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11810                 .channel_mode = alc268_modes,
11811                 .unsol_event = alc268_dell_unsol_event,
11812                 .init_hook = alc268_dell_init_hook,
11813                 .input_mux = &alc268_capture_source,
11814         },
11815         [ALC268_ZEPTO] = {
11816                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11817                             alc268_beep_mixer },
11818                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11819                                 alc268_toshiba_verbs },
11820                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11821                 .dac_nids = alc268_dac_nids,
11822                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11823                 .adc_nids = alc268_adc_nids_alt,
11824                 .capsrc_nids = alc268_capsrc_nids,
11825                 .hp_nid = 0x03,
11826                 .dig_out_nid = ALC268_DIGOUT_NID,
11827                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11828                 .channel_mode = alc268_modes,
11829                 .input_mux = &alc268_capture_source,
11830                 .unsol_event = alc268_toshiba_unsol_event,
11831                 .init_hook = alc268_toshiba_automute
11832         },
11833 #ifdef CONFIG_SND_DEBUG
11834         [ALC268_TEST] = {
11835                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
11836                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11837                                 alc268_volume_init_verbs },
11838                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11839                 .dac_nids = alc268_dac_nids,
11840                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11841                 .adc_nids = alc268_adc_nids_alt,
11842                 .capsrc_nids = alc268_capsrc_nids,
11843                 .hp_nid = 0x03,
11844                 .dig_out_nid = ALC268_DIGOUT_NID,
11845                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11846                 .channel_mode = alc268_modes,
11847                 .input_mux = &alc268_capture_source,
11848         },
11849 #endif
11850 };
11851
11852 static int patch_alc268(struct hda_codec *codec)
11853 {
11854         struct alc_spec *spec;
11855         int board_config;
11856         int err;
11857
11858         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
11859         if (spec == NULL)
11860                 return -ENOMEM;
11861
11862         codec->spec = spec;
11863
11864         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
11865                                                   alc268_models,
11866                                                   alc268_cfg_tbl);
11867
11868         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
11869                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
11870                        "trying auto-probe from BIOS...\n");
11871                 board_config = ALC268_AUTO;
11872         }
11873
11874         if (board_config == ALC268_AUTO) {
11875                 /* automatic parse from the BIOS config */
11876                 err = alc268_parse_auto_config(codec);
11877                 if (err < 0) {
11878                         alc_free(codec);
11879                         return err;
11880                 } else if (!err) {
11881                         printk(KERN_INFO
11882                                "hda_codec: Cannot set up configuration "
11883                                "from BIOS.  Using base mode...\n");
11884                         board_config = ALC268_3ST;
11885                 }
11886         }
11887
11888         if (board_config != ALC268_AUTO)
11889                 setup_preset(spec, &alc268_presets[board_config]);
11890
11891         if (codec->vendor_id == 0x10ec0267) {
11892                 spec->stream_name_analog = "ALC267 Analog";
11893                 spec->stream_name_digital = "ALC267 Digital";
11894         } else {
11895                 spec->stream_name_analog = "ALC268 Analog";
11896                 spec->stream_name_digital = "ALC268 Digital";
11897         }
11898
11899         spec->stream_analog_playback = &alc268_pcm_analog_playback;
11900         spec->stream_analog_capture = &alc268_pcm_analog_capture;
11901         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
11902
11903         spec->stream_digital_playback = &alc268_pcm_digital_playback;
11904
11905         if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
11906                 /* override the amp caps for beep generator */
11907                 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
11908                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
11909                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
11910                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
11911                                           (0 << AC_AMPCAP_MUTE_SHIFT));
11912
11913         if (!spec->adc_nids && spec->input_mux) {
11914                 /* check whether NID 0x07 is valid */
11915                 unsigned int wcap = get_wcaps(codec, 0x07);
11916                 int i;
11917
11918                 /* get type */
11919                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
11920                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
11921                         spec->adc_nids = alc268_adc_nids_alt;
11922                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
11923                         add_mixer(spec, alc268_capture_alt_mixer);
11924                 } else {
11925                         spec->adc_nids = alc268_adc_nids;
11926                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
11927                         add_mixer(spec, alc268_capture_mixer);
11928                 }
11929                 spec->capsrc_nids = alc268_capsrc_nids;
11930                 /* set default input source */
11931                 for (i = 0; i < spec->num_adc_nids; i++)
11932                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
11933                                 0, AC_VERB_SET_CONNECT_SEL,
11934                                 spec->input_mux->items[0].index);
11935         }
11936
11937         spec->vmaster_nid = 0x02;
11938
11939         codec->patch_ops = alc_patch_ops;
11940         if (board_config == ALC268_AUTO)
11941                 spec->init_hook = alc268_auto_init;
11942
11943         codec->proc_widget_hook = print_realtek_coef;
11944
11945         return 0;
11946 }
11947
11948 /*
11949  *  ALC269 channel source setting (2 channel)
11950  */
11951 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
11952
11953 #define alc269_dac_nids         alc260_dac_nids
11954
11955 static hda_nid_t alc269_adc_nids[1] = {
11956         /* ADC1 */
11957         0x08,
11958 };
11959
11960 static hda_nid_t alc269_capsrc_nids[1] = {
11961         0x23,
11962 };
11963
11964 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
11965  *       not a mux!
11966  */
11967
11968 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
11969         .num_items = 2,
11970         .items = {
11971                 { "i-Mic", 0x5 },
11972                 { "e-Mic", 0x0 },
11973         },
11974 };
11975
11976 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
11977         .num_items = 2,
11978         .items = {
11979                 { "i-Mic", 0x1 },
11980                 { "e-Mic", 0x0 },
11981         },
11982 };
11983
11984 #define alc269_modes            alc260_modes
11985 #define alc269_capture_source   alc880_lg_lw_capture_source
11986
11987 static struct snd_kcontrol_new alc269_base_mixer[] = {
11988         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11989         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11990         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11991         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11992         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11993         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11994         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
11995         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
11996         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11997         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11998         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11999         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12000         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12001         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
12002         { } /* end */
12003 };
12004
12005 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
12006         /* output mixer control */
12007         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12008         {
12009                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12010                 .name = "Master Playback Switch",
12011                 .info = snd_hda_mixer_amp_switch_info,
12012                 .get = snd_hda_mixer_amp_switch_get,
12013                 .put = alc268_acer_master_sw_put,
12014                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12015         },
12016         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12017         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12018         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12019         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12020         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12021         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12022         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
12023         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
12024         { }
12025 };
12026
12027 static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12028         /* output mixer control */
12029         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12030         {
12031                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12032                 .name = "Master Playback Switch",
12033                 .info = snd_hda_mixer_amp_switch_info,
12034                 .get = snd_hda_mixer_amp_switch_get,
12035                 .put = alc268_acer_master_sw_put,
12036                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12037         },
12038         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12039         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12040         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12041         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12042         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12043         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12044         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
12045         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
12046         HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
12047         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
12048         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
12049         { }
12050 };
12051
12052 /* bind volumes of both NID 0x0c and 0x0d */
12053 static struct hda_bind_ctls alc269_epc_bind_vol = {
12054         .ops = &snd_hda_bind_vol,
12055         .values = {
12056                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
12057                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
12058                 0
12059         },
12060 };
12061
12062 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12063         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12064         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
12065         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12066         { } /* end */
12067 };
12068
12069 /* capture mixer elements */
12070 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
12071         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12072         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12073         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12074         { } /* end */
12075 };
12076
12077 /* FSC amilo */
12078 static struct snd_kcontrol_new alc269_fujitsu_mixer[] = {
12079         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12080         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12081         HDA_BIND_VOL("PCM Playback Volume", &alc269_epc_bind_vol),
12082         { } /* end */
12083 };
12084
12085 /* beep control */
12086 static struct snd_kcontrol_new alc269_beep_mixer[] = {
12087         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
12088         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
12089         { } /* end */
12090 };
12091
12092 static struct hda_verb alc269_quanta_fl1_verbs[] = {
12093         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12094         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12095         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12096         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12097         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12098         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12099         { }
12100 };
12101
12102 static struct hda_verb alc269_lifebook_verbs[] = {
12103         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12104         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
12105         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12106         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12107         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12108         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12109         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12110         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12111         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12112         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12113         { }
12114 };
12115
12116 /* toggle speaker-output according to the hp-jack state */
12117 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
12118 {
12119         unsigned int present;
12120         unsigned char bits;
12121
12122         present = snd_hda_codec_read(codec, 0x15, 0,
12123                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12124         bits = present ? AMP_IN_MUTE(0) : 0;
12125         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12126                         AMP_IN_MUTE(0), bits);
12127         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12128                         AMP_IN_MUTE(0), bits);
12129
12130         snd_hda_codec_write(codec, 0x20, 0,
12131                         AC_VERB_SET_COEF_INDEX, 0x0c);
12132         snd_hda_codec_write(codec, 0x20, 0,
12133                         AC_VERB_SET_PROC_COEF, 0x680);
12134
12135         snd_hda_codec_write(codec, 0x20, 0,
12136                         AC_VERB_SET_COEF_INDEX, 0x0c);
12137         snd_hda_codec_write(codec, 0x20, 0,
12138                         AC_VERB_SET_PROC_COEF, 0x480);
12139 }
12140
12141 /* toggle speaker-output according to the hp-jacks state */
12142 static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
12143 {
12144         unsigned int present;
12145         unsigned char bits;
12146
12147         /* Check laptop headphone socket */
12148         present = snd_hda_codec_read(codec, 0x15, 0,
12149                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12150
12151         /* Check port replicator headphone socket */
12152         present |= snd_hda_codec_read(codec, 0x1a, 0,
12153                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12154
12155         bits = present ? AMP_IN_MUTE(0) : 0;
12156         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12157                         AMP_IN_MUTE(0), bits);
12158         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12159                         AMP_IN_MUTE(0), bits);
12160
12161         snd_hda_codec_write(codec, 0x20, 0,
12162                         AC_VERB_SET_COEF_INDEX, 0x0c);
12163         snd_hda_codec_write(codec, 0x20, 0,
12164                         AC_VERB_SET_PROC_COEF, 0x680);
12165
12166         snd_hda_codec_write(codec, 0x20, 0,
12167                         AC_VERB_SET_COEF_INDEX, 0x0c);
12168         snd_hda_codec_write(codec, 0x20, 0,
12169                         AC_VERB_SET_PROC_COEF, 0x480);
12170 }
12171
12172 static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
12173 {
12174         unsigned int present;
12175
12176         present = snd_hda_codec_read(codec, 0x18, 0,
12177                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12178         snd_hda_codec_write(codec, 0x23, 0,
12179                             AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
12180 }
12181
12182 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
12183 {
12184         unsigned int present_laptop;
12185         unsigned int present_dock;
12186
12187         present_laptop = snd_hda_codec_read(codec, 0x18, 0,
12188                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12189
12190         present_dock = snd_hda_codec_read(codec, 0x1b, 0,
12191                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12192
12193         /* Laptop mic port overrides dock mic port, design decision */
12194         if (present_dock)
12195                 snd_hda_codec_write(codec, 0x23, 0,
12196                                 AC_VERB_SET_CONNECT_SEL, 0x3);
12197         if (present_laptop)
12198                 snd_hda_codec_write(codec, 0x23, 0,
12199                                 AC_VERB_SET_CONNECT_SEL, 0x0);
12200         if (!present_dock && !present_laptop)
12201                 snd_hda_codec_write(codec, 0x23, 0,
12202                                 AC_VERB_SET_CONNECT_SEL, 0x1);
12203 }
12204
12205 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
12206                                     unsigned int res)
12207 {
12208         if ((res >> 26) == ALC880_HP_EVENT)
12209                 alc269_quanta_fl1_speaker_automute(codec);
12210         if ((res >> 26) == ALC880_MIC_EVENT)
12211                 alc269_quanta_fl1_mic_automute(codec);
12212 }
12213
12214 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
12215                                         unsigned int res)
12216 {
12217         if ((res >> 26) == ALC880_HP_EVENT)
12218                 alc269_lifebook_speaker_automute(codec);
12219         if ((res >> 26) == ALC880_MIC_EVENT)
12220                 alc269_lifebook_mic_autoswitch(codec);
12221 }
12222
12223 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
12224 {
12225         alc269_quanta_fl1_speaker_automute(codec);
12226         alc269_quanta_fl1_mic_automute(codec);
12227 }
12228
12229 static void alc269_lifebook_init_hook(struct hda_codec *codec)
12230 {
12231         alc269_lifebook_speaker_automute(codec);
12232         alc269_lifebook_mic_autoswitch(codec);
12233 }
12234
12235 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
12236         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12237         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
12238         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12239         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
12240         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12241         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12242         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12243         {}
12244 };
12245
12246 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
12247         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12248         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
12249         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12250         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
12251         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12252         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12253         {}
12254 };
12255
12256 /* toggle speaker-output according to the hp-jack state */
12257 static void alc269_speaker_automute(struct hda_codec *codec)
12258 {
12259         unsigned int present;
12260         unsigned char bits;
12261
12262         present = snd_hda_codec_read(codec, 0x15, 0,
12263                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12264         bits = present ? AMP_IN_MUTE(0) : 0;
12265         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12266                                 AMP_IN_MUTE(0), bits);
12267         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12268                                 AMP_IN_MUTE(0), bits);
12269 }
12270
12271 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
12272 {
12273         unsigned int present;
12274
12275         present = snd_hda_codec_read(codec, 0x18, 0,
12276                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12277         snd_hda_codec_write(codec, 0x23, 0,
12278                                 AC_VERB_SET_CONNECT_SEL,  (present ? 0 : 5));
12279 }
12280
12281 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
12282 {
12283         unsigned int present;
12284
12285         present = snd_hda_codec_read(codec, 0x18, 0,
12286                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12287         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12288                                 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
12289         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12290                                 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
12291 }
12292
12293 /* unsolicited event for HP jack sensing */
12294 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
12295                                      unsigned int res)
12296 {
12297         if ((res >> 26) == ALC880_HP_EVENT)
12298                 alc269_speaker_automute(codec);
12299
12300         if ((res >> 26) == ALC880_MIC_EVENT)
12301                 alc269_eeepc_dmic_automute(codec);
12302 }
12303
12304 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
12305 {
12306         alc269_speaker_automute(codec);
12307         alc269_eeepc_dmic_automute(codec);
12308 }
12309
12310 /* unsolicited event for HP jack sensing */
12311 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
12312                                      unsigned int res)
12313 {
12314         if ((res >> 26) == ALC880_HP_EVENT)
12315                 alc269_speaker_automute(codec);
12316
12317         if ((res >> 26) == ALC880_MIC_EVENT)
12318                 alc269_eeepc_amic_automute(codec);
12319 }
12320
12321 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
12322 {
12323         alc269_speaker_automute(codec);
12324         alc269_eeepc_amic_automute(codec);
12325 }
12326
12327 /*
12328  * generic initialization of ADC, input mixers and output mixers
12329  */
12330 static struct hda_verb alc269_init_verbs[] = {
12331         /*
12332          * Unmute ADC0 and set the default input to mic-in
12333          */
12334         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12335
12336         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
12337          * analog-loopback mixer widget
12338          * Note: PASD motherboards uses the Line In 2 as the input for
12339          * front panel mic (mic 2)
12340          */
12341         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12342         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12343         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12344         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12345         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12346         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12347
12348         /*
12349          * Set up output mixers (0x0c - 0x0e)
12350          */
12351         /* set vol=0 to output mixers */
12352         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12353         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12354
12355         /* set up input amps for analog loopback */
12356         /* Amp Indices: DAC = 0, mixer = 1 */
12357         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12358         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12359         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12360         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12361         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12362         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12363
12364         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12365         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12366         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12367         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12368         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12369         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12370         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12371
12372         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12373         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12374         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12375         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12376         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12377         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12378         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12379
12380         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12381         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12382
12383         /* FIXME: use matrix-type input source selection */
12384         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
12385         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
12386         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12387         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12388         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12389         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12390
12391         /* set EAPD */
12392         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
12393         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
12394         { }
12395 };
12396
12397 /* add playback controls from the parsed DAC table */
12398 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
12399                                              const struct auto_pin_cfg *cfg)
12400 {
12401         hda_nid_t nid;
12402         int err;
12403
12404         spec->multiout.num_dacs = 1;    /* only use one dac */
12405         spec->multiout.dac_nids = spec->private_dac_nids;
12406         spec->multiout.dac_nids[0] = 2;
12407
12408         nid = cfg->line_out_pins[0];
12409         if (nid) {
12410                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
12411                                   "Front Playback Volume",
12412                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
12413                 if (err < 0)
12414                         return err;
12415                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12416                                   "Front Playback Switch",
12417                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12418                 if (err < 0)
12419                         return err;
12420         }
12421
12422         nid = cfg->speaker_pins[0];
12423         if (nid) {
12424                 if (!cfg->line_out_pins[0]) {
12425                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12426                                           "Speaker Playback Volume",
12427                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12428                                                               HDA_OUTPUT));
12429                         if (err < 0)
12430                                 return err;
12431                 }
12432                 if (nid == 0x16) {
12433                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12434                                           "Speaker Playback Switch",
12435                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12436                                                               HDA_OUTPUT));
12437                         if (err < 0)
12438                                 return err;
12439                 } else {
12440                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12441                                           "Speaker Playback Switch",
12442                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12443                                                               HDA_OUTPUT));
12444                         if (err < 0)
12445                                 return err;
12446                 }
12447         }
12448         nid = cfg->hp_pins[0];
12449         if (nid) {
12450                 /* spec->multiout.hp_nid = 2; */
12451                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
12452                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12453                                           "Headphone Playback Volume",
12454                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12455                                                               HDA_OUTPUT));
12456                         if (err < 0)
12457                                 return err;
12458                 }
12459                 if (nid == 0x16) {
12460                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12461                                           "Headphone Playback Switch",
12462                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12463                                                               HDA_OUTPUT));
12464                         if (err < 0)
12465                                 return err;
12466                 } else {
12467                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12468                                           "Headphone Playback Switch",
12469                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12470                                                               HDA_OUTPUT));
12471                         if (err < 0)
12472                                 return err;
12473                 }
12474         }
12475         return 0;
12476 }
12477
12478 static int alc269_auto_create_analog_input_ctls(struct alc_spec *spec,
12479                                                 const struct auto_pin_cfg *cfg)
12480 {
12481         int err;
12482
12483         err = alc880_auto_create_analog_input_ctls(spec, cfg);
12484         if (err < 0)
12485                 return err;
12486         /* digital-mic input pin is excluded in alc880_auto_create..()
12487          * because it's under 0x18
12488          */
12489         if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
12490             cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
12491                 struct hda_input_mux *imux = &spec->private_imux;
12492                 imux->items[imux->num_items].label = "Int Mic";
12493                 imux->items[imux->num_items].index = 0x05;
12494                 imux->num_items++;
12495         }
12496         return 0;
12497 }
12498
12499 #ifdef CONFIG_SND_HDA_POWER_SAVE
12500 #define alc269_loopbacks        alc880_loopbacks
12501 #endif
12502
12503 /* pcm configuration: identiacal with ALC880 */
12504 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
12505 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
12506 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
12507 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
12508
12509 /*
12510  * BIOS auto configuration
12511  */
12512 static int alc269_parse_auto_config(struct hda_codec *codec)
12513 {
12514         struct alc_spec *spec = codec->spec;
12515         int i, err;
12516         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
12517
12518         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12519                                            alc269_ignore);
12520         if (err < 0)
12521                 return err;
12522
12523         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
12524         if (err < 0)
12525                 return err;
12526         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
12527         if (err < 0)
12528                 return err;
12529
12530         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12531
12532         if (spec->autocfg.dig_out_pin)
12533                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
12534
12535         if (spec->kctls.list)
12536                 add_mixer(spec, spec->kctls.list);
12537
12538         /* create a beep mixer control if the pin 0x1d isn't assigned */
12539         for (i = 0; i < ARRAY_SIZE(spec->autocfg.input_pins); i++)
12540                 if (spec->autocfg.input_pins[i] == 0x1d)
12541                         break;
12542         if (i >= ARRAY_SIZE(spec->autocfg.input_pins))
12543                 add_mixer(spec, alc269_beep_mixer);
12544
12545         add_verb(spec, alc269_init_verbs);
12546         spec->num_mux_defs = 1;
12547         spec->input_mux = &spec->private_imux;
12548         /* set default input source */
12549         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
12550                                   0, AC_VERB_SET_CONNECT_SEL,
12551                                   spec->input_mux->items[0].index);
12552
12553         err = alc_auto_add_mic_boost(codec);
12554         if (err < 0)
12555                 return err;
12556
12557         if (!spec->cap_mixer)
12558                 set_capture_mixer(spec);
12559
12560         store_pin_configs(codec);
12561         return 1;
12562 }
12563
12564 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
12565 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
12566 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
12567
12568
12569 /* init callback for auto-configuration model -- overriding the default init */
12570 static void alc269_auto_init(struct hda_codec *codec)
12571 {
12572         struct alc_spec *spec = codec->spec;
12573         alc269_auto_init_multi_out(codec);
12574         alc269_auto_init_hp_out(codec);
12575         alc269_auto_init_analog_input(codec);
12576         if (spec->unsol_event)
12577                 alc_inithook(codec);
12578 }
12579
12580 /*
12581  * configuration and preset
12582  */
12583 static const char *alc269_models[ALC269_MODEL_LAST] = {
12584         [ALC269_BASIC]                  = "basic",
12585         [ALC269_QUANTA_FL1]             = "quanta",
12586         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
12587         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901",
12588         [ALC269_FUJITSU]                = "fujitsu",
12589         [ALC269_LIFEBOOK]               = "lifebook"
12590 };
12591
12592 static struct snd_pci_quirk alc269_cfg_tbl[] = {
12593         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
12594         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
12595                       ALC269_ASUS_EEEPC_P703),
12596         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
12597                       ALC269_ASUS_EEEPC_P901),
12598         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
12599                       ALC269_ASUS_EEEPC_P901),
12600         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
12601         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
12602         {}
12603 };
12604
12605 static struct alc_config_preset alc269_presets[] = {
12606         [ALC269_BASIC] = {
12607                 .mixers = { alc269_base_mixer },
12608                 .init_verbs = { alc269_init_verbs },
12609                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12610                 .dac_nids = alc269_dac_nids,
12611                 .hp_nid = 0x03,
12612                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12613                 .channel_mode = alc269_modes,
12614                 .input_mux = &alc269_capture_source,
12615         },
12616         [ALC269_QUANTA_FL1] = {
12617                 .mixers = { alc269_quanta_fl1_mixer },
12618                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
12619                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12620                 .dac_nids = alc269_dac_nids,
12621                 .hp_nid = 0x03,
12622                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12623                 .channel_mode = alc269_modes,
12624                 .input_mux = &alc269_capture_source,
12625                 .unsol_event = alc269_quanta_fl1_unsol_event,
12626                 .init_hook = alc269_quanta_fl1_init_hook,
12627         },
12628         [ALC269_ASUS_EEEPC_P703] = {
12629                 .mixers = { alc269_eeepc_mixer },
12630                 .cap_mixer = alc269_epc_capture_mixer,
12631                 .init_verbs = { alc269_init_verbs,
12632                                 alc269_eeepc_amic_init_verbs },
12633                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12634                 .dac_nids = alc269_dac_nids,
12635                 .hp_nid = 0x03,
12636                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12637                 .channel_mode = alc269_modes,
12638                 .input_mux = &alc269_eeepc_amic_capture_source,
12639                 .unsol_event = alc269_eeepc_amic_unsol_event,
12640                 .init_hook = alc269_eeepc_amic_inithook,
12641         },
12642         [ALC269_ASUS_EEEPC_P901] = {
12643                 .mixers = { alc269_eeepc_mixer },
12644                 .cap_mixer = alc269_epc_capture_mixer,
12645                 .init_verbs = { alc269_init_verbs,
12646                                 alc269_eeepc_dmic_init_verbs },
12647                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12648                 .dac_nids = alc269_dac_nids,
12649                 .hp_nid = 0x03,
12650                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12651                 .channel_mode = alc269_modes,
12652                 .input_mux = &alc269_eeepc_dmic_capture_source,
12653                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12654                 .init_hook = alc269_eeepc_dmic_inithook,
12655         },
12656         [ALC269_FUJITSU] = {
12657                 .mixers = { alc269_fujitsu_mixer, alc269_beep_mixer },
12658                 .cap_mixer = alc269_epc_capture_mixer,
12659                 .init_verbs = { alc269_init_verbs,
12660                                 alc269_eeepc_dmic_init_verbs },
12661                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12662                 .dac_nids = alc269_dac_nids,
12663                 .hp_nid = 0x03,
12664                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12665                 .channel_mode = alc269_modes,
12666                 .input_mux = &alc269_eeepc_dmic_capture_source,
12667                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12668                 .init_hook = alc269_eeepc_dmic_inithook,
12669         },
12670         [ALC269_LIFEBOOK] = {
12671                 .mixers = { alc269_lifebook_mixer },
12672                 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
12673                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12674                 .dac_nids = alc269_dac_nids,
12675                 .hp_nid = 0x03,
12676                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12677                 .channel_mode = alc269_modes,
12678                 .input_mux = &alc269_capture_source,
12679                 .unsol_event = alc269_lifebook_unsol_event,
12680                 .init_hook = alc269_lifebook_init_hook,
12681         },
12682 };
12683
12684 static int patch_alc269(struct hda_codec *codec)
12685 {
12686         struct alc_spec *spec;
12687         int board_config;
12688         int err;
12689
12690         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12691         if (spec == NULL)
12692                 return -ENOMEM;
12693
12694         codec->spec = spec;
12695
12696         alc_fix_pll_init(codec, 0x20, 0x04, 15);
12697
12698         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
12699                                                   alc269_models,
12700                                                   alc269_cfg_tbl);
12701
12702         if (board_config < 0) {
12703                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
12704                        "trying auto-probe from BIOS...\n");
12705                 board_config = ALC269_AUTO;
12706         }
12707
12708         if (board_config == ALC269_AUTO) {
12709                 /* automatic parse from the BIOS config */
12710                 err = alc269_parse_auto_config(codec);
12711                 if (err < 0) {
12712                         alc_free(codec);
12713                         return err;
12714                 } else if (!err) {
12715                         printk(KERN_INFO
12716                                "hda_codec: Cannot set up configuration "
12717                                "from BIOS.  Using base mode...\n");
12718                         board_config = ALC269_BASIC;
12719                 }
12720         }
12721
12722         if (board_config != ALC269_AUTO)
12723                 setup_preset(spec, &alc269_presets[board_config]);
12724
12725         spec->stream_name_analog = "ALC269 Analog";
12726         spec->stream_analog_playback = &alc269_pcm_analog_playback;
12727         spec->stream_analog_capture = &alc269_pcm_analog_capture;
12728
12729         spec->stream_name_digital = "ALC269 Digital";
12730         spec->stream_digital_playback = &alc269_pcm_digital_playback;
12731         spec->stream_digital_capture = &alc269_pcm_digital_capture;
12732
12733         spec->adc_nids = alc269_adc_nids;
12734         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
12735         spec->capsrc_nids = alc269_capsrc_nids;
12736         if (!spec->cap_mixer)
12737                 set_capture_mixer(spec);
12738
12739         codec->patch_ops = alc_patch_ops;
12740         if (board_config == ALC269_AUTO)
12741                 spec->init_hook = alc269_auto_init;
12742 #ifdef CONFIG_SND_HDA_POWER_SAVE
12743         if (!spec->loopback.amplist)
12744                 spec->loopback.amplist = alc269_loopbacks;
12745 #endif
12746         codec->proc_widget_hook = print_realtek_coef;
12747
12748         return 0;
12749 }
12750
12751 /*
12752  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
12753  */
12754
12755 /*
12756  * set the path ways for 2 channel output
12757  * need to set the codec line out and mic 1 pin widgets to inputs
12758  */
12759 static struct hda_verb alc861_threestack_ch2_init[] = {
12760         /* set pin widget 1Ah (line in) for input */
12761         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12762         /* set pin widget 18h (mic1/2) for input, for mic also enable
12763          * the vref
12764          */
12765         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12766
12767         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12768 #if 0
12769         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12770         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12771 #endif
12772         { } /* end */
12773 };
12774 /*
12775  * 6ch mode
12776  * need to set the codec line out and mic 1 pin widgets to outputs
12777  */
12778 static struct hda_verb alc861_threestack_ch6_init[] = {
12779         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12780         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12781         /* set pin widget 18h (mic1) for output (CLFE)*/
12782         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12783
12784         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12785         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12786
12787         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12788 #if 0
12789         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12790         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12791 #endif
12792         { } /* end */
12793 };
12794
12795 static struct hda_channel_mode alc861_threestack_modes[2] = {
12796         { 2, alc861_threestack_ch2_init },
12797         { 6, alc861_threestack_ch6_init },
12798 };
12799 /* Set mic1 as input and unmute the mixer */
12800 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
12801         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12802         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12803         { } /* end */
12804 };
12805 /* Set mic1 as output and mute mixer */
12806 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
12807         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12808         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12809         { } /* end */
12810 };
12811
12812 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
12813         { 2, alc861_uniwill_m31_ch2_init },
12814         { 4, alc861_uniwill_m31_ch4_init },
12815 };
12816
12817 /* Set mic1 and line-in as input and unmute the mixer */
12818 static struct hda_verb alc861_asus_ch2_init[] = {
12819         /* set pin widget 1Ah (line in) for input */
12820         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12821         /* set pin widget 18h (mic1/2) for input, for mic also enable
12822          * the vref
12823          */
12824         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12825
12826         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12827 #if 0
12828         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12829         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12830 #endif
12831         { } /* end */
12832 };
12833 /* Set mic1 nad line-in as output and mute mixer */
12834 static struct hda_verb alc861_asus_ch6_init[] = {
12835         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12836         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12837         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12838         /* set pin widget 18h (mic1) for output (CLFE)*/
12839         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12840         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12841         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12842         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12843
12844         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12845 #if 0
12846         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12847         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12848 #endif
12849         { } /* end */
12850 };
12851
12852 static struct hda_channel_mode alc861_asus_modes[2] = {
12853         { 2, alc861_asus_ch2_init },
12854         { 6, alc861_asus_ch6_init },
12855 };
12856
12857 /* patch-ALC861 */
12858
12859 static struct snd_kcontrol_new alc861_base_mixer[] = {
12860         /* output mixer control */
12861         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12862         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12863         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12864         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12865         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12866
12867         /*Input mixer control */
12868         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12869            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12870         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12871         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12872         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12873         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12874         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12875         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12876         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12877         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12878
12879         { } /* end */
12880 };
12881
12882 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
12883         /* output mixer control */
12884         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12885         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12886         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12887         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12888         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12889
12890         /* Input mixer control */
12891         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12892            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12893         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12894         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12895         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12896         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12897         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12898         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12899         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12900         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12901
12902         {
12903                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12904                 .name = "Channel Mode",
12905                 .info = alc_ch_mode_info,
12906                 .get = alc_ch_mode_get,
12907                 .put = alc_ch_mode_put,
12908                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
12909         },
12910         { } /* end */
12911 };
12912
12913 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
12914         /* output mixer control */
12915         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12916         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12917         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12918
12919         { } /* end */
12920 };
12921
12922 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
12923         /* output mixer control */
12924         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12925         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12926         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12927         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12928         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12929
12930         /* Input mixer control */
12931         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12932            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12933         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12934         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12935         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12936         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12937         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12938         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12939         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12940         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12941
12942         {
12943                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12944                 .name = "Channel Mode",
12945                 .info = alc_ch_mode_info,
12946                 .get = alc_ch_mode_get,
12947                 .put = alc_ch_mode_put,
12948                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
12949         },
12950         { } /* end */
12951 };
12952
12953 static struct snd_kcontrol_new alc861_asus_mixer[] = {
12954         /* output mixer control */
12955         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12956         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12957         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12958         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12959         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12960
12961         /* Input mixer control */
12962         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12963         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12964         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12965         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12966         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12967         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12968         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12969         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12970         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12971         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
12972
12973         {
12974                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12975                 .name = "Channel Mode",
12976                 .info = alc_ch_mode_info,
12977                 .get = alc_ch_mode_get,
12978                 .put = alc_ch_mode_put,
12979                 .private_value = ARRAY_SIZE(alc861_asus_modes),
12980         },
12981         { }
12982 };
12983
12984 /* additional mixer */
12985 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
12986         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12987         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12988         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
12989         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
12990         { }
12991 };
12992
12993 /*
12994  * generic initialization of ADC, input mixers and output mixers
12995  */
12996 static struct hda_verb alc861_base_init_verbs[] = {
12997         /*
12998          * Unmute ADC0 and set the default input to mic-in
12999          */
13000         /* port-A for surround (rear panel) */
13001         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13002         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
13003         /* port-B for mic-in (rear panel) with vref */
13004         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13005         /* port-C for line-in (rear panel) */
13006         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13007         /* port-D for Front */
13008         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13009         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13010         /* port-E for HP out (front panel) */
13011         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13012         /* route front PCM to HP */
13013         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13014         /* port-F for mic-in (front panel) with vref */
13015         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13016         /* port-G for CLFE (rear panel) */
13017         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13018         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13019         /* port-H for side (rear panel) */
13020         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13021         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
13022         /* CD-in */
13023         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13024         /* route front mic to ADC1*/
13025         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13026         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13027
13028         /* Unmute DAC0~3 & spdif out*/
13029         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13030         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13031         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13032         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13033         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13034
13035         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13036         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13037         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13038         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13039         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13040
13041         /* Unmute Stereo Mixer 15 */
13042         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13043         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13044         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13045         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13046
13047         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13048         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13049         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13050         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13051         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13052         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13053         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13054         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13055         /* hp used DAC 3 (Front) */
13056         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13057         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13058
13059         { }
13060 };
13061
13062 static struct hda_verb alc861_threestack_init_verbs[] = {
13063         /*
13064          * Unmute ADC0 and set the default input to mic-in
13065          */
13066         /* port-A for surround (rear panel) */
13067         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13068         /* port-B for mic-in (rear panel) with vref */
13069         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13070         /* port-C for line-in (rear panel) */
13071         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13072         /* port-D for Front */
13073         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13074         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13075         /* port-E for HP out (front panel) */
13076         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13077         /* route front PCM to HP */
13078         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13079         /* port-F for mic-in (front panel) with vref */
13080         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13081         /* port-G for CLFE (rear panel) */
13082         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13083         /* port-H for side (rear panel) */
13084         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13085         /* CD-in */
13086         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13087         /* route front mic to ADC1*/
13088         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13089         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13090         /* Unmute DAC0~3 & spdif out*/
13091         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13092         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13093         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13094         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13095         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13096
13097         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13098         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13099         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13100         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13101         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13102
13103         /* Unmute Stereo Mixer 15 */
13104         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13105         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13106         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13107         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13108
13109         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13110         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13111         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13112         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13113         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13114         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13115         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13116         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13117         /* hp used DAC 3 (Front) */
13118         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13119         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13120         { }
13121 };
13122
13123 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
13124         /*
13125          * Unmute ADC0 and set the default input to mic-in
13126          */
13127         /* port-A for surround (rear panel) */
13128         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13129         /* port-B for mic-in (rear panel) with vref */
13130         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13131         /* port-C for line-in (rear panel) */
13132         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13133         /* port-D for Front */
13134         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13135         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13136         /* port-E for HP out (front panel) */
13137         /* this has to be set to VREF80 */
13138         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13139         /* route front PCM to HP */
13140         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13141         /* port-F for mic-in (front panel) with vref */
13142         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13143         /* port-G for CLFE (rear panel) */
13144         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13145         /* port-H for side (rear panel) */
13146         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13147         /* CD-in */
13148         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13149         /* route front mic to ADC1*/
13150         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13151         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13152         /* Unmute DAC0~3 & spdif out*/
13153         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13154         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13155         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13156         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13157         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13158
13159         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13160         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13161         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13162         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13163         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13164
13165         /* Unmute Stereo Mixer 15 */
13166         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13167         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13168         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13169         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13170
13171         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13172         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13173         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13174         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13175         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13176         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13177         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13178         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13179         /* hp used DAC 3 (Front) */
13180         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13181         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13182         { }
13183 };
13184
13185 static struct hda_verb alc861_asus_init_verbs[] = {
13186         /*
13187          * Unmute ADC0 and set the default input to mic-in
13188          */
13189         /* port-A for surround (rear panel)
13190          * according to codec#0 this is the HP jack
13191          */
13192         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
13193         /* route front PCM to HP */
13194         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
13195         /* port-B for mic-in (rear panel) with vref */
13196         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13197         /* port-C for line-in (rear panel) */
13198         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13199         /* port-D for Front */
13200         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13201         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13202         /* port-E for HP out (front panel) */
13203         /* this has to be set to VREF80 */
13204         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13205         /* route front PCM to HP */
13206         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13207         /* port-F for mic-in (front panel) with vref */
13208         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13209         /* port-G for CLFE (rear panel) */
13210         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13211         /* port-H for side (rear panel) */
13212         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13213         /* CD-in */
13214         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13215         /* route front mic to ADC1*/
13216         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13217         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13218         /* Unmute DAC0~3 & spdif out*/
13219         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13220         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13221         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13222         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13223         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13224         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13225         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13226         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13227         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13228         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13229
13230         /* Unmute Stereo Mixer 15 */
13231         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13232         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13233         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13234         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13235
13236         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13237         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13238         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13239         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13240         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13241         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13242         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13243         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13244         /* hp used DAC 3 (Front) */
13245         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13246         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13247         { }
13248 };
13249
13250 /* additional init verbs for ASUS laptops */
13251 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
13252         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
13253         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
13254         { }
13255 };
13256
13257 /*
13258  * generic initialization of ADC, input mixers and output mixers
13259  */
13260 static struct hda_verb alc861_auto_init_verbs[] = {
13261         /*
13262          * Unmute ADC0 and set the default input to mic-in
13263          */
13264         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
13265         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13266
13267         /* Unmute DAC0~3 & spdif out*/
13268         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13269         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13270         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13271         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13272         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13273
13274         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13275         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13276         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13277         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13278         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13279
13280         /* Unmute Stereo Mixer 15 */
13281         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13282         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13283         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13284         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
13285
13286         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13287         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13288         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13289         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13290         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13291         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13292         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13293         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13294
13295         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13296         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13297         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13298         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13299         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13300         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13301         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13302         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13303
13304         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
13305
13306         { }
13307 };
13308
13309 static struct hda_verb alc861_toshiba_init_verbs[] = {
13310         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13311
13312         { }
13313 };
13314
13315 /* toggle speaker-output according to the hp-jack state */
13316 static void alc861_toshiba_automute(struct hda_codec *codec)
13317 {
13318         unsigned int present;
13319
13320         present = snd_hda_codec_read(codec, 0x0f, 0,
13321                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13322         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
13323                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
13324         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
13325                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
13326 }
13327
13328 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
13329                                        unsigned int res)
13330 {
13331         if ((res >> 26) == ALC880_HP_EVENT)
13332                 alc861_toshiba_automute(codec);
13333 }
13334
13335 /* pcm configuration: identiacal with ALC880 */
13336 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
13337 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
13338 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
13339 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
13340
13341
13342 #define ALC861_DIGOUT_NID       0x07
13343
13344 static struct hda_channel_mode alc861_8ch_modes[1] = {
13345         { 8, NULL }
13346 };
13347
13348 static hda_nid_t alc861_dac_nids[4] = {
13349         /* front, surround, clfe, side */
13350         0x03, 0x06, 0x05, 0x04
13351 };
13352
13353 static hda_nid_t alc660_dac_nids[3] = {
13354         /* front, clfe, surround */
13355         0x03, 0x05, 0x06
13356 };
13357
13358 static hda_nid_t alc861_adc_nids[1] = {
13359         /* ADC0-2 */
13360         0x08,
13361 };
13362
13363 static struct hda_input_mux alc861_capture_source = {
13364         .num_items = 5,
13365         .items = {
13366                 { "Mic", 0x0 },
13367                 { "Front Mic", 0x3 },
13368                 { "Line", 0x1 },
13369                 { "CD", 0x4 },
13370                 { "Mixer", 0x5 },
13371         },
13372 };
13373
13374 /* fill in the dac_nids table from the parsed pin configuration */
13375 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
13376                                      const struct auto_pin_cfg *cfg)
13377 {
13378         int i;
13379         hda_nid_t nid;
13380
13381         spec->multiout.dac_nids = spec->private_dac_nids;
13382         for (i = 0; i < cfg->line_outs; i++) {
13383                 nid = cfg->line_out_pins[i];
13384                 if (nid) {
13385                         if (i >= ARRAY_SIZE(alc861_dac_nids))
13386                                 continue;
13387                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
13388                 }
13389         }
13390         spec->multiout.num_dacs = cfg->line_outs;
13391         return 0;
13392 }
13393
13394 /* add playback controls from the parsed DAC table */
13395 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
13396                                              const struct auto_pin_cfg *cfg)
13397 {
13398         char name[32];
13399         static const char *chname[4] = {
13400                 "Front", "Surround", NULL /*CLFE*/, "Side"
13401         };
13402         hda_nid_t nid;
13403         int i, idx, err;
13404
13405         for (i = 0; i < cfg->line_outs; i++) {
13406                 nid = spec->multiout.dac_nids[i];
13407                 if (!nid)
13408                         continue;
13409                 if (nid == 0x05) {
13410                         /* Center/LFE */
13411                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13412                                           "Center Playback Switch",
13413                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
13414                                                               HDA_OUTPUT));
13415                         if (err < 0)
13416                                 return err;
13417                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13418                                           "LFE Playback Switch",
13419                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13420                                                               HDA_OUTPUT));
13421                         if (err < 0)
13422                                 return err;
13423                 } else {
13424                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
13425                              idx++)
13426                                 if (nid == alc861_dac_nids[idx])
13427                                         break;
13428                         sprintf(name, "%s Playback Switch", chname[idx]);
13429                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13430                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13431                                                               HDA_OUTPUT));
13432                         if (err < 0)
13433                                 return err;
13434                 }
13435         }
13436         return 0;
13437 }
13438
13439 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
13440 {
13441         int err;
13442         hda_nid_t nid;
13443
13444         if (!pin)
13445                 return 0;
13446
13447         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
13448                 nid = 0x03;
13449                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13450                                   "Headphone Playback Switch",
13451                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13452                 if (err < 0)
13453                         return err;
13454                 spec->multiout.hp_nid = nid;
13455         }
13456         return 0;
13457 }
13458
13459 /* create playback/capture controls for input pins */
13460 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
13461                                                 const struct auto_pin_cfg *cfg)
13462 {
13463         struct hda_input_mux *imux = &spec->private_imux;
13464         int i, err, idx, idx1;
13465
13466         for (i = 0; i < AUTO_PIN_LAST; i++) {
13467                 switch (cfg->input_pins[i]) {
13468                 case 0x0c:
13469                         idx1 = 1;
13470                         idx = 2;        /* Line In */
13471                         break;
13472                 case 0x0f:
13473                         idx1 = 2;
13474                         idx = 2;        /* Line In */
13475                         break;
13476                 case 0x0d:
13477                         idx1 = 0;
13478                         idx = 1;        /* Mic In */
13479                         break;
13480                 case 0x10:
13481                         idx1 = 3;
13482                         idx = 1;        /* Mic In */
13483                         break;
13484                 case 0x11:
13485                         idx1 = 4;
13486                         idx = 0;        /* CD */
13487                         break;
13488                 default:
13489                         continue;
13490                 }
13491
13492                 err = new_analog_input(spec, cfg->input_pins[i],
13493                                        auto_pin_cfg_labels[i], idx, 0x15);
13494                 if (err < 0)
13495                         return err;
13496
13497                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
13498                 imux->items[imux->num_items].index = idx1;
13499                 imux->num_items++;
13500         }
13501         return 0;
13502 }
13503
13504 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
13505                                               hda_nid_t nid,
13506                                               int pin_type, int dac_idx)
13507 {
13508         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
13509                             pin_type);
13510         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13511                             AMP_OUT_UNMUTE);
13512 }
13513
13514 static void alc861_auto_init_multi_out(struct hda_codec *codec)
13515 {
13516         struct alc_spec *spec = codec->spec;
13517         int i;
13518
13519         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
13520         for (i = 0; i < spec->autocfg.line_outs; i++) {
13521                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13522                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13523                 if (nid)
13524                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
13525                                                           spec->multiout.dac_nids[i]);
13526         }
13527 }
13528
13529 static void alc861_auto_init_hp_out(struct hda_codec *codec)
13530 {
13531         struct alc_spec *spec = codec->spec;
13532         hda_nid_t pin;
13533
13534         pin = spec->autocfg.hp_pins[0];
13535         if (pin) /* connect to front */
13536                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
13537                                                   spec->multiout.dac_nids[0]);
13538         pin = spec->autocfg.speaker_pins[0];
13539         if (pin)
13540                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13541 }
13542
13543 static void alc861_auto_init_analog_input(struct hda_codec *codec)
13544 {
13545         struct alc_spec *spec = codec->spec;
13546         int i;
13547
13548         for (i = 0; i < AUTO_PIN_LAST; i++) {
13549                 hda_nid_t nid = spec->autocfg.input_pins[i];
13550                 if (nid >= 0x0c && nid <= 0x11) {
13551                         snd_hda_codec_write(codec, nid, 0,
13552                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
13553                                             i <= AUTO_PIN_FRONT_MIC ?
13554                                             PIN_VREF80 : PIN_IN);
13555                 }
13556         }
13557 }
13558
13559 /* parse the BIOS configuration and set up the alc_spec */
13560 /* return 1 if successful, 0 if the proper config is not found,
13561  * or a negative error code
13562  */
13563 static int alc861_parse_auto_config(struct hda_codec *codec)
13564 {
13565         struct alc_spec *spec = codec->spec;
13566         int err;
13567         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
13568
13569         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13570                                            alc861_ignore);
13571         if (err < 0)
13572                 return err;
13573         if (!spec->autocfg.line_outs)
13574                 return 0; /* can't find valid BIOS pin config */
13575
13576         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
13577         if (err < 0)
13578                 return err;
13579         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
13580         if (err < 0)
13581                 return err;
13582         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
13583         if (err < 0)
13584                 return err;
13585         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
13586         if (err < 0)
13587                 return err;
13588
13589         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13590
13591         if (spec->autocfg.dig_out_pin)
13592                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
13593
13594         if (spec->kctls.list)
13595                 add_mixer(spec, spec->kctls.list);
13596
13597         add_verb(spec, alc861_auto_init_verbs);
13598
13599         spec->num_mux_defs = 1;
13600         spec->input_mux = &spec->private_imux;
13601
13602         spec->adc_nids = alc861_adc_nids;
13603         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
13604         set_capture_mixer(spec);
13605
13606         store_pin_configs(codec);
13607         return 1;
13608 }
13609
13610 /* additional initialization for auto-configuration model */
13611 static void alc861_auto_init(struct hda_codec *codec)
13612 {
13613         struct alc_spec *spec = codec->spec;
13614         alc861_auto_init_multi_out(codec);
13615         alc861_auto_init_hp_out(codec);
13616         alc861_auto_init_analog_input(codec);
13617         if (spec->unsol_event)
13618                 alc_inithook(codec);
13619 }
13620
13621 #ifdef CONFIG_SND_HDA_POWER_SAVE
13622 static struct hda_amp_list alc861_loopbacks[] = {
13623         { 0x15, HDA_INPUT, 0 },
13624         { 0x15, HDA_INPUT, 1 },
13625         { 0x15, HDA_INPUT, 2 },
13626         { 0x15, HDA_INPUT, 3 },
13627         { } /* end */
13628 };
13629 #endif
13630
13631
13632 /*
13633  * configuration and preset
13634  */
13635 static const char *alc861_models[ALC861_MODEL_LAST] = {
13636         [ALC861_3ST]            = "3stack",
13637         [ALC660_3ST]            = "3stack-660",
13638         [ALC861_3ST_DIG]        = "3stack-dig",
13639         [ALC861_6ST_DIG]        = "6stack-dig",
13640         [ALC861_UNIWILL_M31]    = "uniwill-m31",
13641         [ALC861_TOSHIBA]        = "toshiba",
13642         [ALC861_ASUS]           = "asus",
13643         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
13644         [ALC861_AUTO]           = "auto",
13645 };
13646
13647 static struct snd_pci_quirk alc861_cfg_tbl[] = {
13648         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
13649         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13650         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13651         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
13652         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
13653         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
13654         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
13655         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
13656          *        Any other models that need this preset?
13657          */
13658         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
13659         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
13660         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
13661         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
13662         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
13663         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
13664         /* FIXME: the below seems conflict */
13665         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
13666         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
13667         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
13668         {}
13669 };
13670
13671 static struct alc_config_preset alc861_presets[] = {
13672         [ALC861_3ST] = {
13673                 .mixers = { alc861_3ST_mixer },
13674                 .init_verbs = { alc861_threestack_init_verbs },
13675                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13676                 .dac_nids = alc861_dac_nids,
13677                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13678                 .channel_mode = alc861_threestack_modes,
13679                 .need_dac_fix = 1,
13680                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13681                 .adc_nids = alc861_adc_nids,
13682                 .input_mux = &alc861_capture_source,
13683         },
13684         [ALC861_3ST_DIG] = {
13685                 .mixers = { alc861_base_mixer },
13686                 .init_verbs = { alc861_threestack_init_verbs },
13687                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13688                 .dac_nids = alc861_dac_nids,
13689                 .dig_out_nid = ALC861_DIGOUT_NID,
13690                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13691                 .channel_mode = alc861_threestack_modes,
13692                 .need_dac_fix = 1,
13693                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13694                 .adc_nids = alc861_adc_nids,
13695                 .input_mux = &alc861_capture_source,
13696         },
13697         [ALC861_6ST_DIG] = {
13698                 .mixers = { alc861_base_mixer },
13699                 .init_verbs = { alc861_base_init_verbs },
13700                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13701                 .dac_nids = alc861_dac_nids,
13702                 .dig_out_nid = ALC861_DIGOUT_NID,
13703                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
13704                 .channel_mode = alc861_8ch_modes,
13705                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13706                 .adc_nids = alc861_adc_nids,
13707                 .input_mux = &alc861_capture_source,
13708         },
13709         [ALC660_3ST] = {
13710                 .mixers = { alc861_3ST_mixer },
13711                 .init_verbs = { alc861_threestack_init_verbs },
13712                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
13713                 .dac_nids = alc660_dac_nids,
13714                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13715                 .channel_mode = alc861_threestack_modes,
13716                 .need_dac_fix = 1,
13717                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13718                 .adc_nids = alc861_adc_nids,
13719                 .input_mux = &alc861_capture_source,
13720         },
13721         [ALC861_UNIWILL_M31] = {
13722                 .mixers = { alc861_uniwill_m31_mixer },
13723                 .init_verbs = { alc861_uniwill_m31_init_verbs },
13724                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13725                 .dac_nids = alc861_dac_nids,
13726                 .dig_out_nid = ALC861_DIGOUT_NID,
13727                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
13728                 .channel_mode = alc861_uniwill_m31_modes,
13729                 .need_dac_fix = 1,
13730                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13731                 .adc_nids = alc861_adc_nids,
13732                 .input_mux = &alc861_capture_source,
13733         },
13734         [ALC861_TOSHIBA] = {
13735                 .mixers = { alc861_toshiba_mixer },
13736                 .init_verbs = { alc861_base_init_verbs,
13737                                 alc861_toshiba_init_verbs },
13738                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13739                 .dac_nids = alc861_dac_nids,
13740                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13741                 .channel_mode = alc883_3ST_2ch_modes,
13742                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13743                 .adc_nids = alc861_adc_nids,
13744                 .input_mux = &alc861_capture_source,
13745                 .unsol_event = alc861_toshiba_unsol_event,
13746                 .init_hook = alc861_toshiba_automute,
13747         },
13748         [ALC861_ASUS] = {
13749                 .mixers = { alc861_asus_mixer },
13750                 .init_verbs = { alc861_asus_init_verbs },
13751                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13752                 .dac_nids = alc861_dac_nids,
13753                 .dig_out_nid = ALC861_DIGOUT_NID,
13754                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
13755                 .channel_mode = alc861_asus_modes,
13756                 .need_dac_fix = 1,
13757                 .hp_nid = 0x06,
13758                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13759                 .adc_nids = alc861_adc_nids,
13760                 .input_mux = &alc861_capture_source,
13761         },
13762         [ALC861_ASUS_LAPTOP] = {
13763                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
13764                 .init_verbs = { alc861_asus_init_verbs,
13765                                 alc861_asus_laptop_init_verbs },
13766                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13767                 .dac_nids = alc861_dac_nids,
13768                 .dig_out_nid = ALC861_DIGOUT_NID,
13769                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13770                 .channel_mode = alc883_3ST_2ch_modes,
13771                 .need_dac_fix = 1,
13772                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13773                 .adc_nids = alc861_adc_nids,
13774                 .input_mux = &alc861_capture_source,
13775         },
13776 };
13777
13778
13779 static int patch_alc861(struct hda_codec *codec)
13780 {
13781         struct alc_spec *spec;
13782         int board_config;
13783         int err;
13784
13785         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13786         if (spec == NULL)
13787                 return -ENOMEM;
13788
13789         codec->spec = spec;
13790
13791         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
13792                                                   alc861_models,
13793                                                   alc861_cfg_tbl);
13794
13795         if (board_config < 0) {
13796                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
13797                        "trying auto-probe from BIOS...\n");
13798                 board_config = ALC861_AUTO;
13799         }
13800
13801         if (board_config == ALC861_AUTO) {
13802                 /* automatic parse from the BIOS config */
13803                 err = alc861_parse_auto_config(codec);
13804                 if (err < 0) {
13805                         alc_free(codec);
13806                         return err;
13807                 } else if (!err) {
13808                         printk(KERN_INFO
13809                                "hda_codec: Cannot set up configuration "
13810                                "from BIOS.  Using base mode...\n");
13811                    board_config = ALC861_3ST_DIG;
13812                 }
13813         }
13814
13815         if (board_config != ALC861_AUTO)
13816                 setup_preset(spec, &alc861_presets[board_config]);
13817
13818         spec->stream_name_analog = "ALC861 Analog";
13819         spec->stream_analog_playback = &alc861_pcm_analog_playback;
13820         spec->stream_analog_capture = &alc861_pcm_analog_capture;
13821
13822         spec->stream_name_digital = "ALC861 Digital";
13823         spec->stream_digital_playback = &alc861_pcm_digital_playback;
13824         spec->stream_digital_capture = &alc861_pcm_digital_capture;
13825
13826         spec->vmaster_nid = 0x03;
13827
13828         codec->patch_ops = alc_patch_ops;
13829         if (board_config == ALC861_AUTO)
13830                 spec->init_hook = alc861_auto_init;
13831 #ifdef CONFIG_SND_HDA_POWER_SAVE
13832         if (!spec->loopback.amplist)
13833                 spec->loopback.amplist = alc861_loopbacks;
13834 #endif
13835         codec->proc_widget_hook = print_realtek_coef;
13836
13837         return 0;
13838 }
13839
13840 /*
13841  * ALC861-VD support
13842  *
13843  * Based on ALC882
13844  *
13845  * In addition, an independent DAC
13846  */
13847 #define ALC861VD_DIGOUT_NID     0x06
13848
13849 static hda_nid_t alc861vd_dac_nids[4] = {
13850         /* front, surr, clfe, side surr */
13851         0x02, 0x03, 0x04, 0x05
13852 };
13853
13854 /* dac_nids for ALC660vd are in a different order - according to
13855  * Realtek's driver.
13856  * This should probably tesult in a different mixer for 6stack models
13857  * of ALC660vd codecs, but for now there is only 3stack mixer
13858  * - and it is the same as in 861vd.
13859  * adc_nids in ALC660vd are (is) the same as in 861vd
13860  */
13861 static hda_nid_t alc660vd_dac_nids[3] = {
13862         /* front, rear, clfe, rear_surr */
13863         0x02, 0x04, 0x03
13864 };
13865
13866 static hda_nid_t alc861vd_adc_nids[1] = {
13867         /* ADC0 */
13868         0x09,
13869 };
13870
13871 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
13872
13873 /* input MUX */
13874 /* FIXME: should be a matrix-type input source selection */
13875 static struct hda_input_mux alc861vd_capture_source = {
13876         .num_items = 4,
13877         .items = {
13878                 { "Mic", 0x0 },
13879                 { "Front Mic", 0x1 },
13880                 { "Line", 0x2 },
13881                 { "CD", 0x4 },
13882         },
13883 };
13884
13885 static struct hda_input_mux alc861vd_dallas_capture_source = {
13886         .num_items = 2,
13887         .items = {
13888                 { "Ext Mic", 0x0 },
13889                 { "Int Mic", 0x1 },
13890         },
13891 };
13892
13893 static struct hda_input_mux alc861vd_hp_capture_source = {
13894         .num_items = 2,
13895         .items = {
13896                 { "Front Mic", 0x0 },
13897                 { "ATAPI Mic", 0x1 },
13898         },
13899 };
13900
13901 /*
13902  * 2ch mode
13903  */
13904 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
13905         { 2, NULL }
13906 };
13907
13908 /*
13909  * 6ch mode
13910  */
13911 static struct hda_verb alc861vd_6stack_ch6_init[] = {
13912         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13913         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13914         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13915         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13916         { } /* end */
13917 };
13918
13919 /*
13920  * 8ch mode
13921  */
13922 static struct hda_verb alc861vd_6stack_ch8_init[] = {
13923         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13924         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13925         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13926         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13927         { } /* end */
13928 };
13929
13930 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
13931         { 6, alc861vd_6stack_ch6_init },
13932         { 8, alc861vd_6stack_ch8_init },
13933 };
13934
13935 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
13936         {
13937                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13938                 .name = "Channel Mode",
13939                 .info = alc_ch_mode_info,
13940                 .get = alc_ch_mode_get,
13941                 .put = alc_ch_mode_put,
13942         },
13943         { } /* end */
13944 };
13945
13946 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
13947  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
13948  */
13949 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
13950         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13951         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13952
13953         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13954         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
13955
13956         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
13957                                 HDA_OUTPUT),
13958         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
13959                                 HDA_OUTPUT),
13960         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
13961         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
13962
13963         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
13964         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
13965
13966         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13967
13968         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13969         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13970         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13971
13972         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13973         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13974         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13975
13976         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13977         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13978
13979         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13980         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13981
13982         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13983         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13984
13985         { } /* end */
13986 };
13987
13988 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
13989         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13990         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13991
13992         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13993
13994         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13995         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13996         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13997
13998         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13999         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14000         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14001
14002         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14003         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14004
14005         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14006         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14007
14008         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14009         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14010
14011         { } /* end */
14012 };
14013
14014 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
14015         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14016         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
14017         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14018
14019         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14020
14021         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14022         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14023         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14024
14025         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14026         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14027         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14028
14029         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14030         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14031
14032         { } /* end */
14033 };
14034
14035 /* Pin assignment: Speaker=0x14, HP = 0x15,
14036  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
14037  */
14038 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
14039         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14040         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
14041         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14042         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14043         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
14044         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14045         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14046         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
14047         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14048         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14049         HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
14050         HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
14051         { } /* end */
14052 };
14053
14054 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
14055  *                 Front Mic=0x18, ATAPI Mic = 0x19,
14056  */
14057 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
14058         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14059         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14060         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14061         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14062         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14063         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14064         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14065         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14066
14067         { } /* end */
14068 };
14069
14070 /*
14071  * generic initialization of ADC, input mixers and output mixers
14072  */
14073 static struct hda_verb alc861vd_volume_init_verbs[] = {
14074         /*
14075          * Unmute ADC0 and set the default input to mic-in
14076          */
14077         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14078         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14079
14080         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
14081          * the analog-loopback mixer widget
14082          */
14083         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14084         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14085         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14086         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14087         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14088         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14089
14090         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
14091         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14092         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14093         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14094         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14095
14096         /*
14097          * Set up output mixers (0x02 - 0x05)
14098          */
14099         /* set vol=0 to output mixers */
14100         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14101         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14102         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14103         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14104
14105         /* set up input amps for analog loopback */
14106         /* Amp Indices: DAC = 0, mixer = 1 */
14107         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14108         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14109         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14110         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14111         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14112         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14113         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14114         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14115
14116         { }
14117 };
14118
14119 /*
14120  * 3-stack pin configuration:
14121  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
14122  */
14123 static struct hda_verb alc861vd_3stack_init_verbs[] = {
14124         /*
14125          * Set pin mode and muting
14126          */
14127         /* set front pin widgets 0x14 for output */
14128         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14129         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14130         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14131
14132         /* Mic (rear) pin: input vref at 80% */
14133         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14134         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14135         /* Front Mic pin: input vref at 80% */
14136         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14137         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14138         /* Line In pin: input */
14139         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14140         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14141         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14142         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14143         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14144         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14145         /* CD pin widget for input */
14146         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14147
14148         { }
14149 };
14150
14151 /*
14152  * 6-stack pin configuration:
14153  */
14154 static struct hda_verb alc861vd_6stack_init_verbs[] = {
14155         /*
14156          * Set pin mode and muting
14157          */
14158         /* set front pin widgets 0x14 for output */
14159         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14160         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14161         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14162
14163         /* Rear Pin: output 1 (0x0d) */
14164         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14165         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14166         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14167         /* CLFE Pin: output 2 (0x0e) */
14168         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14169         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14170         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
14171         /* Side Pin: output 3 (0x0f) */
14172         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14173         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14174         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
14175
14176         /* Mic (rear) pin: input vref at 80% */
14177         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14178         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14179         /* Front Mic pin: input vref at 80% */
14180         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14181         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14182         /* Line In pin: input */
14183         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14184         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14185         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14186         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14187         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14188         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14189         /* CD pin widget for input */
14190         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14191
14192         { }
14193 };
14194
14195 static struct hda_verb alc861vd_eapd_verbs[] = {
14196         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14197         { }
14198 };
14199
14200 static struct hda_verb alc660vd_eapd_verbs[] = {
14201         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14202         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
14203         { }
14204 };
14205
14206 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
14207         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14208         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14209         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
14210         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14211         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14212         {}
14213 };
14214
14215 /* toggle speaker-output according to the hp-jack state */
14216 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
14217 {
14218         unsigned int present;
14219         unsigned char bits;
14220
14221         present = snd_hda_codec_read(codec, 0x1b, 0,
14222                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14223         bits = present ? HDA_AMP_MUTE : 0;
14224         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14225                                  HDA_AMP_MUTE, bits);
14226 }
14227
14228 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
14229 {
14230         unsigned int present;
14231         unsigned char bits;
14232
14233         present = snd_hda_codec_read(codec, 0x18, 0,
14234                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14235         bits = present ? HDA_AMP_MUTE : 0;
14236         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
14237                                  HDA_AMP_MUTE, bits);
14238 }
14239
14240 static void alc861vd_lenovo_automute(struct hda_codec *codec)
14241 {
14242         alc861vd_lenovo_hp_automute(codec);
14243         alc861vd_lenovo_mic_automute(codec);
14244 }
14245
14246 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
14247                                         unsigned int res)
14248 {
14249         switch (res >> 26) {
14250         case ALC880_HP_EVENT:
14251                 alc861vd_lenovo_hp_automute(codec);
14252                 break;
14253         case ALC880_MIC_EVENT:
14254                 alc861vd_lenovo_mic_automute(codec);
14255                 break;
14256         }
14257 }
14258
14259 static struct hda_verb alc861vd_dallas_verbs[] = {
14260         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14261         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14262         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14263         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14264
14265         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14266         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14267         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14268         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14269         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14270         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14271         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14272         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14273
14274         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14275         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14276         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14277         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14278         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14279         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14280         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14281         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14282
14283         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14284         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14285         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14286         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14287         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14288         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14289         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14290         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14291
14292         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14293         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14294         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14295         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14296
14297         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14298         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14299         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14300
14301         { } /* end */
14302 };
14303
14304 /* toggle speaker-output according to the hp-jack state */
14305 static void alc861vd_dallas_automute(struct hda_codec *codec)
14306 {
14307         unsigned int present;
14308
14309         present = snd_hda_codec_read(codec, 0x15, 0,
14310                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14311         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14312                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14313 }
14314
14315 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
14316 {
14317         if ((res >> 26) == ALC880_HP_EVENT)
14318                 alc861vd_dallas_automute(codec);
14319 }
14320
14321 #ifdef CONFIG_SND_HDA_POWER_SAVE
14322 #define alc861vd_loopbacks      alc880_loopbacks
14323 #endif
14324
14325 /* pcm configuration: identiacal with ALC880 */
14326 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
14327 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
14328 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
14329 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
14330
14331 /*
14332  * configuration and preset
14333  */
14334 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
14335         [ALC660VD_3ST]          = "3stack-660",
14336         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
14337         [ALC660VD_ASUS_V1S]     = "asus-v1s",
14338         [ALC861VD_3ST]          = "3stack",
14339         [ALC861VD_3ST_DIG]      = "3stack-digout",
14340         [ALC861VD_6ST_DIG]      = "6stack-digout",
14341         [ALC861VD_LENOVO]       = "lenovo",
14342         [ALC861VD_DALLAS]       = "dallas",
14343         [ALC861VD_HP]           = "hp",
14344         [ALC861VD_AUTO]         = "auto",
14345 };
14346
14347 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
14348         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
14349         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
14350         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
14351         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
14352         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
14353         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
14354         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
14355         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
14356         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
14357         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
14358         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
14359         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
14360         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
14361         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
14362         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
14363         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 N200", ALC861VD_LENOVO),
14364         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
14365         {}
14366 };
14367
14368 static struct alc_config_preset alc861vd_presets[] = {
14369         [ALC660VD_3ST] = {
14370                 .mixers = { alc861vd_3st_mixer },
14371                 .init_verbs = { alc861vd_volume_init_verbs,
14372                                  alc861vd_3stack_init_verbs },
14373                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14374                 .dac_nids = alc660vd_dac_nids,
14375                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14376                 .channel_mode = alc861vd_3stack_2ch_modes,
14377                 .input_mux = &alc861vd_capture_source,
14378         },
14379         [ALC660VD_3ST_DIG] = {
14380                 .mixers = { alc861vd_3st_mixer },
14381                 .init_verbs = { alc861vd_volume_init_verbs,
14382                                  alc861vd_3stack_init_verbs },
14383                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14384                 .dac_nids = alc660vd_dac_nids,
14385                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14386                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14387                 .channel_mode = alc861vd_3stack_2ch_modes,
14388                 .input_mux = &alc861vd_capture_source,
14389         },
14390         [ALC861VD_3ST] = {
14391                 .mixers = { alc861vd_3st_mixer },
14392                 .init_verbs = { alc861vd_volume_init_verbs,
14393                                  alc861vd_3stack_init_verbs },
14394                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14395                 .dac_nids = alc861vd_dac_nids,
14396                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14397                 .channel_mode = alc861vd_3stack_2ch_modes,
14398                 .input_mux = &alc861vd_capture_source,
14399         },
14400         [ALC861VD_3ST_DIG] = {
14401                 .mixers = { alc861vd_3st_mixer },
14402                 .init_verbs = { alc861vd_volume_init_verbs,
14403                                  alc861vd_3stack_init_verbs },
14404                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14405                 .dac_nids = alc861vd_dac_nids,
14406                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14407                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14408                 .channel_mode = alc861vd_3stack_2ch_modes,
14409                 .input_mux = &alc861vd_capture_source,
14410         },
14411         [ALC861VD_6ST_DIG] = {
14412                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
14413                 .init_verbs = { alc861vd_volume_init_verbs,
14414                                 alc861vd_6stack_init_verbs },
14415                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14416                 .dac_nids = alc861vd_dac_nids,
14417                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14418                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
14419                 .channel_mode = alc861vd_6stack_modes,
14420                 .input_mux = &alc861vd_capture_source,
14421         },
14422         [ALC861VD_LENOVO] = {
14423                 .mixers = { alc861vd_lenovo_mixer },
14424                 .init_verbs = { alc861vd_volume_init_verbs,
14425                                 alc861vd_3stack_init_verbs,
14426                                 alc861vd_eapd_verbs,
14427                                 alc861vd_lenovo_unsol_verbs },
14428                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14429                 .dac_nids = alc660vd_dac_nids,
14430                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14431                 .channel_mode = alc861vd_3stack_2ch_modes,
14432                 .input_mux = &alc861vd_capture_source,
14433                 .unsol_event = alc861vd_lenovo_unsol_event,
14434                 .init_hook = alc861vd_lenovo_automute,
14435         },
14436         [ALC861VD_DALLAS] = {
14437                 .mixers = { alc861vd_dallas_mixer },
14438                 .init_verbs = { alc861vd_dallas_verbs },
14439                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14440                 .dac_nids = alc861vd_dac_nids,
14441                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14442                 .channel_mode = alc861vd_3stack_2ch_modes,
14443                 .input_mux = &alc861vd_dallas_capture_source,
14444                 .unsol_event = alc861vd_dallas_unsol_event,
14445                 .init_hook = alc861vd_dallas_automute,
14446         },
14447         [ALC861VD_HP] = {
14448                 .mixers = { alc861vd_hp_mixer },
14449                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
14450                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14451                 .dac_nids = alc861vd_dac_nids,
14452                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14453                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14454                 .channel_mode = alc861vd_3stack_2ch_modes,
14455                 .input_mux = &alc861vd_hp_capture_source,
14456                 .unsol_event = alc861vd_dallas_unsol_event,
14457                 .init_hook = alc861vd_dallas_automute,
14458         },
14459         [ALC660VD_ASUS_V1S] = {
14460                 .mixers = { alc861vd_lenovo_mixer },
14461                 .init_verbs = { alc861vd_volume_init_verbs,
14462                                 alc861vd_3stack_init_verbs,
14463                                 alc861vd_eapd_verbs,
14464                                 alc861vd_lenovo_unsol_verbs },
14465                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14466                 .dac_nids = alc660vd_dac_nids,
14467                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14468                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14469                 .channel_mode = alc861vd_3stack_2ch_modes,
14470                 .input_mux = &alc861vd_capture_source,
14471                 .unsol_event = alc861vd_lenovo_unsol_event,
14472                 .init_hook = alc861vd_lenovo_automute,
14473         },
14474 };
14475
14476 /*
14477  * BIOS auto configuration
14478  */
14479 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
14480                                 hda_nid_t nid, int pin_type, int dac_idx)
14481 {
14482         alc_set_pin_output(codec, nid, pin_type);
14483 }
14484
14485 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
14486 {
14487         struct alc_spec *spec = codec->spec;
14488         int i;
14489
14490         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
14491         for (i = 0; i <= HDA_SIDE; i++) {
14492                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14493                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14494                 if (nid)
14495                         alc861vd_auto_set_output_and_unmute(codec, nid,
14496                                                             pin_type, i);
14497         }
14498 }
14499
14500
14501 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
14502 {
14503         struct alc_spec *spec = codec->spec;
14504         hda_nid_t pin;
14505
14506         pin = spec->autocfg.hp_pins[0];
14507         if (pin) /* connect to front and  use dac 0 */
14508                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
14509         pin = spec->autocfg.speaker_pins[0];
14510         if (pin)
14511                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14512 }
14513
14514 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
14515 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
14516
14517 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
14518 {
14519         struct alc_spec *spec = codec->spec;
14520         int i;
14521
14522         for (i = 0; i < AUTO_PIN_LAST; i++) {
14523                 hda_nid_t nid = spec->autocfg.input_pins[i];
14524                 if (alc861vd_is_input_pin(nid)) {
14525                         snd_hda_codec_write(codec, nid, 0,
14526                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
14527                                         i <= AUTO_PIN_FRONT_MIC ?
14528                                                         PIN_VREF80 : PIN_IN);
14529                         if (nid != ALC861VD_PIN_CD_NID)
14530                                 snd_hda_codec_write(codec, nid, 0,
14531                                                 AC_VERB_SET_AMP_GAIN_MUTE,
14532                                                 AMP_OUT_MUTE);
14533                 }
14534         }
14535 }
14536
14537 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
14538
14539 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
14540 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
14541
14542 /* add playback controls from the parsed DAC table */
14543 /* Based on ALC880 version. But ALC861VD has separate,
14544  * different NIDs for mute/unmute switch and volume control */
14545 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
14546                                              const struct auto_pin_cfg *cfg)
14547 {
14548         char name[32];
14549         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
14550         hda_nid_t nid_v, nid_s;
14551         int i, err;
14552
14553         for (i = 0; i < cfg->line_outs; i++) {
14554                 if (!spec->multiout.dac_nids[i])
14555                         continue;
14556                 nid_v = alc861vd_idx_to_mixer_vol(
14557                                 alc880_dac_to_idx(
14558                                         spec->multiout.dac_nids[i]));
14559                 nid_s = alc861vd_idx_to_mixer_switch(
14560                                 alc880_dac_to_idx(
14561                                         spec->multiout.dac_nids[i]));
14562
14563                 if (i == 2) {
14564                         /* Center/LFE */
14565                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14566                                           "Center Playback Volume",
14567                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
14568                                                               HDA_OUTPUT));
14569                         if (err < 0)
14570                                 return err;
14571                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14572                                           "LFE Playback Volume",
14573                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
14574                                                               HDA_OUTPUT));
14575                         if (err < 0)
14576                                 return err;
14577                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14578                                           "Center Playback Switch",
14579                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
14580                                                               HDA_INPUT));
14581                         if (err < 0)
14582                                 return err;
14583                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14584                                           "LFE Playback Switch",
14585                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
14586                                                               HDA_INPUT));
14587                         if (err < 0)
14588                                 return err;
14589                 } else {
14590                         sprintf(name, "%s Playback Volume", chname[i]);
14591                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14592                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
14593                                                               HDA_OUTPUT));
14594                         if (err < 0)
14595                                 return err;
14596                         sprintf(name, "%s Playback Switch", chname[i]);
14597                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14598                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
14599                                                               HDA_INPUT));
14600                         if (err < 0)
14601                                 return err;
14602                 }
14603         }
14604         return 0;
14605 }
14606
14607 /* add playback controls for speaker and HP outputs */
14608 /* Based on ALC880 version. But ALC861VD has separate,
14609  * different NIDs for mute/unmute switch and volume control */
14610 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
14611                                         hda_nid_t pin, const char *pfx)
14612 {
14613         hda_nid_t nid_v, nid_s;
14614         int err;
14615         char name[32];
14616
14617         if (!pin)
14618                 return 0;
14619
14620         if (alc880_is_fixed_pin(pin)) {
14621                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14622                 /* specify the DAC as the extra output */
14623                 if (!spec->multiout.hp_nid)
14624                         spec->multiout.hp_nid = nid_v;
14625                 else
14626                         spec->multiout.extra_out_nid[0] = nid_v;
14627                 /* control HP volume/switch on the output mixer amp */
14628                 nid_v = alc861vd_idx_to_mixer_vol(
14629                                 alc880_fixed_pin_idx(pin));
14630                 nid_s = alc861vd_idx_to_mixer_switch(
14631                                 alc880_fixed_pin_idx(pin));
14632
14633                 sprintf(name, "%s Playback Volume", pfx);
14634                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14635                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
14636                 if (err < 0)
14637                         return err;
14638                 sprintf(name, "%s Playback Switch", pfx);
14639                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14640                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
14641                 if (err < 0)
14642                         return err;
14643         } else if (alc880_is_multi_pin(pin)) {
14644                 /* set manual connection */
14645                 /* we have only a switch on HP-out PIN */
14646                 sprintf(name, "%s Playback Switch", pfx);
14647                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14648                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
14649                 if (err < 0)
14650                         return err;
14651         }
14652         return 0;
14653 }
14654
14655 /* parse the BIOS configuration and set up the alc_spec
14656  * return 1 if successful, 0 if the proper config is not found,
14657  * or a negative error code
14658  * Based on ALC880 version - had to change it to override
14659  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
14660 static int alc861vd_parse_auto_config(struct hda_codec *codec)
14661 {
14662         struct alc_spec *spec = codec->spec;
14663         int err;
14664         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
14665
14666         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14667                                            alc861vd_ignore);
14668         if (err < 0)
14669                 return err;
14670         if (!spec->autocfg.line_outs)
14671                 return 0; /* can't find valid BIOS pin config */
14672
14673         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
14674         if (err < 0)
14675                 return err;
14676         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
14677         if (err < 0)
14678                 return err;
14679         err = alc861vd_auto_create_extra_out(spec,
14680                                              spec->autocfg.speaker_pins[0],
14681                                              "Speaker");
14682         if (err < 0)
14683                 return err;
14684         err = alc861vd_auto_create_extra_out(spec,
14685                                              spec->autocfg.hp_pins[0],
14686                                              "Headphone");
14687         if (err < 0)
14688                 return err;
14689         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
14690         if (err < 0)
14691                 return err;
14692
14693         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14694
14695         if (spec->autocfg.dig_out_pin)
14696                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
14697
14698         if (spec->kctls.list)
14699                 add_mixer(spec, spec->kctls.list);
14700
14701         add_verb(spec, alc861vd_volume_init_verbs);
14702
14703         spec->num_mux_defs = 1;
14704         spec->input_mux = &spec->private_imux;
14705
14706         err = alc_auto_add_mic_boost(codec);
14707         if (err < 0)
14708                 return err;
14709
14710         store_pin_configs(codec);
14711         return 1;
14712 }
14713
14714 /* additional initialization for auto-configuration model */
14715 static void alc861vd_auto_init(struct hda_codec *codec)
14716 {
14717         struct alc_spec *spec = codec->spec;
14718         alc861vd_auto_init_multi_out(codec);
14719         alc861vd_auto_init_hp_out(codec);
14720         alc861vd_auto_init_analog_input(codec);
14721         alc861vd_auto_init_input_src(codec);
14722         if (spec->unsol_event)
14723                 alc_inithook(codec);
14724 }
14725
14726 static int patch_alc861vd(struct hda_codec *codec)
14727 {
14728         struct alc_spec *spec;
14729         int err, board_config;
14730
14731         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14732         if (spec == NULL)
14733                 return -ENOMEM;
14734
14735         codec->spec = spec;
14736
14737         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
14738                                                   alc861vd_models,
14739                                                   alc861vd_cfg_tbl);
14740
14741         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
14742                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
14743                         "ALC861VD, trying auto-probe from BIOS...\n");
14744                 board_config = ALC861VD_AUTO;
14745         }
14746
14747         if (board_config == ALC861VD_AUTO) {
14748                 /* automatic parse from the BIOS config */
14749                 err = alc861vd_parse_auto_config(codec);
14750                 if (err < 0) {
14751                         alc_free(codec);
14752                         return err;
14753                 } else if (!err) {
14754                         printk(KERN_INFO
14755                                "hda_codec: Cannot set up configuration "
14756                                "from BIOS.  Using base mode...\n");
14757                         board_config = ALC861VD_3ST;
14758                 }
14759         }
14760
14761         if (board_config != ALC861VD_AUTO)
14762                 setup_preset(spec, &alc861vd_presets[board_config]);
14763
14764         if (codec->vendor_id == 0x10ec0660) {
14765                 spec->stream_name_analog = "ALC660-VD Analog";
14766                 spec->stream_name_digital = "ALC660-VD Digital";
14767                 /* always turn on EAPD */
14768                 add_verb(spec, alc660vd_eapd_verbs);
14769         } else {
14770                 spec->stream_name_analog = "ALC861VD Analog";
14771                 spec->stream_name_digital = "ALC861VD Digital";
14772         }
14773
14774         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
14775         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
14776
14777         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
14778         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
14779
14780         spec->adc_nids = alc861vd_adc_nids;
14781         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
14782         spec->capsrc_nids = alc861vd_capsrc_nids;
14783         spec->is_mix_capture = 1;
14784
14785         set_capture_mixer(spec);
14786
14787         spec->vmaster_nid = 0x02;
14788
14789         codec->patch_ops = alc_patch_ops;
14790
14791         if (board_config == ALC861VD_AUTO)
14792                 spec->init_hook = alc861vd_auto_init;
14793 #ifdef CONFIG_SND_HDA_POWER_SAVE
14794         if (!spec->loopback.amplist)
14795                 spec->loopback.amplist = alc861vd_loopbacks;
14796 #endif
14797         codec->proc_widget_hook = print_realtek_coef;
14798
14799         return 0;
14800 }
14801
14802 /*
14803  * ALC662 support
14804  *
14805  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
14806  * configuration.  Each pin widget can choose any input DACs and a mixer.
14807  * Each ADC is connected from a mixer of all inputs.  This makes possible
14808  * 6-channel independent captures.
14809  *
14810  * In addition, an independent DAC for the multi-playback (not used in this
14811  * driver yet).
14812  */
14813 #define ALC662_DIGOUT_NID       0x06
14814 #define ALC662_DIGIN_NID        0x0a
14815
14816 static hda_nid_t alc662_dac_nids[4] = {
14817         /* front, rear, clfe, rear_surr */
14818         0x02, 0x03, 0x04
14819 };
14820
14821 static hda_nid_t alc662_adc_nids[1] = {
14822         /* ADC1-2 */
14823         0x09,
14824 };
14825
14826 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
14827
14828 /* input MUX */
14829 /* FIXME: should be a matrix-type input source selection */
14830 static struct hda_input_mux alc662_capture_source = {
14831         .num_items = 4,
14832         .items = {
14833                 { "Mic", 0x0 },
14834                 { "Front Mic", 0x1 },
14835                 { "Line", 0x2 },
14836                 { "CD", 0x4 },
14837         },
14838 };
14839
14840 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
14841         .num_items = 2,
14842         .items = {
14843                 { "Mic", 0x1 },
14844                 { "Line", 0x2 },
14845         },
14846 };
14847
14848 static struct hda_input_mux alc662_eeepc_capture_source = {
14849         .num_items = 2,
14850         .items = {
14851                 { "i-Mic", 0x1 },
14852                 { "e-Mic", 0x0 },
14853         },
14854 };
14855
14856 static struct hda_input_mux alc663_capture_source = {
14857         .num_items = 3,
14858         .items = {
14859                 { "Mic", 0x0 },
14860                 { "Front Mic", 0x1 },
14861                 { "Line", 0x2 },
14862         },
14863 };
14864
14865 static struct hda_input_mux alc663_m51va_capture_source = {
14866         .num_items = 2,
14867         .items = {
14868                 { "Ext-Mic", 0x0 },
14869                 { "D-Mic", 0x9 },
14870         },
14871 };
14872
14873 /*
14874  * 2ch mode
14875  */
14876 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
14877         { 2, NULL }
14878 };
14879
14880 /*
14881  * 2ch mode
14882  */
14883 static struct hda_verb alc662_3ST_ch2_init[] = {
14884         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
14885         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14886         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
14887         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14888         { } /* end */
14889 };
14890
14891 /*
14892  * 6ch mode
14893  */
14894 static struct hda_verb alc662_3ST_ch6_init[] = {
14895         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14896         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14897         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
14898         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14899         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14900         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
14901         { } /* end */
14902 };
14903
14904 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
14905         { 2, alc662_3ST_ch2_init },
14906         { 6, alc662_3ST_ch6_init },
14907 };
14908
14909 /*
14910  * 2ch mode
14911  */
14912 static struct hda_verb alc662_sixstack_ch6_init[] = {
14913         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14914         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14915         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14916         { } /* end */
14917 };
14918
14919 /*
14920  * 6ch mode
14921  */
14922 static struct hda_verb alc662_sixstack_ch8_init[] = {
14923         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14924         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14925         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14926         { } /* end */
14927 };
14928
14929 static struct hda_channel_mode alc662_5stack_modes[2] = {
14930         { 2, alc662_sixstack_ch6_init },
14931         { 6, alc662_sixstack_ch8_init },
14932 };
14933
14934 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14935  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14936  */
14937
14938 static struct snd_kcontrol_new alc662_base_mixer[] = {
14939         /* output mixer control */
14940         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
14941         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14942         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
14943         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
14944         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14945         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14946         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
14947         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
14948         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14949
14950         /*Input mixer control */
14951         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
14952         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
14953         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
14954         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
14955         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
14956         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
14957         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
14958         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
14959         { } /* end */
14960 };
14961
14962 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
14963         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14964         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14965         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14966         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14967         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14968         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14969         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14970         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14971         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14972         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14973         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14974         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14975         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14976         { } /* end */
14977 };
14978
14979 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
14980         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14981         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14982         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14983         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
14984         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14985         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14986         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
14987         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
14988         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14989         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14990         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14991         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14992         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14993         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14994         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14995         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14996         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14997         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14998         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14999         { } /* end */
15000 };
15001
15002 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
15003         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15004         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
15005         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15006         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
15007         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15008         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15009         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15010         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15011         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15012         { } /* end */
15013 };
15014
15015 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
15016         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15017
15018         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15019         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15020
15021         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
15022         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15023         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15024
15025         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15026         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15027         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15028         { } /* end */
15029 };
15030
15031 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
15032         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15033         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15034         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15035         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
15036         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15037         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15038         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
15039         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
15040         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15041         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
15042         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15043         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15044         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15045         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15046         { } /* end */
15047 };
15048
15049 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
15050         .ops = &snd_hda_bind_vol,
15051         .values = {
15052                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15053                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
15054                 0
15055         },
15056 };
15057
15058 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
15059         .ops = &snd_hda_bind_sw,
15060         .values = {
15061                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15062                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15063                 0
15064         },
15065 };
15066
15067 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
15068         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15069         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
15070         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15071         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15072         { } /* end */
15073 };
15074
15075 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
15076         .ops = &snd_hda_bind_sw,
15077         .values = {
15078                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15079                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15080                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15081                 0
15082         },
15083 };
15084
15085 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
15086         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15087         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
15088         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15089         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15090         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15091         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15092
15093         { } /* end */
15094 };
15095
15096 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
15097         .ops = &snd_hda_bind_sw,
15098         .values = {
15099                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15100                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15101                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15102                 0
15103         },
15104 };
15105
15106 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
15107         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15108         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
15109         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15110         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15111         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15112         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15113         { } /* end */
15114 };
15115
15116 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
15117         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15118         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15119         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15120         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15121         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15122         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15123         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15124         { } /* end */
15125 };
15126
15127 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
15128         .ops = &snd_hda_bind_vol,
15129         .values = {
15130                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15131                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
15132                 0
15133         },
15134 };
15135
15136 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
15137         .ops = &snd_hda_bind_sw,
15138         .values = {
15139                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15140                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
15141                 0
15142         },
15143 };
15144
15145 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
15146         HDA_BIND_VOL("Master Playback Volume",
15147                                 &alc663_asus_two_bind_master_vol),
15148         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15149         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15150         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15151         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15152         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15153         { } /* end */
15154 };
15155
15156 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
15157         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15158         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15159         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15160         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15161         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15162         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15163         { } /* end */
15164 };
15165
15166 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
15167         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15168         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15169         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15170         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15171         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15172
15173         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15174         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15175         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15176         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15177         { } /* end */
15178 };
15179
15180 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
15181         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15182         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15183         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15184
15185         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15186         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15187         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15188         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15189         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15190         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15191         { } /* end */
15192 };
15193
15194 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
15195         {
15196                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15197                 .name = "Channel Mode",
15198                 .info = alc_ch_mode_info,
15199                 .get = alc_ch_mode_get,
15200                 .put = alc_ch_mode_put,
15201         },
15202         { } /* end */
15203 };
15204
15205 static struct hda_verb alc662_init_verbs[] = {
15206         /* ADC: mute amp left and right */
15207         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15208         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15209         /* Front mixer: unmute input/output amp left and right (volume = 0) */
15210
15211         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15212         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15213         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15214         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15215         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15216
15217         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15218         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15219         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15220         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15221         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15222         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15223
15224         /* Front Pin: output 0 (0x0c) */
15225         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15226         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15227
15228         /* Rear Pin: output 1 (0x0d) */
15229         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15230         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15231
15232         /* CLFE Pin: output 2 (0x0e) */
15233         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15234         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15235
15236         /* Mic (rear) pin: input vref at 80% */
15237         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15238         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15239         /* Front Mic pin: input vref at 80% */
15240         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15241         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15242         /* Line In pin: input */
15243         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15244         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15245         /* Line-2 In: Headphone output (output 0 - 0x0c) */
15246         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15247         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15248         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
15249         /* CD pin widget for input */
15250         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15251
15252         /* FIXME: use matrix-type input source selection */
15253         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15254         /* Input mixer */
15255         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15256         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15257         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15258         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15259
15260         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15261         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15262         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15263         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15264
15265         /* always trun on EAPD */
15266         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15267         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
15268
15269         { }
15270 };
15271
15272 static struct hda_verb alc662_sue_init_verbs[] = {
15273         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15274         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15275         {}
15276 };
15277
15278 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
15279         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15280         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15281         {}
15282 };
15283
15284 /* Set Unsolicited Event*/
15285 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
15286         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15287         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15288         {}
15289 };
15290
15291 /*
15292  * generic initialization of ADC, input mixers and output mixers
15293  */
15294 static struct hda_verb alc662_auto_init_verbs[] = {
15295         /*
15296          * Unmute ADC and set the default input to mic-in
15297          */
15298         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15299         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15300
15301         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
15302          * mixer widget
15303          * Note: PASD motherboards uses the Line In 2 as the input for front
15304          * panel mic (mic 2)
15305          */
15306         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
15307         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15308         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15309         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15310         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15311         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15312
15313         /*
15314          * Set up output mixers (0x0c - 0x0f)
15315          */
15316         /* set vol=0 to output mixers */
15317         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15318         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15319         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15320
15321         /* set up input amps for analog loopback */
15322         /* Amp Indices: DAC = 0, mixer = 1 */
15323         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15324         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15325         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15326         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15327         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15328         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15329
15330
15331         /* FIXME: use matrix-type input source selection */
15332         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15333         /* Input mixer */
15334         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15335         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15336         { }
15337 };
15338
15339 /* additional verbs for ALC663 */
15340 static struct hda_verb alc663_auto_init_verbs[] = {
15341         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15342         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15343         { }
15344 };
15345
15346 static struct hda_verb alc663_m51va_init_verbs[] = {
15347         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15348         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15349         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15350         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15351         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15352         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15353         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
15354         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15355         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15356         {}
15357 };
15358
15359 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
15360         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15361         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15362         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15363         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15364         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15365         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15366         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15367         {}
15368 };
15369
15370 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
15371         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15372         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15373         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15374         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15375         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15376         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15377         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15378         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15379         {}
15380 };
15381
15382 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
15383         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15384         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15385         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15386         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15387         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15388         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15389         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15390         {}
15391 };
15392
15393 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
15394         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15395         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15396         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15397         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15398         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15399         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15400         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15401         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15402         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15403         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15404         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15405         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15406         {}
15407 };
15408
15409 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
15410         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15411         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15412         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15413         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15414         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15415         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15416         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15417         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15418         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15419         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15420         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15421         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15422         {}
15423 };
15424
15425 static struct hda_verb alc663_g71v_init_verbs[] = {
15426         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15427         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
15428         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
15429
15430         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15431         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15432         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15433
15434         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15435         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
15436         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15437         {}
15438 };
15439
15440 static struct hda_verb alc663_g50v_init_verbs[] = {
15441         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15442         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15443         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15444
15445         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15446         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15447         {}
15448 };
15449
15450 static struct hda_verb alc662_ecs_init_verbs[] = {
15451         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
15452         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15453         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15454         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15455         {}
15456 };
15457
15458 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
15459         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
15460         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
15461         { } /* end */
15462 };
15463
15464 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
15465 {
15466         unsigned int present;
15467         unsigned char bits;
15468
15469         present = snd_hda_codec_read(codec, 0x14, 0,
15470                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15471         bits = present ? HDA_AMP_MUTE : 0;
15472         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15473                                  HDA_AMP_MUTE, bits);
15474 }
15475
15476 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
15477 {
15478         unsigned int present;
15479         unsigned char bits;
15480
15481         present = snd_hda_codec_read(codec, 0x1b, 0,
15482                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15483         bits = present ? HDA_AMP_MUTE : 0;
15484         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15485                                  HDA_AMP_MUTE, bits);
15486         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15487                                  HDA_AMP_MUTE, bits);
15488 }
15489
15490 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
15491                                            unsigned int res)
15492 {
15493         if ((res >> 26) == ALC880_HP_EVENT)
15494                 alc662_lenovo_101e_all_automute(codec);
15495         if ((res >> 26) == ALC880_FRONT_EVENT)
15496                 alc662_lenovo_101e_ispeaker_automute(codec);
15497 }
15498
15499 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
15500 {
15501         unsigned int present;
15502
15503         present = snd_hda_codec_read(codec, 0x18, 0,
15504                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15505         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15506                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15507         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15508                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15509         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15510                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15511         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15512                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15513 }
15514
15515 /* unsolicited event for HP jack sensing */
15516 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
15517                                      unsigned int res)
15518 {
15519         if ((res >> 26) == ALC880_HP_EVENT)
15520                 alc262_hippo1_automute( codec );
15521
15522         if ((res >> 26) == ALC880_MIC_EVENT)
15523                 alc662_eeepc_mic_automute(codec);
15524 }
15525
15526 static void alc662_eeepc_inithook(struct hda_codec *codec)
15527 {
15528         alc262_hippo1_automute( codec );
15529         alc662_eeepc_mic_automute(codec);
15530 }
15531
15532 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
15533 {
15534         unsigned int mute;
15535         unsigned int present;
15536
15537         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
15538         present = snd_hda_codec_read(codec, 0x14, 0,
15539                                      AC_VERB_GET_PIN_SENSE, 0);
15540         present = (present & 0x80000000) != 0;
15541         if (present) {
15542                 /* mute internal speaker */
15543                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15544                                         HDA_AMP_MUTE, HDA_AMP_MUTE);
15545         } else {
15546                 /* unmute internal speaker if necessary */
15547                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
15548                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15549                                         HDA_AMP_MUTE, mute);
15550         }
15551 }
15552
15553 /* unsolicited event for HP jack sensing */
15554 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
15555                                           unsigned int res)
15556 {
15557         if ((res >> 26) == ALC880_HP_EVENT)
15558                 alc662_eeepc_ep20_automute(codec);
15559 }
15560
15561 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
15562 {
15563         alc662_eeepc_ep20_automute(codec);
15564 }
15565
15566 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
15567 {
15568         unsigned int present;
15569         unsigned char bits;
15570
15571         present = snd_hda_codec_read(codec, 0x21, 0,
15572                         AC_VERB_GET_PIN_SENSE, 0)
15573                         & AC_PINSENSE_PRESENCE;
15574         bits = present ? HDA_AMP_MUTE : 0;
15575         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15576                                 AMP_IN_MUTE(0), bits);
15577         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15578                                 AMP_IN_MUTE(0), bits);
15579 }
15580
15581 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
15582 {
15583         unsigned int present;
15584         unsigned char bits;
15585
15586         present = snd_hda_codec_read(codec, 0x21, 0,
15587                         AC_VERB_GET_PIN_SENSE, 0)
15588                         & AC_PINSENSE_PRESENCE;
15589         bits = present ? HDA_AMP_MUTE : 0;
15590         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15591                                 AMP_IN_MUTE(0), bits);
15592         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15593                                 AMP_IN_MUTE(0), bits);
15594         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15595                                 AMP_IN_MUTE(0), bits);
15596         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15597                                 AMP_IN_MUTE(0), bits);
15598 }
15599
15600 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
15601 {
15602         unsigned int present;
15603         unsigned char bits;
15604
15605         present = snd_hda_codec_read(codec, 0x15, 0,
15606                         AC_VERB_GET_PIN_SENSE, 0)
15607                         & AC_PINSENSE_PRESENCE;
15608         bits = present ? HDA_AMP_MUTE : 0;
15609         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15610                                 AMP_IN_MUTE(0), bits);
15611         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15612                                 AMP_IN_MUTE(0), bits);
15613         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15614                                 AMP_IN_MUTE(0), bits);
15615         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15616                                 AMP_IN_MUTE(0), bits);
15617 }
15618
15619 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
15620 {
15621         unsigned int present;
15622         unsigned char bits;
15623
15624         present = snd_hda_codec_read(codec, 0x1b, 0,
15625                         AC_VERB_GET_PIN_SENSE, 0)
15626                         & AC_PINSENSE_PRESENCE;
15627         bits = present ? 0 : PIN_OUT;
15628         snd_hda_codec_write(codec, 0x14, 0,
15629                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
15630 }
15631
15632 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
15633 {
15634         unsigned int present1, present2;
15635
15636         present1 = snd_hda_codec_read(codec, 0x21, 0,
15637                         AC_VERB_GET_PIN_SENSE, 0)
15638                         & AC_PINSENSE_PRESENCE;
15639         present2 = snd_hda_codec_read(codec, 0x15, 0,
15640                         AC_VERB_GET_PIN_SENSE, 0)
15641                         & AC_PINSENSE_PRESENCE;
15642
15643         if (present1 || present2) {
15644                 snd_hda_codec_write_cache(codec, 0x14, 0,
15645                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
15646         } else {
15647                 snd_hda_codec_write_cache(codec, 0x14, 0,
15648                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
15649         }
15650 }
15651
15652 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
15653 {
15654         unsigned int present1, present2;
15655
15656         present1 = snd_hda_codec_read(codec, 0x1b, 0,
15657                                 AC_VERB_GET_PIN_SENSE, 0)
15658                                 & AC_PINSENSE_PRESENCE;
15659         present2 = snd_hda_codec_read(codec, 0x15, 0,
15660                                 AC_VERB_GET_PIN_SENSE, 0)
15661                                 & AC_PINSENSE_PRESENCE;
15662
15663         if (present1 || present2) {
15664                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15665                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15666                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15667                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15668         } else {
15669                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15670                                 AMP_IN_MUTE(0), 0);
15671                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15672                                 AMP_IN_MUTE(0), 0);
15673         }
15674 }
15675
15676 static void alc663_m51va_mic_automute(struct hda_codec *codec)
15677 {
15678         unsigned int present;
15679
15680         present = snd_hda_codec_read(codec, 0x18, 0,
15681                         AC_VERB_GET_PIN_SENSE, 0)
15682                         & AC_PINSENSE_PRESENCE;
15683         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15684                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15685         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15686                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15687         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15688                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15689         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15690                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15691 }
15692
15693 static void alc663_m51va_unsol_event(struct hda_codec *codec,
15694                                            unsigned int res)
15695 {
15696         switch (res >> 26) {
15697         case ALC880_HP_EVENT:
15698                 alc663_m51va_speaker_automute(codec);
15699                 break;
15700         case ALC880_MIC_EVENT:
15701                 alc663_m51va_mic_automute(codec);
15702                 break;
15703         }
15704 }
15705
15706 static void alc663_m51va_inithook(struct hda_codec *codec)
15707 {
15708         alc663_m51va_speaker_automute(codec);
15709         alc663_m51va_mic_automute(codec);
15710 }
15711
15712 /* ***************** Mode1 ******************************/
15713 static void alc663_mode1_unsol_event(struct hda_codec *codec,
15714                                            unsigned int res)
15715 {
15716         switch (res >> 26) {
15717         case ALC880_HP_EVENT:
15718                 alc663_m51va_speaker_automute(codec);
15719                 break;
15720         case ALC880_MIC_EVENT:
15721                 alc662_eeepc_mic_automute(codec);
15722                 break;
15723         }
15724 }
15725
15726 static void alc663_mode1_inithook(struct hda_codec *codec)
15727 {
15728         alc663_m51va_speaker_automute(codec);
15729         alc662_eeepc_mic_automute(codec);
15730 }
15731 /* ***************** Mode2 ******************************/
15732 static void alc662_mode2_unsol_event(struct hda_codec *codec,
15733                                            unsigned int res)
15734 {
15735         switch (res >> 26) {
15736         case ALC880_HP_EVENT:
15737                 alc662_f5z_speaker_automute(codec);
15738                 break;
15739         case ALC880_MIC_EVENT:
15740                 alc662_eeepc_mic_automute(codec);
15741                 break;
15742         }
15743 }
15744
15745 static void alc662_mode2_inithook(struct hda_codec *codec)
15746 {
15747         alc662_f5z_speaker_automute(codec);
15748         alc662_eeepc_mic_automute(codec);
15749 }
15750 /* ***************** Mode3 ******************************/
15751 static void alc663_mode3_unsol_event(struct hda_codec *codec,
15752                                            unsigned int res)
15753 {
15754         switch (res >> 26) {
15755         case ALC880_HP_EVENT:
15756                 alc663_two_hp_m1_speaker_automute(codec);
15757                 break;
15758         case ALC880_MIC_EVENT:
15759                 alc662_eeepc_mic_automute(codec);
15760                 break;
15761         }
15762 }
15763
15764 static void alc663_mode3_inithook(struct hda_codec *codec)
15765 {
15766         alc663_two_hp_m1_speaker_automute(codec);
15767         alc662_eeepc_mic_automute(codec);
15768 }
15769 /* ***************** Mode4 ******************************/
15770 static void alc663_mode4_unsol_event(struct hda_codec *codec,
15771                                            unsigned int res)
15772 {
15773         switch (res >> 26) {
15774         case ALC880_HP_EVENT:
15775                 alc663_21jd_two_speaker_automute(codec);
15776                 break;
15777         case ALC880_MIC_EVENT:
15778                 alc662_eeepc_mic_automute(codec);
15779                 break;
15780         }
15781 }
15782
15783 static void alc663_mode4_inithook(struct hda_codec *codec)
15784 {
15785         alc663_21jd_two_speaker_automute(codec);
15786         alc662_eeepc_mic_automute(codec);
15787 }
15788 /* ***************** Mode5 ******************************/
15789 static void alc663_mode5_unsol_event(struct hda_codec *codec,
15790                                            unsigned int res)
15791 {
15792         switch (res >> 26) {
15793         case ALC880_HP_EVENT:
15794                 alc663_15jd_two_speaker_automute(codec);
15795                 break;
15796         case ALC880_MIC_EVENT:
15797                 alc662_eeepc_mic_automute(codec);
15798                 break;
15799         }
15800 }
15801
15802 static void alc663_mode5_inithook(struct hda_codec *codec)
15803 {
15804         alc663_15jd_two_speaker_automute(codec);
15805         alc662_eeepc_mic_automute(codec);
15806 }
15807 /* ***************** Mode6 ******************************/
15808 static void alc663_mode6_unsol_event(struct hda_codec *codec,
15809                                            unsigned int res)
15810 {
15811         switch (res >> 26) {
15812         case ALC880_HP_EVENT:
15813                 alc663_two_hp_m2_speaker_automute(codec);
15814                 break;
15815         case ALC880_MIC_EVENT:
15816                 alc662_eeepc_mic_automute(codec);
15817                 break;
15818         }
15819 }
15820
15821 static void alc663_mode6_inithook(struct hda_codec *codec)
15822 {
15823         alc663_two_hp_m2_speaker_automute(codec);
15824         alc662_eeepc_mic_automute(codec);
15825 }
15826
15827 static void alc663_g71v_hp_automute(struct hda_codec *codec)
15828 {
15829         unsigned int present;
15830         unsigned char bits;
15831
15832         present = snd_hda_codec_read(codec, 0x21, 0,
15833                                      AC_VERB_GET_PIN_SENSE, 0)
15834                 & AC_PINSENSE_PRESENCE;
15835         bits = present ? HDA_AMP_MUTE : 0;
15836         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15837                                  HDA_AMP_MUTE, bits);
15838         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15839                                  HDA_AMP_MUTE, bits);
15840 }
15841
15842 static void alc663_g71v_front_automute(struct hda_codec *codec)
15843 {
15844         unsigned int present;
15845         unsigned char bits;
15846
15847         present = snd_hda_codec_read(codec, 0x15, 0,
15848                                      AC_VERB_GET_PIN_SENSE, 0)
15849                 & AC_PINSENSE_PRESENCE;
15850         bits = present ? HDA_AMP_MUTE : 0;
15851         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15852                                  HDA_AMP_MUTE, bits);
15853 }
15854
15855 static void alc663_g71v_unsol_event(struct hda_codec *codec,
15856                                            unsigned int res)
15857 {
15858         switch (res >> 26) {
15859         case ALC880_HP_EVENT:
15860                 alc663_g71v_hp_automute(codec);
15861                 break;
15862         case ALC880_FRONT_EVENT:
15863                 alc663_g71v_front_automute(codec);
15864                 break;
15865         case ALC880_MIC_EVENT:
15866                 alc662_eeepc_mic_automute(codec);
15867                 break;
15868         }
15869 }
15870
15871 static void alc663_g71v_inithook(struct hda_codec *codec)
15872 {
15873         alc663_g71v_front_automute(codec);
15874         alc663_g71v_hp_automute(codec);
15875         alc662_eeepc_mic_automute(codec);
15876 }
15877
15878 static void alc663_g50v_unsol_event(struct hda_codec *codec,
15879                                            unsigned int res)
15880 {
15881         switch (res >> 26) {
15882         case ALC880_HP_EVENT:
15883                 alc663_m51va_speaker_automute(codec);
15884                 break;
15885         case ALC880_MIC_EVENT:
15886                 alc662_eeepc_mic_automute(codec);
15887                 break;
15888         }
15889 }
15890
15891 static void alc663_g50v_inithook(struct hda_codec *codec)
15892 {
15893         alc663_m51va_speaker_automute(codec);
15894         alc662_eeepc_mic_automute(codec);
15895 }
15896
15897 /* bind hp and internal speaker mute (with plug check) */
15898 static int alc662_ecs_master_sw_put(struct snd_kcontrol *kcontrol,
15899                                      struct snd_ctl_elem_value *ucontrol)
15900 {
15901         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
15902         long *valp = ucontrol->value.integer.value;
15903         int change;
15904
15905         change = snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
15906                                           HDA_AMP_MUTE,
15907                                           valp[0] ? 0 : HDA_AMP_MUTE);
15908         change |= snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
15909                                            HDA_AMP_MUTE,
15910                                            valp[1] ? 0 : HDA_AMP_MUTE);
15911         if (change)
15912                 alc262_hippo1_automute(codec);
15913         return change;
15914 }
15915
15916 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
15917         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15918         {
15919                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15920                 .name = "Master Playback Switch",
15921                 .info = snd_hda_mixer_amp_switch_info,
15922                 .get = snd_hda_mixer_amp_switch_get,
15923                 .put = alc662_ecs_master_sw_put,
15924                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15925         },
15926
15927         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
15928         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
15929         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
15930
15931         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15932         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15933         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15934         { } /* end */
15935 };
15936
15937 #ifdef CONFIG_SND_HDA_POWER_SAVE
15938 #define alc662_loopbacks        alc880_loopbacks
15939 #endif
15940
15941
15942 /* pcm configuration: identiacal with ALC880 */
15943 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
15944 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
15945 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
15946 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
15947
15948 /*
15949  * configuration and preset
15950  */
15951 static const char *alc662_models[ALC662_MODEL_LAST] = {
15952         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
15953         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
15954         [ALC662_3ST_6ch]        = "3stack-6ch",
15955         [ALC662_5ST_DIG]        = "6stack-dig",
15956         [ALC662_LENOVO_101E]    = "lenovo-101e",
15957         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
15958         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
15959         [ALC662_ECS] = "ecs",
15960         [ALC663_ASUS_M51VA] = "m51va",
15961         [ALC663_ASUS_G71V] = "g71v",
15962         [ALC663_ASUS_H13] = "h13",
15963         [ALC663_ASUS_G50V] = "g50v",
15964         [ALC663_ASUS_MODE1] = "asus-mode1",
15965         [ALC662_ASUS_MODE2] = "asus-mode2",
15966         [ALC663_ASUS_MODE3] = "asus-mode3",
15967         [ALC663_ASUS_MODE4] = "asus-mode4",
15968         [ALC663_ASUS_MODE5] = "asus-mode5",
15969         [ALC663_ASUS_MODE6] = "asus-mode6",
15970         [ALC662_AUTO]           = "auto",
15971 };
15972
15973 static struct snd_pci_quirk alc662_cfg_tbl[] = {
15974         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
15975         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
15976         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
15977         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
15978         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
15979         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
15980         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),
15981         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
15982         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
15983         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
15984         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),
15985         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
15986         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
15987         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
15988         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
15989         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
15990         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
15991         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
15992         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
15993         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
15994         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
15995         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
15996         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
15997         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
15998         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
15999         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
16000         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
16001         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
16002         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
16003         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
16004         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
16005         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
16006         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
16007         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
16008         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
16009         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
16010         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
16011         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
16012                       ALC662_3ST_6ch_DIG),
16013         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
16014         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
16015         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
16016         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
16017                       ALC662_3ST_6ch_DIG),
16018         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
16019         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
16020                                         ALC662_3ST_6ch_DIG),
16021         SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13),
16022         SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13),
16023         SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13),
16024         {}
16025 };
16026
16027 static struct alc_config_preset alc662_presets[] = {
16028         [ALC662_3ST_2ch_DIG] = {
16029                 .mixers = { alc662_3ST_2ch_mixer },
16030                 .init_verbs = { alc662_init_verbs },
16031                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16032                 .dac_nids = alc662_dac_nids,
16033                 .dig_out_nid = ALC662_DIGOUT_NID,
16034                 .dig_in_nid = ALC662_DIGIN_NID,
16035                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16036                 .channel_mode = alc662_3ST_2ch_modes,
16037                 .input_mux = &alc662_capture_source,
16038         },
16039         [ALC662_3ST_6ch_DIG] = {
16040                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16041                 .init_verbs = { alc662_init_verbs },
16042                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16043                 .dac_nids = alc662_dac_nids,
16044                 .dig_out_nid = ALC662_DIGOUT_NID,
16045                 .dig_in_nid = ALC662_DIGIN_NID,
16046                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16047                 .channel_mode = alc662_3ST_6ch_modes,
16048                 .need_dac_fix = 1,
16049                 .input_mux = &alc662_capture_source,
16050         },
16051         [ALC662_3ST_6ch] = {
16052                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16053                 .init_verbs = { alc662_init_verbs },
16054                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16055                 .dac_nids = alc662_dac_nids,
16056                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16057                 .channel_mode = alc662_3ST_6ch_modes,
16058                 .need_dac_fix = 1,
16059                 .input_mux = &alc662_capture_source,
16060         },
16061         [ALC662_5ST_DIG] = {
16062                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
16063                 .init_verbs = { alc662_init_verbs },
16064                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16065                 .dac_nids = alc662_dac_nids,
16066                 .dig_out_nid = ALC662_DIGOUT_NID,
16067                 .dig_in_nid = ALC662_DIGIN_NID,
16068                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
16069                 .channel_mode = alc662_5stack_modes,
16070                 .input_mux = &alc662_capture_source,
16071         },
16072         [ALC662_LENOVO_101E] = {
16073                 .mixers = { alc662_lenovo_101e_mixer },
16074                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
16075                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16076                 .dac_nids = alc662_dac_nids,
16077                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16078                 .channel_mode = alc662_3ST_2ch_modes,
16079                 .input_mux = &alc662_lenovo_101e_capture_source,
16080                 .unsol_event = alc662_lenovo_101e_unsol_event,
16081                 .init_hook = alc662_lenovo_101e_all_automute,
16082         },
16083         [ALC662_ASUS_EEEPC_P701] = {
16084                 .mixers = { alc662_eeepc_p701_mixer },
16085                 .init_verbs = { alc662_init_verbs,
16086                                 alc662_eeepc_sue_init_verbs },
16087                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16088                 .dac_nids = alc662_dac_nids,
16089                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16090                 .channel_mode = alc662_3ST_2ch_modes,
16091                 .input_mux = &alc662_eeepc_capture_source,
16092                 .unsol_event = alc662_eeepc_unsol_event,
16093                 .init_hook = alc662_eeepc_inithook,
16094         },
16095         [ALC662_ASUS_EEEPC_EP20] = {
16096                 .mixers = { alc662_eeepc_ep20_mixer,
16097                             alc662_chmode_mixer },
16098                 .init_verbs = { alc662_init_verbs,
16099                                 alc662_eeepc_ep20_sue_init_verbs },
16100                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16101                 .dac_nids = alc662_dac_nids,
16102                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16103                 .channel_mode = alc662_3ST_6ch_modes,
16104                 .input_mux = &alc662_lenovo_101e_capture_source,
16105                 .unsol_event = alc662_eeepc_ep20_unsol_event,
16106                 .init_hook = alc662_eeepc_ep20_inithook,
16107         },
16108         [ALC662_ECS] = {
16109                 .mixers = { alc662_ecs_mixer },
16110                 .init_verbs = { alc662_init_verbs,
16111                                 alc662_ecs_init_verbs },
16112                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16113                 .dac_nids = alc662_dac_nids,
16114                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16115                 .channel_mode = alc662_3ST_2ch_modes,
16116                 .input_mux = &alc662_eeepc_capture_source,
16117                 .unsol_event = alc662_eeepc_unsol_event,
16118                 .init_hook = alc662_eeepc_inithook,
16119         },
16120         [ALC663_ASUS_M51VA] = {
16121                 .mixers = { alc663_m51va_mixer },
16122                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16123                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16124                 .dac_nids = alc662_dac_nids,
16125                 .dig_out_nid = ALC662_DIGOUT_NID,
16126                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16127                 .channel_mode = alc662_3ST_2ch_modes,
16128                 .input_mux = &alc663_m51va_capture_source,
16129                 .unsol_event = alc663_m51va_unsol_event,
16130                 .init_hook = alc663_m51va_inithook,
16131         },
16132         [ALC663_ASUS_G71V] = {
16133                 .mixers = { alc663_g71v_mixer },
16134                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
16135                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16136                 .dac_nids = alc662_dac_nids,
16137                 .dig_out_nid = ALC662_DIGOUT_NID,
16138                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16139                 .channel_mode = alc662_3ST_2ch_modes,
16140                 .input_mux = &alc662_eeepc_capture_source,
16141                 .unsol_event = alc663_g71v_unsol_event,
16142                 .init_hook = alc663_g71v_inithook,
16143         },
16144         [ALC663_ASUS_H13] = {
16145                 .mixers = { alc663_m51va_mixer },
16146                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16147                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16148                 .dac_nids = alc662_dac_nids,
16149                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16150                 .channel_mode = alc662_3ST_2ch_modes,
16151                 .input_mux = &alc663_m51va_capture_source,
16152                 .unsol_event = alc663_m51va_unsol_event,
16153                 .init_hook = alc663_m51va_inithook,
16154         },
16155         [ALC663_ASUS_G50V] = {
16156                 .mixers = { alc663_g50v_mixer },
16157                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
16158                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16159                 .dac_nids = alc662_dac_nids,
16160                 .dig_out_nid = ALC662_DIGOUT_NID,
16161                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16162                 .channel_mode = alc662_3ST_6ch_modes,
16163                 .input_mux = &alc663_capture_source,
16164                 .unsol_event = alc663_g50v_unsol_event,
16165                 .init_hook = alc663_g50v_inithook,
16166         },
16167         [ALC663_ASUS_MODE1] = {
16168                 .mixers = { alc663_m51va_mixer },
16169                 .cap_mixer = alc662_auto_capture_mixer,
16170                 .init_verbs = { alc662_init_verbs,
16171                                 alc663_21jd_amic_init_verbs },
16172                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16173                 .hp_nid = 0x03,
16174                 .dac_nids = alc662_dac_nids,
16175                 .dig_out_nid = ALC662_DIGOUT_NID,
16176                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16177                 .channel_mode = alc662_3ST_2ch_modes,
16178                 .input_mux = &alc662_eeepc_capture_source,
16179                 .unsol_event = alc663_mode1_unsol_event,
16180                 .init_hook = alc663_mode1_inithook,
16181         },
16182         [ALC662_ASUS_MODE2] = {
16183                 .mixers = { alc662_1bjd_mixer },
16184                 .cap_mixer = alc662_auto_capture_mixer,
16185                 .init_verbs = { alc662_init_verbs,
16186                                 alc662_1bjd_amic_init_verbs },
16187                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16188                 .dac_nids = alc662_dac_nids,
16189                 .dig_out_nid = ALC662_DIGOUT_NID,
16190                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16191                 .channel_mode = alc662_3ST_2ch_modes,
16192                 .input_mux = &alc662_eeepc_capture_source,
16193                 .unsol_event = alc662_mode2_unsol_event,
16194                 .init_hook = alc662_mode2_inithook,
16195         },
16196         [ALC663_ASUS_MODE3] = {
16197                 .mixers = { alc663_two_hp_m1_mixer },
16198                 .cap_mixer = alc662_auto_capture_mixer,
16199                 .init_verbs = { alc662_init_verbs,
16200                                 alc663_two_hp_amic_m1_init_verbs },
16201                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16202                 .hp_nid = 0x03,
16203                 .dac_nids = alc662_dac_nids,
16204                 .dig_out_nid = ALC662_DIGOUT_NID,
16205                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16206                 .channel_mode = alc662_3ST_2ch_modes,
16207                 .input_mux = &alc662_eeepc_capture_source,
16208                 .unsol_event = alc663_mode3_unsol_event,
16209                 .init_hook = alc663_mode3_inithook,
16210         },
16211         [ALC663_ASUS_MODE4] = {
16212                 .mixers = { alc663_asus_21jd_clfe_mixer },
16213                 .cap_mixer = alc662_auto_capture_mixer,
16214                 .init_verbs = { alc662_init_verbs,
16215                                 alc663_21jd_amic_init_verbs},
16216                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16217                 .hp_nid = 0x03,
16218                 .dac_nids = alc662_dac_nids,
16219                 .dig_out_nid = ALC662_DIGOUT_NID,
16220                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16221                 .channel_mode = alc662_3ST_2ch_modes,
16222                 .input_mux = &alc662_eeepc_capture_source,
16223                 .unsol_event = alc663_mode4_unsol_event,
16224                 .init_hook = alc663_mode4_inithook,
16225         },
16226         [ALC663_ASUS_MODE5] = {
16227                 .mixers = { alc663_asus_15jd_clfe_mixer },
16228                 .cap_mixer = alc662_auto_capture_mixer,
16229                 .init_verbs = { alc662_init_verbs,
16230                                 alc663_15jd_amic_init_verbs },
16231                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16232                 .hp_nid = 0x03,
16233                 .dac_nids = alc662_dac_nids,
16234                 .dig_out_nid = ALC662_DIGOUT_NID,
16235                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16236                 .channel_mode = alc662_3ST_2ch_modes,
16237                 .input_mux = &alc662_eeepc_capture_source,
16238                 .unsol_event = alc663_mode5_unsol_event,
16239                 .init_hook = alc663_mode5_inithook,
16240         },
16241         [ALC663_ASUS_MODE6] = {
16242                 .mixers = { alc663_two_hp_m2_mixer },
16243                 .cap_mixer = alc662_auto_capture_mixer,
16244                 .init_verbs = { alc662_init_verbs,
16245                                 alc663_two_hp_amic_m2_init_verbs },
16246                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16247                 .hp_nid = 0x03,
16248                 .dac_nids = alc662_dac_nids,
16249                 .dig_out_nid = ALC662_DIGOUT_NID,
16250                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16251                 .channel_mode = alc662_3ST_2ch_modes,
16252                 .input_mux = &alc662_eeepc_capture_source,
16253                 .unsol_event = alc663_mode6_unsol_event,
16254                 .init_hook = alc663_mode6_inithook,
16255         },
16256 };
16257
16258
16259 /*
16260  * BIOS auto configuration
16261  */
16262
16263 /* add playback controls from the parsed DAC table */
16264 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
16265                                              const struct auto_pin_cfg *cfg)
16266 {
16267         char name[32];
16268         static const char *chname[4] = {
16269                 "Front", "Surround", NULL /*CLFE*/, "Side"
16270         };
16271         hda_nid_t nid;
16272         int i, err;
16273
16274         for (i = 0; i < cfg->line_outs; i++) {
16275                 if (!spec->multiout.dac_nids[i])
16276                         continue;
16277                 nid = alc880_idx_to_dac(i);
16278                 if (i == 2) {
16279                         /* Center/LFE */
16280                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16281                                           "Center Playback Volume",
16282                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
16283                                                               HDA_OUTPUT));
16284                         if (err < 0)
16285                                 return err;
16286                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16287                                           "LFE Playback Volume",
16288                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
16289                                                               HDA_OUTPUT));
16290                         if (err < 0)
16291                                 return err;
16292                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16293                                           "Center Playback Switch",
16294                                           HDA_COMPOSE_AMP_VAL(0x0e, 1, 0,
16295                                                               HDA_INPUT));
16296                         if (err < 0)
16297                                 return err;
16298                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16299                                           "LFE Playback Switch",
16300                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
16301                                                               HDA_INPUT));
16302                         if (err < 0)
16303                                 return err;
16304                 } else {
16305                         sprintf(name, "%s Playback Volume", chname[i]);
16306                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16307                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
16308                                                               HDA_OUTPUT));
16309                         if (err < 0)
16310                                 return err;
16311                         sprintf(name, "%s Playback Switch", chname[i]);
16312                         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16313                                 HDA_COMPOSE_AMP_VAL(alc880_idx_to_mixer(i),
16314                                                     3, 0, HDA_INPUT));
16315                         if (err < 0)
16316                                 return err;
16317                 }
16318         }
16319         return 0;
16320 }
16321
16322 /* add playback controls for speaker and HP outputs */
16323 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
16324                                         const char *pfx)
16325 {
16326         hda_nid_t nid;
16327         int err;
16328         char name[32];
16329
16330         if (!pin)
16331                 return 0;
16332
16333         if (pin == 0x17) {
16334                 /* ALC663 has a mono output pin on 0x17 */
16335                 sprintf(name, "%s Playback Switch", pfx);
16336                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16337                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
16338                 return err;
16339         }
16340
16341         if (alc880_is_fixed_pin(pin)) {
16342                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16343                 /* printk("DAC nid=%x\n",nid); */
16344                 /* specify the DAC as the extra output */
16345                 if (!spec->multiout.hp_nid)
16346                         spec->multiout.hp_nid = nid;
16347                 else
16348                         spec->multiout.extra_out_nid[0] = nid;
16349                 /* control HP volume/switch on the output mixer amp */
16350                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16351                 sprintf(name, "%s Playback Volume", pfx);
16352                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16353                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
16354                 if (err < 0)
16355                         return err;
16356                 sprintf(name, "%s Playback Switch", pfx);
16357                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
16358                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
16359                 if (err < 0)
16360                         return err;
16361         } else if (alc880_is_multi_pin(pin)) {
16362                 /* set manual connection */
16363                 /* we have only a switch on HP-out PIN */
16364                 sprintf(name, "%s Playback Switch", pfx);
16365                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16366                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
16367                 if (err < 0)
16368                         return err;
16369         }
16370         return 0;
16371 }
16372
16373 /* create playback/capture controls for input pins */
16374 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
16375                                                 const struct auto_pin_cfg *cfg)
16376 {
16377         struct hda_input_mux *imux = &spec->private_imux;
16378         int i, err, idx;
16379
16380         for (i = 0; i < AUTO_PIN_LAST; i++) {
16381                 if (alc880_is_input_pin(cfg->input_pins[i])) {
16382                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
16383                         err = new_analog_input(spec, cfg->input_pins[i],
16384                                                auto_pin_cfg_labels[i],
16385                                                idx, 0x0b);
16386                         if (err < 0)
16387                                 return err;
16388                         imux->items[imux->num_items].label =
16389                                 auto_pin_cfg_labels[i];
16390                         imux->items[imux->num_items].index =
16391                                 alc880_input_pin_idx(cfg->input_pins[i]);
16392                         imux->num_items++;
16393                 }
16394         }
16395         return 0;
16396 }
16397
16398 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
16399                                               hda_nid_t nid, int pin_type,
16400                                               int dac_idx)
16401 {
16402         alc_set_pin_output(codec, nid, pin_type);
16403         /* need the manual connection? */
16404         if (alc880_is_multi_pin(nid)) {
16405                 struct alc_spec *spec = codec->spec;
16406                 int idx = alc880_multi_pin_idx(nid);
16407                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
16408                                     AC_VERB_SET_CONNECT_SEL,
16409                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
16410         }
16411 }
16412
16413 static void alc662_auto_init_multi_out(struct hda_codec *codec)
16414 {
16415         struct alc_spec *spec = codec->spec;
16416         int i;
16417
16418         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
16419         for (i = 0; i <= HDA_SIDE; i++) {
16420                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
16421                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
16422                 if (nid)
16423                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
16424                                                           i);
16425         }
16426 }
16427
16428 static void alc662_auto_init_hp_out(struct hda_codec *codec)
16429 {
16430         struct alc_spec *spec = codec->spec;
16431         hda_nid_t pin;
16432
16433         pin = spec->autocfg.hp_pins[0];
16434         if (pin) /* connect to front */
16435                 /* use dac 0 */
16436                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
16437         pin = spec->autocfg.speaker_pins[0];
16438         if (pin)
16439                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
16440 }
16441
16442 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
16443 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
16444
16445 static void alc662_auto_init_analog_input(struct hda_codec *codec)
16446 {
16447         struct alc_spec *spec = codec->spec;
16448         int i;
16449
16450         for (i = 0; i < AUTO_PIN_LAST; i++) {
16451                 hda_nid_t nid = spec->autocfg.input_pins[i];
16452                 if (alc662_is_input_pin(nid)) {
16453                         snd_hda_codec_write(codec, nid, 0,
16454                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
16455                                             (i <= AUTO_PIN_FRONT_MIC ?
16456                                              PIN_VREF80 : PIN_IN));
16457                         if (nid != ALC662_PIN_CD_NID)
16458                                 snd_hda_codec_write(codec, nid, 0,
16459                                                     AC_VERB_SET_AMP_GAIN_MUTE,
16460                                                     AMP_OUT_MUTE);
16461                 }
16462         }
16463 }
16464
16465 #define alc662_auto_init_input_src      alc882_auto_init_input_src
16466
16467 static int alc662_parse_auto_config(struct hda_codec *codec)
16468 {
16469         struct alc_spec *spec = codec->spec;
16470         int err;
16471         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
16472
16473         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
16474                                            alc662_ignore);
16475         if (err < 0)
16476                 return err;
16477         if (!spec->autocfg.line_outs)
16478                 return 0; /* can't find valid BIOS pin config */
16479
16480         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
16481         if (err < 0)
16482                 return err;
16483         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
16484         if (err < 0)
16485                 return err;
16486         err = alc662_auto_create_extra_out(spec,
16487                                            spec->autocfg.speaker_pins[0],
16488                                            "Speaker");
16489         if (err < 0)
16490                 return err;
16491         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
16492                                            "Headphone");
16493         if (err < 0)
16494                 return err;
16495         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
16496         if (err < 0)
16497                 return err;
16498
16499         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
16500
16501         if (spec->autocfg.dig_out_pin)
16502                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
16503
16504         if (spec->kctls.list)
16505                 add_mixer(spec, spec->kctls.list);
16506
16507         spec->num_mux_defs = 1;
16508         spec->input_mux = &spec->private_imux;
16509
16510         add_verb(spec, alc662_auto_init_verbs);
16511         if (codec->vendor_id == 0x10ec0663)
16512                 add_verb(spec, alc663_auto_init_verbs);
16513
16514         err = alc_auto_add_mic_boost(codec);
16515         if (err < 0)
16516                 return err;
16517
16518         store_pin_configs(codec);
16519         return 1;
16520 }
16521
16522 /* additional initialization for auto-configuration model */
16523 static void alc662_auto_init(struct hda_codec *codec)
16524 {
16525         struct alc_spec *spec = codec->spec;
16526         alc662_auto_init_multi_out(codec);
16527         alc662_auto_init_hp_out(codec);
16528         alc662_auto_init_analog_input(codec);
16529         alc662_auto_init_input_src(codec);
16530         if (spec->unsol_event)
16531                 alc_inithook(codec);
16532 }
16533
16534 static int patch_alc662(struct hda_codec *codec)
16535 {
16536         struct alc_spec *spec;
16537         int err, board_config;
16538
16539         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
16540         if (!spec)
16541                 return -ENOMEM;
16542
16543         codec->spec = spec;
16544
16545         alc_fix_pll_init(codec, 0x20, 0x04, 15);
16546
16547         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
16548                                                   alc662_models,
16549                                                   alc662_cfg_tbl);
16550         if (board_config < 0) {
16551                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
16552                        "trying auto-probe from BIOS...\n");
16553                 board_config = ALC662_AUTO;
16554         }
16555
16556         if (board_config == ALC662_AUTO) {
16557                 /* automatic parse from the BIOS config */
16558                 err = alc662_parse_auto_config(codec);
16559                 if (err < 0) {
16560                         alc_free(codec);
16561                         return err;
16562                 } else if (!err) {
16563                         printk(KERN_INFO
16564                                "hda_codec: Cannot set up configuration "
16565                                "from BIOS.  Using base mode...\n");
16566                         board_config = ALC662_3ST_2ch_DIG;
16567                 }
16568         }
16569
16570         if (board_config != ALC662_AUTO)
16571                 setup_preset(spec, &alc662_presets[board_config]);
16572
16573         if (codec->vendor_id == 0x10ec0663) {
16574                 spec->stream_name_analog = "ALC663 Analog";
16575                 spec->stream_name_digital = "ALC663 Digital";
16576         } else if (codec->vendor_id == 0x10ec0272) {
16577                 spec->stream_name_analog = "ALC272 Analog";
16578                 spec->stream_name_digital = "ALC272 Digital";
16579         } else {
16580                 spec->stream_name_analog = "ALC662 Analog";
16581                 spec->stream_name_digital = "ALC662 Digital";
16582         }
16583
16584         spec->stream_analog_playback = &alc662_pcm_analog_playback;
16585         spec->stream_analog_capture = &alc662_pcm_analog_capture;
16586
16587         spec->stream_digital_playback = &alc662_pcm_digital_playback;
16588         spec->stream_digital_capture = &alc662_pcm_digital_capture;
16589
16590         spec->adc_nids = alc662_adc_nids;
16591         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
16592         spec->capsrc_nids = alc662_capsrc_nids;
16593         spec->is_mix_capture = 1;
16594
16595         if (!spec->cap_mixer)
16596                 set_capture_mixer(spec);
16597
16598         spec->vmaster_nid = 0x02;
16599
16600         codec->patch_ops = alc_patch_ops;
16601         if (board_config == ALC662_AUTO)
16602                 spec->init_hook = alc662_auto_init;
16603 #ifdef CONFIG_SND_HDA_POWER_SAVE
16604         if (!spec->loopback.amplist)
16605                 spec->loopback.amplist = alc662_loopbacks;
16606 #endif
16607         codec->proc_widget_hook = print_realtek_coef;
16608
16609         return 0;
16610 }
16611
16612 /*
16613  * patch entries
16614  */
16615 static struct hda_codec_preset snd_hda_preset_realtek[] = {
16616         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
16617         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
16618         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
16619         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
16620         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
16621         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
16622         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
16623           .patch = patch_alc861 },
16624         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
16625         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
16626         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
16627         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
16628           .patch = patch_alc883 },
16629         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
16630           .patch = patch_alc662 },
16631         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
16632         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
16633         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
16634         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
16635         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
16636           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16637         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
16638           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16639         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
16640         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc883 },
16641         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
16642         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
16643           .patch = patch_alc883 },
16644         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
16645         {} /* terminator */
16646 };
16647
16648 MODULE_ALIAS("snd-hda-codec-id:10ec*");
16649
16650 MODULE_LICENSE("GPL");
16651 MODULE_DESCRIPTION("Realtek HD-audio codec");
16652
16653 static struct hda_codec_preset_list realtek_list = {
16654         .preset = snd_hda_preset_realtek,
16655         .owner = THIS_MODULE,
16656 };
16657
16658 static int __init patch_realtek_init(void)
16659 {
16660         return snd_hda_add_codec_preset(&realtek_list);
16661 }
16662
16663 static void __exit patch_realtek_exit(void)
16664 {
16665         snd_hda_delete_codec_preset(&realtek_list);
16666 }
16667
16668 module_init(patch_realtek_init)
16669 module_exit(patch_realtek_exit)