]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - sound/pci/hda/patch_realtek.c
Merge branches 'topic/asoc', 'topic/misc-fixes' and 'topic/hda' into for-linus
[linux-2.6-omap-h63xx.git] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
33 #include "hda_patch.h"
34
35 #define ALC880_FRONT_EVENT              0x01
36 #define ALC880_DCVOL_EVENT              0x02
37 #define ALC880_HP_EVENT                 0x04
38 #define ALC880_MIC_EVENT                0x08
39
40 /* ALC880 board config type */
41 enum {
42         ALC880_3ST,
43         ALC880_3ST_DIG,
44         ALC880_5ST,
45         ALC880_5ST_DIG,
46         ALC880_W810,
47         ALC880_Z71V,
48         ALC880_6ST,
49         ALC880_6ST_DIG,
50         ALC880_F1734,
51         ALC880_ASUS,
52         ALC880_ASUS_DIG,
53         ALC880_ASUS_W1V,
54         ALC880_ASUS_DIG2,
55         ALC880_FUJITSU,
56         ALC880_UNIWILL_DIG,
57         ALC880_UNIWILL,
58         ALC880_UNIWILL_P53,
59         ALC880_CLEVO,
60         ALC880_TCL_S700,
61         ALC880_LG,
62         ALC880_LG_LW,
63         ALC880_MEDION_RIM,
64 #ifdef CONFIG_SND_DEBUG
65         ALC880_TEST,
66 #endif
67         ALC880_AUTO,
68         ALC880_MODEL_LAST /* last tag */
69 };
70
71 /* ALC260 models */
72 enum {
73         ALC260_BASIC,
74         ALC260_HP,
75         ALC260_HP_DC7600,
76         ALC260_HP_3013,
77         ALC260_FUJITSU_S702X,
78         ALC260_ACER,
79         ALC260_WILL,
80         ALC260_REPLACER_672V,
81 #ifdef CONFIG_SND_DEBUG
82         ALC260_TEST,
83 #endif
84         ALC260_AUTO,
85         ALC260_MODEL_LAST /* last tag */
86 };
87
88 /* ALC262 models */
89 enum {
90         ALC262_BASIC,
91         ALC262_HIPPO,
92         ALC262_HIPPO_1,
93         ALC262_FUJITSU,
94         ALC262_HP_BPC,
95         ALC262_HP_BPC_D7000_WL,
96         ALC262_HP_BPC_D7000_WF,
97         ALC262_HP_TC_T5735,
98         ALC262_HP_RP5700,
99         ALC262_BENQ_ED8,
100         ALC262_SONY_ASSAMD,
101         ALC262_BENQ_T31,
102         ALC262_ULTRA,
103         ALC262_LENOVO_3000,
104         ALC262_NEC,
105         ALC262_TOSHIBA_S06,
106         ALC262_TOSHIBA_RX1,
107         ALC262_AUTO,
108         ALC262_MODEL_LAST /* last tag */
109 };
110
111 /* ALC268 models */
112 enum {
113         ALC267_QUANTA_IL1,
114         ALC268_3ST,
115         ALC268_TOSHIBA,
116         ALC268_ACER,
117         ALC268_ACER_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_AUTO,
134         ALC269_MODEL_LAST /* last tag */
135 };
136
137 /* ALC861 models */
138 enum {
139         ALC861_3ST,
140         ALC660_3ST,
141         ALC861_3ST_DIG,
142         ALC861_6ST_DIG,
143         ALC861_UNIWILL_M31,
144         ALC861_TOSHIBA,
145         ALC861_ASUS,
146         ALC861_ASUS_LAPTOP,
147         ALC861_AUTO,
148         ALC861_MODEL_LAST,
149 };
150
151 /* ALC861-VD models */
152 enum {
153         ALC660VD_3ST,
154         ALC660VD_3ST_DIG,
155         ALC861VD_3ST,
156         ALC861VD_3ST_DIG,
157         ALC861VD_6ST_DIG,
158         ALC861VD_LENOVO,
159         ALC861VD_DALLAS,
160         ALC861VD_HP,
161         ALC861VD_AUTO,
162         ALC861VD_MODEL_LAST,
163 };
164
165 /* ALC662 models */
166 enum {
167         ALC662_3ST_2ch_DIG,
168         ALC662_3ST_6ch_DIG,
169         ALC662_3ST_6ch,
170         ALC662_5ST_DIG,
171         ALC662_LENOVO_101E,
172         ALC662_ASUS_EEEPC_P701,
173         ALC662_ASUS_EEEPC_EP20,
174         ALC663_ASUS_M51VA,
175         ALC663_ASUS_G71V,
176         ALC663_ASUS_H13,
177         ALC663_ASUS_G50V,
178         ALC662_ECS,
179         ALC663_ASUS_MODE1,
180         ALC662_ASUS_MODE2,
181         ALC663_ASUS_MODE3,
182         ALC663_ASUS_MODE4,
183         ALC663_ASUS_MODE5,
184         ALC663_ASUS_MODE6,
185         ALC662_AUTO,
186         ALC662_MODEL_LAST,
187 };
188
189 /* ALC882 models */
190 enum {
191         ALC882_3ST_DIG,
192         ALC882_6ST_DIG,
193         ALC882_ARIMA,
194         ALC882_W2JC,
195         ALC882_TARGA,
196         ALC882_ASUS_A7J,
197         ALC882_ASUS_A7M,
198         ALC885_MACPRO,
199         ALC885_MBP3,
200         ALC885_IMAC24,
201         ALC882_AUTO,
202         ALC882_MODEL_LAST,
203 };
204
205 /* ALC883 models */
206 enum {
207         ALC883_3ST_2ch_DIG,
208         ALC883_3ST_6ch_DIG,
209         ALC883_3ST_6ch,
210         ALC883_6ST_DIG,
211         ALC883_TARGA_DIG,
212         ALC883_TARGA_2ch_DIG,
213         ALC883_ACER,
214         ALC883_ACER_ASPIRE,
215         ALC883_MEDION,
216         ALC883_MEDION_MD2,
217         ALC883_LAPTOP_EAPD,
218         ALC883_LENOVO_101E_2ch,
219         ALC883_LENOVO_NB0763,
220         ALC888_LENOVO_MS7195_DIG,
221         ALC888_LENOVO_SKY,
222         ALC883_HAIER_W66,
223         ALC888_3ST_HP,
224         ALC888_6ST_DELL,
225         ALC883_MITAC,
226         ALC883_CLEVO_M720,
227         ALC883_FUJITSU_PI2515,
228         ALC883_3ST_6ch_INTEL,
229         ALC888_ASUS_M90V,
230         ALC888_ASUS_EEE1601,
231         ALC883_AUTO,
232         ALC883_MODEL_LAST,
233 };
234
235 /* for GPIO Poll */
236 #define GPIO_MASK       0x03
237
238 struct alc_spec {
239         /* codec parameterization */
240         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
241         unsigned int num_mixers;
242
243         const struct hda_verb *init_verbs[5];   /* initialization verbs
244                                                  * don't forget NULL
245                                                  * termination!
246                                                  */
247         unsigned int num_init_verbs;
248
249         char *stream_name_analog;       /* analog PCM stream */
250         struct hda_pcm_stream *stream_analog_playback;
251         struct hda_pcm_stream *stream_analog_capture;
252         struct hda_pcm_stream *stream_analog_alt_playback;
253         struct hda_pcm_stream *stream_analog_alt_capture;
254
255         char *stream_name_digital;      /* digital PCM stream */
256         struct hda_pcm_stream *stream_digital_playback;
257         struct hda_pcm_stream *stream_digital_capture;
258
259         /* playback */
260         struct hda_multi_out multiout;  /* playback set-up
261                                          * max_channels, dacs must be set
262                                          * dig_out_nid and hp_nid are optional
263                                          */
264         hda_nid_t alt_dac_nid;
265
266         /* capture */
267         unsigned int num_adc_nids;
268         hda_nid_t *adc_nids;
269         hda_nid_t *capsrc_nids;
270         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
271
272         /* capture source */
273         unsigned int num_mux_defs;
274         const struct hda_input_mux *input_mux;
275         unsigned int cur_mux[3];
276
277         /* channel model */
278         const struct hda_channel_mode *channel_mode;
279         int num_channel_mode;
280         int need_dac_fix;
281
282         /* PCM information */
283         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
284
285         /* dynamic controls, init_verbs and input_mux */
286         struct auto_pin_cfg autocfg;
287         unsigned int num_kctl_alloc, num_kctl_used;
288         struct snd_kcontrol_new *kctl_alloc;
289         struct hda_input_mux private_imux;
290         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
291
292         /* hooks */
293         void (*init_hook)(struct hda_codec *codec);
294         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
295
296         /* for pin sensing */
297         unsigned int sense_updated: 1;
298         unsigned int jack_present: 1;
299         unsigned int master_sw: 1;
300
301         /* for virtual master */
302         hda_nid_t vmaster_nid;
303 #ifdef CONFIG_SND_HDA_POWER_SAVE
304         struct hda_loopback_check loopback;
305 #endif
306
307         /* for PLL fix */
308         hda_nid_t pll_nid;
309         unsigned int pll_coef_idx, pll_coef_bit;
310 };
311
312 /*
313  * configuration template - to be copied to the spec instance
314  */
315 struct alc_config_preset {
316         struct snd_kcontrol_new *mixers[5]; /* should be identical size
317                                              * with spec
318                                              */
319         const struct hda_verb *init_verbs[5];
320         unsigned int num_dacs;
321         hda_nid_t *dac_nids;
322         hda_nid_t dig_out_nid;          /* optional */
323         hda_nid_t hp_nid;               /* optional */
324         unsigned int num_adc_nids;
325         hda_nid_t *adc_nids;
326         hda_nid_t *capsrc_nids;
327         hda_nid_t dig_in_nid;
328         unsigned int num_channel_mode;
329         const struct hda_channel_mode *channel_mode;
330         int need_dac_fix;
331         unsigned int num_mux_defs;
332         const struct hda_input_mux *input_mux;
333         void (*unsol_event)(struct hda_codec *, unsigned int);
334         void (*init_hook)(struct hda_codec *);
335 #ifdef CONFIG_SND_HDA_POWER_SAVE
336         struct hda_amp_list *loopbacks;
337 #endif
338 };
339
340
341 /*
342  * input MUX handling
343  */
344 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
345                              struct snd_ctl_elem_info *uinfo)
346 {
347         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
348         struct alc_spec *spec = codec->spec;
349         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
350         if (mux_idx >= spec->num_mux_defs)
351                 mux_idx = 0;
352         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
353 }
354
355 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
356                             struct snd_ctl_elem_value *ucontrol)
357 {
358         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
359         struct alc_spec *spec = codec->spec;
360         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
361
362         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
363         return 0;
364 }
365
366 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
367                             struct snd_ctl_elem_value *ucontrol)
368 {
369         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
370         struct alc_spec *spec = codec->spec;
371         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
372         unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
373         hda_nid_t nid = spec->capsrc_nids ?
374                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
375         return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
376                                      nid, &spec->cur_mux[adc_idx]);
377 }
378
379
380 /*
381  * channel mode setting
382  */
383 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
384                             struct snd_ctl_elem_info *uinfo)
385 {
386         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
387         struct alc_spec *spec = codec->spec;
388         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
389                                     spec->num_channel_mode);
390 }
391
392 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
393                            struct snd_ctl_elem_value *ucontrol)
394 {
395         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
396         struct alc_spec *spec = codec->spec;
397         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
398                                    spec->num_channel_mode,
399                                    spec->multiout.max_channels);
400 }
401
402 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
403                            struct snd_ctl_elem_value *ucontrol)
404 {
405         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
406         struct alc_spec *spec = codec->spec;
407         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
408                                       spec->num_channel_mode,
409                                       &spec->multiout.max_channels);
410         if (err >= 0 && spec->need_dac_fix)
411                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
412         return err;
413 }
414
415 /*
416  * Control the mode of pin widget settings via the mixer.  "pc" is used
417  * instead of "%" to avoid consequences of accidently treating the % as
418  * being part of a format specifier.  Maximum allowed length of a value is
419  * 63 characters plus NULL terminator.
420  *
421  * Note: some retasking pin complexes seem to ignore requests for input
422  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
423  * are requested.  Therefore order this list so that this behaviour will not
424  * cause problems when mixer clients move through the enum sequentially.
425  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
426  * March 2006.
427  */
428 static char *alc_pin_mode_names[] = {
429         "Mic 50pc bias", "Mic 80pc bias",
430         "Line in", "Line out", "Headphone out",
431 };
432 static unsigned char alc_pin_mode_values[] = {
433         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
434 };
435 /* The control can present all 5 options, or it can limit the options based
436  * in the pin being assumed to be exclusively an input or an output pin.  In
437  * addition, "input" pins may or may not process the mic bias option
438  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
439  * accept requests for bias as of chip versions up to March 2006) and/or
440  * wiring in the computer.
441  */
442 #define ALC_PIN_DIR_IN              0x00
443 #define ALC_PIN_DIR_OUT             0x01
444 #define ALC_PIN_DIR_INOUT           0x02
445 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
446 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
447
448 /* Info about the pin modes supported by the different pin direction modes.
449  * For each direction the minimum and maximum values are given.
450  */
451 static signed char alc_pin_mode_dir_info[5][2] = {
452         { 0, 2 },    /* ALC_PIN_DIR_IN */
453         { 3, 4 },    /* ALC_PIN_DIR_OUT */
454         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
455         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
456         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
457 };
458 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
459 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
460 #define alc_pin_mode_n_items(_dir) \
461         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
462
463 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
464                              struct snd_ctl_elem_info *uinfo)
465 {
466         unsigned int item_num = uinfo->value.enumerated.item;
467         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
468
469         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
470         uinfo->count = 1;
471         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
472
473         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
474                 item_num = alc_pin_mode_min(dir);
475         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
476         return 0;
477 }
478
479 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
480                             struct snd_ctl_elem_value *ucontrol)
481 {
482         unsigned int i;
483         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
484         hda_nid_t nid = kcontrol->private_value & 0xffff;
485         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
486         long *valp = ucontrol->value.integer.value;
487         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
488                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
489                                                  0x00);
490
491         /* Find enumerated value for current pinctl setting */
492         i = alc_pin_mode_min(dir);
493         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
494                 i++;
495         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
496         return 0;
497 }
498
499 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
500                             struct snd_ctl_elem_value *ucontrol)
501 {
502         signed int change;
503         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
504         hda_nid_t nid = kcontrol->private_value & 0xffff;
505         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
506         long val = *ucontrol->value.integer.value;
507         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
508                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
509                                                  0x00);
510
511         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
512                 val = alc_pin_mode_min(dir);
513
514         change = pinctl != alc_pin_mode_values[val];
515         if (change) {
516                 /* Set pin mode to that requested */
517                 snd_hda_codec_write_cache(codec, nid, 0,
518                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
519                                           alc_pin_mode_values[val]);
520
521                 /* Also enable the retasking pin's input/output as required
522                  * for the requested pin mode.  Enum values of 2 or less are
523                  * input modes.
524                  *
525                  * Dynamically switching the input/output buffers probably
526                  * reduces noise slightly (particularly on input) so we'll
527                  * do it.  However, having both input and output buffers
528                  * enabled simultaneously doesn't seem to be problematic if
529                  * this turns out to be necessary in the future.
530                  */
531                 if (val <= 2) {
532                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
533                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
534                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
535                                                  HDA_AMP_MUTE, 0);
536                 } else {
537                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
538                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
539                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
540                                                  HDA_AMP_MUTE, 0);
541                 }
542         }
543         return change;
544 }
545
546 #define ALC_PIN_MODE(xname, nid, dir) \
547         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
548           .info = alc_pin_mode_info, \
549           .get = alc_pin_mode_get, \
550           .put = alc_pin_mode_put, \
551           .private_value = nid | (dir<<16) }
552
553 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
554  * together using a mask with more than one bit set.  This control is
555  * currently used only by the ALC260 test model.  At this stage they are not
556  * needed for any "production" models.
557  */
558 #ifdef CONFIG_SND_DEBUG
559 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
560
561 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
562                              struct snd_ctl_elem_value *ucontrol)
563 {
564         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
565         hda_nid_t nid = kcontrol->private_value & 0xffff;
566         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
567         long *valp = ucontrol->value.integer.value;
568         unsigned int val = snd_hda_codec_read(codec, nid, 0,
569                                               AC_VERB_GET_GPIO_DATA, 0x00);
570
571         *valp = (val & mask) != 0;
572         return 0;
573 }
574 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
575                              struct snd_ctl_elem_value *ucontrol)
576 {
577         signed int change;
578         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
579         hda_nid_t nid = kcontrol->private_value & 0xffff;
580         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
581         long val = *ucontrol->value.integer.value;
582         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
583                                                     AC_VERB_GET_GPIO_DATA,
584                                                     0x00);
585
586         /* Set/unset the masked GPIO bit(s) as needed */
587         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
588         if (val == 0)
589                 gpio_data &= ~mask;
590         else
591                 gpio_data |= mask;
592         snd_hda_codec_write_cache(codec, nid, 0,
593                                   AC_VERB_SET_GPIO_DATA, gpio_data);
594
595         return change;
596 }
597 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
598         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
599           .info = alc_gpio_data_info, \
600           .get = alc_gpio_data_get, \
601           .put = alc_gpio_data_put, \
602           .private_value = nid | (mask<<16) }
603 #endif   /* CONFIG_SND_DEBUG */
604
605 /* A switch control to allow the enabling of the digital IO pins on the
606  * ALC260.  This is incredibly simplistic; the intention of this control is
607  * to provide something in the test model allowing digital outputs to be
608  * identified if present.  If models are found which can utilise these
609  * outputs a more complete mixer control can be devised for those models if
610  * necessary.
611  */
612 #ifdef CONFIG_SND_DEBUG
613 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
614
615 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
616                               struct snd_ctl_elem_value *ucontrol)
617 {
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 *valp = ucontrol->value.integer.value;
622         unsigned int val = snd_hda_codec_read(codec, nid, 0,
623                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
624
625         *valp = (val & mask) != 0;
626         return 0;
627 }
628 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
629                               struct snd_ctl_elem_value *ucontrol)
630 {
631         signed int change;
632         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
633         hda_nid_t nid = kcontrol->private_value & 0xffff;
634         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
635         long val = *ucontrol->value.integer.value;
636         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
637                                                     AC_VERB_GET_DIGI_CONVERT_1,
638                                                     0x00);
639
640         /* Set/unset the masked control bit(s) as needed */
641         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
642         if (val==0)
643                 ctrl_data &= ~mask;
644         else
645                 ctrl_data |= mask;
646         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
647                                   ctrl_data);
648
649         return change;
650 }
651 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
652         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
653           .info = alc_spdif_ctrl_info, \
654           .get = alc_spdif_ctrl_get, \
655           .put = alc_spdif_ctrl_put, \
656           .private_value = nid | (mask<<16) }
657 #endif   /* CONFIG_SND_DEBUG */
658
659 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
660  * Again, this is only used in the ALC26x test models to help identify when
661  * the EAPD line must be asserted for features to work.
662  */
663 #ifdef CONFIG_SND_DEBUG
664 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
665
666 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
667                               struct snd_ctl_elem_value *ucontrol)
668 {
669         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
670         hda_nid_t nid = kcontrol->private_value & 0xffff;
671         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
672         long *valp = ucontrol->value.integer.value;
673         unsigned int val = snd_hda_codec_read(codec, nid, 0,
674                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
675
676         *valp = (val & mask) != 0;
677         return 0;
678 }
679
680 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
681                               struct snd_ctl_elem_value *ucontrol)
682 {
683         int change;
684         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
685         hda_nid_t nid = kcontrol->private_value & 0xffff;
686         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
687         long val = *ucontrol->value.integer.value;
688         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
689                                                     AC_VERB_GET_EAPD_BTLENABLE,
690                                                     0x00);
691
692         /* Set/unset the masked control bit(s) as needed */
693         change = (!val ? 0 : mask) != (ctrl_data & mask);
694         if (!val)
695                 ctrl_data &= ~mask;
696         else
697                 ctrl_data |= mask;
698         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
699                                   ctrl_data);
700
701         return change;
702 }
703
704 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
705         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
706           .info = alc_eapd_ctrl_info, \
707           .get = alc_eapd_ctrl_get, \
708           .put = alc_eapd_ctrl_put, \
709           .private_value = nid | (mask<<16) }
710 #endif   /* CONFIG_SND_DEBUG */
711
712 /*
713  * set up from the preset table
714  */
715 static void setup_preset(struct alc_spec *spec,
716                          const struct alc_config_preset *preset)
717 {
718         int i;
719
720         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
721                 spec->mixers[spec->num_mixers++] = preset->mixers[i];
722         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
723              i++)
724                 spec->init_verbs[spec->num_init_verbs++] =
725                         preset->init_verbs[i];
726
727         spec->channel_mode = preset->channel_mode;
728         spec->num_channel_mode = preset->num_channel_mode;
729         spec->need_dac_fix = preset->need_dac_fix;
730
731         spec->multiout.max_channels = spec->channel_mode[0].channels;
732
733         spec->multiout.num_dacs = preset->num_dacs;
734         spec->multiout.dac_nids = preset->dac_nids;
735         spec->multiout.dig_out_nid = preset->dig_out_nid;
736         spec->multiout.hp_nid = preset->hp_nid;
737
738         spec->num_mux_defs = preset->num_mux_defs;
739         if (!spec->num_mux_defs)
740                 spec->num_mux_defs = 1;
741         spec->input_mux = preset->input_mux;
742
743         spec->num_adc_nids = preset->num_adc_nids;
744         spec->adc_nids = preset->adc_nids;
745         spec->capsrc_nids = preset->capsrc_nids;
746         spec->dig_in_nid = preset->dig_in_nid;
747
748         spec->unsol_event = preset->unsol_event;
749         spec->init_hook = preset->init_hook;
750 #ifdef CONFIG_SND_HDA_POWER_SAVE
751         spec->loopback.amplist = preset->loopbacks;
752 #endif
753 }
754
755 /* Enable GPIO mask and set output */
756 static struct hda_verb alc_gpio1_init_verbs[] = {
757         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
758         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
759         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
760         { }
761 };
762
763 static struct hda_verb alc_gpio2_init_verbs[] = {
764         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
765         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
766         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
767         { }
768 };
769
770 static struct hda_verb alc_gpio3_init_verbs[] = {
771         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
772         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
773         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
774         { }
775 };
776
777 /*
778  * Fix hardware PLL issue
779  * On some codecs, the analog PLL gating control must be off while
780  * the default value is 1.
781  */
782 static void alc_fix_pll(struct hda_codec *codec)
783 {
784         struct alc_spec *spec = codec->spec;
785         unsigned int val;
786
787         if (!spec->pll_nid)
788                 return;
789         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
790                             spec->pll_coef_idx);
791         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
792                                  AC_VERB_GET_PROC_COEF, 0);
793         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
794                             spec->pll_coef_idx);
795         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
796                             val & ~(1 << spec->pll_coef_bit));
797 }
798
799 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
800                              unsigned int coef_idx, unsigned int coef_bit)
801 {
802         struct alc_spec *spec = codec->spec;
803         spec->pll_nid = nid;
804         spec->pll_coef_idx = coef_idx;
805         spec->pll_coef_bit = coef_bit;
806         alc_fix_pll(codec);
807 }
808
809 static void alc_sku_automute(struct hda_codec *codec)
810 {
811         struct alc_spec *spec = codec->spec;
812         unsigned int present;
813         unsigned int hp_nid = spec->autocfg.hp_pins[0];
814         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
815
816         /* need to execute and sync at first */
817         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
818         present = snd_hda_codec_read(codec, hp_nid, 0,
819                                      AC_VERB_GET_PIN_SENSE, 0);
820         spec->jack_present = (present & 0x80000000) != 0;
821         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
822                             spec->jack_present ? 0 : PIN_OUT);
823 }
824
825 static void alc_mic_automute(struct hda_codec *codec)
826 {
827         struct alc_spec *spec = codec->spec;
828         unsigned int present;
829         unsigned int mic_nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
830         unsigned int fmic_nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
831         unsigned int mix_nid = spec->capsrc_nids[0];
832         unsigned int capsrc_idx_mic, capsrc_idx_fmic;
833
834         capsrc_idx_mic = mic_nid - 0x18;
835         capsrc_idx_fmic = fmic_nid - 0x18;
836         present = snd_hda_codec_read(codec, mic_nid, 0,
837                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
838         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
839                     0x7000 | (capsrc_idx_mic << 8) | (present ? 0 : 0x80));
840         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
841                     0x7000 | (capsrc_idx_fmic << 8) | (present ? 0x80 : 0));
842         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, capsrc_idx_fmic,
843                          HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
844 }
845
846 /* unsolicited event for HP jack sensing */
847 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
848 {
849         if (codec->vendor_id == 0x10ec0880)
850                 res >>= 28;
851         else
852                 res >>= 26;
853         if (res == ALC880_HP_EVENT)
854                 alc_sku_automute(codec);
855
856         if (res == ALC880_MIC_EVENT)
857                 alc_mic_automute(codec);
858 }
859
860 static void alc_inithook(struct hda_codec *codec)
861 {
862         alc_sku_automute(codec);
863         alc_mic_automute(codec);
864 }
865
866 /* additional initialization for ALC888 variants */
867 static void alc888_coef_init(struct hda_codec *codec)
868 {
869         unsigned int tmp;
870
871         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
872         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
873         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
874         if ((tmp & 0xf0) == 2)
875                 /* alc888S-VC */
876                 snd_hda_codec_read(codec, 0x20, 0,
877                                    AC_VERB_SET_PROC_COEF, 0x830);
878          else
879                  /* alc888-VB */
880                  snd_hda_codec_read(codec, 0x20, 0,
881                                     AC_VERB_SET_PROC_COEF, 0x3030);
882 }
883
884 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
885  *      31 ~ 16 :       Manufacture ID
886  *      15 ~ 8  :       SKU ID
887  *      7  ~ 0  :       Assembly ID
888  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
889  */
890 static void alc_subsystem_id(struct hda_codec *codec,
891                              unsigned int porta, unsigned int porte,
892                              unsigned int portd)
893 {
894         unsigned int ass, tmp, i;
895         unsigned nid;
896         struct alc_spec *spec = codec->spec;
897
898         ass = codec->subsystem_id & 0xffff;
899         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
900                 goto do_sku;
901
902         /*
903          * 31~30        : port conetcivity
904          * 29~21        : reserve
905          * 20           : PCBEEP input
906          * 19~16        : Check sum (15:1)
907          * 15~1         : Custom
908          * 0            : override
909         */
910         nid = 0x1d;
911         if (codec->vendor_id == 0x10ec0260)
912                 nid = 0x17;
913         ass = snd_hda_codec_read(codec, nid, 0,
914                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
915         if (!(ass & 1) && !(ass & 0x100000))
916                 return;
917         if ((ass >> 30) != 1)   /* no physical connection */
918                 return;
919
920         /* check sum */
921         tmp = 0;
922         for (i = 1; i < 16; i++) {
923                 if ((ass >> i) & 1)
924                         tmp++;
925         }
926         if (((ass >> 16) & 0xf) != tmp)
927                 return;
928 do_sku:
929         /*
930          * 0 : override
931          * 1 :  Swap Jack
932          * 2 : 0 --> Desktop, 1 --> Laptop
933          * 3~5 : External Amplifier control
934          * 7~6 : Reserved
935         */
936         tmp = (ass & 0x38) >> 3;        /* external Amp control */
937         switch (tmp) {
938         case 1:
939                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
940                 break;
941         case 3:
942                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
943                 break;
944         case 7:
945                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
946                 break;
947         case 5: /* set EAPD output high */
948                 switch (codec->vendor_id) {
949                 case 0x10ec0260:
950                         snd_hda_codec_write(codec, 0x0f, 0,
951                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
952                         snd_hda_codec_write(codec, 0x10, 0,
953                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
954                         break;
955                 case 0x10ec0262:
956                 case 0x10ec0267:
957                 case 0x10ec0268:
958                 case 0x10ec0269:
959                 case 0x10ec0660:
960                 case 0x10ec0662:
961                 case 0x10ec0663:
962                 case 0x10ec0862:
963                 case 0x10ec0889:
964                         snd_hda_codec_write(codec, 0x14, 0,
965                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
966                         snd_hda_codec_write(codec, 0x15, 0,
967                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
968                         break;
969                 }
970                 switch (codec->vendor_id) {
971                 case 0x10ec0260:
972                         snd_hda_codec_write(codec, 0x1a, 0,
973                                             AC_VERB_SET_COEF_INDEX, 7);
974                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
975                                                  AC_VERB_GET_PROC_COEF, 0);
976                         snd_hda_codec_write(codec, 0x1a, 0,
977                                             AC_VERB_SET_COEF_INDEX, 7);
978                         snd_hda_codec_write(codec, 0x1a, 0,
979                                             AC_VERB_SET_PROC_COEF,
980                                             tmp | 0x2010);
981                         break;
982                 case 0x10ec0262:
983                 case 0x10ec0880:
984                 case 0x10ec0882:
985                 case 0x10ec0883:
986                 case 0x10ec0885:
987                 case 0x10ec0889:
988                         snd_hda_codec_write(codec, 0x20, 0,
989                                             AC_VERB_SET_COEF_INDEX, 7);
990                         tmp = snd_hda_codec_read(codec, 0x20, 0,
991                                                  AC_VERB_GET_PROC_COEF, 0);
992                         snd_hda_codec_write(codec, 0x20, 0,
993                                             AC_VERB_SET_COEF_INDEX, 7);
994                         snd_hda_codec_write(codec, 0x20, 0,
995                                             AC_VERB_SET_PROC_COEF,
996                                             tmp | 0x2010);
997                         break;
998                 case 0x10ec0888:
999                         /*alc888_coef_init(codec);*/ /* called in alc_init() */
1000                         break;
1001                 case 0x10ec0267:
1002                 case 0x10ec0268:
1003                         snd_hda_codec_write(codec, 0x20, 0,
1004                                             AC_VERB_SET_COEF_INDEX, 7);
1005                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1006                                                  AC_VERB_GET_PROC_COEF, 0);
1007                         snd_hda_codec_write(codec, 0x20, 0,
1008                                             AC_VERB_SET_COEF_INDEX, 7);
1009                         snd_hda_codec_write(codec, 0x20, 0,
1010                                             AC_VERB_SET_PROC_COEF,
1011                                             tmp | 0x3000);
1012                         break;
1013                 }
1014         default:
1015                 break;
1016         }
1017
1018         /* is laptop or Desktop and enable the function "Mute internal speaker
1019          * when the external headphone out jack is plugged"
1020          */
1021         if (!(ass & 0x8000))
1022                 return;
1023         /*
1024          * 10~8 : Jack location
1025          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1026          * 14~13: Resvered
1027          * 15   : 1 --> enable the function "Mute internal speaker
1028          *              when the external headphone out jack is plugged"
1029          */
1030         if (!spec->autocfg.speaker_pins[0]) {
1031                 if (spec->autocfg.line_out_pins[0])
1032                         spec->autocfg.speaker_pins[0] =
1033                                 spec->autocfg.line_out_pins[0];
1034                 else
1035                         return;
1036         }
1037
1038         if (!spec->autocfg.hp_pins[0]) {
1039                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1040                 if (tmp == 0)
1041                         spec->autocfg.hp_pins[0] = porta;
1042                 else if (tmp == 1)
1043                         spec->autocfg.hp_pins[0] = porte;
1044                 else if (tmp == 2)
1045                         spec->autocfg.hp_pins[0] = portd;
1046                 else
1047                         return;
1048         }
1049         if (spec->autocfg.hp_pins[0])
1050                 snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1051                         AC_VERB_SET_UNSOLICITED_ENABLE,
1052                         AC_USRSP_EN | ALC880_HP_EVENT);
1053
1054         if (spec->autocfg.input_pins[AUTO_PIN_MIC] &&
1055                 spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC])
1056                 snd_hda_codec_write(codec,
1057                         spec->autocfg.input_pins[AUTO_PIN_MIC], 0,
1058                         AC_VERB_SET_UNSOLICITED_ENABLE,
1059                         AC_USRSP_EN | ALC880_MIC_EVENT);
1060
1061         spec->unsol_event = alc_sku_unsol_event;
1062 }
1063
1064 /*
1065  * Fix-up pin default configurations
1066  */
1067
1068 struct alc_pincfg {
1069         hda_nid_t nid;
1070         u32 val;
1071 };
1072
1073 static void alc_fix_pincfg(struct hda_codec *codec,
1074                            const struct snd_pci_quirk *quirk,
1075                            const struct alc_pincfg **pinfix)
1076 {
1077         const struct alc_pincfg *cfg;
1078
1079         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1080         if (!quirk)
1081                 return;
1082
1083         cfg = pinfix[quirk->value];
1084         for (; cfg->nid; cfg++) {
1085                 int i;
1086                 u32 val = cfg->val;
1087                 for (i = 0; i < 4; i++) {
1088                         snd_hda_codec_write(codec, cfg->nid, 0,
1089                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
1090                                     val & 0xff);
1091                         val >>= 8;
1092                 }
1093         }
1094 }
1095
1096 /*
1097  * ALC880 3-stack model
1098  *
1099  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1100  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1101  *                 F-Mic = 0x1b, HP = 0x19
1102  */
1103
1104 static hda_nid_t alc880_dac_nids[4] = {
1105         /* front, rear, clfe, rear_surr */
1106         0x02, 0x05, 0x04, 0x03
1107 };
1108
1109 static hda_nid_t alc880_adc_nids[3] = {
1110         /* ADC0-2 */
1111         0x07, 0x08, 0x09,
1112 };
1113
1114 /* The datasheet says the node 0x07 is connected from inputs,
1115  * but it shows zero connection in the real implementation on some devices.
1116  * Note: this is a 915GAV bug, fixed on 915GLV
1117  */
1118 static hda_nid_t alc880_adc_nids_alt[2] = {
1119         /* ADC1-2 */
1120         0x08, 0x09,
1121 };
1122
1123 #define ALC880_DIGOUT_NID       0x06
1124 #define ALC880_DIGIN_NID        0x0a
1125
1126 static struct hda_input_mux alc880_capture_source = {
1127         .num_items = 4,
1128         .items = {
1129                 { "Mic", 0x0 },
1130                 { "Front Mic", 0x3 },
1131                 { "Line", 0x2 },
1132                 { "CD", 0x4 },
1133         },
1134 };
1135
1136 /* channel source setting (2/6 channel selection for 3-stack) */
1137 /* 2ch mode */
1138 static struct hda_verb alc880_threestack_ch2_init[] = {
1139         /* set line-in to input, mute it */
1140         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1141         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1142         /* set mic-in to input vref 80%, mute it */
1143         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1144         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1145         { } /* end */
1146 };
1147
1148 /* 6ch mode */
1149 static struct hda_verb alc880_threestack_ch6_init[] = {
1150         /* set line-in to output, unmute it */
1151         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1152         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1153         /* set mic-in to output, unmute it */
1154         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1155         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1156         { } /* end */
1157 };
1158
1159 static struct hda_channel_mode alc880_threestack_modes[2] = {
1160         { 2, alc880_threestack_ch2_init },
1161         { 6, alc880_threestack_ch6_init },
1162 };
1163
1164 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1165         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1166         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1167         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1168         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1169         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1170         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1171         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1172         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1173         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1174         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1175         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1176         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1177         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1178         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1179         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1180         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1181         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1182         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1183         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1184         {
1185                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1186                 .name = "Channel Mode",
1187                 .info = alc_ch_mode_info,
1188                 .get = alc_ch_mode_get,
1189                 .put = alc_ch_mode_put,
1190         },
1191         { } /* end */
1192 };
1193
1194 /* capture mixer elements */
1195 static struct snd_kcontrol_new alc880_capture_mixer[] = {
1196         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
1197         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
1198         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
1199         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
1200         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
1201         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
1202         {
1203                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1204                 /* The multiple "Capture Source" controls confuse alsamixer
1205                  * So call somewhat different..
1206                  */
1207                 /* .name = "Capture Source", */
1208                 .name = "Input Source",
1209                 .count = 3,
1210                 .info = alc_mux_enum_info,
1211                 .get = alc_mux_enum_get,
1212                 .put = alc_mux_enum_put,
1213         },
1214         { } /* end */
1215 };
1216
1217 /* capture mixer elements (in case NID 0x07 not available) */
1218 static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
1219         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1220         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1221         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
1222         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
1223         {
1224                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1225                 /* The multiple "Capture Source" controls confuse alsamixer
1226                  * So call somewhat different..
1227                  */
1228                 /* .name = "Capture Source", */
1229                 .name = "Input Source",
1230                 .count = 2,
1231                 .info = alc_mux_enum_info,
1232                 .get = alc_mux_enum_get,
1233                 .put = alc_mux_enum_put,
1234         },
1235         { } /* end */
1236 };
1237
1238
1239
1240 /*
1241  * ALC880 5-stack model
1242  *
1243  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1244  *      Side = 0x02 (0xd)
1245  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1246  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1247  */
1248
1249 /* additional mixers to alc880_three_stack_mixer */
1250 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1251         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1252         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1253         { } /* end */
1254 };
1255
1256 /* channel source setting (6/8 channel selection for 5-stack) */
1257 /* 6ch mode */
1258 static struct hda_verb alc880_fivestack_ch6_init[] = {
1259         /* set line-in to input, mute it */
1260         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1261         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1262         { } /* end */
1263 };
1264
1265 /* 8ch mode */
1266 static struct hda_verb alc880_fivestack_ch8_init[] = {
1267         /* set line-in to output, unmute it */
1268         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1269         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1270         { } /* end */
1271 };
1272
1273 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1274         { 6, alc880_fivestack_ch6_init },
1275         { 8, alc880_fivestack_ch8_init },
1276 };
1277
1278
1279 /*
1280  * ALC880 6-stack model
1281  *
1282  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1283  *      Side = 0x05 (0x0f)
1284  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1285  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1286  */
1287
1288 static hda_nid_t alc880_6st_dac_nids[4] = {
1289         /* front, rear, clfe, rear_surr */
1290         0x02, 0x03, 0x04, 0x05
1291 };
1292
1293 static struct hda_input_mux alc880_6stack_capture_source = {
1294         .num_items = 4,
1295         .items = {
1296                 { "Mic", 0x0 },
1297                 { "Front Mic", 0x1 },
1298                 { "Line", 0x2 },
1299                 { "CD", 0x4 },
1300         },
1301 };
1302
1303 /* fixed 8-channels */
1304 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1305         { 8, NULL },
1306 };
1307
1308 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1309         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1310         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1311         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1312         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1313         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1314         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1315         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1316         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1317         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1318         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1319         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1320         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1321         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1322         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1323         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1324         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1325         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1326         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1327         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1328         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1329         {
1330                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1331                 .name = "Channel Mode",
1332                 .info = alc_ch_mode_info,
1333                 .get = alc_ch_mode_get,
1334                 .put = alc_ch_mode_put,
1335         },
1336         { } /* end */
1337 };
1338
1339
1340 /*
1341  * ALC880 W810 model
1342  *
1343  * W810 has rear IO for:
1344  * Front (DAC 02)
1345  * Surround (DAC 03)
1346  * Center/LFE (DAC 04)
1347  * Digital out (06)
1348  *
1349  * The system also has a pair of internal speakers, and a headphone jack.
1350  * These are both connected to Line2 on the codec, hence to DAC 02.
1351  *
1352  * There is a variable resistor to control the speaker or headphone
1353  * volume. This is a hardware-only device without a software API.
1354  *
1355  * Plugging headphones in will disable the internal speakers. This is
1356  * implemented in hardware, not via the driver using jack sense. In
1357  * a similar fashion, plugging into the rear socket marked "front" will
1358  * disable both the speakers and headphones.
1359  *
1360  * For input, there's a microphone jack, and an "audio in" jack.
1361  * These may not do anything useful with this driver yet, because I
1362  * haven't setup any initialization verbs for these yet...
1363  */
1364
1365 static hda_nid_t alc880_w810_dac_nids[3] = {
1366         /* front, rear/surround, clfe */
1367         0x02, 0x03, 0x04
1368 };
1369
1370 /* fixed 6 channels */
1371 static struct hda_channel_mode alc880_w810_modes[1] = {
1372         { 6, NULL }
1373 };
1374
1375 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1376 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1377         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1378         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1379         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1380         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1381         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1382         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1383         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1384         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1385         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1386         { } /* end */
1387 };
1388
1389
1390 /*
1391  * Z710V model
1392  *
1393  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1394  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1395  *                 Line = 0x1a
1396  */
1397
1398 static hda_nid_t alc880_z71v_dac_nids[1] = {
1399         0x02
1400 };
1401 #define ALC880_Z71V_HP_DAC      0x03
1402
1403 /* fixed 2 channels */
1404 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1405         { 2, NULL }
1406 };
1407
1408 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1409         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1410         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1411         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1412         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1413         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1414         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1415         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1416         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1417         { } /* end */
1418 };
1419
1420
1421 /*
1422  * ALC880 F1734 model
1423  *
1424  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1425  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1426  */
1427
1428 static hda_nid_t alc880_f1734_dac_nids[1] = {
1429         0x03
1430 };
1431 #define ALC880_F1734_HP_DAC     0x02
1432
1433 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1434         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1435         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1436         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1437         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1438         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1439         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1440         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1441         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1442         { } /* end */
1443 };
1444
1445 static struct hda_input_mux alc880_f1734_capture_source = {
1446         .num_items = 2,
1447         .items = {
1448                 { "Mic", 0x1 },
1449                 { "CD", 0x4 },
1450         },
1451 };
1452
1453
1454 /*
1455  * ALC880 ASUS model
1456  *
1457  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1458  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1459  *  Mic = 0x18, Line = 0x1a
1460  */
1461
1462 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1463 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1464
1465 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1466         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1467         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1468         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1469         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1470         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1471         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1472         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1473         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1474         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1475         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1476         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1477         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1478         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1479         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1480         {
1481                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1482                 .name = "Channel Mode",
1483                 .info = alc_ch_mode_info,
1484                 .get = alc_ch_mode_get,
1485                 .put = alc_ch_mode_put,
1486         },
1487         { } /* end */
1488 };
1489
1490 /*
1491  * ALC880 ASUS W1V model
1492  *
1493  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1494  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1495  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1496  */
1497
1498 /* additional mixers to alc880_asus_mixer */
1499 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1500         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1501         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1502         { } /* end */
1503 };
1504
1505 /* additional mixers to alc880_asus_mixer */
1506 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1507         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1508         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1509         { } /* end */
1510 };
1511
1512 /* TCL S700 */
1513 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1514         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1515         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1516         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1517         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1518         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1519         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1520         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1521         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1522         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1523         {
1524                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1525                 /* The multiple "Capture Source" controls confuse alsamixer
1526                  * So call somewhat different..
1527                  */
1528                 /* .name = "Capture Source", */
1529                 .name = "Input Source",
1530                 .count = 1,
1531                 .info = alc_mux_enum_info,
1532                 .get = alc_mux_enum_get,
1533                 .put = alc_mux_enum_put,
1534         },
1535         { } /* end */
1536 };
1537
1538 /* Uniwill */
1539 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1540         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1541         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1542         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1543         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1544         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1545         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1546         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1547         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1548         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1549         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1550         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1551         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1552         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1553         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1554         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1555         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1556         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1557         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1558         {
1559                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1560                 .name = "Channel Mode",
1561                 .info = alc_ch_mode_info,
1562                 .get = alc_ch_mode_get,
1563                 .put = alc_ch_mode_put,
1564         },
1565         { } /* end */
1566 };
1567
1568 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1569         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1570         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1571         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1572         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1573         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1574         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1575         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1576         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1577         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1578         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1579         { } /* end */
1580 };
1581
1582 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1583         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1584         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1585         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1586         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1587         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1588         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1589         { } /* end */
1590 };
1591
1592 /*
1593  * virtual master controls
1594  */
1595
1596 /*
1597  * slave controls for virtual master
1598  */
1599 static const char *alc_slave_vols[] = {
1600         "Front Playback Volume",
1601         "Surround Playback Volume",
1602         "Center Playback Volume",
1603         "LFE Playback Volume",
1604         "Side Playback Volume",
1605         "Headphone Playback Volume",
1606         "Speaker Playback Volume",
1607         "Mono Playback Volume",
1608         "Line-Out Playback Volume",
1609         NULL,
1610 };
1611
1612 static const char *alc_slave_sws[] = {
1613         "Front Playback Switch",
1614         "Surround Playback Switch",
1615         "Center Playback Switch",
1616         "LFE Playback Switch",
1617         "Side Playback Switch",
1618         "Headphone Playback Switch",
1619         "Speaker Playback Switch",
1620         "Mono Playback Switch",
1621         "IEC958 Playback Switch",
1622         NULL,
1623 };
1624
1625 /*
1626  * build control elements
1627  */
1628 static int alc_build_controls(struct hda_codec *codec)
1629 {
1630         struct alc_spec *spec = codec->spec;
1631         int err;
1632         int i;
1633
1634         for (i = 0; i < spec->num_mixers; i++) {
1635                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1636                 if (err < 0)
1637                         return err;
1638         }
1639
1640         if (spec->multiout.dig_out_nid) {
1641                 err = snd_hda_create_spdif_out_ctls(codec,
1642                                                     spec->multiout.dig_out_nid);
1643                 if (err < 0)
1644                         return err;
1645                 err = snd_hda_create_spdif_share_sw(codec,
1646                                                     &spec->multiout);
1647                 if (err < 0)
1648                         return err;
1649                 spec->multiout.share_spdif = 1;
1650         }
1651         if (spec->dig_in_nid) {
1652                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1653                 if (err < 0)
1654                         return err;
1655         }
1656
1657         /* if we have no master control, let's create it */
1658         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1659                 unsigned int vmaster_tlv[4];
1660                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1661                                         HDA_OUTPUT, vmaster_tlv);
1662                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1663                                           vmaster_tlv, alc_slave_vols);
1664                 if (err < 0)
1665                         return err;
1666         }
1667         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1668                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1669                                           NULL, alc_slave_sws);
1670                 if (err < 0)
1671                         return err;
1672         }
1673
1674         return 0;
1675 }
1676
1677
1678 /*
1679  * initialize the codec volumes, etc
1680  */
1681
1682 /*
1683  * generic initialization of ADC, input mixers and output mixers
1684  */
1685 static struct hda_verb alc880_volume_init_verbs[] = {
1686         /*
1687          * Unmute ADC0-2 and set the default input to mic-in
1688          */
1689         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
1690         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1691         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
1692         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1693         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1694         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1695
1696         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1697          * mixer widget
1698          * Note: PASD motherboards uses the Line In 2 as the input for front
1699          * panel mic (mic 2)
1700          */
1701         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
1702         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1703         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1704         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1705         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1706         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1707         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1708         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1709
1710         /*
1711          * Set up output mixers (0x0c - 0x0f)
1712          */
1713         /* set vol=0 to output mixers */
1714         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1715         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1716         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1717         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1718         /* set up input amps for analog loopback */
1719         /* Amp Indices: DAC = 0, mixer = 1 */
1720         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1721         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1722         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1723         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1724         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1725         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1726         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1727         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1728
1729         { }
1730 };
1731
1732 /*
1733  * 3-stack pin configuration:
1734  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
1735  */
1736 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
1737         /*
1738          * preset connection lists of input pins
1739          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1740          */
1741         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1742         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1743         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1744
1745         /*
1746          * Set pin mode and muting
1747          */
1748         /* set front pin widgets 0x14 for output */
1749         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1750         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1751         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1752         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1753         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1754         /* Mic2 (as headphone out) for HP output */
1755         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1756         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1757         /* Line In pin widget for input */
1758         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1759         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1760         /* Line2 (as front mic) pin widget for input and vref at 80% */
1761         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1762         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1763         /* CD pin widget for input */
1764         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1765
1766         { }
1767 };
1768
1769 /*
1770  * 5-stack pin configuration:
1771  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
1772  * line-in/side = 0x1a, f-mic = 0x1b
1773  */
1774 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
1775         /*
1776          * preset connection lists of input pins
1777          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1778          */
1779         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1780         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1781
1782         /*
1783          * Set pin mode and muting
1784          */
1785         /* set pin widgets 0x14-0x17 for output */
1786         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1787         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1788         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1789         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1790         /* unmute pins for output (no gain on this amp) */
1791         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1792         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1793         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1794         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1795
1796         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1797         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1798         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1799         /* Mic2 (as headphone out) for HP output */
1800         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1801         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1802         /* Line In pin widget for input */
1803         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1804         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1805         /* Line2 (as front mic) pin widget for input and vref at 80% */
1806         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1807         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1808         /* CD pin widget for input */
1809         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1810
1811         { }
1812 };
1813
1814 /*
1815  * W810 pin configuration:
1816  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
1817  */
1818 static struct hda_verb alc880_pin_w810_init_verbs[] = {
1819         /* hphone/speaker input selector: front DAC */
1820         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1821
1822         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1823         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1824         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1825         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1826         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1827         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1828
1829         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1830         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1831
1832         { }
1833 };
1834
1835 /*
1836  * Z71V pin configuration:
1837  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
1838  */
1839 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
1840         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1841         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1842         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1843         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1844
1845         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1846         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1847         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1848         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1849
1850         { }
1851 };
1852
1853 /*
1854  * 6-stack pin configuration:
1855  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
1856  * f-mic = 0x19, line = 0x1a, HP = 0x1b
1857  */
1858 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1859         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1860
1861         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1862         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1863         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1864         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1865         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1866         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1867         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1868         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1869
1870         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1871         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1872         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1873         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1874         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1875         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1876         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1877         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1878         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1879
1880         { }
1881 };
1882
1883 /*
1884  * Uniwill pin configuration:
1885  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
1886  * line = 0x1a
1887  */
1888 static struct hda_verb alc880_uniwill_init_verbs[] = {
1889         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1890
1891         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1892         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1893         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1894         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1895         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1896         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1897         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1898         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1899         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1900         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1901         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1902         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1903         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1904         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1905
1906         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1907         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1908         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1909         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1910         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1911         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1912         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
1913         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
1914         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1915
1916         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1917         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
1918
1919         { }
1920 };
1921
1922 /*
1923 * Uniwill P53
1924 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
1925  */
1926 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
1927         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1928
1929         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1930         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1931         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1932         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1933         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1934         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1935         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1936         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1937         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1938         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1939         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1940         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1941
1942         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1943         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1944         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1945         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1946         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1947         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1948
1949         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1950         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
1951
1952         { }
1953 };
1954
1955 static struct hda_verb alc880_beep_init_verbs[] = {
1956         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
1957         { }
1958 };
1959
1960 /* toggle speaker-output according to the hp-jack state */
1961 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
1962 {
1963         unsigned int present;
1964         unsigned char bits;
1965
1966         present = snd_hda_codec_read(codec, 0x14, 0,
1967                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1968         bits = present ? HDA_AMP_MUTE : 0;
1969         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1970                                  HDA_AMP_MUTE, bits);
1971         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
1972                                  HDA_AMP_MUTE, bits);
1973 }
1974
1975 /* auto-toggle front mic */
1976 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
1977 {
1978         unsigned int present;
1979         unsigned char bits;
1980
1981         present = snd_hda_codec_read(codec, 0x18, 0,
1982                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1983         bits = present ? HDA_AMP_MUTE : 0;
1984         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
1985 }
1986
1987 static void alc880_uniwill_automute(struct hda_codec *codec)
1988 {
1989         alc880_uniwill_hp_automute(codec);
1990         alc880_uniwill_mic_automute(codec);
1991 }
1992
1993 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
1994                                        unsigned int res)
1995 {
1996         /* Looks like the unsol event is incompatible with the standard
1997          * definition.  4bit tag is placed at 28 bit!
1998          */
1999         switch (res >> 28) {
2000         case ALC880_HP_EVENT:
2001                 alc880_uniwill_hp_automute(codec);
2002                 break;
2003         case ALC880_MIC_EVENT:
2004                 alc880_uniwill_mic_automute(codec);
2005                 break;
2006         }
2007 }
2008
2009 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
2010 {
2011         unsigned int present;
2012         unsigned char bits;
2013
2014         present = snd_hda_codec_read(codec, 0x14, 0,
2015                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2016         bits = present ? HDA_AMP_MUTE : 0;
2017         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
2018 }
2019
2020 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2021 {
2022         unsigned int present;
2023
2024         present = snd_hda_codec_read(codec, 0x21, 0,
2025                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2026         present &= HDA_AMP_VOLMASK;
2027         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2028                                  HDA_AMP_VOLMASK, present);
2029         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2030                                  HDA_AMP_VOLMASK, present);
2031 }
2032
2033 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2034                                            unsigned int res)
2035 {
2036         /* Looks like the unsol event is incompatible with the standard
2037          * definition.  4bit tag is placed at 28 bit!
2038          */
2039         if ((res >> 28) == ALC880_HP_EVENT)
2040                 alc880_uniwill_p53_hp_automute(codec);
2041         if ((res >> 28) == ALC880_DCVOL_EVENT)
2042                 alc880_uniwill_p53_dcvol_automute(codec);
2043 }
2044
2045 /*
2046  * F1734 pin configuration:
2047  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2048  */
2049 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2050         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2051         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2052         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2053         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2054         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2055
2056         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2057         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2058         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2059         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2060
2061         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2062         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2063         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2064         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2065         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2066         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2067         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2068         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2069         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2070
2071         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2072         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2073
2074         { }
2075 };
2076
2077 /*
2078  * ASUS pin configuration:
2079  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2080  */
2081 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2082         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2083         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2084         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2085         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2086
2087         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2088         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2089         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2090         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2091         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2092         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2093         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2094         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2095
2096         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2097         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2098         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2099         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2100         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2101         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2102         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2103         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2104         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2105
2106         { }
2107 };
2108
2109 /* Enable GPIO mask and set output */
2110 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2111 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2112
2113 /* Clevo m520g init */
2114 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2115         /* headphone output */
2116         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2117         /* line-out */
2118         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2119         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2120         /* Line-in */
2121         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2122         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2123         /* CD */
2124         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2125         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2126         /* Mic1 (rear panel) */
2127         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2128         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2129         /* Mic2 (front panel) */
2130         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2131         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2132         /* headphone */
2133         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2134         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2135         /* change to EAPD mode */
2136         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2137         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2138
2139         { }
2140 };
2141
2142 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2143         /* change to EAPD mode */
2144         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2145         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2146
2147         /* Headphone output */
2148         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2149         /* Front output*/
2150         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2151         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2152
2153         /* Line In pin widget for input */
2154         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2155         /* CD pin widget for input */
2156         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2157         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2158         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2159
2160         /* change to EAPD mode */
2161         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2162         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2163
2164         { }
2165 };
2166
2167 /*
2168  * LG m1 express dual
2169  *
2170  * Pin assignment:
2171  *   Rear Line-In/Out (blue): 0x14
2172  *   Build-in Mic-In: 0x15
2173  *   Speaker-out: 0x17
2174  *   HP-Out (green): 0x1b
2175  *   Mic-In/Out (red): 0x19
2176  *   SPDIF-Out: 0x1e
2177  */
2178
2179 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2180 static hda_nid_t alc880_lg_dac_nids[3] = {
2181         0x05, 0x02, 0x03
2182 };
2183
2184 /* seems analog CD is not working */
2185 static struct hda_input_mux alc880_lg_capture_source = {
2186         .num_items = 3,
2187         .items = {
2188                 { "Mic", 0x1 },
2189                 { "Line", 0x5 },
2190                 { "Internal Mic", 0x6 },
2191         },
2192 };
2193
2194 /* 2,4,6 channel modes */
2195 static struct hda_verb alc880_lg_ch2_init[] = {
2196         /* set line-in and mic-in to input */
2197         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2198         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2199         { }
2200 };
2201
2202 static struct hda_verb alc880_lg_ch4_init[] = {
2203         /* set line-in to out and mic-in to input */
2204         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2205         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2206         { }
2207 };
2208
2209 static struct hda_verb alc880_lg_ch6_init[] = {
2210         /* set line-in and mic-in to output */
2211         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2212         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2213         { }
2214 };
2215
2216 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2217         { 2, alc880_lg_ch2_init },
2218         { 4, alc880_lg_ch4_init },
2219         { 6, alc880_lg_ch6_init },
2220 };
2221
2222 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2223         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2224         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2225         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2226         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2227         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2228         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2229         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2230         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2231         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2232         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2233         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2234         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2235         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2236         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2237         {
2238                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2239                 .name = "Channel Mode",
2240                 .info = alc_ch_mode_info,
2241                 .get = alc_ch_mode_get,
2242                 .put = alc_ch_mode_put,
2243         },
2244         { } /* end */
2245 };
2246
2247 static struct hda_verb alc880_lg_init_verbs[] = {
2248         /* set capture source to mic-in */
2249         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2250         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2251         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2252         /* mute all amp mixer inputs */
2253         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2254         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2255         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2256         /* line-in to input */
2257         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2258         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2259         /* built-in mic */
2260         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2261         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2262         /* speaker-out */
2263         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2264         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2265         /* mic-in to input */
2266         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2267         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2268         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2269         /* HP-out */
2270         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2271         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2272         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2273         /* jack sense */
2274         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2275         { }
2276 };
2277
2278 /* toggle speaker-output according to the hp-jack state */
2279 static void alc880_lg_automute(struct hda_codec *codec)
2280 {
2281         unsigned int present;
2282         unsigned char bits;
2283
2284         present = snd_hda_codec_read(codec, 0x1b, 0,
2285                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2286         bits = present ? HDA_AMP_MUTE : 0;
2287         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2288                                  HDA_AMP_MUTE, bits);
2289 }
2290
2291 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2292 {
2293         /* Looks like the unsol event is incompatible with the standard
2294          * definition.  4bit tag is placed at 28 bit!
2295          */
2296         if ((res >> 28) == 0x01)
2297                 alc880_lg_automute(codec);
2298 }
2299
2300 /*
2301  * LG LW20
2302  *
2303  * Pin assignment:
2304  *   Speaker-out: 0x14
2305  *   Mic-In: 0x18
2306  *   Built-in Mic-In: 0x19
2307  *   Line-In: 0x1b
2308  *   HP-Out: 0x1a
2309  *   SPDIF-Out: 0x1e
2310  */
2311
2312 static struct hda_input_mux alc880_lg_lw_capture_source = {
2313         .num_items = 3,
2314         .items = {
2315                 { "Mic", 0x0 },
2316                 { "Internal Mic", 0x1 },
2317                 { "Line In", 0x2 },
2318         },
2319 };
2320
2321 #define alc880_lg_lw_modes alc880_threestack_modes
2322
2323 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2324         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2325         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2326         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2327         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2328         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2329         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2330         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2331         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2332         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2333         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2334         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2335         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2336         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2337         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2338         {
2339                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2340                 .name = "Channel Mode",
2341                 .info = alc_ch_mode_info,
2342                 .get = alc_ch_mode_get,
2343                 .put = alc_ch_mode_put,
2344         },
2345         { } /* end */
2346 };
2347
2348 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2349         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2350         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2351         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2352
2353         /* set capture source to mic-in */
2354         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2355         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2356         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2357         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2358         /* speaker-out */
2359         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2360         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2361         /* HP-out */
2362         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2363         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2364         /* mic-in to input */
2365         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2366         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2367         /* built-in mic */
2368         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2369         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2370         /* jack sense */
2371         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2372         { }
2373 };
2374
2375 /* toggle speaker-output according to the hp-jack state */
2376 static void alc880_lg_lw_automute(struct hda_codec *codec)
2377 {
2378         unsigned int present;
2379         unsigned char bits;
2380
2381         present = snd_hda_codec_read(codec, 0x1b, 0,
2382                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2383         bits = present ? HDA_AMP_MUTE : 0;
2384         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2385                                  HDA_AMP_MUTE, bits);
2386 }
2387
2388 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2389 {
2390         /* Looks like the unsol event is incompatible with the standard
2391          * definition.  4bit tag is placed at 28 bit!
2392          */
2393         if ((res >> 28) == 0x01)
2394                 alc880_lg_lw_automute(codec);
2395 }
2396
2397 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2398         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2399         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2400         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2401         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2402         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2403         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2404         { } /* end */
2405 };
2406
2407 static struct hda_input_mux alc880_medion_rim_capture_source = {
2408         .num_items = 2,
2409         .items = {
2410                 { "Mic", 0x0 },
2411                 { "Internal Mic", 0x1 },
2412         },
2413 };
2414
2415 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2416         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2417
2418         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2419         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2420
2421         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2422         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2423         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2424         /* Mic2 (as headphone out) for HP output */
2425         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2426         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2427         /* Internal Speaker */
2428         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2429         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2430
2431         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2432         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2433
2434         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2435         { }
2436 };
2437
2438 /* toggle speaker-output according to the hp-jack state */
2439 static void alc880_medion_rim_automute(struct hda_codec *codec)
2440 {
2441         unsigned int present;
2442         unsigned char bits;
2443
2444         present = snd_hda_codec_read(codec, 0x14, 0,
2445                                      AC_VERB_GET_PIN_SENSE, 0)
2446                 & AC_PINSENSE_PRESENCE;
2447         bits = present ? HDA_AMP_MUTE : 0;
2448         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2449                                  HDA_AMP_MUTE, bits);
2450         if (present)
2451                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2452         else
2453                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2454 }
2455
2456 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2457                                           unsigned int res)
2458 {
2459         /* Looks like the unsol event is incompatible with the standard
2460          * definition.  4bit tag is placed at 28 bit!
2461          */
2462         if ((res >> 28) == ALC880_HP_EVENT)
2463                 alc880_medion_rim_automute(codec);
2464 }
2465
2466 #ifdef CONFIG_SND_HDA_POWER_SAVE
2467 static struct hda_amp_list alc880_loopbacks[] = {
2468         { 0x0b, HDA_INPUT, 0 },
2469         { 0x0b, HDA_INPUT, 1 },
2470         { 0x0b, HDA_INPUT, 2 },
2471         { 0x0b, HDA_INPUT, 3 },
2472         { 0x0b, HDA_INPUT, 4 },
2473         { } /* end */
2474 };
2475
2476 static struct hda_amp_list alc880_lg_loopbacks[] = {
2477         { 0x0b, HDA_INPUT, 1 },
2478         { 0x0b, HDA_INPUT, 6 },
2479         { 0x0b, HDA_INPUT, 7 },
2480         { } /* end */
2481 };
2482 #endif
2483
2484 /*
2485  * Common callbacks
2486  */
2487
2488 static int alc_init(struct hda_codec *codec)
2489 {
2490         struct alc_spec *spec = codec->spec;
2491         unsigned int i;
2492
2493         alc_fix_pll(codec);
2494         if (codec->vendor_id == 0x10ec0888)
2495                 alc888_coef_init(codec);
2496
2497         for (i = 0; i < spec->num_init_verbs; i++)
2498                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2499
2500         if (spec->init_hook)
2501                 spec->init_hook(codec);
2502
2503         return 0;
2504 }
2505
2506 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2507 {
2508         struct alc_spec *spec = codec->spec;
2509
2510         if (spec->unsol_event)
2511                 spec->unsol_event(codec, res);
2512 }
2513
2514 #ifdef CONFIG_SND_HDA_POWER_SAVE
2515 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2516 {
2517         struct alc_spec *spec = codec->spec;
2518         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2519 }
2520 #endif
2521
2522 /*
2523  * Analog playback callbacks
2524  */
2525 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2526                                     struct hda_codec *codec,
2527                                     struct snd_pcm_substream *substream)
2528 {
2529         struct alc_spec *spec = codec->spec;
2530         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2531                                              hinfo);
2532 }
2533
2534 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2535                                        struct hda_codec *codec,
2536                                        unsigned int stream_tag,
2537                                        unsigned int format,
2538                                        struct snd_pcm_substream *substream)
2539 {
2540         struct alc_spec *spec = codec->spec;
2541         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2542                                                 stream_tag, format, substream);
2543 }
2544
2545 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2546                                        struct hda_codec *codec,
2547                                        struct snd_pcm_substream *substream)
2548 {
2549         struct alc_spec *spec = codec->spec;
2550         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2551 }
2552
2553 /*
2554  * Digital out
2555  */
2556 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2557                                         struct hda_codec *codec,
2558                                         struct snd_pcm_substream *substream)
2559 {
2560         struct alc_spec *spec = codec->spec;
2561         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2562 }
2563
2564 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2565                                            struct hda_codec *codec,
2566                                            unsigned int stream_tag,
2567                                            unsigned int format,
2568                                            struct snd_pcm_substream *substream)
2569 {
2570         struct alc_spec *spec = codec->spec;
2571         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2572                                              stream_tag, format, substream);
2573 }
2574
2575 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2576                                          struct hda_codec *codec,
2577                                          struct snd_pcm_substream *substream)
2578 {
2579         struct alc_spec *spec = codec->spec;
2580         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2581 }
2582
2583 /*
2584  * Analog capture
2585  */
2586 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2587                                       struct hda_codec *codec,
2588                                       unsigned int stream_tag,
2589                                       unsigned int format,
2590                                       struct snd_pcm_substream *substream)
2591 {
2592         struct alc_spec *spec = codec->spec;
2593
2594         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2595                                    stream_tag, 0, format);
2596         return 0;
2597 }
2598
2599 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2600                                       struct hda_codec *codec,
2601                                       struct snd_pcm_substream *substream)
2602 {
2603         struct alc_spec *spec = codec->spec;
2604
2605         snd_hda_codec_cleanup_stream(codec,
2606                                      spec->adc_nids[substream->number + 1]);
2607         return 0;
2608 }
2609
2610
2611 /*
2612  */
2613 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2614         .substreams = 1,
2615         .channels_min = 2,
2616         .channels_max = 8,
2617         /* NID is set in alc_build_pcms */
2618         .ops = {
2619                 .open = alc880_playback_pcm_open,
2620                 .prepare = alc880_playback_pcm_prepare,
2621                 .cleanup = alc880_playback_pcm_cleanup
2622         },
2623 };
2624
2625 static struct hda_pcm_stream alc880_pcm_analog_capture = {
2626         .substreams = 1,
2627         .channels_min = 2,
2628         .channels_max = 2,
2629         /* NID is set in alc_build_pcms */
2630 };
2631
2632 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
2633         .substreams = 1,
2634         .channels_min = 2,
2635         .channels_max = 2,
2636         /* NID is set in alc_build_pcms */
2637 };
2638
2639 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
2640         .substreams = 2, /* can be overridden */
2641         .channels_min = 2,
2642         .channels_max = 2,
2643         /* NID is set in alc_build_pcms */
2644         .ops = {
2645                 .prepare = alc880_alt_capture_pcm_prepare,
2646                 .cleanup = alc880_alt_capture_pcm_cleanup
2647         },
2648 };
2649
2650 static struct hda_pcm_stream alc880_pcm_digital_playback = {
2651         .substreams = 1,
2652         .channels_min = 2,
2653         .channels_max = 2,
2654         /* NID is set in alc_build_pcms */
2655         .ops = {
2656                 .open = alc880_dig_playback_pcm_open,
2657                 .close = alc880_dig_playback_pcm_close,
2658                 .prepare = alc880_dig_playback_pcm_prepare
2659         },
2660 };
2661
2662 static struct hda_pcm_stream alc880_pcm_digital_capture = {
2663         .substreams = 1,
2664         .channels_min = 2,
2665         .channels_max = 2,
2666         /* NID is set in alc_build_pcms */
2667 };
2668
2669 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2670 static struct hda_pcm_stream alc_pcm_null_stream = {
2671         .substreams = 0,
2672         .channels_min = 0,
2673         .channels_max = 0,
2674 };
2675
2676 static int alc_build_pcms(struct hda_codec *codec)
2677 {
2678         struct alc_spec *spec = codec->spec;
2679         struct hda_pcm *info = spec->pcm_rec;
2680         int i;
2681
2682         codec->num_pcms = 1;
2683         codec->pcm_info = info;
2684
2685         info->name = spec->stream_name_analog;
2686         if (spec->stream_analog_playback) {
2687                 if (snd_BUG_ON(!spec->multiout.dac_nids))
2688                         return -EINVAL;
2689                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
2690                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2691         }
2692         if (spec->stream_analog_capture) {
2693                 if (snd_BUG_ON(!spec->adc_nids))
2694                         return -EINVAL;
2695                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2696                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2697         }
2698
2699         if (spec->channel_mode) {
2700                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2701                 for (i = 0; i < spec->num_channel_mode; i++) {
2702                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2703                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2704                         }
2705                 }
2706         }
2707
2708         /* SPDIF for stream index #1 */
2709         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2710                 codec->num_pcms = 2;
2711                 info = spec->pcm_rec + 1;
2712                 info->name = spec->stream_name_digital;
2713                 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2714                 if (spec->multiout.dig_out_nid &&
2715                     spec->stream_digital_playback) {
2716                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
2717                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2718                 }
2719                 if (spec->dig_in_nid &&
2720                     spec->stream_digital_capture) {
2721                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
2722                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2723                 }
2724                 /* FIXME: do we need this for all Realtek codec models? */
2725                 codec->spdif_status_reset = 1;
2726         }
2727
2728         /* If the use of more than one ADC is requested for the current
2729          * model, configure a second analog capture-only PCM.
2730          */
2731         /* Additional Analaog capture for index #2 */
2732         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
2733             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
2734                 codec->num_pcms = 3;
2735                 info = spec->pcm_rec + 2;
2736                 info->name = spec->stream_name_analog;
2737                 if (spec->alt_dac_nid) {
2738                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2739                                 *spec->stream_analog_alt_playback;
2740                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2741                                 spec->alt_dac_nid;
2742                 } else {
2743                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2744                                 alc_pcm_null_stream;
2745                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2746                 }
2747                 if (spec->num_adc_nids > 1) {
2748                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2749                                 *spec->stream_analog_alt_capture;
2750                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2751                                 spec->adc_nids[1];
2752                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2753                                 spec->num_adc_nids - 1;
2754                 } else {
2755                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2756                                 alc_pcm_null_stream;
2757                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2758                 }
2759         }
2760
2761         return 0;
2762 }
2763
2764 static void alc_free(struct hda_codec *codec)
2765 {
2766         struct alc_spec *spec = codec->spec;
2767         unsigned int i;
2768
2769         if (!spec)
2770                 return;
2771
2772         if (spec->kctl_alloc) {
2773                 for (i = 0; i < spec->num_kctl_used; i++)
2774                         kfree(spec->kctl_alloc[i].name);
2775                 kfree(spec->kctl_alloc);
2776         }
2777         kfree(spec);
2778         codec->spec = NULL; /* to be sure */
2779 }
2780
2781 /*
2782  */
2783 static struct hda_codec_ops alc_patch_ops = {
2784         .build_controls = alc_build_controls,
2785         .build_pcms = alc_build_pcms,
2786         .init = alc_init,
2787         .free = alc_free,
2788         .unsol_event = alc_unsol_event,
2789 #ifdef CONFIG_SND_HDA_POWER_SAVE
2790         .check_power_status = alc_check_power_status,
2791 #endif
2792 };
2793
2794
2795 /*
2796  * Test configuration for debugging
2797  *
2798  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
2799  * enum controls.
2800  */
2801 #ifdef CONFIG_SND_DEBUG
2802 static hda_nid_t alc880_test_dac_nids[4] = {
2803         0x02, 0x03, 0x04, 0x05
2804 };
2805
2806 static struct hda_input_mux alc880_test_capture_source = {
2807         .num_items = 7,
2808         .items = {
2809                 { "In-1", 0x0 },
2810                 { "In-2", 0x1 },
2811                 { "In-3", 0x2 },
2812                 { "In-4", 0x3 },
2813                 { "CD", 0x4 },
2814                 { "Front", 0x5 },
2815                 { "Surround", 0x6 },
2816         },
2817 };
2818
2819 static struct hda_channel_mode alc880_test_modes[4] = {
2820         { 2, NULL },
2821         { 4, NULL },
2822         { 6, NULL },
2823         { 8, NULL },
2824 };
2825
2826 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
2827                                  struct snd_ctl_elem_info *uinfo)
2828 {
2829         static char *texts[] = {
2830                 "N/A", "Line Out", "HP Out",
2831                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
2832         };
2833         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2834         uinfo->count = 1;
2835         uinfo->value.enumerated.items = 8;
2836         if (uinfo->value.enumerated.item >= 8)
2837                 uinfo->value.enumerated.item = 7;
2838         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2839         return 0;
2840 }
2841
2842 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
2843                                 struct snd_ctl_elem_value *ucontrol)
2844 {
2845         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2846         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2847         unsigned int pin_ctl, item = 0;
2848
2849         pin_ctl = snd_hda_codec_read(codec, nid, 0,
2850                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2851         if (pin_ctl & AC_PINCTL_OUT_EN) {
2852                 if (pin_ctl & AC_PINCTL_HP_EN)
2853                         item = 2;
2854                 else
2855                         item = 1;
2856         } else if (pin_ctl & AC_PINCTL_IN_EN) {
2857                 switch (pin_ctl & AC_PINCTL_VREFEN) {
2858                 case AC_PINCTL_VREF_HIZ: item = 3; break;
2859                 case AC_PINCTL_VREF_50:  item = 4; break;
2860                 case AC_PINCTL_VREF_GRD: item = 5; break;
2861                 case AC_PINCTL_VREF_80:  item = 6; break;
2862                 case AC_PINCTL_VREF_100: item = 7; break;
2863                 }
2864         }
2865         ucontrol->value.enumerated.item[0] = item;
2866         return 0;
2867 }
2868
2869 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
2870                                 struct snd_ctl_elem_value *ucontrol)
2871 {
2872         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2873         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2874         static unsigned int ctls[] = {
2875                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
2876                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
2877                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
2878                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
2879                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
2880                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
2881         };
2882         unsigned int old_ctl, new_ctl;
2883
2884         old_ctl = snd_hda_codec_read(codec, nid, 0,
2885                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2886         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
2887         if (old_ctl != new_ctl) {
2888                 int val;
2889                 snd_hda_codec_write_cache(codec, nid, 0,
2890                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
2891                                           new_ctl);
2892                 val = ucontrol->value.enumerated.item[0] >= 3 ?
2893                         HDA_AMP_MUTE : 0;
2894                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
2895                                          HDA_AMP_MUTE, val);
2896                 return 1;
2897         }
2898         return 0;
2899 }
2900
2901 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
2902                                  struct snd_ctl_elem_info *uinfo)
2903 {
2904         static char *texts[] = {
2905                 "Front", "Surround", "CLFE", "Side"
2906         };
2907         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2908         uinfo->count = 1;
2909         uinfo->value.enumerated.items = 4;
2910         if (uinfo->value.enumerated.item >= 4)
2911                 uinfo->value.enumerated.item = 3;
2912         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2913         return 0;
2914 }
2915
2916 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
2917                                 struct snd_ctl_elem_value *ucontrol)
2918 {
2919         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2920         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2921         unsigned int sel;
2922
2923         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
2924         ucontrol->value.enumerated.item[0] = sel & 3;
2925         return 0;
2926 }
2927
2928 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
2929                                 struct snd_ctl_elem_value *ucontrol)
2930 {
2931         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2932         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2933         unsigned int sel;
2934
2935         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
2936         if (ucontrol->value.enumerated.item[0] != sel) {
2937                 sel = ucontrol->value.enumerated.item[0] & 3;
2938                 snd_hda_codec_write_cache(codec, nid, 0,
2939                                           AC_VERB_SET_CONNECT_SEL, sel);
2940                 return 1;
2941         }
2942         return 0;
2943 }
2944
2945 #define PIN_CTL_TEST(xname,nid) {                       \
2946                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2947                         .name = xname,                 \
2948                         .info = alc_test_pin_ctl_info, \
2949                         .get = alc_test_pin_ctl_get,   \
2950                         .put = alc_test_pin_ctl_put,   \
2951                         .private_value = nid           \
2952                         }
2953
2954 #define PIN_SRC_TEST(xname,nid) {                       \
2955                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2956                         .name = xname,                 \
2957                         .info = alc_test_pin_src_info, \
2958                         .get = alc_test_pin_src_get,   \
2959                         .put = alc_test_pin_src_put,   \
2960                         .private_value = nid           \
2961                         }
2962
2963 static struct snd_kcontrol_new alc880_test_mixer[] = {
2964         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2965         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2966         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
2967         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2968         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2969         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2970         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
2971         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2972         PIN_CTL_TEST("Front Pin Mode", 0x14),
2973         PIN_CTL_TEST("Surround Pin Mode", 0x15),
2974         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
2975         PIN_CTL_TEST("Side Pin Mode", 0x17),
2976         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
2977         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
2978         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
2979         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
2980         PIN_SRC_TEST("In-1 Pin Source", 0x18),
2981         PIN_SRC_TEST("In-2 Pin Source", 0x19),
2982         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
2983         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
2984         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
2985         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
2986         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
2987         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
2988         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
2989         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
2990         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
2991         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
2992         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
2993         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
2994         {
2995                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2996                 .name = "Channel Mode",
2997                 .info = alc_ch_mode_info,
2998                 .get = alc_ch_mode_get,
2999                 .put = alc_ch_mode_put,
3000         },
3001         { } /* end */
3002 };
3003
3004 static struct hda_verb alc880_test_init_verbs[] = {
3005         /* Unmute inputs of 0x0c - 0x0f */
3006         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3007         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3008         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3009         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3010         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3011         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3012         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3013         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3014         /* Vol output for 0x0c-0x0f */
3015         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3016         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3017         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3018         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3019         /* Set output pins 0x14-0x17 */
3020         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3021         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3022         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3023         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3024         /* Unmute output pins 0x14-0x17 */
3025         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3026         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3027         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3028         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3029         /* Set input pins 0x18-0x1c */
3030         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3031         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3032         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3033         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3034         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3035         /* Mute input pins 0x18-0x1b */
3036         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3037         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3038         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3039         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3040         /* ADC set up */
3041         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3042         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3043         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3044         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3045         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3046         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3047         /* Analog input/passthru */
3048         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3049         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3050         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3051         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3052         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3053         { }
3054 };
3055 #endif
3056
3057 /*
3058  */
3059
3060 static const char *alc880_models[ALC880_MODEL_LAST] = {
3061         [ALC880_3ST]            = "3stack",
3062         [ALC880_TCL_S700]       = "tcl",
3063         [ALC880_3ST_DIG]        = "3stack-digout",
3064         [ALC880_CLEVO]          = "clevo",
3065         [ALC880_5ST]            = "5stack",
3066         [ALC880_5ST_DIG]        = "5stack-digout",
3067         [ALC880_W810]           = "w810",
3068         [ALC880_Z71V]           = "z71v",
3069         [ALC880_6ST]            = "6stack",
3070         [ALC880_6ST_DIG]        = "6stack-digout",
3071         [ALC880_ASUS]           = "asus",
3072         [ALC880_ASUS_W1V]       = "asus-w1v",
3073         [ALC880_ASUS_DIG]       = "asus-dig",
3074         [ALC880_ASUS_DIG2]      = "asus-dig2",
3075         [ALC880_UNIWILL_DIG]    = "uniwill",
3076         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3077         [ALC880_FUJITSU]        = "fujitsu",
3078         [ALC880_F1734]          = "F1734",
3079         [ALC880_LG]             = "lg",
3080         [ALC880_LG_LW]          = "lg-lw",
3081         [ALC880_MEDION_RIM]     = "medion",
3082 #ifdef CONFIG_SND_DEBUG
3083         [ALC880_TEST]           = "test",
3084 #endif
3085         [ALC880_AUTO]           = "auto",
3086 };
3087
3088 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3089         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3090         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3091         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3092         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3093         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3094         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3095         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3096         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3097         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3098         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3099         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3100         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3101         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3102         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3103         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3104         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3105         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3106         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3107         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3108         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3109         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3110         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3111         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3112         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3113         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3114         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
3115         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3116         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3117         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3118         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3119         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3120         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3121         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3122         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3123         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3124         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3125         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3126         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3127         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3128         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3129         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3130         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3131         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3132         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3133         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3134         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3135         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3136         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3137         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3138         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3139         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3140         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3141         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3142         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3143         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3144         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3145         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3146         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3147         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3148         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3149         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3150         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3151         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3152         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3153         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3154         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3155         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3156         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3157         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
3158         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3159         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3160         {}
3161 };
3162
3163 /*
3164  * ALC880 codec presets
3165  */
3166 static struct alc_config_preset alc880_presets[] = {
3167         [ALC880_3ST] = {
3168                 .mixers = { alc880_three_stack_mixer },
3169                 .init_verbs = { alc880_volume_init_verbs,
3170                                 alc880_pin_3stack_init_verbs },
3171                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3172                 .dac_nids = alc880_dac_nids,
3173                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3174                 .channel_mode = alc880_threestack_modes,
3175                 .need_dac_fix = 1,
3176                 .input_mux = &alc880_capture_source,
3177         },
3178         [ALC880_3ST_DIG] = {
3179                 .mixers = { alc880_three_stack_mixer },
3180                 .init_verbs = { alc880_volume_init_verbs,
3181                                 alc880_pin_3stack_init_verbs },
3182                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3183                 .dac_nids = alc880_dac_nids,
3184                 .dig_out_nid = ALC880_DIGOUT_NID,
3185                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3186                 .channel_mode = alc880_threestack_modes,
3187                 .need_dac_fix = 1,
3188                 .input_mux = &alc880_capture_source,
3189         },
3190         [ALC880_TCL_S700] = {
3191                 .mixers = { alc880_tcl_s700_mixer },
3192                 .init_verbs = { alc880_volume_init_verbs,
3193                                 alc880_pin_tcl_S700_init_verbs,
3194                                 alc880_gpio2_init_verbs },
3195                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3196                 .dac_nids = alc880_dac_nids,
3197                 .hp_nid = 0x03,
3198                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3199                 .channel_mode = alc880_2_jack_modes,
3200                 .input_mux = &alc880_capture_source,
3201         },
3202         [ALC880_5ST] = {
3203                 .mixers = { alc880_three_stack_mixer,
3204                             alc880_five_stack_mixer},
3205                 .init_verbs = { alc880_volume_init_verbs,
3206                                 alc880_pin_5stack_init_verbs },
3207                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3208                 .dac_nids = alc880_dac_nids,
3209                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3210                 .channel_mode = alc880_fivestack_modes,
3211                 .input_mux = &alc880_capture_source,
3212         },
3213         [ALC880_5ST_DIG] = {
3214                 .mixers = { alc880_three_stack_mixer,
3215                             alc880_five_stack_mixer },
3216                 .init_verbs = { alc880_volume_init_verbs,
3217                                 alc880_pin_5stack_init_verbs },
3218                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3219                 .dac_nids = alc880_dac_nids,
3220                 .dig_out_nid = ALC880_DIGOUT_NID,
3221                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3222                 .channel_mode = alc880_fivestack_modes,
3223                 .input_mux = &alc880_capture_source,
3224         },
3225         [ALC880_6ST] = {
3226                 .mixers = { alc880_six_stack_mixer },
3227                 .init_verbs = { alc880_volume_init_verbs,
3228                                 alc880_pin_6stack_init_verbs },
3229                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3230                 .dac_nids = alc880_6st_dac_nids,
3231                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3232                 .channel_mode = alc880_sixstack_modes,
3233                 .input_mux = &alc880_6stack_capture_source,
3234         },
3235         [ALC880_6ST_DIG] = {
3236                 .mixers = { alc880_six_stack_mixer },
3237                 .init_verbs = { alc880_volume_init_verbs,
3238                                 alc880_pin_6stack_init_verbs },
3239                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3240                 .dac_nids = alc880_6st_dac_nids,
3241                 .dig_out_nid = ALC880_DIGOUT_NID,
3242                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3243                 .channel_mode = alc880_sixstack_modes,
3244                 .input_mux = &alc880_6stack_capture_source,
3245         },
3246         [ALC880_W810] = {
3247                 .mixers = { alc880_w810_base_mixer },
3248                 .init_verbs = { alc880_volume_init_verbs,
3249                                 alc880_pin_w810_init_verbs,
3250                                 alc880_gpio2_init_verbs },
3251                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3252                 .dac_nids = alc880_w810_dac_nids,
3253                 .dig_out_nid = ALC880_DIGOUT_NID,
3254                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3255                 .channel_mode = alc880_w810_modes,
3256                 .input_mux = &alc880_capture_source,
3257         },
3258         [ALC880_Z71V] = {
3259                 .mixers = { alc880_z71v_mixer },
3260                 .init_verbs = { alc880_volume_init_verbs,
3261                                 alc880_pin_z71v_init_verbs },
3262                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3263                 .dac_nids = alc880_z71v_dac_nids,
3264                 .dig_out_nid = ALC880_DIGOUT_NID,
3265                 .hp_nid = 0x03,
3266                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3267                 .channel_mode = alc880_2_jack_modes,
3268                 .input_mux = &alc880_capture_source,
3269         },
3270         [ALC880_F1734] = {
3271                 .mixers = { alc880_f1734_mixer },
3272                 .init_verbs = { alc880_volume_init_verbs,
3273                                 alc880_pin_f1734_init_verbs },
3274                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3275                 .dac_nids = alc880_f1734_dac_nids,
3276                 .hp_nid = 0x02,
3277                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3278                 .channel_mode = alc880_2_jack_modes,
3279                 .input_mux = &alc880_f1734_capture_source,
3280                 .unsol_event = alc880_uniwill_p53_unsol_event,
3281                 .init_hook = alc880_uniwill_p53_hp_automute,
3282         },
3283         [ALC880_ASUS] = {
3284                 .mixers = { alc880_asus_mixer },
3285                 .init_verbs = { alc880_volume_init_verbs,
3286                                 alc880_pin_asus_init_verbs,
3287                                 alc880_gpio1_init_verbs },
3288                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3289                 .dac_nids = alc880_asus_dac_nids,
3290                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3291                 .channel_mode = alc880_asus_modes,
3292                 .need_dac_fix = 1,
3293                 .input_mux = &alc880_capture_source,
3294         },
3295         [ALC880_ASUS_DIG] = {
3296                 .mixers = { alc880_asus_mixer },
3297                 .init_verbs = { alc880_volume_init_verbs,
3298                                 alc880_pin_asus_init_verbs,
3299                                 alc880_gpio1_init_verbs },
3300                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3301                 .dac_nids = alc880_asus_dac_nids,
3302                 .dig_out_nid = ALC880_DIGOUT_NID,
3303                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3304                 .channel_mode = alc880_asus_modes,
3305                 .need_dac_fix = 1,
3306                 .input_mux = &alc880_capture_source,
3307         },
3308         [ALC880_ASUS_DIG2] = {
3309                 .mixers = { alc880_asus_mixer },
3310                 .init_verbs = { alc880_volume_init_verbs,
3311                                 alc880_pin_asus_init_verbs,
3312                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3313                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3314                 .dac_nids = alc880_asus_dac_nids,
3315                 .dig_out_nid = ALC880_DIGOUT_NID,
3316                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3317                 .channel_mode = alc880_asus_modes,
3318                 .need_dac_fix = 1,
3319                 .input_mux = &alc880_capture_source,
3320         },
3321         [ALC880_ASUS_W1V] = {
3322                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3323                 .init_verbs = { alc880_volume_init_verbs,
3324                                 alc880_pin_asus_init_verbs,
3325                                 alc880_gpio1_init_verbs },
3326                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3327                 .dac_nids = alc880_asus_dac_nids,
3328                 .dig_out_nid = ALC880_DIGOUT_NID,
3329                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3330                 .channel_mode = alc880_asus_modes,
3331                 .need_dac_fix = 1,
3332                 .input_mux = &alc880_capture_source,
3333         },
3334         [ALC880_UNIWILL_DIG] = {
3335                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3336                 .init_verbs = { alc880_volume_init_verbs,
3337                                 alc880_pin_asus_init_verbs },
3338                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3339                 .dac_nids = alc880_asus_dac_nids,
3340                 .dig_out_nid = ALC880_DIGOUT_NID,
3341                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3342                 .channel_mode = alc880_asus_modes,
3343                 .need_dac_fix = 1,
3344                 .input_mux = &alc880_capture_source,
3345         },
3346         [ALC880_UNIWILL] = {
3347                 .mixers = { alc880_uniwill_mixer },
3348                 .init_verbs = { alc880_volume_init_verbs,
3349                                 alc880_uniwill_init_verbs },
3350                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3351                 .dac_nids = alc880_asus_dac_nids,
3352                 .dig_out_nid = ALC880_DIGOUT_NID,
3353                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3354                 .channel_mode = alc880_threestack_modes,
3355                 .need_dac_fix = 1,
3356                 .input_mux = &alc880_capture_source,
3357                 .unsol_event = alc880_uniwill_unsol_event,
3358                 .init_hook = alc880_uniwill_automute,
3359         },
3360         [ALC880_UNIWILL_P53] = {
3361                 .mixers = { alc880_uniwill_p53_mixer },
3362                 .init_verbs = { alc880_volume_init_verbs,
3363                                 alc880_uniwill_p53_init_verbs },
3364                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3365                 .dac_nids = alc880_asus_dac_nids,
3366                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3367                 .channel_mode = alc880_threestack_modes,
3368                 .input_mux = &alc880_capture_source,
3369                 .unsol_event = alc880_uniwill_p53_unsol_event,
3370                 .init_hook = alc880_uniwill_p53_hp_automute,
3371         },
3372         [ALC880_FUJITSU] = {
3373                 .mixers = { alc880_fujitsu_mixer,
3374                             alc880_pcbeep_mixer, },
3375                 .init_verbs = { alc880_volume_init_verbs,
3376                                 alc880_uniwill_p53_init_verbs,
3377                                 alc880_beep_init_verbs },
3378                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3379                 .dac_nids = alc880_dac_nids,
3380                 .dig_out_nid = ALC880_DIGOUT_NID,
3381                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3382                 .channel_mode = alc880_2_jack_modes,
3383                 .input_mux = &alc880_capture_source,
3384                 .unsol_event = alc880_uniwill_p53_unsol_event,
3385                 .init_hook = alc880_uniwill_p53_hp_automute,
3386         },
3387         [ALC880_CLEVO] = {
3388                 .mixers = { alc880_three_stack_mixer },
3389                 .init_verbs = { alc880_volume_init_verbs,
3390                                 alc880_pin_clevo_init_verbs },
3391                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3392                 .dac_nids = alc880_dac_nids,
3393                 .hp_nid = 0x03,
3394                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3395                 .channel_mode = alc880_threestack_modes,
3396                 .need_dac_fix = 1,
3397                 .input_mux = &alc880_capture_source,
3398         },
3399         [ALC880_LG] = {
3400                 .mixers = { alc880_lg_mixer },
3401                 .init_verbs = { alc880_volume_init_verbs,
3402                                 alc880_lg_init_verbs },
3403                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3404                 .dac_nids = alc880_lg_dac_nids,
3405                 .dig_out_nid = ALC880_DIGOUT_NID,
3406                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3407                 .channel_mode = alc880_lg_ch_modes,
3408                 .need_dac_fix = 1,
3409                 .input_mux = &alc880_lg_capture_source,
3410                 .unsol_event = alc880_lg_unsol_event,
3411                 .init_hook = alc880_lg_automute,
3412 #ifdef CONFIG_SND_HDA_POWER_SAVE
3413                 .loopbacks = alc880_lg_loopbacks,
3414 #endif
3415         },
3416         [ALC880_LG_LW] = {
3417                 .mixers = { alc880_lg_lw_mixer },
3418                 .init_verbs = { alc880_volume_init_verbs,
3419                                 alc880_lg_lw_init_verbs },
3420                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3421                 .dac_nids = alc880_dac_nids,
3422                 .dig_out_nid = ALC880_DIGOUT_NID,
3423                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3424                 .channel_mode = alc880_lg_lw_modes,
3425                 .input_mux = &alc880_lg_lw_capture_source,
3426                 .unsol_event = alc880_lg_lw_unsol_event,
3427                 .init_hook = alc880_lg_lw_automute,
3428         },
3429         [ALC880_MEDION_RIM] = {
3430                 .mixers = { alc880_medion_rim_mixer },
3431                 .init_verbs = { alc880_volume_init_verbs,
3432                                 alc880_medion_rim_init_verbs,
3433                                 alc_gpio2_init_verbs },
3434                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3435                 .dac_nids = alc880_dac_nids,
3436                 .dig_out_nid = ALC880_DIGOUT_NID,
3437                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3438                 .channel_mode = alc880_2_jack_modes,
3439                 .input_mux = &alc880_medion_rim_capture_source,
3440                 .unsol_event = alc880_medion_rim_unsol_event,
3441                 .init_hook = alc880_medion_rim_automute,
3442         },
3443 #ifdef CONFIG_SND_DEBUG
3444         [ALC880_TEST] = {
3445                 .mixers = { alc880_test_mixer },
3446                 .init_verbs = { alc880_test_init_verbs },
3447                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3448                 .dac_nids = alc880_test_dac_nids,
3449                 .dig_out_nid = ALC880_DIGOUT_NID,
3450                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3451                 .channel_mode = alc880_test_modes,
3452                 .input_mux = &alc880_test_capture_source,
3453         },
3454 #endif
3455 };
3456
3457 /*
3458  * Automatic parse of I/O pins from the BIOS configuration
3459  */
3460
3461 #define NUM_CONTROL_ALLOC       32
3462 #define NUM_VERB_ALLOC          32
3463
3464 enum {
3465         ALC_CTL_WIDGET_VOL,
3466         ALC_CTL_WIDGET_MUTE,
3467         ALC_CTL_BIND_MUTE,
3468 };
3469 static struct snd_kcontrol_new alc880_control_templates[] = {
3470         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3471         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3472         HDA_BIND_MUTE(NULL, 0, 0, 0),
3473 };
3474
3475 /* add dynamic controls */
3476 static int add_control(struct alc_spec *spec, int type, const char *name,
3477                        unsigned long val)
3478 {
3479         struct snd_kcontrol_new *knew;
3480
3481         if (spec->num_kctl_used >= spec->num_kctl_alloc) {
3482                 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
3483
3484                 /* array + terminator */
3485                 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
3486                 if (!knew)
3487                         return -ENOMEM;
3488                 if (spec->kctl_alloc) {
3489                         memcpy(knew, spec->kctl_alloc,
3490                                sizeof(*knew) * spec->num_kctl_alloc);
3491                         kfree(spec->kctl_alloc);
3492                 }
3493                 spec->kctl_alloc = knew;
3494                 spec->num_kctl_alloc = num;
3495         }
3496
3497         knew = &spec->kctl_alloc[spec->num_kctl_used];
3498         *knew = alc880_control_templates[type];
3499         knew->name = kstrdup(name, GFP_KERNEL);
3500         if (!knew->name)
3501                 return -ENOMEM;
3502         knew->private_value = val;
3503         spec->num_kctl_used++;
3504         return 0;
3505 }
3506
3507 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3508 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3509 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3510 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3511 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3512 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3513 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3514 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3515 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3516 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3517 #define ALC880_PIN_CD_NID               0x1c
3518
3519 /* fill in the dac_nids table from the parsed pin configuration */
3520 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3521                                      const struct auto_pin_cfg *cfg)
3522 {
3523         hda_nid_t nid;
3524         int assigned[4];
3525         int i, j;
3526
3527         memset(assigned, 0, sizeof(assigned));
3528         spec->multiout.dac_nids = spec->private_dac_nids;
3529
3530         /* check the pins hardwired to audio widget */
3531         for (i = 0; i < cfg->line_outs; i++) {
3532                 nid = cfg->line_out_pins[i];
3533                 if (alc880_is_fixed_pin(nid)) {
3534                         int idx = alc880_fixed_pin_idx(nid);
3535                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3536                         assigned[idx] = 1;
3537                 }
3538         }
3539         /* left pins can be connect to any audio widget */
3540         for (i = 0; i < cfg->line_outs; i++) {
3541                 nid = cfg->line_out_pins[i];
3542                 if (alc880_is_fixed_pin(nid))
3543                         continue;
3544                 /* search for an empty channel */
3545                 for (j = 0; j < cfg->line_outs; j++) {
3546                         if (!assigned[j]) {
3547                                 spec->multiout.dac_nids[i] =
3548                                         alc880_idx_to_dac(j);
3549                                 assigned[j] = 1;
3550                                 break;
3551                         }
3552                 }
3553         }
3554         spec->multiout.num_dacs = cfg->line_outs;
3555         return 0;
3556 }
3557
3558 /* add playback controls from the parsed DAC table */
3559 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3560                                              const struct auto_pin_cfg *cfg)
3561 {
3562         char name[32];
3563         static const char *chname[4] = {
3564                 "Front", "Surround", NULL /*CLFE*/, "Side"
3565         };
3566         hda_nid_t nid;
3567         int i, err;
3568
3569         for (i = 0; i < cfg->line_outs; i++) {
3570                 if (!spec->multiout.dac_nids[i])
3571                         continue;
3572                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3573                 if (i == 2) {
3574                         /* Center/LFE */
3575                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3576                                           "Center Playback Volume",
3577                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3578                                                               HDA_OUTPUT));
3579                         if (err < 0)
3580                                 return err;
3581                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3582                                           "LFE Playback Volume",
3583                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3584                                                               HDA_OUTPUT));
3585                         if (err < 0)
3586                                 return err;
3587                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3588                                           "Center Playback Switch",
3589                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
3590                                                               HDA_INPUT));
3591                         if (err < 0)
3592                                 return err;
3593                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3594                                           "LFE Playback Switch",
3595                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
3596                                                               HDA_INPUT));
3597                         if (err < 0)
3598                                 return err;
3599                 } else {
3600                         sprintf(name, "%s Playback Volume", chname[i]);
3601                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3602                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3603                                                               HDA_OUTPUT));
3604                         if (err < 0)
3605                                 return err;
3606                         sprintf(name, "%s Playback Switch", chname[i]);
3607                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3608                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
3609                                                               HDA_INPUT));
3610                         if (err < 0)
3611                                 return err;
3612                 }
3613         }
3614         return 0;
3615 }
3616
3617 /* add playback controls for speaker and HP outputs */
3618 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
3619                                         const char *pfx)
3620 {
3621         hda_nid_t nid;
3622         int err;
3623         char name[32];
3624
3625         if (!pin)
3626                 return 0;
3627
3628         if (alc880_is_fixed_pin(pin)) {
3629                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
3630                 /* specify the DAC as the extra output */
3631                 if (!spec->multiout.hp_nid)
3632                         spec->multiout.hp_nid = nid;
3633                 else
3634                         spec->multiout.extra_out_nid[0] = nid;
3635                 /* control HP volume/switch on the output mixer amp */
3636                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
3637                 sprintf(name, "%s Playback Volume", pfx);
3638                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3639                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3640                 if (err < 0)
3641                         return err;
3642                 sprintf(name, "%s Playback Switch", pfx);
3643                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3644                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
3645                 if (err < 0)
3646                         return err;
3647         } else if (alc880_is_multi_pin(pin)) {
3648                 /* set manual connection */
3649                 /* we have only a switch on HP-out PIN */
3650                 sprintf(name, "%s Playback Switch", pfx);
3651                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3652                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3653                 if (err < 0)
3654                         return err;
3655         }
3656         return 0;
3657 }
3658
3659 /* create input playback/capture controls for the given pin */
3660 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
3661                             const char *ctlname,
3662                             int idx, hda_nid_t mix_nid)
3663 {
3664         char name[32];
3665         int err;
3666
3667         sprintf(name, "%s Playback Volume", ctlname);
3668         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3669                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3670         if (err < 0)
3671                 return err;
3672         sprintf(name, "%s Playback Switch", ctlname);
3673         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3674                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3675         if (err < 0)
3676                 return err;
3677         return 0;
3678 }
3679
3680 /* create playback/capture controls for input pins */
3681 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3682                                                 const struct auto_pin_cfg *cfg)
3683 {
3684         struct hda_input_mux *imux = &spec->private_imux;
3685         int i, err, idx;
3686
3687         for (i = 0; i < AUTO_PIN_LAST; i++) {
3688                 if (alc880_is_input_pin(cfg->input_pins[i])) {
3689                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
3690                         err = new_analog_input(spec, cfg->input_pins[i],
3691                                                auto_pin_cfg_labels[i],
3692                                                idx, 0x0b);
3693                         if (err < 0)
3694                                 return err;
3695                         imux->items[imux->num_items].label =
3696                                 auto_pin_cfg_labels[i];
3697                         imux->items[imux->num_items].index =
3698                                 alc880_input_pin_idx(cfg->input_pins[i]);
3699                         imux->num_items++;
3700                 }
3701         }
3702         return 0;
3703 }
3704
3705 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
3706                                unsigned int pin_type)
3707 {
3708         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3709                             pin_type);
3710         /* unmute pin */
3711         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3712                             AMP_OUT_UNMUTE);
3713 }
3714
3715 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3716                                               hda_nid_t nid, int pin_type,
3717                                               int dac_idx)
3718 {
3719         alc_set_pin_output(codec, nid, pin_type);
3720         /* need the manual connection? */
3721         if (alc880_is_multi_pin(nid)) {
3722                 struct alc_spec *spec = codec->spec;
3723                 int idx = alc880_multi_pin_idx(nid);
3724                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
3725                                     AC_VERB_SET_CONNECT_SEL,
3726                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
3727         }
3728 }
3729
3730 static int get_pin_type(int line_out_type)
3731 {
3732         if (line_out_type == AUTO_PIN_HP_OUT)
3733                 return PIN_HP;
3734         else
3735                 return PIN_OUT;
3736 }
3737
3738 static void alc880_auto_init_multi_out(struct hda_codec *codec)
3739 {
3740         struct alc_spec *spec = codec->spec;
3741         int i;
3742
3743         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
3744         for (i = 0; i < spec->autocfg.line_outs; i++) {
3745                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3746                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3747                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
3748         }
3749 }
3750
3751 static void alc880_auto_init_extra_out(struct hda_codec *codec)
3752 {
3753         struct alc_spec *spec = codec->spec;
3754         hda_nid_t pin;
3755
3756         pin = spec->autocfg.speaker_pins[0];
3757         if (pin) /* connect to front */
3758                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
3759         pin = spec->autocfg.hp_pins[0];
3760         if (pin) /* connect to front */
3761                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3762 }
3763
3764 static void alc880_auto_init_analog_input(struct hda_codec *codec)
3765 {
3766         struct alc_spec *spec = codec->spec;
3767         int i;
3768
3769         for (i = 0; i < AUTO_PIN_LAST; i++) {
3770                 hda_nid_t nid = spec->autocfg.input_pins[i];
3771                 if (alc880_is_input_pin(nid)) {
3772                         snd_hda_codec_write(codec, nid, 0,
3773                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
3774                                             i <= AUTO_PIN_FRONT_MIC ?
3775                                             PIN_VREF80 : PIN_IN);
3776                         if (nid != ALC880_PIN_CD_NID)
3777                                 snd_hda_codec_write(codec, nid, 0,
3778                                                     AC_VERB_SET_AMP_GAIN_MUTE,
3779                                                     AMP_OUT_MUTE);
3780                 }
3781         }
3782 }
3783
3784 /* parse the BIOS configuration and set up the alc_spec */
3785 /* return 1 if successful, 0 if the proper config is not found,
3786  * or a negative error code
3787  */
3788 static int alc880_parse_auto_config(struct hda_codec *codec)
3789 {
3790         struct alc_spec *spec = codec->spec;
3791         int err;
3792         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3793
3794         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3795                                            alc880_ignore);
3796         if (err < 0)
3797                 return err;
3798         if (!spec->autocfg.line_outs)
3799                 return 0; /* can't find valid BIOS pin config */
3800
3801         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
3802         if (err < 0)
3803                 return err;
3804         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
3805         if (err < 0)
3806                 return err;
3807         err = alc880_auto_create_extra_out(spec,
3808                                            spec->autocfg.speaker_pins[0],
3809                                            "Speaker");
3810         if (err < 0)
3811                 return err;
3812         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
3813                                            "Headphone");
3814         if (err < 0)
3815                 return err;
3816         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
3817         if (err < 0)
3818                 return err;
3819
3820         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3821
3822         if (spec->autocfg.dig_out_pin)
3823                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
3824         if (spec->autocfg.dig_in_pin)
3825                 spec->dig_in_nid = ALC880_DIGIN_NID;
3826
3827         if (spec->kctl_alloc)
3828                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3829
3830         spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
3831
3832         spec->num_mux_defs = 1;
3833         spec->input_mux = &spec->private_imux;
3834
3835         return 1;
3836 }
3837
3838 /* additional initialization for auto-configuration model */
3839 static void alc880_auto_init(struct hda_codec *codec)
3840 {
3841         struct alc_spec *spec = codec->spec;
3842         alc880_auto_init_multi_out(codec);
3843         alc880_auto_init_extra_out(codec);
3844         alc880_auto_init_analog_input(codec);
3845         if (spec->unsol_event)
3846                 alc_inithook(codec);
3847 }
3848
3849 /*
3850  * OK, here we have finally the patch for ALC880
3851  */
3852
3853 static int patch_alc880(struct hda_codec *codec)
3854 {
3855         struct alc_spec *spec;
3856         int board_config;
3857         int err;
3858
3859         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3860         if (spec == NULL)
3861                 return -ENOMEM;
3862
3863         codec->spec = spec;
3864
3865         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
3866                                                   alc880_models,
3867                                                   alc880_cfg_tbl);
3868         if (board_config < 0) {
3869                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
3870                        "trying auto-probe from BIOS...\n");
3871                 board_config = ALC880_AUTO;
3872         }
3873
3874         if (board_config == ALC880_AUTO) {
3875                 /* automatic parse from the BIOS config */
3876                 err = alc880_parse_auto_config(codec);
3877                 if (err < 0) {
3878                         alc_free(codec);
3879                         return err;
3880                 } else if (!err) {
3881                         printk(KERN_INFO
3882                                "hda_codec: Cannot set up configuration "
3883                                "from BIOS.  Using 3-stack mode...\n");
3884                         board_config = ALC880_3ST;
3885                 }
3886         }
3887
3888         if (board_config != ALC880_AUTO)
3889                 setup_preset(spec, &alc880_presets[board_config]);
3890
3891         spec->stream_name_analog = "ALC880 Analog";
3892         spec->stream_analog_playback = &alc880_pcm_analog_playback;
3893         spec->stream_analog_capture = &alc880_pcm_analog_capture;
3894         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
3895
3896         spec->stream_name_digital = "ALC880 Digital";
3897         spec->stream_digital_playback = &alc880_pcm_digital_playback;
3898         spec->stream_digital_capture = &alc880_pcm_digital_capture;
3899
3900         if (!spec->adc_nids && spec->input_mux) {
3901                 /* check whether NID 0x07 is valid */
3902                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
3903                 /* get type */
3904                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3905                 if (wcap != AC_WID_AUD_IN) {
3906                         spec->adc_nids = alc880_adc_nids_alt;
3907                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
3908                         spec->mixers[spec->num_mixers] =
3909                                 alc880_capture_alt_mixer;
3910                         spec->num_mixers++;
3911                 } else {
3912                         spec->adc_nids = alc880_adc_nids;
3913                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
3914                         spec->mixers[spec->num_mixers] = alc880_capture_mixer;
3915                         spec->num_mixers++;
3916                 }
3917         }
3918
3919         spec->vmaster_nid = 0x0c;
3920
3921         codec->patch_ops = alc_patch_ops;
3922         if (board_config == ALC880_AUTO)
3923                 spec->init_hook = alc880_auto_init;
3924 #ifdef CONFIG_SND_HDA_POWER_SAVE
3925         if (!spec->loopback.amplist)
3926                 spec->loopback.amplist = alc880_loopbacks;
3927 #endif
3928
3929         return 0;
3930 }
3931
3932
3933 /*
3934  * ALC260 support
3935  */
3936
3937 static hda_nid_t alc260_dac_nids[1] = {
3938         /* front */
3939         0x02,
3940 };
3941
3942 static hda_nid_t alc260_adc_nids[1] = {
3943         /* ADC0 */
3944         0x04,
3945 };
3946
3947 static hda_nid_t alc260_adc_nids_alt[1] = {
3948         /* ADC1 */
3949         0x05,
3950 };
3951
3952 static hda_nid_t alc260_hp_adc_nids[2] = {
3953         /* ADC1, 0 */
3954         0x05, 0x04
3955 };
3956
3957 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
3958  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
3959  */
3960 static hda_nid_t alc260_dual_adc_nids[2] = {
3961         /* ADC0, ADC1 */
3962         0x04, 0x05
3963 };
3964
3965 #define ALC260_DIGOUT_NID       0x03
3966 #define ALC260_DIGIN_NID        0x06
3967
3968 static struct hda_input_mux alc260_capture_source = {
3969         .num_items = 4,
3970         .items = {
3971                 { "Mic", 0x0 },
3972                 { "Front Mic", 0x1 },
3973                 { "Line", 0x2 },
3974                 { "CD", 0x4 },
3975         },
3976 };
3977
3978 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
3979  * headphone jack and the internal CD lines since these are the only pins at
3980  * which audio can appear.  For flexibility, also allow the option of
3981  * recording the mixer output on the second ADC (ADC0 doesn't have a
3982  * connection to the mixer output).
3983  */
3984 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
3985         {
3986                 .num_items = 3,
3987                 .items = {
3988                         { "Mic/Line", 0x0 },
3989                         { "CD", 0x4 },
3990                         { "Headphone", 0x2 },
3991                 },
3992         },
3993         {
3994                 .num_items = 4,
3995                 .items = {
3996                         { "Mic/Line", 0x0 },
3997                         { "CD", 0x4 },
3998                         { "Headphone", 0x2 },
3999                         { "Mixer", 0x5 },
4000                 },
4001         },
4002
4003 };
4004
4005 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4006  * the Fujitsu S702x, but jacks are marked differently.
4007  */
4008 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4009         {
4010                 .num_items = 4,
4011                 .items = {
4012                         { "Mic", 0x0 },
4013                         { "Line", 0x2 },
4014                         { "CD", 0x4 },
4015                         { "Headphone", 0x5 },
4016                 },
4017         },
4018         {
4019                 .num_items = 5,
4020                 .items = {
4021                         { "Mic", 0x0 },
4022                         { "Line", 0x2 },
4023                         { "CD", 0x4 },
4024                         { "Headphone", 0x6 },
4025                         { "Mixer", 0x5 },
4026                 },
4027         },
4028 };
4029 /*
4030  * This is just place-holder, so there's something for alc_build_pcms to look
4031  * at when it calculates the maximum number of channels. ALC260 has no mixer
4032  * element which allows changing the channel mode, so the verb list is
4033  * never used.
4034  */
4035 static struct hda_channel_mode alc260_modes[1] = {
4036         { 2, NULL },
4037 };
4038
4039
4040 /* Mixer combinations
4041  *
4042  * basic: base_output + input + pc_beep + capture
4043  * HP: base_output + input + capture_alt
4044  * HP_3013: hp_3013 + input + capture
4045  * fujitsu: fujitsu + capture
4046  * acer: acer + capture
4047  */
4048
4049 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
4050         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4051         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4052         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4053         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4054         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4055         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4056         { } /* end */
4057 };
4058
4059 static struct snd_kcontrol_new alc260_input_mixer[] = {
4060         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4061         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4062         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4063         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4064         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4065         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4066         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4067         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4068         { } /* end */
4069 };
4070
4071 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
4072         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
4073         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
4074         { } /* end */
4075 };
4076
4077 /* update HP, line and mono out pins according to the master switch */
4078 static void alc260_hp_master_update(struct hda_codec *codec,
4079                                     hda_nid_t hp, hda_nid_t line,
4080                                     hda_nid_t mono)
4081 {
4082         struct alc_spec *spec = codec->spec;
4083         unsigned int val = spec->master_sw ? PIN_HP : 0;
4084         /* change HP and line-out pins */
4085         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4086                             val);
4087         snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4088                             val);
4089         /* mono (speaker) depending on the HP jack sense */
4090         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4091         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4092                             val);
4093 }
4094
4095 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4096                                    struct snd_ctl_elem_value *ucontrol)
4097 {
4098         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4099         struct alc_spec *spec = codec->spec;
4100         *ucontrol->value.integer.value = spec->master_sw;
4101         return 0;
4102 }
4103
4104 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4105                                    struct snd_ctl_elem_value *ucontrol)
4106 {
4107         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4108         struct alc_spec *spec = codec->spec;
4109         int val = !!*ucontrol->value.integer.value;
4110         hda_nid_t hp, line, mono;
4111
4112         if (val == spec->master_sw)
4113                 return 0;
4114         spec->master_sw = val;
4115         hp = (kcontrol->private_value >> 16) & 0xff;
4116         line = (kcontrol->private_value >> 8) & 0xff;
4117         mono = kcontrol->private_value & 0xff;
4118         alc260_hp_master_update(codec, hp, line, mono);
4119         return 1;
4120 }
4121
4122 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4123         {
4124                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4125                 .name = "Master Playback Switch",
4126                 .info = snd_ctl_boolean_mono_info,
4127                 .get = alc260_hp_master_sw_get,
4128                 .put = alc260_hp_master_sw_put,
4129                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4130         },
4131         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4132         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4133         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4134         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4135         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4136                               HDA_OUTPUT),
4137         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4138         { } /* end */
4139 };
4140
4141 static struct hda_verb alc260_hp_unsol_verbs[] = {
4142         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4143         {},
4144 };
4145
4146 static void alc260_hp_automute(struct hda_codec *codec)
4147 {
4148         struct alc_spec *spec = codec->spec;
4149         unsigned int present;
4150
4151         present = snd_hda_codec_read(codec, 0x10, 0,
4152                                      AC_VERB_GET_PIN_SENSE, 0);
4153         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4154         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4155 }
4156
4157 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4158 {
4159         if ((res >> 26) == ALC880_HP_EVENT)
4160                 alc260_hp_automute(codec);
4161 }
4162
4163 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4164         {
4165                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4166                 .name = "Master Playback Switch",
4167                 .info = snd_ctl_boolean_mono_info,
4168                 .get = alc260_hp_master_sw_get,
4169                 .put = alc260_hp_master_sw_put,
4170                 .private_value = (0x10 << 16) | (0x15 << 8) | 0x11
4171         },
4172         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4173         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4174         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4175         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4176         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4177         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4178         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4179         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4180         { } /* end */
4181 };
4182
4183 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
4184         .ops = &snd_hda_bind_vol,
4185         .values = {
4186                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
4187                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
4188                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
4189                 0
4190         },
4191 };
4192
4193 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
4194         .ops = &snd_hda_bind_sw,
4195         .values = {
4196                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
4197                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
4198                 0
4199         },
4200 };
4201
4202 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
4203         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
4204         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
4205         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
4206         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4207         { } /* end */
4208 };
4209
4210 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4211         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4212         {},
4213 };
4214
4215 static void alc260_hp_3013_automute(struct hda_codec *codec)
4216 {
4217         struct alc_spec *spec = codec->spec;
4218         unsigned int present;
4219
4220         present = snd_hda_codec_read(codec, 0x15, 0,
4221                                      AC_VERB_GET_PIN_SENSE, 0);
4222         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4223         alc260_hp_master_update(codec, 0x10, 0x15, 0x11);
4224 }
4225
4226 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4227                                        unsigned int res)
4228 {
4229         if ((res >> 26) == ALC880_HP_EVENT)
4230                 alc260_hp_3013_automute(codec);
4231 }
4232
4233 static void alc260_hp_3012_automute(struct hda_codec *codec)
4234 {
4235         unsigned int present, bits;
4236
4237         present = snd_hda_codec_read(codec, 0x10, 0,
4238                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
4239
4240         bits = present ? 0 : PIN_OUT;
4241         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4242                             bits);
4243         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4244                             bits);
4245         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4246                             bits);
4247 }
4248
4249 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
4250                                        unsigned int res)
4251 {
4252         if ((res >> 26) == ALC880_HP_EVENT)
4253                 alc260_hp_3012_automute(codec);
4254 }
4255
4256 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
4257  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4258  */
4259 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4260         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4261         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4262         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4263         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4264         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4265         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4266         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4267         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4268         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4269         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4270         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4271         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4272         { } /* end */
4273 };
4274
4275 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4276  * versions of the ALC260 don't act on requests to enable mic bias from NID
4277  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4278  * datasheet doesn't mention this restriction.  At this stage it's not clear
4279  * whether this behaviour is intentional or is a hardware bug in chip
4280  * revisions available in early 2006.  Therefore for now allow the
4281  * "Headphone Jack Mode" control to span all choices, but if it turns out
4282  * that the lack of mic bias for this NID is intentional we could change the
4283  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4284  *
4285  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4286  * don't appear to make the mic bias available from the "line" jack, even
4287  * though the NID used for this jack (0x14) can supply it.  The theory is
4288  * that perhaps Acer have included blocking capacitors between the ALC260
4289  * and the output jack.  If this turns out to be the case for all such
4290  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4291  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4292  *
4293  * The C20x Tablet series have a mono internal speaker which is controlled
4294  * via the chip's Mono sum widget and pin complex, so include the necessary
4295  * controls for such models.  On models without a "mono speaker" the control
4296  * won't do anything.
4297  */
4298 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4299         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4300         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4301         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4302         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4303                               HDA_OUTPUT),
4304         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4305                            HDA_INPUT),
4306         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4307         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4308         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4309         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4310         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4311         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4312         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4313         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4314         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4315         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4316         { } /* end */
4317 };
4318
4319 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4320  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4321  */
4322 static struct snd_kcontrol_new alc260_will_mixer[] = {
4323         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4324         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4325         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4326         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4327         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4328         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4329         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4330         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4331         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4332         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4333         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4334         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4335         { } /* end */
4336 };
4337
4338 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4339  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4340  */
4341 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4342         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4343         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4344         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4345         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4346         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4347         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4348         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4349         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4350         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4351         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4352         { } /* end */
4353 };
4354
4355 /* capture mixer elements */
4356 static struct snd_kcontrol_new alc260_capture_mixer[] = {
4357         HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
4358         HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
4359         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
4360         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),
4361         {
4362                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4363                 /* The multiple "Capture Source" controls confuse alsamixer
4364                  * So call somewhat different..
4365                  */
4366                 /* .name = "Capture Source", */
4367                 .name = "Input Source",
4368                 .count = 2,
4369                 .info = alc_mux_enum_info,
4370                 .get = alc_mux_enum_get,
4371                 .put = alc_mux_enum_put,
4372         },
4373         { } /* end */
4374 };
4375
4376 static struct snd_kcontrol_new alc260_capture_alt_mixer[] = {
4377         HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
4378         HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
4379         {
4380                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4381                 /* The multiple "Capture Source" controls confuse alsamixer
4382                  * So call somewhat different..
4383                  */
4384                 /* .name = "Capture Source", */
4385                 .name = "Input Source",
4386                 .count = 1,
4387                 .info = alc_mux_enum_info,
4388                 .get = alc_mux_enum_get,
4389                 .put = alc_mux_enum_put,
4390         },
4391         { } /* end */
4392 };
4393
4394 /*
4395  * initialization verbs
4396  */
4397 static struct hda_verb alc260_init_verbs[] = {
4398         /* Line In pin widget for input */
4399         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4400         /* CD pin widget for input */
4401         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4402         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4403         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4404         /* Mic2 (front panel) pin widget for input and vref at 80% */
4405         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4406         /* LINE-2 is used for line-out in rear */
4407         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4408         /* select line-out */
4409         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4410         /* LINE-OUT pin */
4411         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4412         /* enable HP */
4413         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4414         /* enable Mono */
4415         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4416         /* mute capture amp left and right */
4417         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4418         /* set connection select to line in (default select for this ADC) */
4419         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4420         /* mute capture amp left and right */
4421         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4422         /* set connection select to line in (default select for this ADC) */
4423         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4424         /* set vol=0 Line-Out mixer amp left and right */
4425         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4426         /* unmute pin widget amp left and right (no gain on this amp) */
4427         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4428         /* set vol=0 HP mixer amp left and right */
4429         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4430         /* unmute pin widget amp left and right (no gain on this amp) */
4431         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4432         /* set vol=0 Mono mixer amp left and right */
4433         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4434         /* unmute pin widget amp left and right (no gain on this amp) */
4435         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4436         /* unmute LINE-2 out pin */
4437         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4438         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4439          * Line In 2 = 0x03
4440          */
4441         /* mute analog inputs */
4442         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4443         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4444         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4445         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4446         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4447         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4448         /* mute Front out path */
4449         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4450         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4451         /* mute Headphone out path */
4452         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4453         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4454         /* mute Mono out path */
4455         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4456         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4457         { }
4458 };
4459
4460 #if 0 /* should be identical with alc260_init_verbs? */
4461 static struct hda_verb alc260_hp_init_verbs[] = {
4462         /* Headphone and output */
4463         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4464         /* mono output */
4465         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4466         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4467         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4468         /* Mic2 (front panel) pin widget for input and vref at 80% */
4469         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4470         /* Line In pin widget for input */
4471         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4472         /* Line-2 pin widget for output */
4473         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4474         /* CD pin widget for input */
4475         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4476         /* unmute amp left and right */
4477         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4478         /* set connection select to line in (default select for this ADC) */
4479         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4480         /* unmute Line-Out mixer amp left and right (volume = 0) */
4481         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4482         /* mute pin widget amp left and right (no gain on this amp) */
4483         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4484         /* unmute HP mixer amp left and right (volume = 0) */
4485         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4486         /* mute pin widget amp left and right (no gain on this amp) */
4487         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4488         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4489          * Line In 2 = 0x03
4490          */
4491         /* mute analog inputs */
4492         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4493         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4494         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4495         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4496         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4497         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4498         /* Unmute Front out path */
4499         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4500         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4501         /* Unmute Headphone out path */
4502         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4503         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4504         /* Unmute Mono out path */
4505         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4506         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4507         { }
4508 };
4509 #endif
4510
4511 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4512         /* Line out and output */
4513         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4514         /* mono output */
4515         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4516         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4517         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4518         /* Mic2 (front panel) pin widget for input and vref at 80% */
4519         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4520         /* Line In pin widget for input */
4521         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4522         /* Headphone pin widget for output */
4523         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4524         /* CD pin widget for input */
4525         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4526         /* unmute amp left and right */
4527         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4528         /* set connection select to line in (default select for this ADC) */
4529         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4530         /* unmute Line-Out mixer amp left and right (volume = 0) */
4531         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4532         /* mute pin widget amp left and right (no gain on this amp) */
4533         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4534         /* unmute HP mixer amp left and right (volume = 0) */
4535         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4536         /* mute pin widget amp left and right (no gain on this amp) */
4537         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4538         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4539          * Line In 2 = 0x03
4540          */
4541         /* mute analog inputs */
4542         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4543         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4544         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4545         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4546         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4547         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4548         /* Unmute Front out path */
4549         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4550         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4551         /* Unmute Headphone out path */
4552         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4553         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4554         /* Unmute Mono out path */
4555         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4556         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4557         { }
4558 };
4559
4560 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4561  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4562  * audio = 0x16, internal speaker = 0x10.
4563  */
4564 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4565         /* Disable all GPIOs */
4566         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4567         /* Internal speaker is connected to headphone pin */
4568         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4569         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4570         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4571         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4572         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4573         /* Ensure all other unused pins are disabled and muted. */
4574         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4575         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4576         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4577         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4578         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4579         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4580         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4581         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4582
4583         /* Disable digital (SPDIF) pins */
4584         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4585         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4586
4587         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
4588          * when acting as an output.
4589          */
4590         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4591
4592         /* Start with output sum widgets muted and their output gains at min */
4593         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4594         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4595         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4596         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4597         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4598         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4599         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4600         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4601         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4602
4603         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
4604         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4605         /* Unmute Line1 pin widget output buffer since it starts as an output.
4606          * If the pin mode is changed by the user the pin mode control will
4607          * take care of enabling the pin's input/output buffers as needed.
4608          * Therefore there's no need to enable the input buffer at this
4609          * stage.
4610          */
4611         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4612         /* Unmute input buffer of pin widget used for Line-in (no equiv
4613          * mixer ctrl)
4614          */
4615         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4616
4617         /* Mute capture amp left and right */
4618         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4619         /* Set ADC connection select to match default mixer setting - line
4620          * in (on mic1 pin)
4621          */
4622         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4623
4624         /* Do the same for the second ADC: mute capture input amp and
4625          * set ADC connection to line in (on mic1 pin)
4626          */
4627         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4628         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4629
4630         /* Mute all inputs to mixer widget (even unconnected ones) */
4631         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4632         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4633         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4634         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4635         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4636         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4637         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4638         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4639
4640         { }
4641 };
4642
4643 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
4644  * similar laptops (adapted from Fujitsu init verbs).
4645  */
4646 static struct hda_verb alc260_acer_init_verbs[] = {
4647         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
4648          * the headphone jack.  Turn this on and rely on the standard mute
4649          * methods whenever the user wants to turn these outputs off.
4650          */
4651         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4652         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4653         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
4654         /* Internal speaker/Headphone jack is connected to Line-out pin */
4655         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4656         /* Internal microphone/Mic jack is connected to Mic1 pin */
4657         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
4658         /* Line In jack is connected to Line1 pin */
4659         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4660         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
4661         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4662         /* Ensure all other unused pins are disabled and muted. */
4663         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4664         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4665         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4666         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4667         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4668         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4669         /* Disable digital (SPDIF) pins */
4670         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4671         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4672
4673         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
4674          * bus when acting as outputs.
4675          */
4676         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4677         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4678
4679         /* Start with output sum widgets muted and their output gains at min */
4680         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4681         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4682         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4683         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4684         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4685         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4686         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4687         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4688         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4689
4690         /* Unmute Line-out pin widget amp left and right
4691          * (no equiv mixer ctrl)
4692          */
4693         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4694         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
4695         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4696         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
4697          * inputs. If the pin mode is changed by the user the pin mode control
4698          * will take care of enabling the pin's input/output buffers as needed.
4699          * Therefore there's no need to enable the input buffer at this
4700          * stage.
4701          */
4702         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4703         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4704
4705         /* Mute capture amp left and right */
4706         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4707         /* Set ADC connection select to match default mixer setting - mic
4708          * (on mic1 pin)
4709          */
4710         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4711
4712         /* Do similar with the second ADC: mute capture input amp and
4713          * set ADC connection to mic to match ALSA's default state.
4714          */
4715         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4716         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4717
4718         /* Mute all inputs to mixer widget (even unconnected ones) */
4719         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4720         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4721         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4722         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4723         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4724         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4725         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4726         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4727
4728         { }
4729 };
4730
4731 static struct hda_verb alc260_will_verbs[] = {
4732         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4733         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
4734         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
4735         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4736         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4737         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
4738         {}
4739 };
4740
4741 static struct hda_verb alc260_replacer_672v_verbs[] = {
4742         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4743         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4744         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
4745
4746         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4747         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4748         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4749
4750         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4751         {}
4752 };
4753
4754 /* toggle speaker-output according to the hp-jack state */
4755 static void alc260_replacer_672v_automute(struct hda_codec *codec)
4756 {
4757         unsigned int present;
4758
4759         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
4760         present = snd_hda_codec_read(codec, 0x0f, 0,
4761                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
4762         if (present) {
4763                 snd_hda_codec_write_cache(codec, 0x01, 0,
4764                                           AC_VERB_SET_GPIO_DATA, 1);
4765                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4766                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4767                                           PIN_HP);
4768         } else {
4769                 snd_hda_codec_write_cache(codec, 0x01, 0,
4770                                           AC_VERB_SET_GPIO_DATA, 0);
4771                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4772                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4773                                           PIN_OUT);
4774         }
4775 }
4776
4777 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
4778                                        unsigned int res)
4779 {
4780         if ((res >> 26) == ALC880_HP_EVENT)
4781                 alc260_replacer_672v_automute(codec);
4782 }
4783
4784 static struct hda_verb alc260_hp_dc7600_verbs[] = {
4785         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
4786         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
4787         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4788         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4789         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4790         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4791         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4792         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4793         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4794         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4795         {}
4796 };
4797
4798 /* Test configuration for debugging, modelled after the ALC880 test
4799  * configuration.
4800  */
4801 #ifdef CONFIG_SND_DEBUG
4802 static hda_nid_t alc260_test_dac_nids[1] = {
4803         0x02,
4804 };
4805 static hda_nid_t alc260_test_adc_nids[2] = {
4806         0x04, 0x05,
4807 };
4808 /* For testing the ALC260, each input MUX needs its own definition since
4809  * the signal assignments are different.  This assumes that the first ADC
4810  * is NID 0x04.
4811  */
4812 static struct hda_input_mux alc260_test_capture_sources[2] = {
4813         {
4814                 .num_items = 7,
4815                 .items = {
4816                         { "MIC1 pin", 0x0 },
4817                         { "MIC2 pin", 0x1 },
4818                         { "LINE1 pin", 0x2 },
4819                         { "LINE2 pin", 0x3 },
4820                         { "CD pin", 0x4 },
4821                         { "LINE-OUT pin", 0x5 },
4822                         { "HP-OUT pin", 0x6 },
4823                 },
4824         },
4825         {
4826                 .num_items = 8,
4827                 .items = {
4828                         { "MIC1 pin", 0x0 },
4829                         { "MIC2 pin", 0x1 },
4830                         { "LINE1 pin", 0x2 },
4831                         { "LINE2 pin", 0x3 },
4832                         { "CD pin", 0x4 },
4833                         { "Mixer", 0x5 },
4834                         { "LINE-OUT pin", 0x6 },
4835                         { "HP-OUT pin", 0x7 },
4836                 },
4837         },
4838 };
4839 static struct snd_kcontrol_new alc260_test_mixer[] = {
4840         /* Output driver widgets */
4841         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4842         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4843         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4844         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
4845         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4846         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
4847
4848         /* Modes for retasking pin widgets
4849          * Note: the ALC260 doesn't seem to act on requests to enable mic
4850          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
4851          * mention this restriction.  At this stage it's not clear whether
4852          * this behaviour is intentional or is a hardware bug in chip
4853          * revisions available at least up until early 2006.  Therefore for
4854          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
4855          * choices, but if it turns out that the lack of mic bias for these
4856          * NIDs is intentional we could change their modes from
4857          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4858          */
4859         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
4860         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
4861         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
4862         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
4863         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
4864         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
4865
4866         /* Loopback mixer controls */
4867         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
4868         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
4869         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
4870         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
4871         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
4872         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
4873         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
4874         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
4875         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4876         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4877         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4878         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4879         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
4880         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
4881         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
4882         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
4883
4884         /* Controls for GPIO pins, assuming they are configured as outputs */
4885         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
4886         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
4887         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
4888         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
4889
4890         /* Switches to allow the digital IO pins to be enabled.  The datasheet
4891          * is ambigious as to which NID is which; testing on laptops which
4892          * make this output available should provide clarification.
4893          */
4894         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
4895         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
4896
4897         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
4898          * this output to turn on an external amplifier.
4899          */
4900         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
4901         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
4902
4903         { } /* end */
4904 };
4905 static struct hda_verb alc260_test_init_verbs[] = {
4906         /* Enable all GPIOs as outputs with an initial value of 0 */
4907         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
4908         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4909         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
4910
4911         /* Enable retasking pins as output, initially without power amp */
4912         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4913         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4914         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4915         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4916         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4917         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4918
4919         /* Disable digital (SPDIF) pins initially, but users can enable
4920          * them via a mixer switch.  In the case of SPDIF-out, this initverb
4921          * payload also sets the generation to 0, output to be in "consumer"
4922          * PCM format, copyright asserted, no pre-emphasis and no validity
4923          * control.
4924          */
4925         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4926         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4927
4928         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
4929          * OUT1 sum bus when acting as an output.
4930          */
4931         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4932         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
4933         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4934         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
4935
4936         /* Start with output sum widgets muted and their output gains at min */
4937         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4938         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4939         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4940         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4941         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4942         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4943         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4944         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4945         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4946
4947         /* Unmute retasking pin widget output buffers since the default
4948          * state appears to be output.  As the pin mode is changed by the
4949          * user the pin mode control will take care of enabling the pin's
4950          * input/output buffers as needed.
4951          */
4952         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4953         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4954         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4955         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4956         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4957         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4958         /* Also unmute the mono-out pin widget */
4959         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4960
4961         /* Mute capture amp left and right */
4962         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4963         /* Set ADC connection select to match default mixer setting (mic1
4964          * pin)
4965          */
4966         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4967
4968         /* Do the same for the second ADC: mute capture input amp and
4969          * set ADC connection to mic1 pin
4970          */
4971         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4972         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4973
4974         /* Mute all inputs to mixer widget (even unconnected ones) */
4975         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4976         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4977         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4978         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4979         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4980         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4981         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4982         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4983
4984         { }
4985 };
4986 #endif
4987
4988 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
4989 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
4990
4991 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
4992 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
4993
4994 /*
4995  * for BIOS auto-configuration
4996  */
4997
4998 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
4999                                         const char *pfx, int *vol_bits)
5000 {
5001         hda_nid_t nid_vol;
5002         unsigned long vol_val, sw_val;
5003         char name[32];
5004         int err;
5005
5006         if (nid >= 0x0f && nid < 0x11) {
5007                 nid_vol = nid - 0x7;
5008                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5009                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5010         } else if (nid == 0x11) {
5011                 nid_vol = nid - 0x7;
5012                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
5013                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
5014         } else if (nid >= 0x12 && nid <= 0x15) {
5015                 nid_vol = 0x08;
5016                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5017                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5018         } else
5019                 return 0; /* N/A */
5020
5021         if (!(*vol_bits & (1 << nid_vol))) {
5022                 /* first control for the volume widget */
5023                 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
5024                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
5025                 if (err < 0)
5026                         return err;
5027                 *vol_bits |= (1 << nid_vol);
5028         }
5029         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
5030         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
5031         if (err < 0)
5032                 return err;
5033         return 1;
5034 }
5035
5036 /* add playback controls from the parsed DAC table */
5037 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5038                                              const struct auto_pin_cfg *cfg)
5039 {
5040         hda_nid_t nid;
5041         int err;
5042         int vols = 0;
5043
5044         spec->multiout.num_dacs = 1;
5045         spec->multiout.dac_nids = spec->private_dac_nids;
5046         spec->multiout.dac_nids[0] = 0x02;
5047
5048         nid = cfg->line_out_pins[0];
5049         if (nid) {
5050                 err = alc260_add_playback_controls(spec, nid, "Front", &vols);
5051                 if (err < 0)
5052                         return err;
5053         }
5054
5055         nid = cfg->speaker_pins[0];
5056         if (nid) {
5057                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
5058                 if (err < 0)
5059                         return err;
5060         }
5061
5062         nid = cfg->hp_pins[0];
5063         if (nid) {
5064                 err = alc260_add_playback_controls(spec, nid, "Headphone",
5065                                                    &vols);
5066                 if (err < 0)
5067                         return err;
5068         }
5069         return 0;
5070 }
5071
5072 /* create playback/capture controls for input pins */
5073 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
5074                                                 const struct auto_pin_cfg *cfg)
5075 {
5076         struct hda_input_mux *imux = &spec->private_imux;
5077         int i, err, idx;
5078
5079         for (i = 0; i < AUTO_PIN_LAST; i++) {
5080                 if (cfg->input_pins[i] >= 0x12) {
5081                         idx = cfg->input_pins[i] - 0x12;
5082                         err = new_analog_input(spec, cfg->input_pins[i],
5083                                                auto_pin_cfg_labels[i], idx,
5084                                                0x07);
5085                         if (err < 0)
5086                                 return err;
5087                         imux->items[imux->num_items].label =
5088                                 auto_pin_cfg_labels[i];
5089                         imux->items[imux->num_items].index = idx;
5090                         imux->num_items++;
5091                 }
5092                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
5093                         idx = cfg->input_pins[i] - 0x09;
5094                         err = new_analog_input(spec, cfg->input_pins[i],
5095                                                auto_pin_cfg_labels[i], idx,
5096                                                0x07);
5097                         if (err < 0)
5098                                 return err;
5099                         imux->items[imux->num_items].label =
5100                                 auto_pin_cfg_labels[i];
5101                         imux->items[imux->num_items].index = idx;
5102                         imux->num_items++;
5103                 }
5104         }
5105         return 0;
5106 }
5107
5108 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
5109                                               hda_nid_t nid, int pin_type,
5110                                               int sel_idx)
5111 {
5112         alc_set_pin_output(codec, nid, pin_type);
5113         /* need the manual connection? */
5114         if (nid >= 0x12) {
5115                 int idx = nid - 0x12;
5116                 snd_hda_codec_write(codec, idx + 0x0b, 0,
5117                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
5118         }
5119 }
5120
5121 static void alc260_auto_init_multi_out(struct hda_codec *codec)
5122 {
5123         struct alc_spec *spec = codec->spec;
5124         hda_nid_t nid;
5125
5126         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
5127         nid = spec->autocfg.line_out_pins[0];
5128         if (nid) {
5129                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5130                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5131         }
5132
5133         nid = spec->autocfg.speaker_pins[0];
5134         if (nid)
5135                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5136
5137         nid = spec->autocfg.hp_pins[0];
5138         if (nid)
5139                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5140 }
5141
5142 #define ALC260_PIN_CD_NID               0x16
5143 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5144 {
5145         struct alc_spec *spec = codec->spec;
5146         int i;
5147
5148         for (i = 0; i < AUTO_PIN_LAST; i++) {
5149                 hda_nid_t nid = spec->autocfg.input_pins[i];
5150                 if (nid >= 0x12) {
5151                         snd_hda_codec_write(codec, nid, 0,
5152                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5153                                             i <= AUTO_PIN_FRONT_MIC ?
5154                                             PIN_VREF80 : PIN_IN);
5155                         if (nid != ALC260_PIN_CD_NID)
5156                                 snd_hda_codec_write(codec, nid, 0,
5157                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5158                                                     AMP_OUT_MUTE);
5159                 }
5160         }
5161 }
5162
5163 /*
5164  * generic initialization of ADC, input mixers and output mixers
5165  */
5166 static struct hda_verb alc260_volume_init_verbs[] = {
5167         /*
5168          * Unmute ADC0-1 and set the default input to mic-in
5169          */
5170         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5171         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5172         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5173         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5174
5175         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5176          * mixer widget
5177          * Note: PASD motherboards uses the Line In 2 as the input for
5178          * front panel mic (mic 2)
5179          */
5180         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5181         /* mute analog inputs */
5182         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5183         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5184         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5185         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5186         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5187
5188         /*
5189          * Set up output mixers (0x08 - 0x0a)
5190          */
5191         /* set vol=0 to output mixers */
5192         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5193         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5194         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5195         /* set up input amps for analog loopback */
5196         /* Amp Indices: DAC = 0, mixer = 1 */
5197         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5198         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5199         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5200         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5201         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5202         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5203
5204         { }
5205 };
5206
5207 static int alc260_parse_auto_config(struct hda_codec *codec)
5208 {
5209         struct alc_spec *spec = codec->spec;
5210         unsigned int wcap;
5211         int err;
5212         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5213
5214         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5215                                            alc260_ignore);
5216         if (err < 0)
5217                 return err;
5218         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5219         if (err < 0)
5220                 return err;
5221         if (!spec->kctl_alloc)
5222                 return 0; /* can't find valid BIOS pin config */
5223         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5224         if (err < 0)
5225                 return err;
5226
5227         spec->multiout.max_channels = 2;
5228
5229         if (spec->autocfg.dig_out_pin)
5230                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5231         if (spec->kctl_alloc)
5232                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
5233
5234         spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs;
5235
5236         spec->num_mux_defs = 1;
5237         spec->input_mux = &spec->private_imux;
5238
5239         /* check whether NID 0x04 is valid */
5240         wcap = get_wcaps(codec, 0x04);
5241         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
5242         if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
5243                 spec->adc_nids = alc260_adc_nids_alt;
5244                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
5245                 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
5246         } else {
5247                 spec->adc_nids = alc260_adc_nids;
5248                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
5249                 spec->mixers[spec->num_mixers] = alc260_capture_mixer;
5250         }
5251         spec->num_mixers++;
5252
5253         return 1;
5254 }
5255
5256 /* additional initialization for auto-configuration model */
5257 static void alc260_auto_init(struct hda_codec *codec)
5258 {
5259         struct alc_spec *spec = codec->spec;
5260         alc260_auto_init_multi_out(codec);
5261         alc260_auto_init_analog_input(codec);
5262         if (spec->unsol_event)
5263                 alc_inithook(codec);
5264 }
5265
5266 #ifdef CONFIG_SND_HDA_POWER_SAVE
5267 static struct hda_amp_list alc260_loopbacks[] = {
5268         { 0x07, HDA_INPUT, 0 },
5269         { 0x07, HDA_INPUT, 1 },
5270         { 0x07, HDA_INPUT, 2 },
5271         { 0x07, HDA_INPUT, 3 },
5272         { 0x07, HDA_INPUT, 4 },
5273         { } /* end */
5274 };
5275 #endif
5276
5277 /*
5278  * ALC260 configurations
5279  */
5280 static const char *alc260_models[ALC260_MODEL_LAST] = {
5281         [ALC260_BASIC]          = "basic",
5282         [ALC260_HP]             = "hp",
5283         [ALC260_HP_3013]        = "hp-3013",
5284         [ALC260_HP_DC7600]      = "hp-dc7600",
5285         [ALC260_FUJITSU_S702X]  = "fujitsu",
5286         [ALC260_ACER]           = "acer",
5287         [ALC260_WILL]           = "will",
5288         [ALC260_REPLACER_672V]  = "replacer",
5289 #ifdef CONFIG_SND_DEBUG
5290         [ALC260_TEST]           = "test",
5291 #endif
5292         [ALC260_AUTO]           = "auto",
5293 };
5294
5295 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5296         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5297         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5298         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5299         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5300         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5301         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
5302         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
5303         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5304         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5305         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5306         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5307         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5308         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5309         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5310         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5311         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5312         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5313         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5314         {}
5315 };
5316
5317 static struct alc_config_preset alc260_presets[] = {
5318         [ALC260_BASIC] = {
5319                 .mixers = { alc260_base_output_mixer,
5320                             alc260_input_mixer,
5321                             alc260_pc_beep_mixer,
5322                             alc260_capture_mixer },
5323                 .init_verbs = { alc260_init_verbs },
5324                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5325                 .dac_nids = alc260_dac_nids,
5326                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5327                 .adc_nids = alc260_adc_nids,
5328                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5329                 .channel_mode = alc260_modes,
5330                 .input_mux = &alc260_capture_source,
5331         },
5332         [ALC260_HP] = {
5333                 .mixers = { alc260_hp_output_mixer,
5334                             alc260_input_mixer,
5335                             alc260_capture_alt_mixer },
5336                 .init_verbs = { alc260_init_verbs,
5337                                 alc260_hp_unsol_verbs },
5338                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5339                 .dac_nids = alc260_dac_nids,
5340                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5341                 .adc_nids = alc260_hp_adc_nids,
5342                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5343                 .channel_mode = alc260_modes,
5344                 .input_mux = &alc260_capture_source,
5345                 .unsol_event = alc260_hp_unsol_event,
5346                 .init_hook = alc260_hp_automute,
5347         },
5348         [ALC260_HP_DC7600] = {
5349                 .mixers = { alc260_hp_dc7600_mixer,
5350                             alc260_input_mixer,
5351                             alc260_capture_alt_mixer },
5352                 .init_verbs = { alc260_init_verbs,
5353                                 alc260_hp_dc7600_verbs },
5354                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5355                 .dac_nids = alc260_dac_nids,
5356                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5357                 .adc_nids = alc260_hp_adc_nids,
5358                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5359                 .channel_mode = alc260_modes,
5360                 .input_mux = &alc260_capture_source,
5361                 .unsol_event = alc260_hp_3012_unsol_event,
5362                 .init_hook = alc260_hp_3012_automute,
5363         },
5364         [ALC260_HP_3013] = {
5365                 .mixers = { alc260_hp_3013_mixer,
5366                             alc260_input_mixer,
5367                             alc260_capture_alt_mixer },
5368                 .init_verbs = { alc260_hp_3013_init_verbs,
5369                                 alc260_hp_3013_unsol_verbs },
5370                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5371                 .dac_nids = alc260_dac_nids,
5372                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5373                 .adc_nids = alc260_hp_adc_nids,
5374                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5375                 .channel_mode = alc260_modes,
5376                 .input_mux = &alc260_capture_source,
5377                 .unsol_event = alc260_hp_3013_unsol_event,
5378                 .init_hook = alc260_hp_3013_automute,
5379         },
5380         [ALC260_FUJITSU_S702X] = {
5381                 .mixers = { alc260_fujitsu_mixer,
5382                             alc260_capture_mixer },
5383                 .init_verbs = { alc260_fujitsu_init_verbs },
5384                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5385                 .dac_nids = alc260_dac_nids,
5386                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5387                 .adc_nids = alc260_dual_adc_nids,
5388                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5389                 .channel_mode = alc260_modes,
5390                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5391                 .input_mux = alc260_fujitsu_capture_sources,
5392         },
5393         [ALC260_ACER] = {
5394                 .mixers = { alc260_acer_mixer,
5395                             alc260_capture_mixer },
5396                 .init_verbs = { alc260_acer_init_verbs },
5397                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5398                 .dac_nids = alc260_dac_nids,
5399                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5400                 .adc_nids = alc260_dual_adc_nids,
5401                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5402                 .channel_mode = alc260_modes,
5403                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5404                 .input_mux = alc260_acer_capture_sources,
5405         },
5406         [ALC260_WILL] = {
5407                 .mixers = { alc260_will_mixer,
5408                             alc260_capture_mixer },
5409                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5410                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5411                 .dac_nids = alc260_dac_nids,
5412                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5413                 .adc_nids = alc260_adc_nids,
5414                 .dig_out_nid = ALC260_DIGOUT_NID,
5415                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5416                 .channel_mode = alc260_modes,
5417                 .input_mux = &alc260_capture_source,
5418         },
5419         [ALC260_REPLACER_672V] = {
5420                 .mixers = { alc260_replacer_672v_mixer,
5421                             alc260_capture_mixer },
5422                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5423                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5424                 .dac_nids = alc260_dac_nids,
5425                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5426                 .adc_nids = alc260_adc_nids,
5427                 .dig_out_nid = ALC260_DIGOUT_NID,
5428                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5429                 .channel_mode = alc260_modes,
5430                 .input_mux = &alc260_capture_source,
5431                 .unsol_event = alc260_replacer_672v_unsol_event,
5432                 .init_hook = alc260_replacer_672v_automute,
5433         },
5434 #ifdef CONFIG_SND_DEBUG
5435         [ALC260_TEST] = {
5436                 .mixers = { alc260_test_mixer,
5437                             alc260_capture_mixer },
5438                 .init_verbs = { alc260_test_init_verbs },
5439                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5440                 .dac_nids = alc260_test_dac_nids,
5441                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5442                 .adc_nids = alc260_test_adc_nids,
5443                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5444                 .channel_mode = alc260_modes,
5445                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5446                 .input_mux = alc260_test_capture_sources,
5447         },
5448 #endif
5449 };
5450
5451 static int patch_alc260(struct hda_codec *codec)
5452 {
5453         struct alc_spec *spec;
5454         int err, board_config;
5455
5456         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5457         if (spec == NULL)
5458                 return -ENOMEM;
5459
5460         codec->spec = spec;
5461
5462         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
5463                                                   alc260_models,
5464                                                   alc260_cfg_tbl);
5465         if (board_config < 0) {
5466                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
5467                            "trying auto-probe from BIOS...\n");
5468                 board_config = ALC260_AUTO;
5469         }
5470
5471         if (board_config == ALC260_AUTO) {
5472                 /* automatic parse from the BIOS config */
5473                 err = alc260_parse_auto_config(codec);
5474                 if (err < 0) {
5475                         alc_free(codec);
5476                         return err;
5477                 } else if (!err) {
5478                         printk(KERN_INFO
5479                                "hda_codec: Cannot set up configuration "
5480                                "from BIOS.  Using base mode...\n");
5481                         board_config = ALC260_BASIC;
5482                 }
5483         }
5484
5485         if (board_config != ALC260_AUTO)
5486                 setup_preset(spec, &alc260_presets[board_config]);
5487
5488         spec->stream_name_analog = "ALC260 Analog";
5489         spec->stream_analog_playback = &alc260_pcm_analog_playback;
5490         spec->stream_analog_capture = &alc260_pcm_analog_capture;
5491
5492         spec->stream_name_digital = "ALC260 Digital";
5493         spec->stream_digital_playback = &alc260_pcm_digital_playback;
5494         spec->stream_digital_capture = &alc260_pcm_digital_capture;
5495
5496         spec->vmaster_nid = 0x08;
5497
5498         codec->patch_ops = alc_patch_ops;
5499         if (board_config == ALC260_AUTO)
5500                 spec->init_hook = alc260_auto_init;
5501 #ifdef CONFIG_SND_HDA_POWER_SAVE
5502         if (!spec->loopback.amplist)
5503                 spec->loopback.amplist = alc260_loopbacks;
5504 #endif
5505
5506         return 0;
5507 }
5508
5509
5510 /*
5511  * ALC882 support
5512  *
5513  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5514  * configuration.  Each pin widget can choose any input DACs and a mixer.
5515  * Each ADC is connected from a mixer of all inputs.  This makes possible
5516  * 6-channel independent captures.
5517  *
5518  * In addition, an independent DAC for the multi-playback (not used in this
5519  * driver yet).
5520  */
5521 #define ALC882_DIGOUT_NID       0x06
5522 #define ALC882_DIGIN_NID        0x0a
5523
5524 static struct hda_channel_mode alc882_ch_modes[1] = {
5525         { 8, NULL }
5526 };
5527
5528 static hda_nid_t alc882_dac_nids[4] = {
5529         /* front, rear, clfe, rear_surr */
5530         0x02, 0x03, 0x04, 0x05
5531 };
5532
5533 /* identical with ALC880 */
5534 #define alc882_adc_nids         alc880_adc_nids
5535 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5536
5537 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5538 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5539
5540 /* input MUX */
5541 /* FIXME: should be a matrix-type input source selection */
5542
5543 static struct hda_input_mux alc882_capture_source = {
5544         .num_items = 4,
5545         .items = {
5546                 { "Mic", 0x0 },
5547                 { "Front Mic", 0x1 },
5548                 { "Line", 0x2 },
5549                 { "CD", 0x4 },
5550         },
5551 };
5552 #define alc882_mux_enum_info alc_mux_enum_info
5553 #define alc882_mux_enum_get alc_mux_enum_get
5554
5555 static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol,
5556                                struct snd_ctl_elem_value *ucontrol)
5557 {
5558         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5559         struct alc_spec *spec = codec->spec;
5560         const struct hda_input_mux *imux = spec->input_mux;
5561         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
5562         hda_nid_t nid = spec->capsrc_nids ?
5563                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
5564         unsigned int *cur_val = &spec->cur_mux[adc_idx];
5565         unsigned int i, idx;
5566
5567         idx = ucontrol->value.enumerated.item[0];
5568         if (idx >= imux->num_items)
5569                 idx = imux->num_items - 1;
5570         if (*cur_val == idx)
5571                 return 0;
5572         for (i = 0; i < imux->num_items; i++) {
5573                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
5574                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
5575                                          imux->items[i].index,
5576                                          HDA_AMP_MUTE, v);
5577         }
5578         *cur_val = idx;
5579         return 1;
5580 }
5581
5582 /*
5583  * 2ch mode
5584  */
5585 static struct hda_verb alc882_3ST_ch2_init[] = {
5586         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5587         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5588         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5589         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5590         { } /* end */
5591 };
5592
5593 /*
5594  * 6ch mode
5595  */
5596 static struct hda_verb alc882_3ST_ch6_init[] = {
5597         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5598         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5599         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5600         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5601         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5602         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5603         { } /* end */
5604 };
5605
5606 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5607         { 2, alc882_3ST_ch2_init },
5608         { 6, alc882_3ST_ch6_init },
5609 };
5610
5611 /*
5612  * 6ch mode
5613  */
5614 static struct hda_verb alc882_sixstack_ch6_init[] = {
5615         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5616         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5617         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5618         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5619         { } /* end */
5620 };
5621
5622 /*
5623  * 8ch mode
5624  */
5625 static struct hda_verb alc882_sixstack_ch8_init[] = {
5626         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5627         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5628         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5629         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5630         { } /* end */
5631 };
5632
5633 static struct hda_channel_mode alc882_sixstack_modes[2] = {
5634         { 6, alc882_sixstack_ch6_init },
5635         { 8, alc882_sixstack_ch8_init },
5636 };
5637
5638 /*
5639  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
5640  */
5641
5642 /*
5643  * 2ch mode
5644  */
5645 static struct hda_verb alc885_mbp_ch2_init[] = {
5646         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5647         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5648         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5649         { } /* end */
5650 };
5651
5652 /*
5653  * 6ch mode
5654  */
5655 static struct hda_verb alc885_mbp_ch6_init[] = {
5656         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5657         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5658         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5659         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5660         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5661         { } /* end */
5662 };
5663
5664 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
5665         { 2, alc885_mbp_ch2_init },
5666         { 6, alc885_mbp_ch6_init },
5667 };
5668
5669
5670 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
5671  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
5672  */
5673 static struct snd_kcontrol_new alc882_base_mixer[] = {
5674         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5675         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5676         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5677         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5678         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5679         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5680         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5681         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5682         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
5683         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
5684         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5685         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5686         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5687         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5688         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5689         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5690         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5691         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5692         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5693         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5694         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5695         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5696         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5697         { } /* end */
5698 };
5699
5700 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
5701         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5702         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
5703         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
5704         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
5705         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5706         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5707         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
5708         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
5709         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
5710         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
5711         { } /* end */
5712 };
5713 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
5714         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5715         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5716         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5717         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5718         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5719         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5720         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5721         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5722         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5723         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5724         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5725         { } /* end */
5726 };
5727
5728 static struct snd_kcontrol_new alc882_targa_mixer[] = {
5729         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5730         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5731         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5732         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5733         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5734         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5735         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5736         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5737         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5738         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5739         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5740         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5741         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5742         { } /* end */
5743 };
5744
5745 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
5746  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
5747  */
5748 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
5749         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5750         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5751         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5752         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
5753         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5754         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5755         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5756         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5757         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
5758         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
5759         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5760         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5761         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5762         { } /* end */
5763 };
5764
5765 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
5766         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5767         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5768         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5769         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5770         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5771         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5772         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5773         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5774         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5775         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5776         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5777         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5778         { } /* end */
5779 };
5780
5781 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
5782         {
5783                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5784                 .name = "Channel Mode",
5785                 .info = alc_ch_mode_info,
5786                 .get = alc_ch_mode_get,
5787                 .put = alc_ch_mode_put,
5788         },
5789         { } /* end */
5790 };
5791
5792 static struct hda_verb alc882_init_verbs[] = {
5793         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5794         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5795         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5796         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5797         /* Rear mixer */
5798         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5799         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5800         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5801         /* CLFE mixer */
5802         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5803         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5804         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5805         /* Side mixer */
5806         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5807         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5808         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5809
5810         /* Front Pin: output 0 (0x0c) */
5811         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5812         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5813         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5814         /* Rear Pin: output 1 (0x0d) */
5815         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5816         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5817         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5818         /* CLFE Pin: output 2 (0x0e) */
5819         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5820         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5821         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
5822         /* Side Pin: output 3 (0x0f) */
5823         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5824         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5825         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
5826         /* Mic (rear) pin: input vref at 80% */
5827         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5828         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5829         /* Front Mic pin: input vref at 80% */
5830         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5831         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5832         /* Line In pin: input */
5833         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5834         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5835         /* Line-2 In: Headphone output (output 0 - 0x0c) */
5836         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5837         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5838         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
5839         /* CD pin widget for input */
5840         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5841
5842         /* FIXME: use matrix-type input source selection */
5843         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5844         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5845         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5846         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5847         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5848         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5849         /* Input mixer2 */
5850         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5851         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5852         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5853         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5854         /* Input mixer3 */
5855         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5856         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5857         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5858         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5859         /* ADC1: mute amp left and right */
5860         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5861         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5862         /* ADC2: mute amp left and right */
5863         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5864         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5865         /* ADC3: mute amp left and right */
5866         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5867         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5868
5869         { }
5870 };
5871
5872 static struct hda_verb alc882_eapd_verbs[] = {
5873         /* change to EAPD mode */
5874         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5875         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
5876         { }
5877 };
5878
5879 /* Mac Pro test */
5880 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
5881         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5882         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5883         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
5884         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
5885         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
5886         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
5887         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
5888         { } /* end */
5889 };
5890
5891 static struct hda_verb alc882_macpro_init_verbs[] = {
5892         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5893         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5894         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5895         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5896         /* Front Pin: output 0 (0x0c) */
5897         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5898         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5899         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5900         /* Front Mic pin: input vref at 80% */
5901         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5902         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5903         /* Speaker:  output */
5904         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5905         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5906         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
5907         /* Headphone output (output 0 - 0x0c) */
5908         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5909         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5910         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5911
5912         /* FIXME: use matrix-type input source selection */
5913         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5914         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5915         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5916         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5917         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5918         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5919         /* Input mixer2 */
5920         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5921         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5922         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5923         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5924         /* Input mixer3 */
5925         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5926         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5927         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5928         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5929         /* ADC1: mute amp left and right */
5930         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5931         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5932         /* ADC2: mute amp left and right */
5933         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5934         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5935         /* ADC3: mute amp left and right */
5936         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5937         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5938
5939         { }
5940 };
5941
5942 /* Macbook Pro rev3 */
5943 static struct hda_verb alc885_mbp3_init_verbs[] = {
5944         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5945         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5946         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5947         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5948         /* Rear mixer */
5949         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5950         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5951         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5952         /* Front Pin: output 0 (0x0c) */
5953         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5954         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5955         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5956         /* HP Pin: output 0 (0x0d) */
5957         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
5958         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5959         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5960         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5961         /* Mic (rear) pin: input vref at 80% */
5962         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5963         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5964         /* Front Mic pin: input vref at 80% */
5965         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5966         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5967         /* Line In pin: use output 1 when in LineOut mode */
5968         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5969         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5970         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
5971
5972         /* FIXME: use matrix-type input source selection */
5973         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5974         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5975         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5976         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5977         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5978         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5979         /* Input mixer2 */
5980         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5981         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5982         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5983         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5984         /* Input mixer3 */
5985         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5986         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5987         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5988         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5989         /* ADC1: mute amp left and right */
5990         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5991         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5992         /* ADC2: mute amp left and right */
5993         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5994         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5995         /* ADC3: mute amp left and right */
5996         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5997         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5998
5999         { }
6000 };
6001
6002 /* iMac 24 mixer. */
6003 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
6004         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6005         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
6006         { } /* end */
6007 };
6008
6009 /* iMac 24 init verbs. */
6010 static struct hda_verb alc885_imac24_init_verbs[] = {
6011         /* Internal speakers: output 0 (0x0c) */
6012         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6013         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6014         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6015         /* Internal speakers: output 0 (0x0c) */
6016         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6017         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6018         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
6019         /* Headphone: output 0 (0x0c) */
6020         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6021         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6022         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6023         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6024         /* Front Mic: input vref at 80% */
6025         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6026         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6027         { }
6028 };
6029
6030 /* Toggle speaker-output according to the hp-jack state */
6031 static void alc885_imac24_automute(struct hda_codec *codec)
6032 {
6033         unsigned int present;
6034
6035         present = snd_hda_codec_read(codec, 0x14, 0,
6036                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6037         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
6038                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6039         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
6040                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6041 }
6042
6043 /* Processes unsolicited events. */
6044 static void alc885_imac24_unsol_event(struct hda_codec *codec,
6045                                       unsigned int res)
6046 {
6047         /* Headphone insertion or removal. */
6048         if ((res >> 26) == ALC880_HP_EVENT)
6049                 alc885_imac24_automute(codec);
6050 }
6051
6052 static void alc885_mbp3_automute(struct hda_codec *codec)
6053 {
6054         unsigned int present;
6055
6056         present = snd_hda_codec_read(codec, 0x15, 0,
6057                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6058         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
6059                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6060         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6061                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
6062
6063 }
6064 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
6065                                     unsigned int res)
6066 {
6067         /* Headphone insertion or removal. */
6068         if ((res >> 26) == ALC880_HP_EVENT)
6069                 alc885_mbp3_automute(codec);
6070 }
6071
6072
6073 static struct hda_verb alc882_targa_verbs[] = {
6074         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6075         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6076
6077         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6078         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6079
6080         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6081         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6082         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6083
6084         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6085         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6086         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6087         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6088         { } /* end */
6089 };
6090
6091 /* toggle speaker-output according to the hp-jack state */
6092 static void alc882_targa_automute(struct hda_codec *codec)
6093 {
6094         unsigned int present;
6095
6096         present = snd_hda_codec_read(codec, 0x14, 0,
6097                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6098         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
6099                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6100         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6101                                   present ? 1 : 3);
6102 }
6103
6104 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
6105 {
6106         /* Looks like the unsol event is incompatible with the standard
6107          * definition.  4bit tag is placed at 26 bit!
6108          */
6109         if (((res >> 26) == ALC880_HP_EVENT)) {
6110                 alc882_targa_automute(codec);
6111         }
6112 }
6113
6114 static struct hda_verb alc882_asus_a7j_verbs[] = {
6115         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6116         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6117
6118         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6119         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6120         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6121
6122         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6123         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6124         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6125
6126         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6127         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6128         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6129         { } /* end */
6130 };
6131
6132 static struct hda_verb alc882_asus_a7m_verbs[] = {
6133         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6134         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6135
6136         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6137         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6138         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6139
6140         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6141         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6142         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6143
6144         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6145         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6146         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6147         { } /* end */
6148 };
6149
6150 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6151 {
6152         unsigned int gpiostate, gpiomask, gpiodir;
6153
6154         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6155                                        AC_VERB_GET_GPIO_DATA, 0);
6156
6157         if (!muted)
6158                 gpiostate |= (1 << pin);
6159         else
6160                 gpiostate &= ~(1 << pin);
6161
6162         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
6163                                       AC_VERB_GET_GPIO_MASK, 0);
6164         gpiomask |= (1 << pin);
6165
6166         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
6167                                      AC_VERB_GET_GPIO_DIRECTION, 0);
6168         gpiodir |= (1 << pin);
6169
6170
6171         snd_hda_codec_write(codec, codec->afg, 0,
6172                             AC_VERB_SET_GPIO_MASK, gpiomask);
6173         snd_hda_codec_write(codec, codec->afg, 0,
6174                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
6175
6176         msleep(1);
6177
6178         snd_hda_codec_write(codec, codec->afg, 0,
6179                             AC_VERB_SET_GPIO_DATA, gpiostate);
6180 }
6181
6182 /* set up GPIO at initialization */
6183 static void alc885_macpro_init_hook(struct hda_codec *codec)
6184 {
6185         alc882_gpio_mute(codec, 0, 0);
6186         alc882_gpio_mute(codec, 1, 0);
6187 }
6188
6189 /* set up GPIO and update auto-muting at initialization */
6190 static void alc885_imac24_init_hook(struct hda_codec *codec)
6191 {
6192         alc885_macpro_init_hook(codec);
6193         alc885_imac24_automute(codec);
6194 }
6195
6196 /*
6197  * generic initialization of ADC, input mixers and output mixers
6198  */
6199 static struct hda_verb alc882_auto_init_verbs[] = {
6200         /*
6201          * Unmute ADC0-2 and set the default input to mic-in
6202          */
6203         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6204         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6205         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6206         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6207         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6208         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6209
6210         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6211          * mixer widget
6212          * Note: PASD motherboards uses the Line In 2 as the input for
6213          * front panel mic (mic 2)
6214          */
6215         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6216         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6217         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6218         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6219         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6220         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6221
6222         /*
6223          * Set up output mixers (0x0c - 0x0f)
6224          */
6225         /* set vol=0 to output mixers */
6226         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6227         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6228         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6229         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6230         /* set up input amps for analog loopback */
6231         /* Amp Indices: DAC = 0, mixer = 1 */
6232         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6233         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6234         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6235         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6236         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6237         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6238         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6239         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6240         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6241         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6242
6243         /* FIXME: use matrix-type input source selection */
6244         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6245         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6246         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6247         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6248         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6249         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6250         /* Input mixer2 */
6251         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6252         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6253         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6254         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6255         /* Input mixer3 */
6256         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6257         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6258         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6259         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6260
6261         { }
6262 };
6263
6264 /* capture mixer elements */
6265 static struct snd_kcontrol_new alc882_capture_alt_mixer[] = {
6266         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6267         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6268         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6269         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6270         {
6271                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6272                 /* The multiple "Capture Source" controls confuse alsamixer
6273                  * So call somewhat different..
6274                  */
6275                 /* .name = "Capture Source", */
6276                 .name = "Input Source",
6277                 .count = 2,
6278                 .info = alc882_mux_enum_info,
6279                 .get = alc882_mux_enum_get,
6280                 .put = alc882_mux_enum_put,
6281         },
6282         { } /* end */
6283 };
6284
6285 static struct snd_kcontrol_new alc882_capture_mixer[] = {
6286         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
6287         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
6288         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
6289         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
6290         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
6291         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
6292         {
6293                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6294                 /* The multiple "Capture Source" controls confuse alsamixer
6295                  * So call somewhat different..
6296                  */
6297                 /* .name = "Capture Source", */
6298                 .name = "Input Source",
6299                 .count = 3,
6300                 .info = alc882_mux_enum_info,
6301                 .get = alc882_mux_enum_get,
6302                 .put = alc882_mux_enum_put,
6303         },
6304         { } /* end */
6305 };
6306
6307 #ifdef CONFIG_SND_HDA_POWER_SAVE
6308 #define alc882_loopbacks        alc880_loopbacks
6309 #endif
6310
6311 /* pcm configuration: identiacal with ALC880 */
6312 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6313 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6314 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6315 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6316
6317 /*
6318  * configuration and preset
6319  */
6320 static const char *alc882_models[ALC882_MODEL_LAST] = {
6321         [ALC882_3ST_DIG]        = "3stack-dig",
6322         [ALC882_6ST_DIG]        = "6stack-dig",
6323         [ALC882_ARIMA]          = "arima",
6324         [ALC882_W2JC]           = "w2jc",
6325         [ALC882_TARGA]          = "targa",
6326         [ALC882_ASUS_A7J]       = "asus-a7j",
6327         [ALC882_ASUS_A7M]       = "asus-a7m",
6328         [ALC885_MACPRO]         = "macpro",
6329         [ALC885_MBP3]           = "mbp3",
6330         [ALC885_IMAC24]         = "imac24",
6331         [ALC882_AUTO]           = "auto",
6332 };
6333
6334 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6335         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6336         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6337         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6338         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6339         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6340         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6341         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6342         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6343         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6344         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6345         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6346         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6347         {}
6348 };
6349
6350 static struct alc_config_preset alc882_presets[] = {
6351         [ALC882_3ST_DIG] = {
6352                 .mixers = { alc882_base_mixer },
6353                 .init_verbs = { alc882_init_verbs },
6354                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6355                 .dac_nids = alc882_dac_nids,
6356                 .dig_out_nid = ALC882_DIGOUT_NID,
6357                 .dig_in_nid = ALC882_DIGIN_NID,
6358                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6359                 .channel_mode = alc882_ch_modes,
6360                 .need_dac_fix = 1,
6361                 .input_mux = &alc882_capture_source,
6362         },
6363         [ALC882_6ST_DIG] = {
6364                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6365                 .init_verbs = { alc882_init_verbs },
6366                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6367                 .dac_nids = alc882_dac_nids,
6368                 .dig_out_nid = ALC882_DIGOUT_NID,
6369                 .dig_in_nid = ALC882_DIGIN_NID,
6370                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6371                 .channel_mode = alc882_sixstack_modes,
6372                 .input_mux = &alc882_capture_source,
6373         },
6374         [ALC882_ARIMA] = {
6375                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6376                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6377                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6378                 .dac_nids = alc882_dac_nids,
6379                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6380                 .channel_mode = alc882_sixstack_modes,
6381                 .input_mux = &alc882_capture_source,
6382         },
6383         [ALC882_W2JC] = {
6384                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6385                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6386                                 alc880_gpio1_init_verbs },
6387                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6388                 .dac_nids = alc882_dac_nids,
6389                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6390                 .channel_mode = alc880_threestack_modes,
6391                 .need_dac_fix = 1,
6392                 .input_mux = &alc882_capture_source,
6393                 .dig_out_nid = ALC882_DIGOUT_NID,
6394         },
6395         [ALC885_MBP3] = {
6396                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6397                 .init_verbs = { alc885_mbp3_init_verbs,
6398                                 alc880_gpio1_init_verbs },
6399                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6400                 .dac_nids = alc882_dac_nids,
6401                 .channel_mode = alc885_mbp_6ch_modes,
6402                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
6403                 .input_mux = &alc882_capture_source,
6404                 .dig_out_nid = ALC882_DIGOUT_NID,
6405                 .dig_in_nid = ALC882_DIGIN_NID,
6406                 .unsol_event = alc885_mbp3_unsol_event,
6407                 .init_hook = alc885_mbp3_automute,
6408         },
6409         [ALC885_MACPRO] = {
6410                 .mixers = { alc882_macpro_mixer },
6411                 .init_verbs = { alc882_macpro_init_verbs },
6412                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6413                 .dac_nids = alc882_dac_nids,
6414                 .dig_out_nid = ALC882_DIGOUT_NID,
6415                 .dig_in_nid = ALC882_DIGIN_NID,
6416                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6417                 .channel_mode = alc882_ch_modes,
6418                 .input_mux = &alc882_capture_source,
6419                 .init_hook = alc885_macpro_init_hook,
6420         },
6421         [ALC885_IMAC24] = {
6422                 .mixers = { alc885_imac24_mixer },
6423                 .init_verbs = { alc885_imac24_init_verbs },
6424                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6425                 .dac_nids = alc882_dac_nids,
6426                 .dig_out_nid = ALC882_DIGOUT_NID,
6427                 .dig_in_nid = ALC882_DIGIN_NID,
6428                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6429                 .channel_mode = alc882_ch_modes,
6430                 .input_mux = &alc882_capture_source,
6431                 .unsol_event = alc885_imac24_unsol_event,
6432                 .init_hook = alc885_imac24_init_hook,
6433         },
6434         [ALC882_TARGA] = {
6435                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer,
6436                             alc882_capture_mixer },
6437                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6438                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6439                 .dac_nids = alc882_dac_nids,
6440                 .dig_out_nid = ALC882_DIGOUT_NID,
6441                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6442                 .adc_nids = alc882_adc_nids,
6443                 .capsrc_nids = alc882_capsrc_nids,
6444                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6445                 .channel_mode = alc882_3ST_6ch_modes,
6446                 .need_dac_fix = 1,
6447                 .input_mux = &alc882_capture_source,
6448                 .unsol_event = alc882_targa_unsol_event,
6449                 .init_hook = alc882_targa_automute,
6450         },
6451         [ALC882_ASUS_A7J] = {
6452                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer,
6453                             alc882_capture_mixer },
6454                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6455                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6456                 .dac_nids = alc882_dac_nids,
6457                 .dig_out_nid = ALC882_DIGOUT_NID,
6458                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6459                 .adc_nids = alc882_adc_nids,
6460                 .capsrc_nids = alc882_capsrc_nids,
6461                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6462                 .channel_mode = alc882_3ST_6ch_modes,
6463                 .need_dac_fix = 1,
6464                 .input_mux = &alc882_capture_source,
6465         },
6466         [ALC882_ASUS_A7M] = {
6467                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6468                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6469                                 alc880_gpio1_init_verbs,
6470                                 alc882_asus_a7m_verbs },
6471                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6472                 .dac_nids = alc882_dac_nids,
6473                 .dig_out_nid = ALC882_DIGOUT_NID,
6474                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6475                 .channel_mode = alc880_threestack_modes,
6476                 .need_dac_fix = 1,
6477                 .input_mux = &alc882_capture_source,
6478         },
6479 };
6480
6481
6482 /*
6483  * Pin config fixes
6484  */
6485 enum {
6486         PINFIX_ABIT_AW9D_MAX
6487 };
6488
6489 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6490         { 0x15, 0x01080104 }, /* side */
6491         { 0x16, 0x01011012 }, /* rear */
6492         { 0x17, 0x01016011 }, /* clfe */
6493         { }
6494 };
6495
6496 static const struct alc_pincfg *alc882_pin_fixes[] = {
6497         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6498 };
6499
6500 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6501         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6502         {}
6503 };
6504
6505 /*
6506  * BIOS auto configuration
6507  */
6508 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6509                                               hda_nid_t nid, int pin_type,
6510                                               int dac_idx)
6511 {
6512         /* set as output */
6513         struct alc_spec *spec = codec->spec;
6514         int idx;
6515
6516         alc_set_pin_output(codec, nid, pin_type);
6517         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6518                 idx = 4;
6519         else
6520                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6521         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6522
6523 }
6524
6525 static void alc882_auto_init_multi_out(struct hda_codec *codec)
6526 {
6527         struct alc_spec *spec = codec->spec;
6528         int i;
6529
6530         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6531         for (i = 0; i <= HDA_SIDE; i++) {
6532                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6533                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6534                 if (nid)
6535                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6536                                                           i);
6537         }
6538 }
6539
6540 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6541 {
6542         struct alc_spec *spec = codec->spec;
6543         hda_nid_t pin;
6544
6545         pin = spec->autocfg.hp_pins[0];
6546         if (pin) /* connect to front */
6547                 /* use dac 0 */
6548                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6549         pin = spec->autocfg.speaker_pins[0];
6550         if (pin)
6551                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6552 }
6553
6554 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6555 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6556
6557 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6558 {
6559         struct alc_spec *spec = codec->spec;
6560         int i;
6561
6562         for (i = 0; i < AUTO_PIN_LAST; i++) {
6563                 hda_nid_t nid = spec->autocfg.input_pins[i];
6564                 unsigned int vref;
6565                 if (!nid)
6566                         continue;
6567                 vref = PIN_IN;
6568                 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6569                         unsigned int pincap;
6570                         pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
6571                         if ((pincap >> AC_PINCAP_VREF_SHIFT) &
6572                             AC_PINCAP_VREF_80)
6573                                 vref = PIN_VREF80;
6574                 }
6575                 snd_hda_codec_write(codec, nid, 0,
6576                                     AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6577                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6578                         snd_hda_codec_write(codec, nid, 0,
6579                                             AC_VERB_SET_AMP_GAIN_MUTE,
6580                                             AMP_OUT_MUTE);
6581         }
6582 }
6583
6584 static void alc882_auto_init_input_src(struct hda_codec *codec)
6585 {
6586         struct alc_spec *spec = codec->spec;
6587         const struct hda_input_mux *imux = spec->input_mux;
6588         int c;
6589
6590         for (c = 0; c < spec->num_adc_nids; c++) {
6591                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
6592                 hda_nid_t nid = spec->capsrc_nids[c];
6593                 int conns, mute, idx, item;
6594
6595                 conns = snd_hda_get_connections(codec, nid, conn_list,
6596                                                 ARRAY_SIZE(conn_list));
6597                 if (conns < 0)
6598                         continue;
6599                 for (idx = 0; idx < conns; idx++) {
6600                         /* if the current connection is the selected one,
6601                          * unmute it as default - otherwise mute it
6602                          */
6603                         mute = AMP_IN_MUTE(idx);
6604                         for (item = 0; item < imux->num_items; item++) {
6605                                 if (imux->items[item].index == idx) {
6606                                         if (spec->cur_mux[c] == item)
6607                                                 mute = AMP_IN_UNMUTE(idx);
6608                                         break;
6609                                 }
6610                         }
6611                         snd_hda_codec_write(codec, nid, 0,
6612                                             AC_VERB_SET_AMP_GAIN_MUTE, mute);
6613                 }
6614         }
6615 }
6616
6617 /* add mic boosts if needed */
6618 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6619 {
6620         struct alc_spec *spec = codec->spec;
6621         int err;
6622         hda_nid_t nid;
6623
6624         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6625         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6626                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6627                                   "Mic Boost",
6628                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6629                 if (err < 0)
6630                         return err;
6631         }
6632         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6633         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6634                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6635                                   "Front Mic Boost",
6636                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6637                 if (err < 0)
6638                         return err;
6639         }
6640         return 0;
6641 }
6642
6643 /* almost identical with ALC880 parser... */
6644 static int alc882_parse_auto_config(struct hda_codec *codec)
6645 {
6646         struct alc_spec *spec = codec->spec;
6647         int err = alc880_parse_auto_config(codec);
6648
6649         if (err < 0)
6650                 return err;
6651         else if (!err)
6652                 return 0; /* no config found */
6653
6654         err = alc_auto_add_mic_boost(codec);
6655         if (err < 0)
6656                 return err;
6657
6658         /* hack - override the init verbs */
6659         spec->init_verbs[0] = alc882_auto_init_verbs;
6660
6661         return 1; /* config found */
6662 }
6663
6664 /* additional initialization for auto-configuration model */
6665 static void alc882_auto_init(struct hda_codec *codec)
6666 {
6667         struct alc_spec *spec = codec->spec;
6668         alc882_auto_init_multi_out(codec);
6669         alc882_auto_init_hp_out(codec);
6670         alc882_auto_init_analog_input(codec);
6671         alc882_auto_init_input_src(codec);
6672         if (spec->unsol_event)
6673                 alc_inithook(codec);
6674 }
6675
6676 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
6677
6678 static int patch_alc882(struct hda_codec *codec)
6679 {
6680         struct alc_spec *spec;
6681         int err, board_config;
6682
6683         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6684         if (spec == NULL)
6685                 return -ENOMEM;
6686
6687         codec->spec = spec;
6688
6689         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
6690                                                   alc882_models,
6691                                                   alc882_cfg_tbl);
6692
6693         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
6694                 /* Pick up systems that don't supply PCI SSID */
6695                 switch (codec->subsystem_id) {
6696                 case 0x106b0c00: /* Mac Pro */
6697                         board_config = ALC885_MACPRO;
6698                         break;
6699                 case 0x106b1000: /* iMac 24 */
6700                 case 0x106b2800: /* AppleTV */
6701                         board_config = ALC885_IMAC24;
6702                         break;
6703                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
6704                 case 0x106b00a4: /* MacbookPro4,1 */
6705                 case 0x106b2c00: /* Macbook Pro rev3 */
6706                 case 0x106b3600: /* Macbook 3.1 */
6707                         board_config = ALC885_MBP3;
6708                         break;
6709                 default:
6710                         /* ALC889A is handled better as ALC888-compatible */
6711                         if (codec->revision_id == 0x100101 ||
6712                             codec->revision_id == 0x100103) {
6713                                 alc_free(codec);
6714                                 return patch_alc883(codec);
6715                         }
6716                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
6717                                          "trying auto-probe from BIOS...\n");
6718                         board_config = ALC882_AUTO;
6719                 }
6720         }
6721
6722         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
6723
6724         if (board_config == ALC882_AUTO) {
6725                 /* automatic parse from the BIOS config */
6726                 err = alc882_parse_auto_config(codec);
6727                 if (err < 0) {
6728                         alc_free(codec);
6729                         return err;
6730                 } else if (!err) {
6731                         printk(KERN_INFO
6732                                "hda_codec: Cannot set up configuration "
6733                                "from BIOS.  Using base mode...\n");
6734                         board_config = ALC882_3ST_DIG;
6735                 }
6736         }
6737
6738         if (board_config != ALC882_AUTO)
6739                 setup_preset(spec, &alc882_presets[board_config]);
6740
6741         if (codec->vendor_id == 0x10ec0885) {
6742                 spec->stream_name_analog = "ALC885 Analog";
6743                 spec->stream_name_digital = "ALC885 Digital";
6744         } else {
6745                 spec->stream_name_analog = "ALC882 Analog";
6746                 spec->stream_name_digital = "ALC882 Digital";
6747         }
6748
6749         spec->stream_analog_playback = &alc882_pcm_analog_playback;
6750         spec->stream_analog_capture = &alc882_pcm_analog_capture;
6751         /* FIXME: setup DAC5 */
6752         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
6753         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
6754
6755         spec->stream_digital_playback = &alc882_pcm_digital_playback;
6756         spec->stream_digital_capture = &alc882_pcm_digital_capture;
6757
6758         if (!spec->adc_nids && spec->input_mux) {
6759                 /* check whether NID 0x07 is valid */
6760                 unsigned int wcap = get_wcaps(codec, 0x07);
6761                 /* get type */
6762                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
6763                 if (wcap != AC_WID_AUD_IN) {
6764                         spec->adc_nids = alc882_adc_nids_alt;
6765                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
6766                         spec->capsrc_nids = alc882_capsrc_nids_alt;
6767                         spec->mixers[spec->num_mixers] =
6768                                 alc882_capture_alt_mixer;
6769                         spec->num_mixers++;
6770                 } else {
6771                         spec->adc_nids = alc882_adc_nids;
6772                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
6773                         spec->capsrc_nids = alc882_capsrc_nids;
6774                         spec->mixers[spec->num_mixers] = alc882_capture_mixer;
6775                         spec->num_mixers++;
6776                 }
6777         }
6778
6779         spec->vmaster_nid = 0x0c;
6780
6781         codec->patch_ops = alc_patch_ops;
6782         if (board_config == ALC882_AUTO)
6783                 spec->init_hook = alc882_auto_init;
6784 #ifdef CONFIG_SND_HDA_POWER_SAVE
6785         if (!spec->loopback.amplist)
6786                 spec->loopback.amplist = alc882_loopbacks;
6787 #endif
6788
6789         return 0;
6790 }
6791
6792 /*
6793  * ALC883 support
6794  *
6795  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
6796  * configuration.  Each pin widget can choose any input DACs and a mixer.
6797  * Each ADC is connected from a mixer of all inputs.  This makes possible
6798  * 6-channel independent captures.
6799  *
6800  * In addition, an independent DAC for the multi-playback (not used in this
6801  * driver yet).
6802  */
6803 #define ALC883_DIGOUT_NID       0x06
6804 #define ALC883_DIGIN_NID        0x0a
6805
6806 static hda_nid_t alc883_dac_nids[4] = {
6807         /* front, rear, clfe, rear_surr */
6808         0x02, 0x03, 0x04, 0x05
6809 };
6810
6811 static hda_nid_t alc883_adc_nids[2] = {
6812         /* ADC1-2 */
6813         0x08, 0x09,
6814 };
6815
6816 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
6817
6818 /* input MUX */
6819 /* FIXME: should be a matrix-type input source selection */
6820
6821 static struct hda_input_mux alc883_capture_source = {
6822         .num_items = 4,
6823         .items = {
6824                 { "Mic", 0x0 },
6825                 { "Front Mic", 0x1 },
6826                 { "Line", 0x2 },
6827                 { "CD", 0x4 },
6828         },
6829 };
6830
6831 static struct hda_input_mux alc883_3stack_6ch_intel = {
6832         .num_items = 4,
6833         .items = {
6834                 { "Mic", 0x1 },
6835                 { "Front Mic", 0x0 },
6836                 { "Line", 0x2 },
6837                 { "CD", 0x4 },
6838         },
6839 };
6840
6841 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6842         .num_items = 2,
6843         .items = {
6844                 { "Mic", 0x1 },
6845                 { "Line", 0x2 },
6846         },
6847 };
6848
6849 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6850         .num_items = 4,
6851         .items = {
6852                 { "Mic", 0x0 },
6853                 { "iMic", 0x1 },
6854                 { "Line", 0x2 },
6855                 { "CD", 0x4 },
6856         },
6857 };
6858
6859 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6860         .num_items = 2,
6861         .items = {
6862                 { "Mic", 0x0 },
6863                 { "Int Mic", 0x1 },
6864         },
6865 };
6866
6867 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
6868         .num_items = 3,
6869         .items = {
6870                 { "Mic", 0x0 },
6871                 { "Front Mic", 0x1 },
6872                 { "Line", 0x4 },
6873         },
6874 };
6875
6876 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
6877         .num_items = 2,
6878         .items = {
6879                 { "Mic", 0x0 },
6880                 { "Line", 0x2 },
6881         },
6882 };
6883
6884 #define alc883_mux_enum_info alc_mux_enum_info
6885 #define alc883_mux_enum_get alc_mux_enum_get
6886 /* ALC883 has the ALC882-type input selection */
6887 #define alc883_mux_enum_put alc882_mux_enum_put
6888
6889 /*
6890  * 2ch mode
6891  */
6892 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6893         { 2, NULL }
6894 };
6895
6896 /*
6897  * 2ch mode
6898  */
6899 static struct hda_verb alc883_3ST_ch2_init[] = {
6900         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6901         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6902         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6903         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6904         { } /* end */
6905 };
6906
6907 /*
6908  * 4ch mode
6909  */
6910 static struct hda_verb alc883_3ST_ch4_init[] = {
6911         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6912         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6913         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6914         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6915         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6916         { } /* end */
6917 };
6918
6919 /*
6920  * 6ch mode
6921  */
6922 static struct hda_verb alc883_3ST_ch6_init[] = {
6923         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6924         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6925         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6926         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6927         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6928         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6929         { } /* end */
6930 };
6931
6932 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
6933         { 2, alc883_3ST_ch2_init },
6934         { 4, alc883_3ST_ch4_init },
6935         { 6, alc883_3ST_ch6_init },
6936 };
6937
6938 /*
6939  * 2ch mode
6940  */
6941 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
6942         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6943         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6944         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6945         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6946         { } /* end */
6947 };
6948
6949 /*
6950  * 4ch mode
6951  */
6952 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
6953         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6954         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6955         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6956         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6957         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6958         { } /* end */
6959 };
6960
6961 /*
6962  * 6ch mode
6963  */
6964 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
6965         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6966         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6967         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
6968         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6969         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6970         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6971         { } /* end */
6972 };
6973
6974 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
6975         { 2, alc883_3ST_ch2_intel_init },
6976         { 4, alc883_3ST_ch4_intel_init },
6977         { 6, alc883_3ST_ch6_intel_init },
6978 };
6979
6980 /*
6981  * 6ch mode
6982  */
6983 static struct hda_verb alc883_sixstack_ch6_init[] = {
6984         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6985         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6986         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6987         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6988         { } /* end */
6989 };
6990
6991 /*
6992  * 8ch mode
6993  */
6994 static struct hda_verb alc883_sixstack_ch8_init[] = {
6995         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6996         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6997         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6998         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6999         { } /* end */
7000 };
7001
7002 static struct hda_channel_mode alc883_sixstack_modes[2] = {
7003         { 6, alc883_sixstack_ch6_init },
7004         { 8, alc883_sixstack_ch8_init },
7005 };
7006
7007 static struct hda_verb alc883_medion_eapd_verbs[] = {
7008         /* eanable EAPD on medion laptop */
7009         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7010         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7011         { }
7012 };
7013
7014 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
7015  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
7016  */
7017
7018 static struct snd_kcontrol_new alc883_base_mixer[] = {
7019         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7020         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7021         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7022         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7023         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7024         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7025         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7026         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7027         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7028         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7029         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7030         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7031         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7032         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7033         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7034         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7035         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7036         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7037         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7038         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7039         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7040         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7041         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7042         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7043         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7044         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7045         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7046         {
7047                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7048                 /* .name = "Capture Source", */
7049                 .name = "Input Source",
7050                 .count = 2,
7051                 .info = alc883_mux_enum_info,
7052                 .get = alc883_mux_enum_get,
7053                 .put = alc883_mux_enum_put,
7054         },
7055         { } /* end */
7056 };
7057
7058 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7059         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7060         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7061         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7062         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7063         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7064         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7065         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7066         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7067         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7068         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7069         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7070         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7071         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7072         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7073         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7074         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7075         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7076         {
7077                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7078                 /* .name = "Capture Source", */
7079                 .name = "Input Source",
7080                 .count = 2,
7081                 .info = alc883_mux_enum_info,
7082                 .get = alc883_mux_enum_get,
7083                 .put = alc883_mux_enum_put,
7084         },
7085         { } /* end */
7086 };
7087
7088 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7089         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7090         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7091         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7092         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7093         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7094         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7095         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7096         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7097         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7098         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7099         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7100         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7101         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7102         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7103         {
7104                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7105                 /* .name = "Capture Source", */
7106                 .name = "Input Source",
7107                 .count = 2,
7108                 .info = alc883_mux_enum_info,
7109                 .get = alc883_mux_enum_get,
7110                 .put = alc883_mux_enum_put,
7111         },
7112         { } /* end */
7113 };
7114
7115 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7116         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7117         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7118         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7119         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7120         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7121         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7122         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7123         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7124         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7125         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7126         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7127         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7128         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7129         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7130         {
7131                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7132                 /* .name = "Capture Source", */
7133                 .name = "Input Source",
7134                 .count = 2,
7135                 .info = alc883_mux_enum_info,
7136                 .get = alc883_mux_enum_get,
7137                 .put = alc883_mux_enum_put,
7138         },
7139         { } /* end */
7140 };
7141
7142 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7143         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7144         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7145         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7146         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7147         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7148         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7149         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7150         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7151         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7152         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7153         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7154         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7155         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7156         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7157         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7158         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7159         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7160         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7161         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7162         {
7163                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7164                 /* .name = "Capture Source", */
7165                 .name = "Input Source",
7166                 .count = 2,
7167                 .info = alc883_mux_enum_info,
7168                 .get = alc883_mux_enum_get,
7169                 .put = alc883_mux_enum_put,
7170         },
7171         { } /* end */
7172 };
7173
7174 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7175         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7176         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7177         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7178         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7179         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7180         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7181         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7182         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7183         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7184         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7185         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7186         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7187         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7188         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7189         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7190         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7191         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7192         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7193         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7194         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7195         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7196         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7197         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7198         {
7199                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7200                 /* .name = "Capture Source", */
7201                 .name = "Input Source",
7202                 .count = 1,
7203                 .info = alc883_mux_enum_info,
7204                 .get = alc883_mux_enum_get,
7205                 .put = alc883_mux_enum_put,
7206         },
7207         { } /* end */
7208 };
7209
7210 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7211         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7212         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7213         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7214         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7215         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7216                               HDA_OUTPUT),
7217         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7218         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7219         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7220         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7221         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7222         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7223         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7224         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7225         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7226         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7227         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7228         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7229         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7230         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7231         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7232         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7233         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7234         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7235         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7236         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7237         {
7238                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7239                 /* .name = "Capture Source", */
7240                 .name = "Input Source",
7241                 .count = 2,
7242                 .info = alc883_mux_enum_info,
7243                 .get = alc883_mux_enum_get,
7244                 .put = alc883_mux_enum_put,
7245         },
7246         { } /* end */
7247 };
7248
7249 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7250         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7251         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7252         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7253         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7254         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7255         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7256         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7257         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7258         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7259         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7260         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7261         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7262         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7263         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7264         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7265         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7266         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7267         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7268         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7269         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7270         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7271         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7272         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7273
7274         {
7275                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7276                 /* .name = "Capture Source", */
7277                 .name = "Input Source",
7278                 .count = 1,
7279                 .info = alc883_mux_enum_info,
7280                 .get = alc883_mux_enum_get,
7281                 .put = alc883_mux_enum_put,
7282         },
7283         { } /* end */
7284 };
7285
7286 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
7287         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7288         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7289         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7290         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7291         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7292         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7293         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7294         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7295         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7296         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7297         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7298         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7299         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7300         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7301         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7302         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7303         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7304         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7305         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7306         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7307         {
7308                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7309                 /* .name = "Capture Source", */
7310                 .name = "Input Source",
7311                 .count = 2,
7312                 .info = alc883_mux_enum_info,
7313                 .get = alc883_mux_enum_get,
7314                 .put = alc883_mux_enum_put,
7315         },
7316         { } /* end */
7317 };
7318
7319 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
7320         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7321         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7322         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7323         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7324         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7325         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7326         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7327         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7328         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7329         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7330         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7331         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7332         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7333         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7334         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7335         {
7336                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7337                 /* .name = "Capture Source", */
7338                 .name = "Input Source",
7339                 .count = 2,
7340                 .info = alc883_mux_enum_info,
7341                 .get = alc883_mux_enum_get,
7342                 .put = alc883_mux_enum_put,
7343         },
7344         { } /* end */
7345 };
7346
7347 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7348         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7349         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7350         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7351         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7352         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7353         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7354         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7355         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7356         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7357         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7358         {
7359                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7360                 /* .name = "Capture Source", */
7361                 .name = "Input Source",
7362                 .count = 1,
7363                 .info = alc883_mux_enum_info,
7364                 .get = alc883_mux_enum_get,
7365                 .put = alc883_mux_enum_put,
7366         },
7367         { } /* end */
7368 };
7369
7370 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7371         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7372         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7373         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7374         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7375         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7376         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7377         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7378         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7379         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7380         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7381         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7382         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7383         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7384         {
7385                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7386                 /* .name = "Capture Source", */
7387                 .name = "Input Source",
7388                 .count = 2,
7389                 .info = alc883_mux_enum_info,
7390                 .get = alc883_mux_enum_get,
7391                 .put = alc883_mux_enum_put,
7392         },
7393         { } /* end */
7394 };
7395
7396 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7397         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7398         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7399         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7400         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7401         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7402         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7403         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7404         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7405         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7406         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7407         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7408         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7409         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7410         {
7411                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7412                 /* .name = "Capture Source", */
7413                 .name = "Input Source",
7414                 .count = 2,
7415                 .info = alc883_mux_enum_info,
7416                 .get = alc883_mux_enum_get,
7417                 .put = alc883_mux_enum_put,
7418         },
7419         { } /* end */
7420 };
7421
7422 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7423         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7424         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7425         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7426         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7427         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7428         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7429         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7430         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7431         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7432         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7433         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7434         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7435         {
7436                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7437                 /* .name = "Capture Source", */
7438                 .name = "Input Source",
7439                 .count = 2,
7440                 .info = alc883_mux_enum_info,
7441                 .get = alc883_mux_enum_get,
7442                 .put = alc883_mux_enum_put,
7443         },
7444         { } /* end */
7445 };
7446
7447 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
7448         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7449         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7450         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
7451         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
7452         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
7453                                                 0x0d, 1, 0x0, HDA_OUTPUT),
7454         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
7455         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
7456         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
7457         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7458         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7459         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7460         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
7461         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7462         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7463         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7464         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7465         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7466         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7467         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7468         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7469         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7470         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7471         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7472         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7473         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7474         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7475         {
7476                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7477                 /* .name = "Capture Source", */
7478                 .name = "Input Source",
7479                 .count = 2,
7480                 .info = alc883_mux_enum_info,
7481                 .get = alc883_mux_enum_get,
7482                 .put = alc883_mux_enum_put,
7483         },
7484         { } /* end */
7485 };
7486
7487 static struct hda_bind_ctls alc883_bind_cap_vol = {
7488         .ops = &snd_hda_bind_vol,
7489         .values = {
7490                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7491                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7492                 0
7493         },
7494 };
7495
7496 static struct hda_bind_ctls alc883_bind_cap_switch = {
7497         .ops = &snd_hda_bind_sw,
7498         .values = {
7499                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7500                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7501                 0
7502         },
7503 };
7504
7505 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
7506         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7507         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7508         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7509         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7510         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7511         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7512         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7513         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7514         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
7515         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
7516         {
7517                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7518                 /* .name = "Capture Source", */
7519                 .name = "Input Source",
7520                 .count = 1,
7521                 .info = alc883_mux_enum_info,
7522                 .get = alc883_mux_enum_get,
7523                 .put = alc883_mux_enum_put,
7524         },
7525         { } /* end */
7526 };
7527
7528 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7529         {
7530                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7531                 .name = "Channel Mode",
7532                 .info = alc_ch_mode_info,
7533                 .get = alc_ch_mode_get,
7534                 .put = alc_ch_mode_put,
7535         },
7536         { } /* end */
7537 };
7538
7539 static struct hda_verb alc883_init_verbs[] = {
7540         /* ADC1: mute amp left and right */
7541         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7542         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7543         /* ADC2: mute amp left and right */
7544         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7545         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7546         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7547         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7548         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7549         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7550         /* Rear mixer */
7551         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7552         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7553         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7554         /* CLFE mixer */
7555         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7556         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7557         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7558         /* Side mixer */
7559         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7560         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7561         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7562
7563         /* mute analog input loopbacks */
7564         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7565         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7566         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7567         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7568         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7569
7570         /* Front Pin: output 0 (0x0c) */
7571         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7572         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7573         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7574         /* Rear Pin: output 1 (0x0d) */
7575         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7576         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7577         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7578         /* CLFE Pin: output 2 (0x0e) */
7579         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7580         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7581         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7582         /* Side Pin: output 3 (0x0f) */
7583         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7584         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7585         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7586         /* Mic (rear) pin: input vref at 80% */
7587         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7588         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7589         /* Front Mic pin: input vref at 80% */
7590         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7591         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7592         /* Line In pin: input */
7593         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7594         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7595         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7596         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7597         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7598         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7599         /* CD pin widget for input */
7600         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7601
7602         /* FIXME: use matrix-type input source selection */
7603         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7604         /* Input mixer2 */
7605         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7606         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7607         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7608         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7609         /* Input mixer3 */
7610         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7611         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7612         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7613         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7614         { }
7615 };
7616
7617 /* toggle speaker-output according to the hp-jack state */
7618 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7619 {
7620         unsigned int present;
7621
7622         present = snd_hda_codec_read(codec, 0x15, 0,
7623                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7624         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7625                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7626         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7627                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7628 }
7629
7630 /* auto-toggle front mic */
7631 /*
7632 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7633 {
7634         unsigned int present;
7635         unsigned char bits;
7636
7637         present = snd_hda_codec_read(codec, 0x18, 0,
7638                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7639         bits = present ? HDA_AMP_MUTE : 0;
7640         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7641 }
7642 */
7643
7644 static void alc883_mitac_automute(struct hda_codec *codec)
7645 {
7646         alc883_mitac_hp_automute(codec);
7647         /* alc883_mitac_mic_automute(codec); */
7648 }
7649
7650 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7651                                            unsigned int res)
7652 {
7653         switch (res >> 26) {
7654         case ALC880_HP_EVENT:
7655                 alc883_mitac_hp_automute(codec);
7656                 break;
7657         case ALC880_MIC_EVENT:
7658                 /* alc883_mitac_mic_automute(codec); */
7659                 break;
7660         }
7661 }
7662
7663 static struct hda_verb alc883_mitac_verbs[] = {
7664         /* HP */
7665         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7666         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7667         /* Subwoofer */
7668         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7669         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7670
7671         /* enable unsolicited event */
7672         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7673         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7674
7675         { } /* end */
7676 };
7677
7678 static struct hda_verb alc883_clevo_m720_verbs[] = {
7679         /* HP */
7680         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7681         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7682         /* Int speaker */
7683         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7684         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7685
7686         /* enable unsolicited event */
7687         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7688         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7689
7690         { } /* end */
7691 };
7692
7693 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7694         /* HP */
7695         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7696         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7697         /* Subwoofer */
7698         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7699         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7700
7701         /* enable unsolicited event */
7702         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7703
7704         { } /* end */
7705 };
7706
7707 static struct hda_verb alc883_tagra_verbs[] = {
7708         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7709         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7710
7711         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7712         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7713
7714         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7715         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7716         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7717
7718         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7719         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7720         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7721         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7722
7723         { } /* end */
7724 };
7725
7726 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7727         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7728         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7729         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7730         { } /* end */
7731 };
7732
7733 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7734         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7735         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7736         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7737         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7738         { } /* end */
7739 };
7740
7741 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7742         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7743         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7744         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7745         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7746         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7747         { } /* end */
7748 };
7749
7750 static struct hda_verb alc883_haier_w66_verbs[] = {
7751         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7752         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7753
7754         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7755
7756         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7757         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7758         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7759         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7760         { } /* end */
7761 };
7762
7763 static struct hda_verb alc888_lenovo_sky_verbs[] = {
7764         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7765         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7766         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7767         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7768         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7769         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7770         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7771         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7772         { } /* end */
7773 };
7774
7775 static struct hda_verb alc888_3st_hp_verbs[] = {
7776         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7777         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7778         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7779         { }
7780 };
7781
7782 static struct hda_verb alc888_6st_dell_verbs[] = {
7783         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7784         { }
7785 };
7786
7787 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7788         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7789         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7790         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7791         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7792         { }
7793 };
7794
7795 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7796         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7797         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7798         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7799         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7800         { }
7801 };
7802
7803 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7804         { 2, alc888_3st_hp_2ch_init },
7805         { 6, alc888_3st_hp_6ch_init },
7806 };
7807
7808 /* toggle front-jack and RCA according to the hp-jack state */
7809 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7810 {
7811         unsigned int present;
7812
7813         present = snd_hda_codec_read(codec, 0x1b, 0,
7814                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7815         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7816                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7817         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7818                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7819 }
7820
7821 /* toggle RCA according to the front-jack state */
7822 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7823 {
7824         unsigned int present;
7825
7826         present = snd_hda_codec_read(codec, 0x14, 0,
7827                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7828         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7829                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7830 }
7831
7832 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7833                                              unsigned int res)
7834 {
7835         if ((res >> 26) == ALC880_HP_EVENT)
7836                 alc888_lenovo_ms7195_front_automute(codec);
7837         if ((res >> 26) == ALC880_FRONT_EVENT)
7838                 alc888_lenovo_ms7195_rca_automute(codec);
7839 }
7840
7841 static struct hda_verb alc883_medion_md2_verbs[] = {
7842         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7843         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7844
7845         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7846
7847         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7848         { } /* end */
7849 };
7850
7851 /* toggle speaker-output according to the hp-jack state */
7852 static void alc883_medion_md2_automute(struct hda_codec *codec)
7853 {
7854         unsigned int present;
7855
7856         present = snd_hda_codec_read(codec, 0x14, 0,
7857                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7858         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7859                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7860 }
7861
7862 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
7863                                           unsigned int res)
7864 {
7865         if ((res >> 26) == ALC880_HP_EVENT)
7866                 alc883_medion_md2_automute(codec);
7867 }
7868
7869 /* toggle speaker-output according to the hp-jack state */
7870 static void alc883_tagra_automute(struct hda_codec *codec)
7871 {
7872         unsigned int present;
7873         unsigned char bits;
7874
7875         present = snd_hda_codec_read(codec, 0x14, 0,
7876                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7877         bits = present ? HDA_AMP_MUTE : 0;
7878         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
7879                                  HDA_AMP_MUTE, bits);
7880         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7881                                   present ? 1 : 3);
7882 }
7883
7884 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
7885 {
7886         if ((res >> 26) == ALC880_HP_EVENT)
7887                 alc883_tagra_automute(codec);
7888 }
7889
7890 /* toggle speaker-output according to the hp-jack state */
7891 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
7892 {
7893         unsigned int present;
7894         unsigned char bits;
7895
7896         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
7897                 & AC_PINSENSE_PRESENCE;
7898         bits = present ? HDA_AMP_MUTE : 0;
7899         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7900                                  HDA_AMP_MUTE, bits);
7901 }
7902
7903 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
7904 {
7905         unsigned int present;
7906
7907         present = snd_hda_codec_read(codec, 0x18, 0,
7908                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7909         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
7910                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7911 }
7912
7913 static void alc883_clevo_m720_automute(struct hda_codec *codec)
7914 {
7915         alc883_clevo_m720_hp_automute(codec);
7916         alc883_clevo_m720_mic_automute(codec);
7917 }
7918
7919 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
7920                                            unsigned int res)
7921 {
7922         switch (res >> 26) {
7923         case ALC880_HP_EVENT:
7924                 alc883_clevo_m720_hp_automute(codec);
7925                 break;
7926         case ALC880_MIC_EVENT:
7927                 alc883_clevo_m720_mic_automute(codec);
7928                 break;
7929         }
7930 }
7931
7932 /* toggle speaker-output according to the hp-jack state */
7933 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
7934 {
7935         unsigned int present;
7936         unsigned char bits;
7937
7938         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
7939                 & AC_PINSENSE_PRESENCE;
7940         bits = present ? HDA_AMP_MUTE : 0;
7941         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7942                                  HDA_AMP_MUTE, bits);
7943 }
7944
7945 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
7946                                                   unsigned int res)
7947 {
7948         if ((res >> 26) == ALC880_HP_EVENT)
7949                 alc883_2ch_fujitsu_pi2515_automute(codec);
7950 }
7951
7952 static void alc883_haier_w66_automute(struct hda_codec *codec)
7953 {
7954         unsigned int present;
7955         unsigned char bits;
7956
7957         present = snd_hda_codec_read(codec, 0x1b, 0,
7958                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7959         bits = present ? 0x80 : 0;
7960         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7961                                  0x80, bits);
7962 }
7963
7964 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
7965                                          unsigned int res)
7966 {
7967         if ((res >> 26) == ALC880_HP_EVENT)
7968                 alc883_haier_w66_automute(codec);
7969 }
7970
7971 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
7972 {
7973         unsigned int present;
7974         unsigned char bits;
7975
7976         present = snd_hda_codec_read(codec, 0x14, 0,
7977                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7978         bits = present ? HDA_AMP_MUTE : 0;
7979         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7980                                  HDA_AMP_MUTE, bits);
7981 }
7982
7983 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
7984 {
7985         unsigned int present;
7986         unsigned char bits;
7987
7988         present = snd_hda_codec_read(codec, 0x1b, 0,
7989                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7990         bits = present ? HDA_AMP_MUTE : 0;
7991         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7992                                  HDA_AMP_MUTE, bits);
7993         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7994                                  HDA_AMP_MUTE, bits);
7995 }
7996
7997 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
7998                                            unsigned int res)
7999 {
8000         if ((res >> 26) == ALC880_HP_EVENT)
8001                 alc883_lenovo_101e_all_automute(codec);
8002         if ((res >> 26) == ALC880_FRONT_EVENT)
8003                 alc883_lenovo_101e_ispeaker_automute(codec);
8004 }
8005
8006 /* toggle speaker-output according to the hp-jack state */
8007 static void alc883_acer_aspire_automute(struct hda_codec *codec)
8008 {
8009         unsigned int present;
8010
8011         present = snd_hda_codec_read(codec, 0x14, 0,
8012                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8013         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8014                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8015         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8016                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8017 }
8018
8019 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
8020                                            unsigned int res)
8021 {
8022         if ((res >> 26) == ALC880_HP_EVENT)
8023                 alc883_acer_aspire_automute(codec);
8024 }
8025
8026 static struct hda_verb alc883_acer_eapd_verbs[] = {
8027         /* HP Pin: output 0 (0x0c) */
8028         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8029         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8030         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8031         /* Front Pin: output 0 (0x0c) */
8032         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8033         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8034         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8035         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
8036         /* eanable EAPD on medion laptop */
8037         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8038         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8039         /* enable unsolicited event */
8040         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8041         { }
8042 };
8043
8044 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
8045 {
8046         unsigned int present;
8047
8048         present = snd_hda_codec_read(codec, 0x1b, 0,
8049                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8050         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8051                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8052         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8053                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8054         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8055                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8056         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8057                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8058 }
8059
8060 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
8061                                              unsigned int res)
8062 {
8063         switch (res >> 26) {
8064         case ALC880_HP_EVENT:
8065                 printk("hp_event\n");
8066                 alc888_6st_dell_front_automute(codec);
8067                 break;
8068         }
8069 }
8070
8071 static void alc888_lenovo_sky_front_automute(struct hda_codec *codec)
8072 {
8073         unsigned int mute;
8074         unsigned int present;
8075
8076         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8077         present = snd_hda_codec_read(codec, 0x1b, 0,
8078                                      AC_VERB_GET_PIN_SENSE, 0);
8079         present = (present & 0x80000000) != 0;
8080         if (present) {
8081                 /* mute internal speaker */
8082                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8083                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8084                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8085                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8086                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8087                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8088                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8089                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8090                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8091                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8092         } else {
8093                 /* unmute internal speaker if necessary */
8094                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8095                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8096                                          HDA_AMP_MUTE, mute);
8097                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8098                                          HDA_AMP_MUTE, mute);
8099                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8100                                          HDA_AMP_MUTE, mute);
8101                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8102                                          HDA_AMP_MUTE, mute);
8103                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8104                                          HDA_AMP_MUTE, mute);
8105         }
8106 }
8107
8108 static void alc883_lenovo_sky_unsol_event(struct hda_codec *codec,
8109                                              unsigned int res)
8110 {
8111         if ((res >> 26) == ALC880_HP_EVENT)
8112                 alc888_lenovo_sky_front_automute(codec);
8113 }
8114
8115 /*
8116  * generic initialization of ADC, input mixers and output mixers
8117  */
8118 static struct hda_verb alc883_auto_init_verbs[] = {
8119         /*
8120          * Unmute ADC0-2 and set the default input to mic-in
8121          */
8122         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8123         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8124         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8125         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8126
8127         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8128          * mixer widget
8129          * Note: PASD motherboards uses the Line In 2 as the input for
8130          * front panel mic (mic 2)
8131          */
8132         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8133         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8134         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8135         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8136         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8137         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8138
8139         /*
8140          * Set up output mixers (0x0c - 0x0f)
8141          */
8142         /* set vol=0 to output mixers */
8143         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8144         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8145         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8146         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8147         /* set up input amps for analog loopback */
8148         /* Amp Indices: DAC = 0, mixer = 1 */
8149         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8150         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8151         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8152         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8153         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8154         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8155         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8156         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8157         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8158         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8159
8160         /* FIXME: use matrix-type input source selection */
8161         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8162         /* Input mixer1 */
8163         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8164         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8165         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8166         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8167         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8168         /* Input mixer2 */
8169         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8170         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8171         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8172         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8173         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8174
8175         { }
8176 };
8177
8178 /* capture mixer elements */
8179 static struct snd_kcontrol_new alc883_capture_mixer[] = {
8180         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
8181         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
8182         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
8183         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
8184         {
8185                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8186                 /* The multiple "Capture Source" controls confuse alsamixer
8187                  * So call somewhat different..
8188                  */
8189                 /* .name = "Capture Source", */
8190                 .name = "Input Source",
8191                 .count = 2,
8192                 .info = alc882_mux_enum_info,
8193                 .get = alc882_mux_enum_get,
8194                 .put = alc882_mux_enum_put,
8195         },
8196         { } /* end */
8197 };
8198
8199 static struct hda_verb alc888_asus_m90v_verbs[] = {
8200         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8201         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8202         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8203         /* enable unsolicited event */
8204         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8205         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8206         { } /* end */
8207 };
8208
8209 static void alc883_nb_mic_automute(struct hda_codec *codec)
8210 {
8211         unsigned int present;
8212
8213         present = snd_hda_codec_read(codec, 0x18, 0,
8214                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8215         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8216                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
8217         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8218                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
8219 }
8220
8221 static void alc883_M90V_speaker_automute(struct hda_codec *codec)
8222 {
8223         unsigned int present;
8224         unsigned char bits;
8225
8226         present = snd_hda_codec_read(codec, 0x1b, 0,
8227                                      AC_VERB_GET_PIN_SENSE, 0)
8228                 & AC_PINSENSE_PRESENCE;
8229         bits = present ? 0 : PIN_OUT;
8230         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8231                             bits);
8232         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8233                             bits);
8234         snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8235                             bits);
8236 }
8237
8238 static void alc883_mode2_unsol_event(struct hda_codec *codec,
8239                                            unsigned int res)
8240 {
8241         switch (res >> 26) {
8242         case ALC880_HP_EVENT:
8243                 alc883_M90V_speaker_automute(codec);
8244                 break;
8245         case ALC880_MIC_EVENT:
8246                 alc883_nb_mic_automute(codec);
8247                 break;
8248         }
8249 }
8250
8251 static void alc883_mode2_inithook(struct hda_codec *codec)
8252 {
8253         alc883_M90V_speaker_automute(codec);
8254         alc883_nb_mic_automute(codec);
8255 }
8256
8257 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8258         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8259         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8260         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8261         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8262         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8263         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8264         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8265         /* enable unsolicited event */
8266         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8267         { } /* end */
8268 };
8269
8270 static void alc883_eee1601_speaker_automute(struct hda_codec *codec)
8271 {
8272         unsigned int present;
8273         unsigned char bits;
8274
8275         present = snd_hda_codec_read(codec, 0x14, 0,
8276                                      AC_VERB_GET_PIN_SENSE, 0)
8277                 & AC_PINSENSE_PRESENCE;
8278         bits = present ? 0 : PIN_OUT;
8279         snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8280                             bits);
8281 }
8282
8283 static void alc883_eee1601_unsol_event(struct hda_codec *codec,
8284                                            unsigned int res)
8285 {
8286         switch (res >> 26) {
8287         case ALC880_HP_EVENT:
8288                 alc883_eee1601_speaker_automute(codec);
8289                 break;
8290         }
8291 }
8292
8293 static void alc883_eee1601_inithook(struct hda_codec *codec)
8294 {
8295         alc883_eee1601_speaker_automute(codec);
8296 }
8297
8298 #ifdef CONFIG_SND_HDA_POWER_SAVE
8299 #define alc883_loopbacks        alc880_loopbacks
8300 #endif
8301
8302 /* pcm configuration: identiacal with ALC880 */
8303 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
8304 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
8305 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
8306 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
8307 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
8308
8309 /*
8310  * configuration and preset
8311  */
8312 static const char *alc883_models[ALC883_MODEL_LAST] = {
8313         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
8314         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8315         [ALC883_3ST_6ch]        = "3stack-6ch",
8316         [ALC883_6ST_DIG]        = "6stack-dig",
8317         [ALC883_TARGA_DIG]      = "targa-dig",
8318         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8319         [ALC883_ACER]           = "acer",
8320         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8321         [ALC883_MEDION]         = "medion",
8322         [ALC883_MEDION_MD2]     = "medion-md2",
8323         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8324         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8325         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8326         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8327         [ALC888_LENOVO_SKY] = "lenovo-sky",
8328         [ALC883_HAIER_W66]      = "haier-w66",
8329         [ALC888_3ST_HP]         = "3stack-hp",
8330         [ALC888_6ST_DELL]       = "6stack-dell",
8331         [ALC883_MITAC]          = "mitac",
8332         [ALC883_CLEVO_M720]     = "clevo-m720",
8333         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8334         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8335         [ALC883_AUTO]           = "auto",
8336 };
8337
8338 static struct snd_pci_quirk alc883_cfg_tbl[] = {
8339         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
8340         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8341         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8342         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8343         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8344         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
8345         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8346         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8347         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8348         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8349         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8350         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8351         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8352         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8353         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8354         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
8355         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8356         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8357         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
8358         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8359         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
8360         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8361         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8362         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8363         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8364         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8365         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8366         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8367         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8368         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8369         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8370         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8371         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8372         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8373         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8374         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8375         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8376         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8377         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8378         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8379         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8380         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8381         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8382         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8383         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8384         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8385         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
8386         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8387         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8388         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
8389         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8390         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8391         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8392         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8393         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
8394         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8395         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8396         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8397         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8398         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8399         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8400         {}
8401 };
8402
8403 static struct alc_config_preset alc883_presets[] = {
8404         [ALC883_3ST_2ch_DIG] = {
8405                 .mixers = { alc883_3ST_2ch_mixer },
8406                 .init_verbs = { alc883_init_verbs },
8407                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8408                 .dac_nids = alc883_dac_nids,
8409                 .dig_out_nid = ALC883_DIGOUT_NID,
8410                 .dig_in_nid = ALC883_DIGIN_NID,
8411                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8412                 .channel_mode = alc883_3ST_2ch_modes,
8413                 .input_mux = &alc883_capture_source,
8414         },
8415         [ALC883_3ST_6ch_DIG] = {
8416                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8417                 .init_verbs = { alc883_init_verbs },
8418                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8419                 .dac_nids = alc883_dac_nids,
8420                 .dig_out_nid = ALC883_DIGOUT_NID,
8421                 .dig_in_nid = ALC883_DIGIN_NID,
8422                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8423                 .channel_mode = alc883_3ST_6ch_modes,
8424                 .need_dac_fix = 1,
8425                 .input_mux = &alc883_capture_source,
8426         },
8427         [ALC883_3ST_6ch] = {
8428                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8429                 .init_verbs = { alc883_init_verbs },
8430                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8431                 .dac_nids = alc883_dac_nids,
8432                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8433                 .channel_mode = alc883_3ST_6ch_modes,
8434                 .need_dac_fix = 1,
8435                 .input_mux = &alc883_capture_source,
8436         },
8437         [ALC883_3ST_6ch_INTEL] = {
8438                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
8439                 .init_verbs = { alc883_init_verbs },
8440                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8441                 .dac_nids = alc883_dac_nids,
8442                 .dig_out_nid = ALC883_DIGOUT_NID,
8443                 .dig_in_nid = ALC883_DIGIN_NID,
8444                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
8445                 .channel_mode = alc883_3ST_6ch_intel_modes,
8446                 .need_dac_fix = 1,
8447                 .input_mux = &alc883_3stack_6ch_intel,
8448         },
8449         [ALC883_6ST_DIG] = {
8450                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8451                 .init_verbs = { alc883_init_verbs },
8452                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8453                 .dac_nids = alc883_dac_nids,
8454                 .dig_out_nid = ALC883_DIGOUT_NID,
8455                 .dig_in_nid = ALC883_DIGIN_NID,
8456                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8457                 .channel_mode = alc883_sixstack_modes,
8458                 .input_mux = &alc883_capture_source,
8459         },
8460         [ALC883_TARGA_DIG] = {
8461                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
8462                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8463                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8464                 .dac_nids = alc883_dac_nids,
8465                 .dig_out_nid = ALC883_DIGOUT_NID,
8466                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8467                 .channel_mode = alc883_3ST_6ch_modes,
8468                 .need_dac_fix = 1,
8469                 .input_mux = &alc883_capture_source,
8470                 .unsol_event = alc883_tagra_unsol_event,
8471                 .init_hook = alc883_tagra_automute,
8472         },
8473         [ALC883_TARGA_2ch_DIG] = {
8474                 .mixers = { alc883_tagra_2ch_mixer},
8475                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8476                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8477                 .dac_nids = alc883_dac_nids,
8478                 .dig_out_nid = ALC883_DIGOUT_NID,
8479                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8480                 .channel_mode = alc883_3ST_2ch_modes,
8481                 .input_mux = &alc883_capture_source,
8482                 .unsol_event = alc883_tagra_unsol_event,
8483                 .init_hook = alc883_tagra_automute,
8484         },
8485         [ALC883_ACER] = {
8486                 .mixers = { alc883_base_mixer },
8487                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
8488                  * and the headphone jack.  Turn this on and rely on the
8489                  * standard mute methods whenever the user wants to turn
8490                  * these outputs off.
8491                  */
8492                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
8493                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8494                 .dac_nids = alc883_dac_nids,
8495                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8496                 .channel_mode = alc883_3ST_2ch_modes,
8497                 .input_mux = &alc883_capture_source,
8498         },
8499         [ALC883_ACER_ASPIRE] = {
8500                 .mixers = { alc883_acer_aspire_mixer },
8501                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
8502                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8503                 .dac_nids = alc883_dac_nids,
8504                 .dig_out_nid = ALC883_DIGOUT_NID,
8505                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8506                 .channel_mode = alc883_3ST_2ch_modes,
8507                 .input_mux = &alc883_capture_source,
8508                 .unsol_event = alc883_acer_aspire_unsol_event,
8509                 .init_hook = alc883_acer_aspire_automute,
8510         },
8511         [ALC883_MEDION] = {
8512                 .mixers = { alc883_fivestack_mixer,
8513                             alc883_chmode_mixer },
8514                 .init_verbs = { alc883_init_verbs,
8515                                 alc883_medion_eapd_verbs },
8516                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8517                 .dac_nids = alc883_dac_nids,
8518                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8519                 .channel_mode = alc883_sixstack_modes,
8520                 .input_mux = &alc883_capture_source,
8521         },
8522         [ALC883_MEDION_MD2] = {
8523                 .mixers = { alc883_medion_md2_mixer},
8524                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
8525                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8526                 .dac_nids = alc883_dac_nids,
8527                 .dig_out_nid = ALC883_DIGOUT_NID,
8528                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8529                 .channel_mode = alc883_3ST_2ch_modes,
8530                 .input_mux = &alc883_capture_source,
8531                 .unsol_event = alc883_medion_md2_unsol_event,
8532                 .init_hook = alc883_medion_md2_automute,
8533         },
8534         [ALC883_LAPTOP_EAPD] = {
8535                 .mixers = { alc883_base_mixer },
8536                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
8537                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8538                 .dac_nids = alc883_dac_nids,
8539                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8540                 .channel_mode = alc883_3ST_2ch_modes,
8541                 .input_mux = &alc883_capture_source,
8542         },
8543         [ALC883_CLEVO_M720] = {
8544                 .mixers = { alc883_clevo_m720_mixer },
8545                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
8546                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8547                 .dac_nids = alc883_dac_nids,
8548                 .dig_out_nid = ALC883_DIGOUT_NID,
8549                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8550                 .channel_mode = alc883_3ST_2ch_modes,
8551                 .input_mux = &alc883_capture_source,
8552                 .unsol_event = alc883_clevo_m720_unsol_event,
8553                 .init_hook = alc883_clevo_m720_automute,
8554         },
8555         [ALC883_LENOVO_101E_2ch] = {
8556                 .mixers = { alc883_lenovo_101e_2ch_mixer},
8557                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
8558                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8559                 .dac_nids = alc883_dac_nids,
8560                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8561                 .channel_mode = alc883_3ST_2ch_modes,
8562                 .input_mux = &alc883_lenovo_101e_capture_source,
8563                 .unsol_event = alc883_lenovo_101e_unsol_event,
8564                 .init_hook = alc883_lenovo_101e_all_automute,
8565         },
8566         [ALC883_LENOVO_NB0763] = {
8567                 .mixers = { alc883_lenovo_nb0763_mixer },
8568                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
8569                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8570                 .dac_nids = alc883_dac_nids,
8571                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8572                 .channel_mode = alc883_3ST_2ch_modes,
8573                 .need_dac_fix = 1,
8574                 .input_mux = &alc883_lenovo_nb0763_capture_source,
8575                 .unsol_event = alc883_medion_md2_unsol_event,
8576                 .init_hook = alc883_medion_md2_automute,
8577         },
8578         [ALC888_LENOVO_MS7195_DIG] = {
8579                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8580                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
8581                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8582                 .dac_nids = alc883_dac_nids,
8583                 .dig_out_nid = ALC883_DIGOUT_NID,
8584                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8585                 .channel_mode = alc883_3ST_6ch_modes,
8586                 .need_dac_fix = 1,
8587                 .input_mux = &alc883_capture_source,
8588                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
8589                 .init_hook = alc888_lenovo_ms7195_front_automute,
8590         },
8591         [ALC883_HAIER_W66] = {
8592                 .mixers = { alc883_tagra_2ch_mixer},
8593                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
8594                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8595                 .dac_nids = alc883_dac_nids,
8596                 .dig_out_nid = ALC883_DIGOUT_NID,
8597                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8598                 .channel_mode = alc883_3ST_2ch_modes,
8599                 .input_mux = &alc883_capture_source,
8600                 .unsol_event = alc883_haier_w66_unsol_event,
8601                 .init_hook = alc883_haier_w66_automute,
8602         },
8603         [ALC888_3ST_HP] = {
8604                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8605                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
8606                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8607                 .dac_nids = alc883_dac_nids,
8608                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
8609                 .channel_mode = alc888_3st_hp_modes,
8610                 .need_dac_fix = 1,
8611                 .input_mux = &alc883_capture_source,
8612         },
8613         [ALC888_6ST_DELL] = {
8614                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8615                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
8616                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8617                 .dac_nids = alc883_dac_nids,
8618                 .dig_out_nid = ALC883_DIGOUT_NID,
8619                 .dig_in_nid = ALC883_DIGIN_NID,
8620                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8621                 .channel_mode = alc883_sixstack_modes,
8622                 .input_mux = &alc883_capture_source,
8623                 .unsol_event = alc888_6st_dell_unsol_event,
8624                 .init_hook = alc888_6st_dell_front_automute,
8625         },
8626         [ALC883_MITAC] = {
8627                 .mixers = { alc883_mitac_mixer },
8628                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
8629                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8630                 .dac_nids = alc883_dac_nids,
8631                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8632                 .channel_mode = alc883_3ST_2ch_modes,
8633                 .input_mux = &alc883_capture_source,
8634                 .unsol_event = alc883_mitac_unsol_event,
8635                 .init_hook = alc883_mitac_automute,
8636         },
8637         [ALC883_FUJITSU_PI2515] = {
8638                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
8639                 .init_verbs = { alc883_init_verbs,
8640                                 alc883_2ch_fujitsu_pi2515_verbs},
8641                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8642                 .dac_nids = alc883_dac_nids,
8643                 .dig_out_nid = ALC883_DIGOUT_NID,
8644                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8645                 .channel_mode = alc883_3ST_2ch_modes,
8646                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8647                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8648                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8649         },
8650         [ALC888_LENOVO_SKY] = {
8651                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
8652                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
8653                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8654                 .dac_nids = alc883_dac_nids,
8655                 .dig_out_nid = ALC883_DIGOUT_NID,
8656                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
8657                 .adc_nids = alc883_adc_nids,
8658                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8659                 .channel_mode = alc883_sixstack_modes,
8660                 .need_dac_fix = 1,
8661                 .input_mux = &alc883_lenovo_sky_capture_source,
8662                 .unsol_event = alc883_lenovo_sky_unsol_event,
8663                 .init_hook = alc888_lenovo_sky_front_automute,
8664         },
8665         [ALC888_ASUS_M90V] = {
8666                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8667                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
8668                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8669                 .dac_nids = alc883_dac_nids,
8670                 .dig_out_nid = ALC883_DIGOUT_NID,
8671                 .dig_in_nid = ALC883_DIGIN_NID,
8672                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8673                 .channel_mode = alc883_3ST_6ch_modes,
8674                 .need_dac_fix = 1,
8675                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8676                 .unsol_event = alc883_mode2_unsol_event,
8677                 .init_hook = alc883_mode2_inithook,
8678         },
8679         [ALC888_ASUS_EEE1601] = {
8680                 .mixers = { alc883_asus_eee1601_mixer },
8681                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
8682                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8683                 .dac_nids = alc883_dac_nids,
8684                 .dig_out_nid = ALC883_DIGOUT_NID,
8685                 .dig_in_nid = ALC883_DIGIN_NID,
8686                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8687                 .channel_mode = alc883_3ST_2ch_modes,
8688                 .need_dac_fix = 1,
8689                 .input_mux = &alc883_asus_eee1601_capture_source,
8690                 .unsol_event = alc883_eee1601_unsol_event,
8691                 .init_hook = alc883_eee1601_inithook,
8692         },
8693 };
8694
8695
8696 /*
8697  * BIOS auto configuration
8698  */
8699 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
8700                                               hda_nid_t nid, int pin_type,
8701                                               int dac_idx)
8702 {
8703         /* set as output */
8704         struct alc_spec *spec = codec->spec;
8705         int idx;
8706
8707         alc_set_pin_output(codec, nid, pin_type);
8708         if (spec->multiout.dac_nids[dac_idx] == 0x25)
8709                 idx = 4;
8710         else
8711                 idx = spec->multiout.dac_nids[dac_idx] - 2;
8712         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
8713
8714 }
8715
8716 static void alc883_auto_init_multi_out(struct hda_codec *codec)
8717 {
8718         struct alc_spec *spec = codec->spec;
8719         int i;
8720
8721         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
8722         for (i = 0; i <= HDA_SIDE; i++) {
8723                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
8724                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
8725                 if (nid)
8726                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
8727                                                           i);
8728         }
8729 }
8730
8731 static void alc883_auto_init_hp_out(struct hda_codec *codec)
8732 {
8733         struct alc_spec *spec = codec->spec;
8734         hda_nid_t pin;
8735
8736         pin = spec->autocfg.hp_pins[0];
8737         if (pin) /* connect to front */
8738                 /* use dac 0 */
8739                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8740         pin = spec->autocfg.speaker_pins[0];
8741         if (pin)
8742                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
8743 }
8744
8745 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
8746 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
8747
8748 static void alc883_auto_init_analog_input(struct hda_codec *codec)
8749 {
8750         struct alc_spec *spec = codec->spec;
8751         int i;
8752
8753         for (i = 0; i < AUTO_PIN_LAST; i++) {
8754                 hda_nid_t nid = spec->autocfg.input_pins[i];
8755                 if (alc883_is_input_pin(nid)) {
8756                         snd_hda_codec_write(codec, nid, 0,
8757                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
8758                                             (i <= AUTO_PIN_FRONT_MIC ?
8759                                              PIN_VREF80 : PIN_IN));
8760                         if (nid != ALC883_PIN_CD_NID)
8761                                 snd_hda_codec_write(codec, nid, 0,
8762                                                     AC_VERB_SET_AMP_GAIN_MUTE,
8763                                                     AMP_OUT_MUTE);
8764                 }
8765         }
8766 }
8767
8768 #define alc883_auto_init_input_src      alc882_auto_init_input_src
8769
8770 /* almost identical with ALC880 parser... */
8771 static int alc883_parse_auto_config(struct hda_codec *codec)
8772 {
8773         struct alc_spec *spec = codec->spec;
8774         int err = alc880_parse_auto_config(codec);
8775
8776         if (err < 0)
8777                 return err;
8778         else if (!err)
8779                 return 0; /* no config found */
8780
8781         err = alc_auto_add_mic_boost(codec);
8782         if (err < 0)
8783                 return err;
8784
8785         /* hack - override the init verbs */
8786         spec->init_verbs[0] = alc883_auto_init_verbs;
8787         spec->mixers[spec->num_mixers] = alc883_capture_mixer;
8788         spec->num_mixers++;
8789
8790         return 1; /* config found */
8791 }
8792
8793 /* additional initialization for auto-configuration model */
8794 static void alc883_auto_init(struct hda_codec *codec)
8795 {
8796         struct alc_spec *spec = codec->spec;
8797         alc883_auto_init_multi_out(codec);
8798         alc883_auto_init_hp_out(codec);
8799         alc883_auto_init_analog_input(codec);
8800         alc883_auto_init_input_src(codec);
8801         if (spec->unsol_event)
8802                 alc_inithook(codec);
8803 }
8804
8805 static int patch_alc883(struct hda_codec *codec)
8806 {
8807         struct alc_spec *spec;
8808         int err, board_config;
8809
8810         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8811         if (spec == NULL)
8812                 return -ENOMEM;
8813
8814         codec->spec = spec;
8815
8816         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
8817
8818         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
8819                                                   alc883_models,
8820                                                   alc883_cfg_tbl);
8821         if (board_config < 0) {
8822                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
8823                        "trying auto-probe from BIOS...\n");
8824                 board_config = ALC883_AUTO;
8825         }
8826
8827         if (board_config == ALC883_AUTO) {
8828                 /* automatic parse from the BIOS config */
8829                 err = alc883_parse_auto_config(codec);
8830                 if (err < 0) {
8831                         alc_free(codec);
8832                         return err;
8833                 } else if (!err) {
8834                         printk(KERN_INFO
8835                                "hda_codec: Cannot set up configuration "
8836                                "from BIOS.  Using base mode...\n");
8837                         board_config = ALC883_3ST_2ch_DIG;
8838                 }
8839         }
8840
8841         if (board_config != ALC883_AUTO)
8842                 setup_preset(spec, &alc883_presets[board_config]);
8843
8844         switch (codec->vendor_id) {
8845         case 0x10ec0888:
8846                 if (codec->revision_id == 0x100101) {
8847                         spec->stream_name_analog = "ALC1200 Analog";
8848                         spec->stream_name_digital = "ALC1200 Digital";
8849                 } else {
8850                         spec->stream_name_analog = "ALC888 Analog";
8851                         spec->stream_name_digital = "ALC888 Digital";
8852                 }
8853                 break;
8854         case 0x10ec0889:
8855                 spec->stream_name_analog = "ALC889 Analog";
8856                 spec->stream_name_digital = "ALC889 Digital";
8857                 break;
8858         default:
8859                 spec->stream_name_analog = "ALC883 Analog";
8860                 spec->stream_name_digital = "ALC883 Digital";
8861                 break;
8862         }
8863
8864         spec->stream_analog_playback = &alc883_pcm_analog_playback;
8865         spec->stream_analog_capture = &alc883_pcm_analog_capture;
8866         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
8867
8868         spec->stream_digital_playback = &alc883_pcm_digital_playback;
8869         spec->stream_digital_capture = &alc883_pcm_digital_capture;
8870
8871         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
8872         spec->adc_nids = alc883_adc_nids;
8873         spec->capsrc_nids = alc883_capsrc_nids;
8874
8875         spec->vmaster_nid = 0x0c;
8876
8877         codec->patch_ops = alc_patch_ops;
8878         if (board_config == ALC883_AUTO)
8879                 spec->init_hook = alc883_auto_init;
8880
8881 #ifdef CONFIG_SND_HDA_POWER_SAVE
8882         if (!spec->loopback.amplist)
8883                 spec->loopback.amplist = alc883_loopbacks;
8884 #endif
8885
8886         return 0;
8887 }
8888
8889 /*
8890  * ALC262 support
8891  */
8892
8893 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
8894 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
8895
8896 #define alc262_dac_nids         alc260_dac_nids
8897 #define alc262_adc_nids         alc882_adc_nids
8898 #define alc262_adc_nids_alt     alc882_adc_nids_alt
8899 #define alc262_capsrc_nids      alc882_capsrc_nids
8900 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
8901
8902 #define alc262_modes            alc260_modes
8903 #define alc262_capture_source   alc882_capture_source
8904
8905 static hda_nid_t alc262_dmic_adc_nids[1] = {
8906         /* ADC0 */
8907         0x09
8908 };
8909
8910 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
8911
8912 static struct snd_kcontrol_new alc262_base_mixer[] = {
8913         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8914         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8915         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8916         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8917         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8918         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8919         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8920         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8921         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8922         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8923         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8924         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8925         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8926            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8927         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
8928         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8929         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8930         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
8931         { } /* end */
8932 };
8933
8934 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
8935         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8936         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8937         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8938         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8939         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8940         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8941         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8942         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8943         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8944         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8945         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8946         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8947         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8948            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8949         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
8950         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8951         { } /* end */
8952 };
8953
8954 /* update HP, line and mono-out pins according to the master switch */
8955 static void alc262_hp_master_update(struct hda_codec *codec)
8956 {
8957         struct alc_spec *spec = codec->spec;
8958         int val = spec->master_sw;
8959
8960         /* HP & line-out */
8961         snd_hda_codec_write_cache(codec, 0x1b, 0,
8962                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8963                                   val ? PIN_HP : 0);
8964         snd_hda_codec_write_cache(codec, 0x15, 0,
8965                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8966                                   val ? PIN_HP : 0);
8967         /* mono (speaker) depending on the HP jack sense */
8968         val = val && !spec->jack_present;
8969         snd_hda_codec_write_cache(codec, 0x16, 0,
8970                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8971                                   val ? PIN_OUT : 0);
8972 }
8973
8974 static void alc262_hp_bpc_automute(struct hda_codec *codec)
8975 {
8976         struct alc_spec *spec = codec->spec;
8977         unsigned int presence;
8978         presence = snd_hda_codec_read(codec, 0x1b, 0,
8979                                       AC_VERB_GET_PIN_SENSE, 0);
8980         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8981         alc262_hp_master_update(codec);
8982 }
8983
8984 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
8985 {
8986         if ((res >> 26) != ALC880_HP_EVENT)
8987                 return;
8988         alc262_hp_bpc_automute(codec);
8989 }
8990
8991 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
8992 {
8993         struct alc_spec *spec = codec->spec;
8994         unsigned int presence;
8995         presence = snd_hda_codec_read(codec, 0x15, 0,
8996                                       AC_VERB_GET_PIN_SENSE, 0);
8997         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8998         alc262_hp_master_update(codec);
8999 }
9000
9001 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
9002                                            unsigned int res)
9003 {
9004         if ((res >> 26) != ALC880_HP_EVENT)
9005                 return;
9006         alc262_hp_wildwest_automute(codec);
9007 }
9008
9009 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
9010                                    struct snd_ctl_elem_value *ucontrol)
9011 {
9012         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9013         struct alc_spec *spec = codec->spec;
9014         *ucontrol->value.integer.value = spec->master_sw;
9015         return 0;
9016 }
9017
9018 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
9019                                    struct snd_ctl_elem_value *ucontrol)
9020 {
9021         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9022         struct alc_spec *spec = codec->spec;
9023         int val = !!*ucontrol->value.integer.value;
9024
9025         if (val == spec->master_sw)
9026                 return 0;
9027         spec->master_sw = val;
9028         alc262_hp_master_update(codec);
9029         return 1;
9030 }
9031
9032 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
9033         {
9034                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9035                 .name = "Master Playback Switch",
9036                 .info = snd_ctl_boolean_mono_info,
9037                 .get = alc262_hp_master_sw_get,
9038                 .put = alc262_hp_master_sw_put,
9039         },
9040         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9041         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9042         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9043         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9044                               HDA_OUTPUT),
9045         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9046                             HDA_OUTPUT),
9047         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9048         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9049         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9050         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9051         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9052         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9053         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9054         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9055         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9056         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9057         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9058         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9059         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
9060         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
9061         { } /* end */
9062 };
9063
9064 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
9065         {
9066                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9067                 .name = "Master Playback Switch",
9068                 .info = snd_ctl_boolean_mono_info,
9069                 .get = alc262_hp_master_sw_get,
9070                 .put = alc262_hp_master_sw_put,
9071         },
9072         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9073         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9074         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9075         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9076         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9077                               HDA_OUTPUT),
9078         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9079                             HDA_OUTPUT),
9080         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
9081         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
9082         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
9083         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9084         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9085         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9086         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9087         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9088         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9089         { } /* end */
9090 };
9091
9092 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
9093         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9094         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9095         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
9096         { } /* end */
9097 };
9098
9099 /* mute/unmute internal speaker according to the hp jack and mute state */
9100 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
9101 {
9102         struct alc_spec *spec = codec->spec;
9103
9104         if (force || !spec->sense_updated) {
9105                 unsigned int present;
9106                 present = snd_hda_codec_read(codec, 0x15, 0,
9107                                              AC_VERB_GET_PIN_SENSE, 0);
9108                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9109                 spec->sense_updated = 1;
9110         }
9111         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
9112                                  spec->jack_present ? HDA_AMP_MUTE : 0);
9113 }
9114
9115 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
9116                                         unsigned int res)
9117 {
9118         if ((res >> 26) != ALC880_HP_EVENT)
9119                 return;
9120         alc262_hp_t5735_automute(codec, 1);
9121 }
9122
9123 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
9124 {
9125         alc262_hp_t5735_automute(codec, 1);
9126 }
9127
9128 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
9129         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9130         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9131         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9132         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9133         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9134         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9135         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9136         { } /* end */
9137 };
9138
9139 static struct hda_verb alc262_hp_t5735_verbs[] = {
9140         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9141         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9142
9143         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9144         { }
9145 };
9146
9147 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
9148         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9149         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9150         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
9151         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
9152         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9153         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9154         { } /* end */
9155 };
9156
9157 static struct hda_verb alc262_hp_rp5700_verbs[] = {
9158         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9159         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9160         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9161         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9162         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9163         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9164         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9165         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9166         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9167         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9168         {}
9169 };
9170
9171 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
9172         .num_items = 1,
9173         .items = {
9174                 { "Line", 0x1 },
9175         },
9176 };
9177
9178 /* bind hp and internal speaker mute (with plug check) */
9179 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
9180                                      struct snd_ctl_elem_value *ucontrol)
9181 {
9182         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9183         long *valp = ucontrol->value.integer.value;
9184         int change;
9185
9186         /* change hp mute */
9187         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
9188                                           HDA_AMP_MUTE,
9189                                           valp[0] ? 0 : HDA_AMP_MUTE);
9190         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
9191                                            HDA_AMP_MUTE,
9192                                            valp[1] ? 0 : HDA_AMP_MUTE);
9193         if (change) {
9194                 /* change speaker according to HP jack state */
9195                 struct alc_spec *spec = codec->spec;
9196                 unsigned int mute;
9197                 if (spec->jack_present)
9198                         mute = HDA_AMP_MUTE;
9199                 else
9200                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
9201                                                       HDA_OUTPUT, 0);
9202                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9203                                          HDA_AMP_MUTE, mute);
9204         }
9205         return change;
9206 }
9207
9208 static struct snd_kcontrol_new alc262_sony_mixer[] = {
9209         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9210         {
9211                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9212                 .name = "Master Playback Switch",
9213                 .info = snd_hda_mixer_amp_switch_info,
9214                 .get = snd_hda_mixer_amp_switch_get,
9215                 .put = alc262_sony_master_sw_put,
9216                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9217         },
9218         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9219         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9220         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9221         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9222         { } /* end */
9223 };
9224
9225 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
9226         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9227         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9228         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9229         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9230         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9231         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9232         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9233         { } /* end */
9234 };
9235
9236 #define alc262_capture_mixer            alc882_capture_mixer
9237 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
9238
9239 /*
9240  * generic initialization of ADC, input mixers and output mixers
9241  */
9242 static struct hda_verb alc262_init_verbs[] = {
9243         /*
9244          * Unmute ADC0-2 and set the default input to mic-in
9245          */
9246         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9247         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9248         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9249         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9250         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9251         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9252
9253         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9254          * mixer widget
9255          * Note: PASD motherboards uses the Line In 2 as the input for
9256          * front panel mic (mic 2)
9257          */
9258         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9259         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9260         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9261         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9262         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9263         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9264
9265         /*
9266          * Set up output mixers (0x0c - 0x0e)
9267          */
9268         /* set vol=0 to output mixers */
9269         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9270         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9271         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9272         /* set up input amps for analog loopback */
9273         /* Amp Indices: DAC = 0, mixer = 1 */
9274         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9275         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9276         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9277         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9278         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9279         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9280
9281         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9282         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9283         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9284         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9285         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9286         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9287
9288         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9289         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9290         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9291         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9292         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9293
9294         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9295         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9296
9297         /* FIXME: use matrix-type input source selection */
9298         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9299         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9300         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9301         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9302         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9303         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9304         /* Input mixer2 */
9305         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9306         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9307         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9308         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9309         /* Input mixer3 */
9310         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9311         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9312         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9313         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9314
9315         { }
9316 };
9317
9318 static struct hda_verb alc262_eapd_verbs[] = {
9319         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9320         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9321         { }
9322 };
9323
9324 static struct hda_verb alc262_hippo_unsol_verbs[] = {
9325         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9326         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9327         {}
9328 };
9329
9330 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
9331         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9332         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9333         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9334
9335         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9336         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9337         {}
9338 };
9339
9340 static struct hda_verb alc262_sony_unsol_verbs[] = {
9341         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9342         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9343         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
9344
9345         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9346         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9347         {}
9348 };
9349
9350 static struct hda_input_mux alc262_dmic_capture_source = {
9351         .num_items = 2,
9352         .items = {
9353                 { "Int DMic", 0x9 },
9354                 { "Mic", 0x0 },
9355         },
9356 };
9357
9358 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
9359         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9360         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9361         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9362         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9363         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9364         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
9365         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
9366         {
9367                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9368                 /* The multiple "Capture Source" controls confuse alsamixer
9369                  * So call somewhat different..
9370                  */
9371                 /* .name = "Capture Source", */
9372                 .name = "Input Source",
9373                 .count = 1,
9374                 .info = alc_mux_enum_info,
9375                 .get = alc_mux_enum_get,
9376                 .put = alc_mux_enum_put,
9377         },
9378         { } /* end */
9379 };
9380
9381 static struct hda_verb alc262_toshiba_s06_verbs[] = {
9382         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9383         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9384         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9385         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9386         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
9387         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9388         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
9389         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9390         {}
9391 };
9392
9393 static void alc262_dmic_automute(struct hda_codec *codec)
9394 {
9395         unsigned int present;
9396
9397         present = snd_hda_codec_read(codec, 0x18, 0,
9398                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9399         snd_hda_codec_write(codec, 0x22, 0,
9400                                 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x09);
9401 }
9402
9403 /* toggle speaker-output according to the hp-jack state */
9404 static void alc262_toshiba_s06_speaker_automute(struct hda_codec *codec)
9405 {
9406         unsigned int present;
9407         unsigned char bits;
9408
9409         present = snd_hda_codec_read(codec, 0x15, 0,
9410                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9411         bits = present ? 0 : PIN_OUT;
9412         snd_hda_codec_write(codec, 0x14, 0,
9413                                         AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
9414 }
9415
9416
9417
9418 /* unsolicited event for HP jack sensing */
9419 static void alc262_toshiba_s06_unsol_event(struct hda_codec *codec,
9420                                        unsigned int res)
9421 {
9422         if ((res >> 26) == ALC880_HP_EVENT)
9423                 alc262_toshiba_s06_speaker_automute(codec);
9424         if ((res >> 26) == ALC880_MIC_EVENT)
9425                 alc262_dmic_automute(codec);
9426
9427 }
9428
9429 static void alc262_toshiba_s06_init_hook(struct hda_codec *codec)
9430 {
9431         alc262_toshiba_s06_speaker_automute(codec);
9432         alc262_dmic_automute(codec);
9433 }
9434
9435 /* mute/unmute internal speaker according to the hp jack and mute state */
9436 static void alc262_hippo_automute(struct hda_codec *codec)
9437 {
9438         struct alc_spec *spec = codec->spec;
9439         unsigned int mute;
9440         unsigned int present;
9441
9442         /* need to execute and sync at first */
9443         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9444         present = snd_hda_codec_read(codec, 0x15, 0,
9445                                      AC_VERB_GET_PIN_SENSE, 0);
9446         spec->jack_present = (present & 0x80000000) != 0;
9447         if (spec->jack_present) {
9448                 /* mute internal speaker */
9449                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9450                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9451         } else {
9452                 /* unmute internal speaker if necessary */
9453                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
9454                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9455                                          HDA_AMP_MUTE, mute);
9456         }
9457 }
9458
9459 /* unsolicited event for HP jack sensing */
9460 static void alc262_hippo_unsol_event(struct hda_codec *codec,
9461                                        unsigned int res)
9462 {
9463         if ((res >> 26) != ALC880_HP_EVENT)
9464                 return;
9465         alc262_hippo_automute(codec);
9466 }
9467
9468 static void alc262_hippo1_automute(struct hda_codec *codec)
9469 {
9470         unsigned int mute;
9471         unsigned int present;
9472
9473         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9474         present = snd_hda_codec_read(codec, 0x1b, 0,
9475                                      AC_VERB_GET_PIN_SENSE, 0);
9476         present = (present & 0x80000000) != 0;
9477         if (present) {
9478                 /* mute internal speaker */
9479                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9480                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9481         } else {
9482                 /* unmute internal speaker if necessary */
9483                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9484                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9485                                          HDA_AMP_MUTE, mute);
9486         }
9487 }
9488
9489 /* unsolicited event for HP jack sensing */
9490 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
9491                                        unsigned int res)
9492 {
9493         if ((res >> 26) != ALC880_HP_EVENT)
9494                 return;
9495         alc262_hippo1_automute(codec);
9496 }
9497
9498 /*
9499  * nec model
9500  *  0x15 = headphone
9501  *  0x16 = internal speaker
9502  *  0x18 = external mic
9503  */
9504
9505 static struct snd_kcontrol_new alc262_nec_mixer[] = {
9506         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9507         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
9508
9509         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9510         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9511         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9512
9513         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9514         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9515         { } /* end */
9516 };
9517
9518 static struct hda_verb alc262_nec_verbs[] = {
9519         /* Unmute Speaker */
9520         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9521
9522         /* Headphone */
9523         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9524         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9525
9526         /* External mic to headphone */
9527         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9528         /* External mic to speaker */
9529         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9530         {}
9531 };
9532
9533 /*
9534  * fujitsu model
9535  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
9536  *  0x1b = port replicator headphone out
9537  */
9538
9539 #define ALC_HP_EVENT    0x37
9540
9541 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
9542         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9543         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9544         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9545         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9546         {}
9547 };
9548
9549 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
9550         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9551         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9552         {}
9553 };
9554
9555 static struct hda_input_mux alc262_fujitsu_capture_source = {
9556         .num_items = 3,
9557         .items = {
9558                 { "Mic", 0x0 },
9559                 { "Int Mic", 0x1 },
9560                 { "CD", 0x4 },
9561         },
9562 };
9563
9564 static struct hda_input_mux alc262_HP_capture_source = {
9565         .num_items = 5,
9566         .items = {
9567                 { "Mic", 0x0 },
9568                 { "Front Mic", 0x1 },
9569                 { "Line", 0x2 },
9570                 { "CD", 0x4 },
9571                 { "AUX IN", 0x6 },
9572         },
9573 };
9574
9575 static struct hda_input_mux alc262_HP_D7000_capture_source = {
9576         .num_items = 4,
9577         .items = {
9578                 { "Mic", 0x0 },
9579                 { "Front Mic", 0x2 },
9580                 { "Line", 0x1 },
9581                 { "CD", 0x4 },
9582         },
9583 };
9584
9585 /* mute/unmute internal speaker according to the hp jacks and mute state */
9586 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
9587 {
9588         struct alc_spec *spec = codec->spec;
9589         unsigned int mute;
9590
9591         if (force || !spec->sense_updated) {
9592                 unsigned int present;
9593                 /* need to execute and sync at first */
9594                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
9595                 /* check laptop HP jack */
9596                 present = snd_hda_codec_read(codec, 0x14, 0,
9597                                              AC_VERB_GET_PIN_SENSE, 0);
9598                 /* need to execute and sync at first */
9599                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9600                 /* check docking HP jack */
9601                 present |= snd_hda_codec_read(codec, 0x1b, 0,
9602                                               AC_VERB_GET_PIN_SENSE, 0);
9603                 if (present & AC_PINSENSE_PRESENCE)
9604                         spec->jack_present = 1;
9605                 else
9606                         spec->jack_present = 0;
9607                 spec->sense_updated = 1;
9608         }
9609         /* unmute internal speaker only if both HPs are unplugged and
9610          * master switch is on
9611          */
9612         if (spec->jack_present)
9613                 mute = HDA_AMP_MUTE;
9614         else
9615                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9616         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9617                                  HDA_AMP_MUTE, mute);
9618 }
9619
9620 /* unsolicited event for HP jack sensing */
9621 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
9622                                        unsigned int res)
9623 {
9624         if ((res >> 26) != ALC_HP_EVENT)
9625                 return;
9626         alc262_fujitsu_automute(codec, 1);
9627 }
9628
9629 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
9630 {
9631         alc262_fujitsu_automute(codec, 1);
9632 }
9633
9634 /* bind volumes of both NID 0x0c and 0x0d */
9635 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
9636         .ops = &snd_hda_bind_vol,
9637         .values = {
9638                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
9639                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
9640                 0
9641         },
9642 };
9643
9644 /* mute/unmute internal speaker according to the hp jack and mute state */
9645 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
9646 {
9647         struct alc_spec *spec = codec->spec;
9648         unsigned int mute;
9649
9650         if (force || !spec->sense_updated) {
9651                 unsigned int present_int_hp;
9652                 /* need to execute and sync at first */
9653                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9654                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
9655                                         AC_VERB_GET_PIN_SENSE, 0);
9656                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
9657                 spec->sense_updated = 1;
9658         }
9659         if (spec->jack_present) {
9660                 /* mute internal speaker */
9661                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9662                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9663                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9664                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9665         } else {
9666                 /* unmute internal speaker if necessary */
9667                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9668                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9669                                          HDA_AMP_MUTE, mute);
9670                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9671                                          HDA_AMP_MUTE, mute);
9672         }
9673 }
9674
9675 /* unsolicited event for HP jack sensing */
9676 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
9677                                        unsigned int res)
9678 {
9679         if ((res >> 26) != ALC_HP_EVENT)
9680                 return;
9681         alc262_lenovo_3000_automute(codec, 1);
9682 }
9683
9684 /* bind hp and internal speaker mute (with plug check) */
9685 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
9686                                          struct snd_ctl_elem_value *ucontrol)
9687 {
9688         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9689         long *valp = ucontrol->value.integer.value;
9690         int change;
9691
9692         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9693                                                  HDA_AMP_MUTE,
9694                                                  valp ? 0 : HDA_AMP_MUTE);
9695         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9696                                                  HDA_AMP_MUTE,
9697                                                  valp ? 0 : HDA_AMP_MUTE);
9698
9699         if (change)
9700                 alc262_fujitsu_automute(codec, 0);
9701         return change;
9702 }
9703
9704 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
9705         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9706         {
9707                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9708                 .name = "Master Playback Switch",
9709                 .info = snd_hda_mixer_amp_switch_info,
9710                 .get = snd_hda_mixer_amp_switch_get,
9711                 .put = alc262_fujitsu_master_sw_put,
9712                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9713         },
9714         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9715         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9716         HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
9717         HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
9718         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9719         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9720         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9721         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9722         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9723         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9724         { } /* end */
9725 };
9726
9727 /* bind hp and internal speaker mute (with plug check) */
9728 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
9729                                          struct snd_ctl_elem_value *ucontrol)
9730 {
9731         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9732         long *valp = ucontrol->value.integer.value;
9733         int change;
9734
9735         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9736                                                  HDA_AMP_MUTE,
9737                                                  valp ? 0 : HDA_AMP_MUTE);
9738
9739         if (change)
9740                 alc262_lenovo_3000_automute(codec, 0);
9741         return change;
9742 }
9743
9744 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
9745         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9746         {
9747                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9748                 .name = "Master Playback Switch",
9749                 .info = snd_hda_mixer_amp_switch_info,
9750                 .get = snd_hda_mixer_amp_switch_get,
9751                 .put = alc262_lenovo_3000_master_sw_put,
9752                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
9753         },
9754         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9755         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9756         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9757         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9758         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9759         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9760         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9761         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9762         { } /* end */
9763 };
9764
9765 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
9766         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9767         {
9768                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9769                 .name = "Master Playback Switch",
9770                 .info = snd_hda_mixer_amp_switch_info,
9771                 .get = snd_hda_mixer_amp_switch_get,
9772                 .put = alc262_sony_master_sw_put,
9773                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9774         },
9775         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9776         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9777         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9778         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9779         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9780         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9781         { } /* end */
9782 };
9783
9784 /* additional init verbs for Benq laptops */
9785 static struct hda_verb alc262_EAPD_verbs[] = {
9786         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9787         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
9788         {}
9789 };
9790
9791 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
9792         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9793         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9794
9795         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9796         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
9797         {}
9798 };
9799
9800 /* Samsung Q1 Ultra Vista model setup */
9801 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
9802         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9803         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
9804         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9805         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9806         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
9807         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
9808         { } /* end */
9809 };
9810
9811 static struct hda_verb alc262_ultra_verbs[] = {
9812         /* output mixer */
9813         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9814         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9815         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9816         /* speaker */
9817         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9818         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9819         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9820         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9821         /* HP */
9822         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9823         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9824         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9825         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9826         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9827         /* internal mic */
9828         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9829         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9830         /* ADC, choose mic */
9831         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9832         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9833         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9834         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9835         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9836         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9837         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9838         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9839         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
9840         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
9841         {}
9842 };
9843
9844 /* mute/unmute internal speaker according to the hp jack and mute state */
9845 static void alc262_ultra_automute(struct hda_codec *codec)
9846 {
9847         struct alc_spec *spec = codec->spec;
9848         unsigned int mute;
9849
9850         mute = 0;
9851         /* auto-mute only when HP is used as HP */
9852         if (!spec->cur_mux[0]) {
9853                 unsigned int present;
9854                 /* need to execute and sync at first */
9855                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9856                 present = snd_hda_codec_read(codec, 0x15, 0,
9857                                              AC_VERB_GET_PIN_SENSE, 0);
9858                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9859                 if (spec->jack_present)
9860                         mute = HDA_AMP_MUTE;
9861         }
9862         /* mute/unmute internal speaker */
9863         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9864                                  HDA_AMP_MUTE, mute);
9865         /* mute/unmute HP */
9866         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9867                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
9868 }
9869
9870 /* unsolicited event for HP jack sensing */
9871 static void alc262_ultra_unsol_event(struct hda_codec *codec,
9872                                        unsigned int res)
9873 {
9874         if ((res >> 26) != ALC880_HP_EVENT)
9875                 return;
9876         alc262_ultra_automute(codec);
9877 }
9878
9879 static struct hda_input_mux alc262_ultra_capture_source = {
9880         .num_items = 2,
9881         .items = {
9882                 { "Mic", 0x1 },
9883                 { "Headphone", 0x7 },
9884         },
9885 };
9886
9887 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
9888                                      struct snd_ctl_elem_value *ucontrol)
9889 {
9890         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9891         struct alc_spec *spec = codec->spec;
9892         int ret;
9893
9894         ret = alc882_mux_enum_put(kcontrol, ucontrol);
9895         if (!ret)
9896                 return 0;
9897         /* reprogram the HP pin as mic or HP according to the input source */
9898         snd_hda_codec_write_cache(codec, 0x15, 0,
9899                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9900                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
9901         alc262_ultra_automute(codec); /* mute/unmute HP */
9902         return ret;
9903 }
9904
9905 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
9906         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
9907         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
9908         {
9909                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9910                 .name = "Capture Source",
9911                 .info = alc882_mux_enum_info,
9912                 .get = alc882_mux_enum_get,
9913                 .put = alc262_ultra_mux_enum_put,
9914         },
9915         { } /* end */
9916 };
9917
9918 /* add playback controls from the parsed DAC table */
9919 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
9920                                              const struct auto_pin_cfg *cfg)
9921 {
9922         hda_nid_t nid;
9923         int err;
9924
9925         spec->multiout.num_dacs = 1;    /* only use one dac */
9926         spec->multiout.dac_nids = spec->private_dac_nids;
9927         spec->multiout.dac_nids[0] = 2;
9928
9929         nid = cfg->line_out_pins[0];
9930         if (nid) {
9931                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9932                                   "Front Playback Volume",
9933                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
9934                 if (err < 0)
9935                         return err;
9936                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9937                                   "Front Playback Switch",
9938                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
9939                 if (err < 0)
9940                         return err;
9941         }
9942
9943         nid = cfg->speaker_pins[0];
9944         if (nid) {
9945                 if (nid == 0x16) {
9946                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9947                                           "Speaker Playback Volume",
9948                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9949                                                               HDA_OUTPUT));
9950                         if (err < 0)
9951                                 return err;
9952                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9953                                           "Speaker Playback Switch",
9954                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9955                                                               HDA_OUTPUT));
9956                         if (err < 0)
9957                                 return err;
9958                 } else {
9959                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9960                                           "Speaker Playback Switch",
9961                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9962                                                               HDA_OUTPUT));
9963                         if (err < 0)
9964                                 return err;
9965                 }
9966         }
9967         nid = cfg->hp_pins[0];
9968         if (nid) {
9969                 /* spec->multiout.hp_nid = 2; */
9970                 if (nid == 0x16) {
9971                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9972                                           "Headphone Playback Volume",
9973                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9974                                                               HDA_OUTPUT));
9975                         if (err < 0)
9976                                 return err;
9977                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9978                                           "Headphone Playback Switch",
9979                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9980                                                               HDA_OUTPUT));
9981                         if (err < 0)
9982                                 return err;
9983                 } else {
9984                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9985                                           "Headphone Playback Switch",
9986                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9987                                                               HDA_OUTPUT));
9988                         if (err < 0)
9989                                 return err;
9990                 }
9991         }
9992         return 0;
9993 }
9994
9995 /* identical with ALC880 */
9996 #define alc262_auto_create_analog_input_ctls \
9997         alc880_auto_create_analog_input_ctls
9998
9999 /*
10000  * generic initialization of ADC, input mixers and output mixers
10001  */
10002 static struct hda_verb alc262_volume_init_verbs[] = {
10003         /*
10004          * Unmute ADC0-2 and set the default input to mic-in
10005          */
10006         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10007         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10008         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10009         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10010         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10011         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10012
10013         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10014          * mixer widget
10015          * Note: PASD motherboards uses the Line In 2 as the input for
10016          * front panel mic (mic 2)
10017          */
10018         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10019         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10020         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10021         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10022         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10023         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10024
10025         /*
10026          * Set up output mixers (0x0c - 0x0f)
10027          */
10028         /* set vol=0 to output mixers */
10029         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10030         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10031         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10032
10033         /* set up input amps for analog loopback */
10034         /* Amp Indices: DAC = 0, mixer = 1 */
10035         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10036         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10037         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10038         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10039         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10040         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10041
10042         /* FIXME: use matrix-type input source selection */
10043         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10044         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10045         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10046         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10047         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10048         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10049         /* Input mixer2 */
10050         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10051         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10052         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10053         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10054         /* Input mixer3 */
10055         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10056         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10057         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10058         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10059
10060         { }
10061 };
10062
10063 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
10064         /*
10065          * Unmute ADC0-2 and set the default input to mic-in
10066          */
10067         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10068         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10069         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10070         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10071         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10072         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10073
10074         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10075          * mixer widget
10076          * Note: PASD motherboards uses the Line In 2 as the input for
10077          * front panel mic (mic 2)
10078          */
10079         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10080         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10081         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10082         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10083         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10084         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10085         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10086         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10087
10088         /*
10089          * Set up output mixers (0x0c - 0x0e)
10090          */
10091         /* set vol=0 to output mixers */
10092         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10093         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10094         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10095
10096         /* set up input amps for analog loopback */
10097         /* Amp Indices: DAC = 0, mixer = 1 */
10098         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10099         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10100         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10101         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10102         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10103         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10104
10105         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10106         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10107         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10108
10109         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10110         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10111
10112         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10113         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10114
10115         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10116         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10117         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10118         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10119         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10120
10121         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10122         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10123         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10124         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10125         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10126         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10127
10128
10129         /* FIXME: use matrix-type input source selection */
10130         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10131         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10132         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10133         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10134         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10135         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10136         /* Input mixer2 */
10137         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10138         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10139         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10140         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10141         /* Input mixer3 */
10142         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10143         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10144         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10145         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10146
10147         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10148
10149         { }
10150 };
10151
10152 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
10153         /*
10154          * Unmute ADC0-2 and set the default input to mic-in
10155          */
10156         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10157         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10158         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10159         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10160         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10161         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10162
10163         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10164          * mixer widget
10165          * Note: PASD motherboards uses the Line In 2 as the input for front
10166          * panel mic (mic 2)
10167          */
10168         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10169         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10170         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10171         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10172         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10173         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10174         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10175         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10176         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10177         /*
10178          * Set up output mixers (0x0c - 0x0e)
10179          */
10180         /* set vol=0 to output mixers */
10181         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10182         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10183         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10184
10185         /* set up input amps for analog loopback */
10186         /* Amp Indices: DAC = 0, mixer = 1 */
10187         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10188         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10189         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10190         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10191         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10192         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10193
10194
10195         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
10196         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
10197         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
10198         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
10199         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10200         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
10201         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
10202
10203         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10204         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10205
10206         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10207         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10208
10209         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
10210         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10211         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10212         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10213         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10214         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10215
10216         /* FIXME: use matrix-type input source selection */
10217         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10218         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10219         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
10220         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
10221         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
10222         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
10223         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
10224         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
10225         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
10226         /* Input mixer2 */
10227         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10228         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10229         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10230         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10231         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10232         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10233         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10234         /* Input mixer3 */
10235         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10236         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10237         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10238         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10239         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10240         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10241         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10242
10243         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10244
10245         { }
10246 };
10247
10248 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
10249
10250         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
10251         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10252         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
10253
10254         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
10255         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10256         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10257         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10258
10259         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
10260         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10261         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10262         {}
10263 };
10264
10265
10266 #ifdef CONFIG_SND_HDA_POWER_SAVE
10267 #define alc262_loopbacks        alc880_loopbacks
10268 #endif
10269
10270 /* pcm configuration: identiacal with ALC880 */
10271 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
10272 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
10273 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
10274 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
10275
10276 /*
10277  * BIOS auto configuration
10278  */
10279 static int alc262_parse_auto_config(struct hda_codec *codec)
10280 {
10281         struct alc_spec *spec = codec->spec;
10282         int err;
10283         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
10284
10285         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10286                                            alc262_ignore);
10287         if (err < 0)
10288                 return err;
10289         if (!spec->autocfg.line_outs)
10290                 return 0; /* can't find valid BIOS pin config */
10291         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
10292         if (err < 0)
10293                 return err;
10294         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
10295         if (err < 0)
10296                 return err;
10297
10298         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10299
10300         if (spec->autocfg.dig_out_pin)
10301                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
10302         if (spec->autocfg.dig_in_pin)
10303                 spec->dig_in_nid = ALC262_DIGIN_NID;
10304
10305         if (spec->kctl_alloc)
10306                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10307
10308         spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs;
10309         spec->num_mux_defs = 1;
10310         spec->input_mux = &spec->private_imux;
10311
10312         err = alc_auto_add_mic_boost(codec);
10313         if (err < 0)
10314                 return err;
10315
10316         return 1;
10317 }
10318
10319 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
10320 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
10321 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
10322 #define alc262_auto_init_input_src      alc882_auto_init_input_src
10323
10324
10325 /* init callback for auto-configuration model -- overriding the default init */
10326 static void alc262_auto_init(struct hda_codec *codec)
10327 {
10328         struct alc_spec *spec = codec->spec;
10329         alc262_auto_init_multi_out(codec);
10330         alc262_auto_init_hp_out(codec);
10331         alc262_auto_init_analog_input(codec);
10332         alc262_auto_init_input_src(codec);
10333         if (spec->unsol_event)
10334                 alc_inithook(codec);
10335 }
10336
10337 /*
10338  * configuration and preset
10339  */
10340 static const char *alc262_models[ALC262_MODEL_LAST] = {
10341         [ALC262_BASIC]          = "basic",
10342         [ALC262_HIPPO]          = "hippo",
10343         [ALC262_HIPPO_1]        = "hippo_1",
10344         [ALC262_FUJITSU]        = "fujitsu",
10345         [ALC262_HP_BPC]         = "hp-bpc",
10346         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
10347         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
10348         [ALC262_HP_RP5700]      = "hp-rp5700",
10349         [ALC262_BENQ_ED8]       = "benq",
10350         [ALC262_BENQ_T31]       = "benq-t31",
10351         [ALC262_SONY_ASSAMD]    = "sony-assamd",
10352         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
10353         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
10354         [ALC262_ULTRA]          = "ultra",
10355         [ALC262_LENOVO_3000]    = "lenovo-3000",
10356         [ALC262_NEC]            = "nec",
10357         [ALC262_AUTO]           = "auto",
10358 };
10359
10360 static struct snd_pci_quirk alc262_cfg_tbl[] = {
10361         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
10362         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
10363         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
10364         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
10365         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
10366         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
10367         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
10368         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
10369         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
10370         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
10371         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
10372         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
10373         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
10374         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
10375         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
10376         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
10377         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
10378         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
10379         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
10380         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
10381         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
10382         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
10383                       ALC262_HP_TC_T5735),
10384         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
10385         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10386         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
10387         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10388         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10389         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
10390         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
10391                       ALC262_TOSHIBA_RX1),
10392         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
10393         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
10394         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
10395         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
10396         SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
10397         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
10398         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
10399         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
10400         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
10401         {}
10402 };
10403
10404 static struct alc_config_preset alc262_presets[] = {
10405         [ALC262_BASIC] = {
10406                 .mixers = { alc262_base_mixer },
10407                 .init_verbs = { alc262_init_verbs },
10408                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10409                 .dac_nids = alc262_dac_nids,
10410                 .hp_nid = 0x03,
10411                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10412                 .channel_mode = alc262_modes,
10413                 .input_mux = &alc262_capture_source,
10414         },
10415         [ALC262_HIPPO] = {
10416                 .mixers = { alc262_base_mixer },
10417                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
10418                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10419                 .dac_nids = alc262_dac_nids,
10420                 .hp_nid = 0x03,
10421                 .dig_out_nid = ALC262_DIGOUT_NID,
10422                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10423                 .channel_mode = alc262_modes,
10424                 .input_mux = &alc262_capture_source,
10425                 .unsol_event = alc262_hippo_unsol_event,
10426                 .init_hook = alc262_hippo_automute,
10427         },
10428         [ALC262_HIPPO_1] = {
10429                 .mixers = { alc262_hippo1_mixer },
10430                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
10431                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10432                 .dac_nids = alc262_dac_nids,
10433                 .hp_nid = 0x02,
10434                 .dig_out_nid = ALC262_DIGOUT_NID,
10435                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10436                 .channel_mode = alc262_modes,
10437                 .input_mux = &alc262_capture_source,
10438                 .unsol_event = alc262_hippo1_unsol_event,
10439                 .init_hook = alc262_hippo1_automute,
10440         },
10441         [ALC262_FUJITSU] = {
10442                 .mixers = { alc262_fujitsu_mixer },
10443                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10444                                 alc262_fujitsu_unsol_verbs },
10445                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10446                 .dac_nids = alc262_dac_nids,
10447                 .hp_nid = 0x03,
10448                 .dig_out_nid = ALC262_DIGOUT_NID,
10449                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10450                 .channel_mode = alc262_modes,
10451                 .input_mux = &alc262_fujitsu_capture_source,
10452                 .unsol_event = alc262_fujitsu_unsol_event,
10453                 .init_hook = alc262_fujitsu_init_hook,
10454         },
10455         [ALC262_HP_BPC] = {
10456                 .mixers = { alc262_HP_BPC_mixer },
10457                 .init_verbs = { alc262_HP_BPC_init_verbs },
10458                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10459                 .dac_nids = alc262_dac_nids,
10460                 .hp_nid = 0x03,
10461                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10462                 .channel_mode = alc262_modes,
10463                 .input_mux = &alc262_HP_capture_source,
10464                 .unsol_event = alc262_hp_bpc_unsol_event,
10465                 .init_hook = alc262_hp_bpc_automute,
10466         },
10467         [ALC262_HP_BPC_D7000_WF] = {
10468                 .mixers = { alc262_HP_BPC_WildWest_mixer },
10469                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10470                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10471                 .dac_nids = alc262_dac_nids,
10472                 .hp_nid = 0x03,
10473                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10474                 .channel_mode = alc262_modes,
10475                 .input_mux = &alc262_HP_D7000_capture_source,
10476                 .unsol_event = alc262_hp_wildwest_unsol_event,
10477                 .init_hook = alc262_hp_wildwest_automute,
10478         },
10479         [ALC262_HP_BPC_D7000_WL] = {
10480                 .mixers = { alc262_HP_BPC_WildWest_mixer,
10481                             alc262_HP_BPC_WildWest_option_mixer },
10482                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10483                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10484                 .dac_nids = alc262_dac_nids,
10485                 .hp_nid = 0x03,
10486                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10487                 .channel_mode = alc262_modes,
10488                 .input_mux = &alc262_HP_D7000_capture_source,
10489                 .unsol_event = alc262_hp_wildwest_unsol_event,
10490                 .init_hook = alc262_hp_wildwest_automute,
10491         },
10492         [ALC262_HP_TC_T5735] = {
10493                 .mixers = { alc262_hp_t5735_mixer },
10494                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
10495                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10496                 .dac_nids = alc262_dac_nids,
10497                 .hp_nid = 0x03,
10498                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10499                 .channel_mode = alc262_modes,
10500                 .input_mux = &alc262_capture_source,
10501                 .unsol_event = alc262_hp_t5735_unsol_event,
10502                 .init_hook = alc262_hp_t5735_init_hook,
10503         },
10504         [ALC262_HP_RP5700] = {
10505                 .mixers = { alc262_hp_rp5700_mixer },
10506                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
10507                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10508                 .dac_nids = alc262_dac_nids,
10509                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10510                 .channel_mode = alc262_modes,
10511                 .input_mux = &alc262_hp_rp5700_capture_source,
10512         },
10513         [ALC262_BENQ_ED8] = {
10514                 .mixers = { alc262_base_mixer },
10515                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
10516                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10517                 .dac_nids = alc262_dac_nids,
10518                 .hp_nid = 0x03,
10519                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10520                 .channel_mode = alc262_modes,
10521                 .input_mux = &alc262_capture_source,
10522         },
10523         [ALC262_SONY_ASSAMD] = {
10524                 .mixers = { alc262_sony_mixer },
10525                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
10526                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10527                 .dac_nids = alc262_dac_nids,
10528                 .hp_nid = 0x02,
10529                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10530                 .channel_mode = alc262_modes,
10531                 .input_mux = &alc262_capture_source,
10532                 .unsol_event = alc262_hippo_unsol_event,
10533                 .init_hook = alc262_hippo_automute,
10534         },
10535         [ALC262_BENQ_T31] = {
10536                 .mixers = { alc262_benq_t31_mixer },
10537                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
10538                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10539                 .dac_nids = alc262_dac_nids,
10540                 .hp_nid = 0x03,
10541                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10542                 .channel_mode = alc262_modes,
10543                 .input_mux = &alc262_capture_source,
10544                 .unsol_event = alc262_hippo_unsol_event,
10545                 .init_hook = alc262_hippo_automute,
10546         },
10547         [ALC262_ULTRA] = {
10548                 .mixers = { alc262_ultra_mixer, alc262_ultra_capture_mixer },
10549                 .init_verbs = { alc262_ultra_verbs },
10550                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10551                 .dac_nids = alc262_dac_nids,
10552                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10553                 .channel_mode = alc262_modes,
10554                 .input_mux = &alc262_ultra_capture_source,
10555                 .adc_nids = alc262_adc_nids, /* ADC0 */
10556                 .capsrc_nids = alc262_capsrc_nids,
10557                 .num_adc_nids = 1, /* single ADC */
10558                 .unsol_event = alc262_ultra_unsol_event,
10559                 .init_hook = alc262_ultra_automute,
10560         },
10561         [ALC262_LENOVO_3000] = {
10562                 .mixers = { alc262_lenovo_3000_mixer },
10563                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10564                                 alc262_lenovo_3000_unsol_verbs },
10565                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10566                 .dac_nids = alc262_dac_nids,
10567                 .hp_nid = 0x03,
10568                 .dig_out_nid = ALC262_DIGOUT_NID,
10569                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10570                 .channel_mode = alc262_modes,
10571                 .input_mux = &alc262_fujitsu_capture_source,
10572                 .unsol_event = alc262_lenovo_3000_unsol_event,
10573         },
10574         [ALC262_NEC] = {
10575                 .mixers = { alc262_nec_mixer },
10576                 .init_verbs = { alc262_nec_verbs },
10577                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10578                 .dac_nids = alc262_dac_nids,
10579                 .hp_nid = 0x03,
10580                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10581                 .channel_mode = alc262_modes,
10582                 .input_mux = &alc262_capture_source,
10583         },
10584         [ALC262_TOSHIBA_S06] = {
10585                 .mixers = { alc262_toshiba_s06_mixer },
10586                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
10587                                                         alc262_eapd_verbs },
10588                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10589                 .capsrc_nids = alc262_dmic_capsrc_nids,
10590                 .dac_nids = alc262_dac_nids,
10591                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
10592                 .dig_out_nid = ALC262_DIGOUT_NID,
10593                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10594                 .channel_mode = alc262_modes,
10595                 .input_mux = &alc262_dmic_capture_source,
10596                 .unsol_event = alc262_toshiba_s06_unsol_event,
10597                 .init_hook = alc262_toshiba_s06_init_hook,
10598         },
10599         [ALC262_TOSHIBA_RX1] = {
10600                 .mixers = { alc262_toshiba_rx1_mixer },
10601                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
10602                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10603                 .dac_nids = alc262_dac_nids,
10604                 .hp_nid = 0x03,
10605                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10606                 .channel_mode = alc262_modes,
10607                 .input_mux = &alc262_capture_source,
10608                 .unsol_event = alc262_hippo_unsol_event,
10609                 .init_hook = alc262_hippo_automute,
10610         },
10611 };
10612
10613 static int patch_alc262(struct hda_codec *codec)
10614 {
10615         struct alc_spec *spec;
10616         int board_config;
10617         int err;
10618
10619         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10620         if (spec == NULL)
10621                 return -ENOMEM;
10622
10623         codec->spec = spec;
10624 #if 0
10625         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
10626          * under-run
10627          */
10628         {
10629         int tmp;
10630         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10631         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
10632         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10633         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
10634         }
10635 #endif
10636
10637         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
10638
10639         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
10640                                                   alc262_models,
10641                                                   alc262_cfg_tbl);
10642
10643         if (board_config < 0) {
10644                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
10645                        "trying auto-probe from BIOS...\n");
10646                 board_config = ALC262_AUTO;
10647         }
10648
10649         if (board_config == ALC262_AUTO) {
10650                 /* automatic parse from the BIOS config */
10651                 err = alc262_parse_auto_config(codec);
10652                 if (err < 0) {
10653                         alc_free(codec);
10654                         return err;
10655                 } else if (!err) {
10656                         printk(KERN_INFO
10657                                "hda_codec: Cannot set up configuration "
10658                                "from BIOS.  Using base mode...\n");
10659                         board_config = ALC262_BASIC;
10660                 }
10661         }
10662
10663         if (board_config != ALC262_AUTO)
10664                 setup_preset(spec, &alc262_presets[board_config]);
10665
10666         spec->stream_name_analog = "ALC262 Analog";
10667         spec->stream_analog_playback = &alc262_pcm_analog_playback;
10668         spec->stream_analog_capture = &alc262_pcm_analog_capture;
10669
10670         spec->stream_name_digital = "ALC262 Digital";
10671         spec->stream_digital_playback = &alc262_pcm_digital_playback;
10672         spec->stream_digital_capture = &alc262_pcm_digital_capture;
10673
10674         if (!spec->adc_nids && spec->input_mux) {
10675                 /* check whether NID 0x07 is valid */
10676                 unsigned int wcap = get_wcaps(codec, 0x07);
10677
10678                 /* get type */
10679                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10680                 if (wcap != AC_WID_AUD_IN) {
10681                         spec->adc_nids = alc262_adc_nids_alt;
10682                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
10683                         spec->capsrc_nids = alc262_capsrc_nids_alt;
10684                         spec->mixers[spec->num_mixers] =
10685                                 alc262_capture_alt_mixer;
10686                         spec->num_mixers++;
10687                 } else {
10688                         spec->adc_nids = alc262_adc_nids;
10689                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
10690                         spec->capsrc_nids = alc262_capsrc_nids;
10691                         spec->mixers[spec->num_mixers] = alc262_capture_mixer;
10692                         spec->num_mixers++;
10693                 }
10694         }
10695
10696         spec->vmaster_nid = 0x0c;
10697
10698         codec->patch_ops = alc_patch_ops;
10699         if (board_config == ALC262_AUTO)
10700                 spec->init_hook = alc262_auto_init;
10701 #ifdef CONFIG_SND_HDA_POWER_SAVE
10702         if (!spec->loopback.amplist)
10703                 spec->loopback.amplist = alc262_loopbacks;
10704 #endif
10705
10706         return 0;
10707 }
10708
10709 /*
10710  *  ALC268 channel source setting (2 channel)
10711  */
10712 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
10713 #define alc268_modes            alc260_modes
10714
10715 static hda_nid_t alc268_dac_nids[2] = {
10716         /* front, hp */
10717         0x02, 0x03
10718 };
10719
10720 static hda_nid_t alc268_adc_nids[2] = {
10721         /* ADC0-1 */
10722         0x08, 0x07
10723 };
10724
10725 static hda_nid_t alc268_adc_nids_alt[1] = {
10726         /* ADC0 */
10727         0x08
10728 };
10729
10730 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
10731
10732 static struct snd_kcontrol_new alc268_base_mixer[] = {
10733         /* output mixer control */
10734         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10735         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10736         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10737         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10738         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10739         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10740         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10741         { }
10742 };
10743
10744 /* bind Beep switches of both NID 0x0f and 0x10 */
10745 static struct hda_bind_ctls alc268_bind_beep_sw = {
10746         .ops = &snd_hda_bind_sw,
10747         .values = {
10748                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
10749                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
10750                 0
10751         },
10752 };
10753
10754 static struct snd_kcontrol_new alc268_beep_mixer[] = {
10755         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
10756         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
10757         { }
10758 };
10759
10760 static struct hda_verb alc268_eapd_verbs[] = {
10761         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10762         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10763         { }
10764 };
10765
10766 /* Toshiba specific */
10767 #define alc268_toshiba_automute alc262_hippo_automute
10768
10769 static struct hda_verb alc268_toshiba_verbs[] = {
10770         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10771         { } /* end */
10772 };
10773
10774 static struct hda_input_mux alc268_acer_lc_capture_source = {
10775         .num_items = 2,
10776         .items = {
10777                 { "i-Mic", 0x6 },
10778                 { "E-Mic", 0x0 },
10779         },
10780 };
10781
10782 /* Acer specific */
10783 /* bind volumes of both NID 0x02 and 0x03 */
10784 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
10785         .ops = &snd_hda_bind_vol,
10786         .values = {
10787                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
10788                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
10789                 0
10790         },
10791 };
10792
10793 /* mute/unmute internal speaker according to the hp jack and mute state */
10794 static void alc268_acer_automute(struct hda_codec *codec, int force)
10795 {
10796         struct alc_spec *spec = codec->spec;
10797         unsigned int mute;
10798
10799         if (force || !spec->sense_updated) {
10800                 unsigned int present;
10801                 present = snd_hda_codec_read(codec, 0x14, 0,
10802                                          AC_VERB_GET_PIN_SENSE, 0);
10803                 spec->jack_present = (present & 0x80000000) != 0;
10804                 spec->sense_updated = 1;
10805         }
10806         if (spec->jack_present)
10807                 mute = HDA_AMP_MUTE; /* mute internal speaker */
10808         else /* unmute internal speaker if necessary */
10809                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10810         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10811                                  HDA_AMP_MUTE, mute);
10812 }
10813
10814
10815 /* bind hp and internal speaker mute (with plug check) */
10816 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
10817                                      struct snd_ctl_elem_value *ucontrol)
10818 {
10819         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10820         long *valp = ucontrol->value.integer.value;
10821         int change;
10822
10823         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
10824                                           HDA_AMP_MUTE,
10825                                           valp[0] ? 0 : HDA_AMP_MUTE);
10826         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
10827                                            HDA_AMP_MUTE,
10828                                            valp[1] ? 0 : HDA_AMP_MUTE);
10829         if (change)
10830                 alc268_acer_automute(codec, 0);
10831         return change;
10832 }
10833
10834 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
10835         /* output mixer control */
10836         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
10837         {
10838                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10839                 .name = "Master Playback Switch",
10840                 .info = snd_hda_mixer_amp_switch_info,
10841                 .get = snd_hda_mixer_amp_switch_get,
10842                 .put = alc268_acer_master_sw_put,
10843                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10844         },
10845         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
10846         { }
10847 };
10848
10849 static struct snd_kcontrol_new alc268_acer_mixer[] = {
10850         /* output mixer control */
10851         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
10852         {
10853                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10854                 .name = "Master Playback Switch",
10855                 .info = snd_hda_mixer_amp_switch_info,
10856                 .get = snd_hda_mixer_amp_switch_get,
10857                 .put = alc268_acer_master_sw_put,
10858                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10859         },
10860         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10861         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
10862         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10863         { }
10864 };
10865
10866 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
10867         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10868         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10869         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10870         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
10871         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
10872         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
10873         { }
10874 };
10875
10876 static struct hda_verb alc268_acer_verbs[] = {
10877         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
10878         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10879         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10880         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10881         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10882         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10883         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10884         { }
10885 };
10886
10887 /* unsolicited event for HP jack sensing */
10888 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
10889                                        unsigned int res)
10890 {
10891         if ((res >> 26) != ALC880_HP_EVENT)
10892                 return;
10893         alc268_toshiba_automute(codec);
10894 }
10895
10896 static void alc268_acer_unsol_event(struct hda_codec *codec,
10897                                        unsigned int res)
10898 {
10899         if ((res >> 26) != ALC880_HP_EVENT)
10900                 return;
10901         alc268_acer_automute(codec, 1);
10902 }
10903
10904 static void alc268_acer_init_hook(struct hda_codec *codec)
10905 {
10906         alc268_acer_automute(codec, 1);
10907 }
10908
10909 /* toggle speaker-output according to the hp-jack state */
10910 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
10911 {
10912         unsigned int present;
10913         unsigned char bits;
10914
10915         present = snd_hda_codec_read(codec, 0x15, 0,
10916                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10917         bits = present ? AMP_IN_MUTE(0) : 0;
10918         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
10919                                 AMP_IN_MUTE(0), bits);
10920         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
10921                                 AMP_IN_MUTE(0), bits);
10922 }
10923
10924
10925 static void alc268_acer_mic_automute(struct hda_codec *codec)
10926 {
10927         unsigned int present;
10928
10929         present = snd_hda_codec_read(codec, 0x18, 0,
10930                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10931         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
10932                             present ? 0x0 : 0x6);
10933 }
10934
10935 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
10936                                     unsigned int res)
10937 {
10938         if ((res >> 26) == ALC880_HP_EVENT)
10939                 alc268_aspire_one_speaker_automute(codec);
10940         if ((res >> 26) == ALC880_MIC_EVENT)
10941                 alc268_acer_mic_automute(codec);
10942 }
10943
10944 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
10945 {
10946         alc268_aspire_one_speaker_automute(codec);
10947         alc268_acer_mic_automute(codec);
10948 }
10949
10950 static struct snd_kcontrol_new alc268_dell_mixer[] = {
10951         /* output mixer control */
10952         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10953         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10954         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10955         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10956         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10957         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
10958         { }
10959 };
10960
10961 static struct hda_verb alc268_dell_verbs[] = {
10962         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10963         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10964         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10965         { }
10966 };
10967
10968 /* mute/unmute internal speaker according to the hp jack and mute state */
10969 static void alc268_dell_automute(struct hda_codec *codec)
10970 {
10971         unsigned int present;
10972         unsigned int mute;
10973
10974         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
10975         if (present & 0x80000000)
10976                 mute = HDA_AMP_MUTE;
10977         else
10978                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
10979         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10980                                  HDA_AMP_MUTE, mute);
10981 }
10982
10983 static void alc268_dell_unsol_event(struct hda_codec *codec,
10984                                     unsigned int res)
10985 {
10986         if ((res >> 26) != ALC880_HP_EVENT)
10987                 return;
10988         alc268_dell_automute(codec);
10989 }
10990
10991 #define alc268_dell_init_hook   alc268_dell_automute
10992
10993 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
10994         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10995         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10996         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10997         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10998         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10999         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
11000         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
11001         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
11002         { }
11003 };
11004
11005 static struct hda_verb alc267_quanta_il1_verbs[] = {
11006         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11007         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
11008         { }
11009 };
11010
11011 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
11012 {
11013         unsigned int present;
11014
11015         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
11016                 & AC_PINSENSE_PRESENCE;
11017         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
11018                             present ? 0 : PIN_OUT);
11019 }
11020
11021 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
11022 {
11023         unsigned int present;
11024
11025         present = snd_hda_codec_read(codec, 0x18, 0,
11026                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11027         snd_hda_codec_write(codec, 0x23, 0,
11028                             AC_VERB_SET_CONNECT_SEL,
11029                             present ? 0x00 : 0x01);
11030 }
11031
11032 static void alc267_quanta_il1_automute(struct hda_codec *codec)
11033 {
11034         alc267_quanta_il1_hp_automute(codec);
11035         alc267_quanta_il1_mic_automute(codec);
11036 }
11037
11038 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
11039                                            unsigned int res)
11040 {
11041         switch (res >> 26) {
11042         case ALC880_HP_EVENT:
11043                 alc267_quanta_il1_hp_automute(codec);
11044                 break;
11045         case ALC880_MIC_EVENT:
11046                 alc267_quanta_il1_mic_automute(codec);
11047                 break;
11048         }
11049 }
11050
11051 /*
11052  * generic initialization of ADC, input mixers and output mixers
11053  */
11054 static struct hda_verb alc268_base_init_verbs[] = {
11055         /* Unmute DAC0-1 and set vol = 0 */
11056         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11057         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11058         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11059         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11060         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11061         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11062
11063         /*
11064          * Set up output mixers (0x0c - 0x0e)
11065          */
11066         /* set vol=0 to output mixers */
11067         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11068         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11069         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11070         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
11071
11072         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11073         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11074
11075         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11076         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
11077         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11078         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11079         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11080         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11081         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11082         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11083
11084         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11085         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11086         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11087         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11088         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11089         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11090         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11091
11092         /* set PCBEEP vol = 0, mute connections */
11093         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11094         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11095         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11096
11097         /* Unmute Selector 23h,24h and set the default input to mic-in */
11098
11099         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
11100         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11101         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
11102         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11103
11104         { }
11105 };
11106
11107 /*
11108  * generic initialization of ADC, input mixers and output mixers
11109  */
11110 static struct hda_verb alc268_volume_init_verbs[] = {
11111         /* set output DAC */
11112         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11113         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11114         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11115         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11116
11117         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11118         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11119         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11120         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11121         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11122
11123         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11124         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11125         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11126         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11127         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11128
11129         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11130         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11131         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11132         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11133
11134         /* set PCBEEP vol = 0, mute connections */
11135         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11136         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11137         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11138
11139         { }
11140 };
11141
11142 #define alc268_mux_enum_info alc_mux_enum_info
11143 #define alc268_mux_enum_get alc_mux_enum_get
11144 #define alc268_mux_enum_put alc_mux_enum_put
11145
11146 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
11147         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11148         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11149         {
11150                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11151                 /* The multiple "Capture Source" controls confuse alsamixer
11152                  * So call somewhat different..
11153                  */
11154                 /* .name = "Capture Source", */
11155                 .name = "Input Source",
11156                 .count = 1,
11157                 .info = alc268_mux_enum_info,
11158                 .get = alc268_mux_enum_get,
11159                 .put = alc268_mux_enum_put,
11160         },
11161         { } /* end */
11162 };
11163
11164 static struct snd_kcontrol_new alc268_capture_mixer[] = {
11165         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11166         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11167         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
11168         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
11169         {
11170                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11171                 /* The multiple "Capture Source" controls confuse alsamixer
11172                  * So call somewhat different..
11173                  */
11174                 /* .name = "Capture Source", */
11175                 .name = "Input Source",
11176                 .count = 2,
11177                 .info = alc268_mux_enum_info,
11178                 .get = alc268_mux_enum_get,
11179                 .put = alc268_mux_enum_put,
11180         },
11181         { } /* end */
11182 };
11183
11184 static struct hda_input_mux alc268_capture_source = {
11185         .num_items = 4,
11186         .items = {
11187                 { "Mic", 0x0 },
11188                 { "Front Mic", 0x1 },
11189                 { "Line", 0x2 },
11190                 { "CD", 0x3 },
11191         },
11192 };
11193
11194 static struct hda_input_mux alc268_acer_capture_source = {
11195         .num_items = 3,
11196         .items = {
11197                 { "Mic", 0x0 },
11198                 { "Internal Mic", 0x6 },
11199                 { "Line", 0x2 },
11200         },
11201 };
11202
11203 #ifdef CONFIG_SND_DEBUG
11204 static struct snd_kcontrol_new alc268_test_mixer[] = {
11205         /* Volume widgets */
11206         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11207         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11208         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
11209         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
11210         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
11211         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
11212         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
11213         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
11214         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
11215         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
11216         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
11217         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
11218         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
11219         /* The below appears problematic on some hardwares */
11220         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
11221         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11222         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
11223         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
11224         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
11225
11226         /* Modes for retasking pin widgets */
11227         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
11228         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
11229         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
11230         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
11231
11232         /* Controls for GPIO pins, assuming they are configured as outputs */
11233         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
11234         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
11235         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
11236         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
11237
11238         /* Switches to allow the digital SPDIF output pin to be enabled.
11239          * The ALC268 does not have an SPDIF input.
11240          */
11241         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
11242
11243         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
11244          * this output to turn on an external amplifier.
11245          */
11246         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
11247         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
11248
11249         { } /* end */
11250 };
11251 #endif
11252
11253 /* create input playback/capture controls for the given pin */
11254 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
11255                                     const char *ctlname, int idx)
11256 {
11257         char name[32];
11258         int err;
11259
11260         sprintf(name, "%s Playback Volume", ctlname);
11261         if (nid == 0x14) {
11262                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11263                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
11264                                                       HDA_OUTPUT));
11265                 if (err < 0)
11266                         return err;
11267         } else if (nid == 0x15) {
11268                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11269                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
11270                                                       HDA_OUTPUT));
11271                 if (err < 0)
11272                         return err;
11273         } else
11274                 return -1;
11275         sprintf(name, "%s Playback Switch", ctlname);
11276         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11277                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
11278         if (err < 0)
11279                 return err;
11280         return 0;
11281 }
11282
11283 /* add playback controls from the parsed DAC table */
11284 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
11285                                              const struct auto_pin_cfg *cfg)
11286 {
11287         hda_nid_t nid;
11288         int err;
11289
11290         spec->multiout.num_dacs = 2;    /* only use one dac */
11291         spec->multiout.dac_nids = spec->private_dac_nids;
11292         spec->multiout.dac_nids[0] = 2;
11293         spec->multiout.dac_nids[1] = 3;
11294
11295         nid = cfg->line_out_pins[0];
11296         if (nid)
11297                 alc268_new_analog_output(spec, nid, "Front", 0);
11298
11299         nid = cfg->speaker_pins[0];
11300         if (nid == 0x1d) {
11301                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
11302                                   "Speaker Playback Volume",
11303                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
11304                 if (err < 0)
11305                         return err;
11306         }
11307         nid = cfg->hp_pins[0];
11308         if (nid)
11309                 alc268_new_analog_output(spec, nid, "Headphone", 0);
11310
11311         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
11312         if (nid == 0x16) {
11313                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11314                                   "Mono Playback Switch",
11315                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
11316                 if (err < 0)
11317                         return err;
11318         }
11319         return 0;
11320 }
11321
11322 /* create playback/capture controls for input pins */
11323 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
11324                                                 const struct auto_pin_cfg *cfg)
11325 {
11326         struct hda_input_mux *imux = &spec->private_imux;
11327         int i, idx1;
11328
11329         for (i = 0; i < AUTO_PIN_LAST; i++) {
11330                 switch(cfg->input_pins[i]) {
11331                 case 0x18:
11332                         idx1 = 0;       /* Mic 1 */
11333                         break;
11334                 case 0x19:
11335                         idx1 = 1;       /* Mic 2 */
11336                         break;
11337                 case 0x1a:
11338                         idx1 = 2;       /* Line In */
11339                         break;
11340                 case 0x1c:
11341                         idx1 = 3;       /* CD */
11342                         break;
11343                 case 0x12:
11344                 case 0x13:
11345                         idx1 = 6;       /* digital mics */
11346                         break;
11347                 default:
11348                         continue;
11349                 }
11350                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
11351                 imux->items[imux->num_items].index = idx1;
11352                 imux->num_items++;
11353         }
11354         return 0;
11355 }
11356
11357 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
11358 {
11359         struct alc_spec *spec = codec->spec;
11360         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
11361         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
11362         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
11363         unsigned int    dac_vol1, dac_vol2;
11364
11365         if (speaker_nid) {
11366                 snd_hda_codec_write(codec, speaker_nid, 0,
11367                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
11368                 snd_hda_codec_write(codec, 0x0f, 0,
11369                                     AC_VERB_SET_AMP_GAIN_MUTE,
11370                                     AMP_IN_UNMUTE(1));
11371                 snd_hda_codec_write(codec, 0x10, 0,
11372                                     AC_VERB_SET_AMP_GAIN_MUTE,
11373                                     AMP_IN_UNMUTE(1));
11374         } else {
11375                 snd_hda_codec_write(codec, 0x0f, 0,
11376                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11377                 snd_hda_codec_write(codec, 0x10, 0,
11378                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11379         }
11380
11381         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
11382         if (line_nid == 0x14)
11383                 dac_vol2 = AMP_OUT_ZERO;
11384         else if (line_nid == 0x15)
11385                 dac_vol1 = AMP_OUT_ZERO;
11386         if (hp_nid == 0x14)
11387                 dac_vol2 = AMP_OUT_ZERO;
11388         else if (hp_nid == 0x15)
11389                 dac_vol1 = AMP_OUT_ZERO;
11390         if (line_nid != 0x16 || hp_nid != 0x16 ||
11391             spec->autocfg.line_out_pins[1] != 0x16 ||
11392             spec->autocfg.line_out_pins[2] != 0x16)
11393                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
11394
11395         snd_hda_codec_write(codec, 0x02, 0,
11396                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
11397         snd_hda_codec_write(codec, 0x03, 0,
11398                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
11399 }
11400
11401 /* pcm configuration: identiacal with ALC880 */
11402 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
11403 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
11404 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
11405 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
11406
11407 /*
11408  * BIOS auto configuration
11409  */
11410 static int alc268_parse_auto_config(struct hda_codec *codec)
11411 {
11412         struct alc_spec *spec = codec->spec;
11413         int err;
11414         static hda_nid_t alc268_ignore[] = { 0 };
11415
11416         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11417                                            alc268_ignore);
11418         if (err < 0)
11419                 return err;
11420         if (!spec->autocfg.line_outs)
11421                 return 0; /* can't find valid BIOS pin config */
11422
11423         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
11424         if (err < 0)
11425                 return err;
11426         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
11427         if (err < 0)
11428                 return err;
11429
11430         spec->multiout.max_channels = 2;
11431
11432         /* digital only support output */
11433         if (spec->autocfg.dig_out_pin)
11434                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
11435
11436         if (spec->kctl_alloc)
11437                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
11438
11439         if (spec->autocfg.speaker_pins[0] != 0x1d)
11440                 spec->mixers[spec->num_mixers++] = alc268_beep_mixer;
11441
11442         spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs;
11443         spec->num_mux_defs = 1;
11444         spec->input_mux = &spec->private_imux;
11445
11446         err = alc_auto_add_mic_boost(codec);
11447         if (err < 0)
11448                 return err;
11449
11450         return 1;
11451 }
11452
11453 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
11454 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
11455 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
11456
11457 /* init callback for auto-configuration model -- overriding the default init */
11458 static void alc268_auto_init(struct hda_codec *codec)
11459 {
11460         struct alc_spec *spec = codec->spec;
11461         alc268_auto_init_multi_out(codec);
11462         alc268_auto_init_hp_out(codec);
11463         alc268_auto_init_mono_speaker_out(codec);
11464         alc268_auto_init_analog_input(codec);
11465         if (spec->unsol_event)
11466                 alc_inithook(codec);
11467 }
11468
11469 /*
11470  * configuration and preset
11471  */
11472 static const char *alc268_models[ALC268_MODEL_LAST] = {
11473         [ALC267_QUANTA_IL1]     = "quanta-il1",
11474         [ALC268_3ST]            = "3stack",
11475         [ALC268_TOSHIBA]        = "toshiba",
11476         [ALC268_ACER]           = "acer",
11477         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
11478         [ALC268_DELL]           = "dell",
11479         [ALC268_ZEPTO]          = "zepto",
11480 #ifdef CONFIG_SND_DEBUG
11481         [ALC268_TEST]           = "test",
11482 #endif
11483         [ALC268_AUTO]           = "auto",
11484 };
11485
11486 static struct snd_pci_quirk alc268_cfg_tbl[] = {
11487         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
11488         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
11489         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
11490         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
11491         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
11492         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
11493                                                 ALC268_ACER_ASPIRE_ONE),
11494         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
11495         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
11496         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
11497         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
11498         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
11499         SND_PCI_QUIRK(0x1179, 0xff64, "TOSHIBA L305", ALC268_TOSHIBA),
11500         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
11501         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
11502         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
11503         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
11504         {}
11505 };
11506
11507 static struct alc_config_preset alc268_presets[] = {
11508         [ALC267_QUANTA_IL1] = {
11509                 .mixers = { alc267_quanta_il1_mixer },
11510                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11511                                 alc267_quanta_il1_verbs },
11512                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11513                 .dac_nids = alc268_dac_nids,
11514                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11515                 .adc_nids = alc268_adc_nids_alt,
11516                 .hp_nid = 0x03,
11517                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11518                 .channel_mode = alc268_modes,
11519                 .input_mux = &alc268_capture_source,
11520                 .unsol_event = alc267_quanta_il1_unsol_event,
11521                 .init_hook = alc267_quanta_il1_automute,
11522         },
11523         [ALC268_3ST] = {
11524                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11525                             alc268_beep_mixer },
11526                 .init_verbs = { alc268_base_init_verbs },
11527                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11528                 .dac_nids = alc268_dac_nids,
11529                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11530                 .adc_nids = alc268_adc_nids_alt,
11531                 .capsrc_nids = alc268_capsrc_nids,
11532                 .hp_nid = 0x03,
11533                 .dig_out_nid = ALC268_DIGOUT_NID,
11534                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11535                 .channel_mode = alc268_modes,
11536                 .input_mux = &alc268_capture_source,
11537         },
11538         [ALC268_TOSHIBA] = {
11539                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11540                             alc268_beep_mixer },
11541                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11542                                 alc268_toshiba_verbs },
11543                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11544                 .dac_nids = alc268_dac_nids,
11545                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11546                 .adc_nids = alc268_adc_nids_alt,
11547                 .capsrc_nids = alc268_capsrc_nids,
11548                 .hp_nid = 0x03,
11549                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11550                 .channel_mode = alc268_modes,
11551                 .input_mux = &alc268_capture_source,
11552                 .unsol_event = alc268_toshiba_unsol_event,
11553                 .init_hook = alc268_toshiba_automute,
11554         },
11555         [ALC268_ACER] = {
11556                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
11557                             alc268_beep_mixer },
11558                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11559                                 alc268_acer_verbs },
11560                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11561                 .dac_nids = alc268_dac_nids,
11562                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11563                 .adc_nids = alc268_adc_nids_alt,
11564                 .capsrc_nids = alc268_capsrc_nids,
11565                 .hp_nid = 0x02,
11566                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11567                 .channel_mode = alc268_modes,
11568                 .input_mux = &alc268_acer_capture_source,
11569                 .unsol_event = alc268_acer_unsol_event,
11570                 .init_hook = alc268_acer_init_hook,
11571         },
11572         [ALC268_ACER_ASPIRE_ONE] = {
11573                 .mixers = { alc268_acer_aspire_one_mixer,
11574                                 alc268_capture_alt_mixer },
11575                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11576                                 alc268_acer_aspire_one_verbs },
11577                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11578                 .dac_nids = alc268_dac_nids,
11579                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11580                 .adc_nids = alc268_adc_nids_alt,
11581                 .capsrc_nids = alc268_capsrc_nids,
11582                 .hp_nid = 0x03,
11583                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11584                 .channel_mode = alc268_modes,
11585                 .input_mux = &alc268_acer_lc_capture_source,
11586                 .unsol_event = alc268_acer_lc_unsol_event,
11587                 .init_hook = alc268_acer_lc_init_hook,
11588         },
11589         [ALC268_DELL] = {
11590                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
11591                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11592                                 alc268_dell_verbs },
11593                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11594                 .dac_nids = alc268_dac_nids,
11595                 .hp_nid = 0x02,
11596                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11597                 .channel_mode = alc268_modes,
11598                 .unsol_event = alc268_dell_unsol_event,
11599                 .init_hook = alc268_dell_init_hook,
11600                 .input_mux = &alc268_capture_source,
11601         },
11602         [ALC268_ZEPTO] = {
11603                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11604                             alc268_beep_mixer },
11605                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11606                                 alc268_toshiba_verbs },
11607                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11608                 .dac_nids = alc268_dac_nids,
11609                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11610                 .adc_nids = alc268_adc_nids_alt,
11611                 .capsrc_nids = alc268_capsrc_nids,
11612                 .hp_nid = 0x03,
11613                 .dig_out_nid = ALC268_DIGOUT_NID,
11614                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11615                 .channel_mode = alc268_modes,
11616                 .input_mux = &alc268_capture_source,
11617                 .unsol_event = alc268_toshiba_unsol_event,
11618                 .init_hook = alc268_toshiba_automute
11619         },
11620 #ifdef CONFIG_SND_DEBUG
11621         [ALC268_TEST] = {
11622                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
11623                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11624                                 alc268_volume_init_verbs },
11625                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11626                 .dac_nids = alc268_dac_nids,
11627                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11628                 .adc_nids = alc268_adc_nids_alt,
11629                 .capsrc_nids = alc268_capsrc_nids,
11630                 .hp_nid = 0x03,
11631                 .dig_out_nid = ALC268_DIGOUT_NID,
11632                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11633                 .channel_mode = alc268_modes,
11634                 .input_mux = &alc268_capture_source,
11635         },
11636 #endif
11637 };
11638
11639 static int patch_alc268(struct hda_codec *codec)
11640 {
11641         struct alc_spec *spec;
11642         int board_config;
11643         int err;
11644
11645         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
11646         if (spec == NULL)
11647                 return -ENOMEM;
11648
11649         codec->spec = spec;
11650
11651         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
11652                                                   alc268_models,
11653                                                   alc268_cfg_tbl);
11654
11655         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
11656                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
11657                        "trying auto-probe from BIOS...\n");
11658                 board_config = ALC268_AUTO;
11659         }
11660
11661         if (board_config == ALC268_AUTO) {
11662                 /* automatic parse from the BIOS config */
11663                 err = alc268_parse_auto_config(codec);
11664                 if (err < 0) {
11665                         alc_free(codec);
11666                         return err;
11667                 } else if (!err) {
11668                         printk(KERN_INFO
11669                                "hda_codec: Cannot set up configuration "
11670                                "from BIOS.  Using base mode...\n");
11671                         board_config = ALC268_3ST;
11672                 }
11673         }
11674
11675         if (board_config != ALC268_AUTO)
11676                 setup_preset(spec, &alc268_presets[board_config]);
11677
11678         if (codec->vendor_id == 0x10ec0267) {
11679                 spec->stream_name_analog = "ALC267 Analog";
11680                 spec->stream_name_digital = "ALC267 Digital";
11681         } else {
11682                 spec->stream_name_analog = "ALC268 Analog";
11683                 spec->stream_name_digital = "ALC268 Digital";
11684         }
11685
11686         spec->stream_analog_playback = &alc268_pcm_analog_playback;
11687         spec->stream_analog_capture = &alc268_pcm_analog_capture;
11688         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
11689
11690         spec->stream_digital_playback = &alc268_pcm_digital_playback;
11691
11692         if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
11693                 /* override the amp caps for beep generator */
11694                 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
11695                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
11696                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
11697                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
11698                                           (0 << AC_AMPCAP_MUTE_SHIFT));
11699
11700         if (!spec->adc_nids && spec->input_mux) {
11701                 /* check whether NID 0x07 is valid */
11702                 unsigned int wcap = get_wcaps(codec, 0x07);
11703                 int i;
11704
11705                 /* get type */
11706                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
11707                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
11708                         spec->adc_nids = alc268_adc_nids_alt;
11709                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
11710                         spec->mixers[spec->num_mixers] =
11711                                         alc268_capture_alt_mixer;
11712                         spec->num_mixers++;
11713                 } else {
11714                         spec->adc_nids = alc268_adc_nids;
11715                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
11716                         spec->mixers[spec->num_mixers] =
11717                                 alc268_capture_mixer;
11718                         spec->num_mixers++;
11719                 }
11720                 spec->capsrc_nids = alc268_capsrc_nids;
11721                 /* set default input source */
11722                 for (i = 0; i < spec->num_adc_nids; i++)
11723                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
11724                                 0, AC_VERB_SET_CONNECT_SEL,
11725                                 spec->input_mux->items[0].index);
11726         }
11727
11728         spec->vmaster_nid = 0x02;
11729
11730         codec->patch_ops = alc_patch_ops;
11731         if (board_config == ALC268_AUTO)
11732                 spec->init_hook = alc268_auto_init;
11733
11734         return 0;
11735 }
11736
11737 /*
11738  *  ALC269 channel source setting (2 channel)
11739  */
11740 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
11741
11742 #define alc269_dac_nids         alc260_dac_nids
11743
11744 static hda_nid_t alc269_adc_nids[1] = {
11745         /* ADC1 */
11746         0x08,
11747 };
11748
11749 static hda_nid_t alc269_capsrc_nids[1] = {
11750         0x23,
11751 };
11752
11753 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
11754  *       not a mux!
11755  */
11756
11757 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
11758         .num_items = 2,
11759         .items = {
11760                 { "i-Mic", 0x5 },
11761                 { "e-Mic", 0x0 },
11762         },
11763 };
11764
11765 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
11766         .num_items = 2,
11767         .items = {
11768                 { "i-Mic", 0x1 },
11769                 { "e-Mic", 0x0 },
11770         },
11771 };
11772
11773 #define alc269_modes            alc260_modes
11774 #define alc269_capture_source   alc880_lg_lw_capture_source
11775
11776 static struct snd_kcontrol_new alc269_base_mixer[] = {
11777         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11778         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11779         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11780         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11781         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11782         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11783         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
11784         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
11785         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11786         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11787         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11788         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11789         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11790         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
11791         { } /* end */
11792 };
11793
11794 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
11795         /* output mixer control */
11796         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11797         {
11798                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11799                 .name = "Master Playback Switch",
11800                 .info = snd_hda_mixer_amp_switch_info,
11801                 .get = snd_hda_mixer_amp_switch_get,
11802                 .put = alc268_acer_master_sw_put,
11803                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11804         },
11805         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11806         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11807         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11808         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11809         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11810         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11811         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
11812         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
11813         { }
11814 };
11815
11816 /* bind volumes of both NID 0x0c and 0x0d */
11817 static struct hda_bind_ctls alc269_epc_bind_vol = {
11818         .ops = &snd_hda_bind_vol,
11819         .values = {
11820                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
11821                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
11822                 0
11823         },
11824 };
11825
11826 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
11827         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11828         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
11829         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11830         { } /* end */
11831 };
11832
11833 /* capture mixer elements */
11834 static struct snd_kcontrol_new alc269_capture_mixer[] = {
11835         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11836         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11837         {
11838                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11839                 /* The multiple "Capture Source" controls confuse alsamixer
11840                  * So call somewhat different..
11841                  */
11842                 /* .name = "Capture Source", */
11843                 .name = "Input Source",
11844                 .count = 1,
11845                 .info = alc_mux_enum_info,
11846                 .get = alc_mux_enum_get,
11847                 .put = alc_mux_enum_put,
11848         },
11849         { } /* end */
11850 };
11851
11852 /* capture mixer elements */
11853 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
11854         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11855         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11856         { } /* end */
11857 };
11858
11859 /* beep control */
11860 static struct snd_kcontrol_new alc269_beep_mixer[] = {
11861         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
11862         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
11863         { } /* end */
11864 };
11865
11866 static struct hda_verb alc269_quanta_fl1_verbs[] = {
11867         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11868         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11869         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11870         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11871         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11872         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11873         { }
11874 };
11875
11876 /* toggle speaker-output according to the hp-jack state */
11877 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
11878 {
11879         unsigned int present;
11880         unsigned char bits;
11881
11882         present = snd_hda_codec_read(codec, 0x15, 0,
11883                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11884         bits = present ? AMP_IN_MUTE(0) : 0;
11885         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
11886                         AMP_IN_MUTE(0), bits);
11887         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
11888                         AMP_IN_MUTE(0), bits);
11889
11890         snd_hda_codec_write(codec, 0x20, 0,
11891                         AC_VERB_SET_COEF_INDEX, 0x0c);
11892         snd_hda_codec_write(codec, 0x20, 0,
11893                         AC_VERB_SET_PROC_COEF, 0x680);
11894
11895         snd_hda_codec_write(codec, 0x20, 0,
11896                         AC_VERB_SET_COEF_INDEX, 0x0c);
11897         snd_hda_codec_write(codec, 0x20, 0,
11898                         AC_VERB_SET_PROC_COEF, 0x480);
11899 }
11900
11901 static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
11902 {
11903         unsigned int present;
11904
11905         present = snd_hda_codec_read(codec, 0x18, 0,
11906                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11907         snd_hda_codec_write(codec, 0x23, 0,
11908                             AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
11909 }
11910
11911 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
11912                                     unsigned int res)
11913 {
11914         if ((res >> 26) == ALC880_HP_EVENT)
11915                 alc269_quanta_fl1_speaker_automute(codec);
11916         if ((res >> 26) == ALC880_MIC_EVENT)
11917                 alc269_quanta_fl1_mic_automute(codec);
11918 }
11919
11920 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
11921 {
11922         alc269_quanta_fl1_speaker_automute(codec);
11923         alc269_quanta_fl1_mic_automute(codec);
11924 }
11925
11926 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
11927         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11928         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
11929         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
11930         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
11931         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11932         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11933         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11934         {}
11935 };
11936
11937 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
11938         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11939         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
11940         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
11941         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
11942         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11943         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11944         {}
11945 };
11946
11947 /* toggle speaker-output according to the hp-jack state */
11948 static void alc269_speaker_automute(struct hda_codec *codec)
11949 {
11950         unsigned int present;
11951         unsigned char bits;
11952
11953         present = snd_hda_codec_read(codec, 0x15, 0,
11954                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11955         bits = present ? AMP_IN_MUTE(0) : 0;
11956         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
11957                                 AMP_IN_MUTE(0), bits);
11958         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
11959                                 AMP_IN_MUTE(0), bits);
11960 }
11961
11962 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
11963 {
11964         unsigned int present;
11965
11966         present = snd_hda_codec_read(codec, 0x18, 0,
11967                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11968         snd_hda_codec_write(codec, 0x23, 0,
11969                                 AC_VERB_SET_CONNECT_SEL,  (present ? 0 : 5));
11970 }
11971
11972 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
11973 {
11974         unsigned int present;
11975
11976         present = snd_hda_codec_read(codec, 0x18, 0,
11977                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11978         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11979                                 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
11980         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11981                                 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
11982 }
11983
11984 /* unsolicited event for HP jack sensing */
11985 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
11986                                      unsigned int res)
11987 {
11988         if ((res >> 26) == ALC880_HP_EVENT)
11989                 alc269_speaker_automute(codec);
11990
11991         if ((res >> 26) == ALC880_MIC_EVENT)
11992                 alc269_eeepc_dmic_automute(codec);
11993 }
11994
11995 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
11996 {
11997         alc269_speaker_automute(codec);
11998         alc269_eeepc_dmic_automute(codec);
11999 }
12000
12001 /* unsolicited event for HP jack sensing */
12002 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
12003                                      unsigned int res)
12004 {
12005         if ((res >> 26) == ALC880_HP_EVENT)
12006                 alc269_speaker_automute(codec);
12007
12008         if ((res >> 26) == ALC880_MIC_EVENT)
12009                 alc269_eeepc_amic_automute(codec);
12010 }
12011
12012 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
12013 {
12014         alc269_speaker_automute(codec);
12015         alc269_eeepc_amic_automute(codec);
12016 }
12017
12018 /*
12019  * generic initialization of ADC, input mixers and output mixers
12020  */
12021 static struct hda_verb alc269_init_verbs[] = {
12022         /*
12023          * Unmute ADC0 and set the default input to mic-in
12024          */
12025         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12026
12027         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
12028          * analog-loopback mixer widget
12029          * Note: PASD motherboards uses the Line In 2 as the input for
12030          * front panel mic (mic 2)
12031          */
12032         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12033         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12034         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12035         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12036         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12037         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12038
12039         /*
12040          * Set up output mixers (0x0c - 0x0e)
12041          */
12042         /* set vol=0 to output mixers */
12043         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12044         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12045
12046         /* set up input amps for analog loopback */
12047         /* Amp Indices: DAC = 0, mixer = 1 */
12048         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12049         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12050         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12051         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12052         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12053         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12054
12055         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12056         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12057         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12058         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12059         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12060         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12061         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12062
12063         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12064         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12065         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12066         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12067         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12068         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12069         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12070
12071         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12072         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12073
12074         /* FIXME: use matrix-type input source selection */
12075         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
12076         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
12077         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12078         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12079         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12080         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12081
12082         /* set EAPD */
12083         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
12084         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
12085         { }
12086 };
12087
12088 /* add playback controls from the parsed DAC table */
12089 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
12090                                              const struct auto_pin_cfg *cfg)
12091 {
12092         hda_nid_t nid;
12093         int err;
12094
12095         spec->multiout.num_dacs = 1;    /* only use one dac */
12096         spec->multiout.dac_nids = spec->private_dac_nids;
12097         spec->multiout.dac_nids[0] = 2;
12098
12099         nid = cfg->line_out_pins[0];
12100         if (nid) {
12101                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
12102                                   "Front Playback Volume",
12103                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
12104                 if (err < 0)
12105                         return err;
12106                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12107                                   "Front Playback Switch",
12108                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12109                 if (err < 0)
12110                         return err;
12111         }
12112
12113         nid = cfg->speaker_pins[0];
12114         if (nid) {
12115                 if (!cfg->line_out_pins[0]) {
12116                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12117                                           "Speaker Playback Volume",
12118                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12119                                                               HDA_OUTPUT));
12120                         if (err < 0)
12121                                 return err;
12122                 }
12123                 if (nid == 0x16) {
12124                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12125                                           "Speaker Playback Switch",
12126                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12127                                                               HDA_OUTPUT));
12128                         if (err < 0)
12129                                 return err;
12130                 } else {
12131                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12132                                           "Speaker Playback Switch",
12133                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12134                                                               HDA_OUTPUT));
12135                         if (err < 0)
12136                                 return err;
12137                 }
12138         }
12139         nid = cfg->hp_pins[0];
12140         if (nid) {
12141                 /* spec->multiout.hp_nid = 2; */
12142                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
12143                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12144                                           "Headphone Playback Volume",
12145                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12146                                                               HDA_OUTPUT));
12147                         if (err < 0)
12148                                 return err;
12149                 }
12150                 if (nid == 0x16) {
12151                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12152                                           "Headphone Playback Switch",
12153                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12154                                                               HDA_OUTPUT));
12155                         if (err < 0)
12156                                 return err;
12157                 } else {
12158                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12159                                           "Headphone Playback Switch",
12160                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12161                                                               HDA_OUTPUT));
12162                         if (err < 0)
12163                                 return err;
12164                 }
12165         }
12166         return 0;
12167 }
12168
12169 #define alc269_auto_create_analog_input_ctls \
12170         alc880_auto_create_analog_input_ctls
12171
12172 #ifdef CONFIG_SND_HDA_POWER_SAVE
12173 #define alc269_loopbacks        alc880_loopbacks
12174 #endif
12175
12176 /* pcm configuration: identiacal with ALC880 */
12177 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
12178 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
12179 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
12180 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
12181
12182 /*
12183  * BIOS auto configuration
12184  */
12185 static int alc269_parse_auto_config(struct hda_codec *codec)
12186 {
12187         struct alc_spec *spec = codec->spec;
12188         int i, err;
12189         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
12190
12191         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12192                                            alc269_ignore);
12193         if (err < 0)
12194                 return err;
12195
12196         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
12197         if (err < 0)
12198                 return err;
12199         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
12200         if (err < 0)
12201                 return err;
12202
12203         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12204
12205         if (spec->autocfg.dig_out_pin)
12206                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
12207
12208         if (spec->kctl_alloc)
12209                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
12210
12211         /* create a beep mixer control if the pin 0x1d isn't assigned */
12212         for (i = 0; i < ARRAY_SIZE(spec->autocfg.input_pins); i++)
12213                 if (spec->autocfg.input_pins[i] == 0x1d)
12214                         break;
12215         if (i >= ARRAY_SIZE(spec->autocfg.input_pins))
12216                 spec->mixers[spec->num_mixers++] = alc269_beep_mixer;
12217
12218         spec->init_verbs[spec->num_init_verbs++] = alc269_init_verbs;
12219         spec->num_mux_defs = 1;
12220         spec->input_mux = &spec->private_imux;
12221         /* set default input source */
12222         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
12223                                   0, AC_VERB_SET_CONNECT_SEL,
12224                                   spec->input_mux->items[0].index);
12225
12226         err = alc_auto_add_mic_boost(codec);
12227         if (err < 0)
12228                 return err;
12229
12230         spec->mixers[spec->num_mixers] = alc269_capture_mixer;
12231         spec->num_mixers++;
12232
12233         return 1;
12234 }
12235
12236 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
12237 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
12238 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
12239
12240
12241 /* init callback for auto-configuration model -- overriding the default init */
12242 static void alc269_auto_init(struct hda_codec *codec)
12243 {
12244         struct alc_spec *spec = codec->spec;
12245         alc269_auto_init_multi_out(codec);
12246         alc269_auto_init_hp_out(codec);
12247         alc269_auto_init_analog_input(codec);
12248         if (spec->unsol_event)
12249                 alc_inithook(codec);
12250 }
12251
12252 /*
12253  * configuration and preset
12254  */
12255 static const char *alc269_models[ALC269_MODEL_LAST] = {
12256         [ALC269_BASIC]                  = "basic",
12257         [ALC269_QUANTA_FL1]             = "quanta",
12258         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
12259         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901"
12260 };
12261
12262 static struct snd_pci_quirk alc269_cfg_tbl[] = {
12263         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
12264         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
12265                       ALC269_ASUS_EEEPC_P703),
12266         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
12267                       ALC269_ASUS_EEEPC_P901),
12268         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
12269                       ALC269_ASUS_EEEPC_P901),
12270         {}
12271 };
12272
12273 static struct alc_config_preset alc269_presets[] = {
12274         [ALC269_BASIC] = {
12275                 .mixers = { alc269_base_mixer, alc269_capture_mixer },
12276                 .init_verbs = { alc269_init_verbs },
12277                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12278                 .dac_nids = alc269_dac_nids,
12279                 .hp_nid = 0x03,
12280                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12281                 .channel_mode = alc269_modes,
12282                 .input_mux = &alc269_capture_source,
12283         },
12284         [ALC269_QUANTA_FL1] = {
12285                 .mixers = { alc269_quanta_fl1_mixer },
12286                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
12287                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12288                 .dac_nids = alc269_dac_nids,
12289                 .hp_nid = 0x03,
12290                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12291                 .channel_mode = alc269_modes,
12292                 .input_mux = &alc269_capture_source,
12293                 .unsol_event = alc269_quanta_fl1_unsol_event,
12294                 .init_hook = alc269_quanta_fl1_init_hook,
12295         },
12296         [ALC269_ASUS_EEEPC_P703] = {
12297                 .mixers = { alc269_eeepc_mixer, alc269_epc_capture_mixer },
12298                 .init_verbs = { alc269_init_verbs,
12299                                 alc269_eeepc_amic_init_verbs },
12300                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12301                 .dac_nids = alc269_dac_nids,
12302                 .hp_nid = 0x03,
12303                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12304                 .channel_mode = alc269_modes,
12305                 .input_mux = &alc269_eeepc_amic_capture_source,
12306                 .unsol_event = alc269_eeepc_amic_unsol_event,
12307                 .init_hook = alc269_eeepc_amic_inithook,
12308         },
12309         [ALC269_ASUS_EEEPC_P901] = {
12310                 .mixers = { alc269_eeepc_mixer, alc269_epc_capture_mixer},
12311                 .init_verbs = { alc269_init_verbs,
12312                                 alc269_eeepc_dmic_init_verbs },
12313                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12314                 .dac_nids = alc269_dac_nids,
12315                 .hp_nid = 0x03,
12316                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12317                 .channel_mode = alc269_modes,
12318                 .input_mux = &alc269_eeepc_dmic_capture_source,
12319                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12320                 .init_hook = alc269_eeepc_dmic_inithook,
12321         },
12322 };
12323
12324 static int patch_alc269(struct hda_codec *codec)
12325 {
12326         struct alc_spec *spec;
12327         int board_config;
12328         int err;
12329
12330         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12331         if (spec == NULL)
12332                 return -ENOMEM;
12333
12334         codec->spec = spec;
12335
12336         alc_fix_pll_init(codec, 0x20, 0x04, 15);
12337
12338         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
12339                                                   alc269_models,
12340                                                   alc269_cfg_tbl);
12341
12342         if (board_config < 0) {
12343                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
12344                        "trying auto-probe from BIOS...\n");
12345                 board_config = ALC269_AUTO;
12346         }
12347
12348         if (board_config == ALC269_AUTO) {
12349                 /* automatic parse from the BIOS config */
12350                 err = alc269_parse_auto_config(codec);
12351                 if (err < 0) {
12352                         alc_free(codec);
12353                         return err;
12354                 } else if (!err) {
12355                         printk(KERN_INFO
12356                                "hda_codec: Cannot set up configuration "
12357                                "from BIOS.  Using base mode...\n");
12358                         board_config = ALC269_BASIC;
12359                 }
12360         }
12361
12362         if (board_config != ALC269_AUTO)
12363                 setup_preset(spec, &alc269_presets[board_config]);
12364
12365         spec->stream_name_analog = "ALC269 Analog";
12366         spec->stream_analog_playback = &alc269_pcm_analog_playback;
12367         spec->stream_analog_capture = &alc269_pcm_analog_capture;
12368
12369         spec->stream_name_digital = "ALC269 Digital";
12370         spec->stream_digital_playback = &alc269_pcm_digital_playback;
12371         spec->stream_digital_capture = &alc269_pcm_digital_capture;
12372
12373         spec->adc_nids = alc269_adc_nids;
12374         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
12375         spec->capsrc_nids = alc269_capsrc_nids;
12376
12377         codec->patch_ops = alc_patch_ops;
12378         if (board_config == ALC269_AUTO)
12379                 spec->init_hook = alc269_auto_init;
12380 #ifdef CONFIG_SND_HDA_POWER_SAVE
12381         if (!spec->loopback.amplist)
12382                 spec->loopback.amplist = alc269_loopbacks;
12383 #endif
12384
12385         return 0;
12386 }
12387
12388 /*
12389  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
12390  */
12391
12392 /*
12393  * set the path ways for 2 channel output
12394  * need to set the codec line out and mic 1 pin widgets to inputs
12395  */
12396 static struct hda_verb alc861_threestack_ch2_init[] = {
12397         /* set pin widget 1Ah (line in) for input */
12398         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12399         /* set pin widget 18h (mic1/2) for input, for mic also enable
12400          * the vref
12401          */
12402         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12403
12404         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12405 #if 0
12406         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12407         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12408 #endif
12409         { } /* end */
12410 };
12411 /*
12412  * 6ch mode
12413  * need to set the codec line out and mic 1 pin widgets to outputs
12414  */
12415 static struct hda_verb alc861_threestack_ch6_init[] = {
12416         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12417         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12418         /* set pin widget 18h (mic1) for output (CLFE)*/
12419         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12420
12421         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12422         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12423
12424         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12425 #if 0
12426         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12427         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12428 #endif
12429         { } /* end */
12430 };
12431
12432 static struct hda_channel_mode alc861_threestack_modes[2] = {
12433         { 2, alc861_threestack_ch2_init },
12434         { 6, alc861_threestack_ch6_init },
12435 };
12436 /* Set mic1 as input and unmute the mixer */
12437 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
12438         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12439         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12440         { } /* end */
12441 };
12442 /* Set mic1 as output and mute mixer */
12443 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
12444         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12445         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12446         { } /* end */
12447 };
12448
12449 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
12450         { 2, alc861_uniwill_m31_ch2_init },
12451         { 4, alc861_uniwill_m31_ch4_init },
12452 };
12453
12454 /* Set mic1 and line-in as input and unmute the mixer */
12455 static struct hda_verb alc861_asus_ch2_init[] = {
12456         /* set pin widget 1Ah (line in) for input */
12457         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12458         /* set pin widget 18h (mic1/2) for input, for mic also enable
12459          * the vref
12460          */
12461         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12462
12463         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12464 #if 0
12465         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12466         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12467 #endif
12468         { } /* end */
12469 };
12470 /* Set mic1 nad line-in as output and mute mixer */
12471 static struct hda_verb alc861_asus_ch6_init[] = {
12472         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12473         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12474         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12475         /* set pin widget 18h (mic1) for output (CLFE)*/
12476         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12477         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12478         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12479         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12480
12481         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12482 #if 0
12483         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12484         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12485 #endif
12486         { } /* end */
12487 };
12488
12489 static struct hda_channel_mode alc861_asus_modes[2] = {
12490         { 2, alc861_asus_ch2_init },
12491         { 6, alc861_asus_ch6_init },
12492 };
12493
12494 /* patch-ALC861 */
12495
12496 static struct snd_kcontrol_new alc861_base_mixer[] = {
12497         /* output mixer control */
12498         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12499         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12500         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12501         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12502         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12503
12504         /*Input mixer control */
12505         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12506            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12507         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12508         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12509         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12510         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12511         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12512         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12513         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12514         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12515
12516         /* Capture mixer control */
12517         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12518         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12519         {
12520                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12521                 .name = "Capture Source",
12522                 .count = 1,
12523                 .info = alc_mux_enum_info,
12524                 .get = alc_mux_enum_get,
12525                 .put = alc_mux_enum_put,
12526         },
12527         { } /* end */
12528 };
12529
12530 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
12531         /* output mixer control */
12532         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12533         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12534         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12535         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12536         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12537
12538         /* Input mixer control */
12539         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12540            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12541         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12542         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12543         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12544         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12545         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12546         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12547         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12548         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12549
12550         /* Capture mixer control */
12551         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12552         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12553         {
12554                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12555                 .name = "Capture Source",
12556                 .count = 1,
12557                 .info = alc_mux_enum_info,
12558                 .get = alc_mux_enum_get,
12559                 .put = alc_mux_enum_put,
12560         },
12561         {
12562                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12563                 .name = "Channel Mode",
12564                 .info = alc_ch_mode_info,
12565                 .get = alc_ch_mode_get,
12566                 .put = alc_ch_mode_put,
12567                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
12568         },
12569         { } /* end */
12570 };
12571
12572 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
12573         /* output mixer control */
12574         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12575         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12576         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12577
12578         /*Capture mixer control */
12579         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12580         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12581         {
12582                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12583                 .name = "Capture Source",
12584                 .count = 1,
12585                 .info = alc_mux_enum_info,
12586                 .get = alc_mux_enum_get,
12587                 .put = alc_mux_enum_put,
12588         },
12589
12590         { } /* end */
12591 };
12592
12593 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
12594         /* output mixer control */
12595         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12596         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12597         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12598         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12599         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12600
12601         /* Input mixer control */
12602         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12603            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12604         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12605         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12606         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12607         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12608         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12609         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12610         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12611         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12612
12613         /* Capture mixer control */
12614         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12615         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12616         {
12617                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12618                 .name = "Capture Source",
12619                 .count = 1,
12620                 .info = alc_mux_enum_info,
12621                 .get = alc_mux_enum_get,
12622                 .put = alc_mux_enum_put,
12623         },
12624         {
12625                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12626                 .name = "Channel Mode",
12627                 .info = alc_ch_mode_info,
12628                 .get = alc_ch_mode_get,
12629                 .put = alc_ch_mode_put,
12630                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
12631         },
12632         { } /* end */
12633 };
12634
12635 static struct snd_kcontrol_new alc861_asus_mixer[] = {
12636         /* output mixer control */
12637         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12638         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12639         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12640         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12641         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12642
12643         /* Input mixer control */
12644         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12645         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12646         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12647         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12648         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12649         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12650         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12651         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12652         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12653         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
12654
12655         /* Capture mixer control */
12656         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12657         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12658         {
12659                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12660                 .name = "Capture Source",
12661                 .count = 1,
12662                 .info = alc_mux_enum_info,
12663                 .get = alc_mux_enum_get,
12664                 .put = alc_mux_enum_put,
12665         },
12666         {
12667                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12668                 .name = "Channel Mode",
12669                 .info = alc_ch_mode_info,
12670                 .get = alc_ch_mode_get,
12671                 .put = alc_ch_mode_put,
12672                 .private_value = ARRAY_SIZE(alc861_asus_modes),
12673         },
12674         { }
12675 };
12676
12677 /* additional mixer */
12678 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
12679         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12680         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12681         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
12682         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
12683         { }
12684 };
12685
12686 /*
12687  * generic initialization of ADC, input mixers and output mixers
12688  */
12689 static struct hda_verb alc861_base_init_verbs[] = {
12690         /*
12691          * Unmute ADC0 and set the default input to mic-in
12692          */
12693         /* port-A for surround (rear panel) */
12694         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12695         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
12696         /* port-B for mic-in (rear panel) with vref */
12697         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12698         /* port-C for line-in (rear panel) */
12699         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12700         /* port-D for Front */
12701         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12702         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12703         /* port-E for HP out (front panel) */
12704         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
12705         /* route front PCM to HP */
12706         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12707         /* port-F for mic-in (front panel) with vref */
12708         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12709         /* port-G for CLFE (rear panel) */
12710         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12711         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12712         /* port-H for side (rear panel) */
12713         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12714         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
12715         /* CD-in */
12716         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12717         /* route front mic to ADC1*/
12718         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12719         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12720
12721         /* Unmute DAC0~3 & spdif out*/
12722         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12723         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12724         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12725         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12726         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12727
12728         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12729         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12730         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12731         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12732         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12733
12734         /* Unmute Stereo Mixer 15 */
12735         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12736         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12737         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12738         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12739
12740         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12741         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12742         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12743         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12744         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12745         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12746         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12747         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12748         /* hp used DAC 3 (Front) */
12749         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12750         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12751
12752         { }
12753 };
12754
12755 static struct hda_verb alc861_threestack_init_verbs[] = {
12756         /*
12757          * Unmute ADC0 and set the default input to mic-in
12758          */
12759         /* port-A for surround (rear panel) */
12760         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12761         /* port-B for mic-in (rear panel) with vref */
12762         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12763         /* port-C for line-in (rear panel) */
12764         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12765         /* port-D for Front */
12766         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12767         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12768         /* port-E for HP out (front panel) */
12769         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
12770         /* route front PCM to HP */
12771         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12772         /* port-F for mic-in (front panel) with vref */
12773         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12774         /* port-G for CLFE (rear panel) */
12775         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12776         /* port-H for side (rear panel) */
12777         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12778         /* CD-in */
12779         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12780         /* route front mic to ADC1*/
12781         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12782         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12783         /* Unmute DAC0~3 & spdif out*/
12784         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12785         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12786         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12787         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12788         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12789
12790         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12791         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12792         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12793         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12794         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12795
12796         /* Unmute Stereo Mixer 15 */
12797         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12798         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12799         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12800         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12801
12802         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12803         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12804         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12805         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12806         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12807         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12808         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12809         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12810         /* hp used DAC 3 (Front) */
12811         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12812         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12813         { }
12814 };
12815
12816 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
12817         /*
12818          * Unmute ADC0 and set the default input to mic-in
12819          */
12820         /* port-A for surround (rear panel) */
12821         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12822         /* port-B for mic-in (rear panel) with vref */
12823         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12824         /* port-C for line-in (rear panel) */
12825         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12826         /* port-D for Front */
12827         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12828         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12829         /* port-E for HP out (front panel) */
12830         /* this has to be set to VREF80 */
12831         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12832         /* route front PCM to HP */
12833         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12834         /* port-F for mic-in (front panel) with vref */
12835         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12836         /* port-G for CLFE (rear panel) */
12837         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12838         /* port-H for side (rear panel) */
12839         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12840         /* CD-in */
12841         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12842         /* route front mic to ADC1*/
12843         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12844         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12845         /* Unmute DAC0~3 & spdif out*/
12846         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12847         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12848         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12849         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12850         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12851
12852         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12853         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12854         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12855         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12856         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12857
12858         /* Unmute Stereo Mixer 15 */
12859         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12860         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12861         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12862         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12863
12864         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12865         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12866         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12867         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12868         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12869         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12870         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12871         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12872         /* hp used DAC 3 (Front) */
12873         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12874         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12875         { }
12876 };
12877
12878 static struct hda_verb alc861_asus_init_verbs[] = {
12879         /*
12880          * Unmute ADC0 and set the default input to mic-in
12881          */
12882         /* port-A for surround (rear panel)
12883          * according to codec#0 this is the HP jack
12884          */
12885         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
12886         /* route front PCM to HP */
12887         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
12888         /* port-B for mic-in (rear panel) with vref */
12889         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12890         /* port-C for line-in (rear panel) */
12891         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12892         /* port-D for Front */
12893         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12894         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12895         /* port-E for HP out (front panel) */
12896         /* this has to be set to VREF80 */
12897         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12898         /* route front PCM to HP */
12899         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12900         /* port-F for mic-in (front panel) with vref */
12901         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12902         /* port-G for CLFE (rear panel) */
12903         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12904         /* port-H for side (rear panel) */
12905         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12906         /* CD-in */
12907         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12908         /* route front mic to ADC1*/
12909         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12910         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12911         /* Unmute DAC0~3 & spdif out*/
12912         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12913         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12914         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12915         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12916         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12917         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12918         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12919         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12920         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12921         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12922
12923         /* Unmute Stereo Mixer 15 */
12924         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12925         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12926         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12927         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12928
12929         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12930         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12931         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12932         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12933         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12934         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12935         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12936         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12937         /* hp used DAC 3 (Front) */
12938         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12939         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12940         { }
12941 };
12942
12943 /* additional init verbs for ASUS laptops */
12944 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
12945         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
12946         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
12947         { }
12948 };
12949
12950 /*
12951  * generic initialization of ADC, input mixers and output mixers
12952  */
12953 static struct hda_verb alc861_auto_init_verbs[] = {
12954         /*
12955          * Unmute ADC0 and set the default input to mic-in
12956          */
12957         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
12958         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12959
12960         /* Unmute DAC0~3 & spdif out*/
12961         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12962         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12963         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12964         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12965         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12966
12967         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12968         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12969         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12970         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12971         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12972
12973         /* Unmute Stereo Mixer 15 */
12974         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12975         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12976         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12977         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
12978
12979         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12980         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12981         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12982         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12983         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12984         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12985         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12986         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12987
12988         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12989         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12990         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12991         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12992         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12993         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12994         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12995         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12996
12997         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
12998
12999         { }
13000 };
13001
13002 static struct hda_verb alc861_toshiba_init_verbs[] = {
13003         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13004
13005         { }
13006 };
13007
13008 /* toggle speaker-output according to the hp-jack state */
13009 static void alc861_toshiba_automute(struct hda_codec *codec)
13010 {
13011         unsigned int present;
13012
13013         present = snd_hda_codec_read(codec, 0x0f, 0,
13014                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13015         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
13016                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
13017         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
13018                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
13019 }
13020
13021 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
13022                                        unsigned int res)
13023 {
13024         if ((res >> 26) == ALC880_HP_EVENT)
13025                 alc861_toshiba_automute(codec);
13026 }
13027
13028 /* pcm configuration: identiacal with ALC880 */
13029 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
13030 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
13031 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
13032 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
13033
13034
13035 #define ALC861_DIGOUT_NID       0x07
13036
13037 static struct hda_channel_mode alc861_8ch_modes[1] = {
13038         { 8, NULL }
13039 };
13040
13041 static hda_nid_t alc861_dac_nids[4] = {
13042         /* front, surround, clfe, side */
13043         0x03, 0x06, 0x05, 0x04
13044 };
13045
13046 static hda_nid_t alc660_dac_nids[3] = {
13047         /* front, clfe, surround */
13048         0x03, 0x05, 0x06
13049 };
13050
13051 static hda_nid_t alc861_adc_nids[1] = {
13052         /* ADC0-2 */
13053         0x08,
13054 };
13055
13056 static struct hda_input_mux alc861_capture_source = {
13057         .num_items = 5,
13058         .items = {
13059                 { "Mic", 0x0 },
13060                 { "Front Mic", 0x3 },
13061                 { "Line", 0x1 },
13062                 { "CD", 0x4 },
13063                 { "Mixer", 0x5 },
13064         },
13065 };
13066
13067 /* fill in the dac_nids table from the parsed pin configuration */
13068 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
13069                                      const struct auto_pin_cfg *cfg)
13070 {
13071         int i;
13072         hda_nid_t nid;
13073
13074         spec->multiout.dac_nids = spec->private_dac_nids;
13075         for (i = 0; i < cfg->line_outs; i++) {
13076                 nid = cfg->line_out_pins[i];
13077                 if (nid) {
13078                         if (i >= ARRAY_SIZE(alc861_dac_nids))
13079                                 continue;
13080                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
13081                 }
13082         }
13083         spec->multiout.num_dacs = cfg->line_outs;
13084         return 0;
13085 }
13086
13087 /* add playback controls from the parsed DAC table */
13088 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
13089                                              const struct auto_pin_cfg *cfg)
13090 {
13091         char name[32];
13092         static const char *chname[4] = {
13093                 "Front", "Surround", NULL /*CLFE*/, "Side"
13094         };
13095         hda_nid_t nid;
13096         int i, idx, err;
13097
13098         for (i = 0; i < cfg->line_outs; i++) {
13099                 nid = spec->multiout.dac_nids[i];
13100                 if (!nid)
13101                         continue;
13102                 if (nid == 0x05) {
13103                         /* Center/LFE */
13104                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13105                                           "Center Playback Switch",
13106                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
13107                                                               HDA_OUTPUT));
13108                         if (err < 0)
13109                                 return err;
13110                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13111                                           "LFE Playback Switch",
13112                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13113                                                               HDA_OUTPUT));
13114                         if (err < 0)
13115                                 return err;
13116                 } else {
13117                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
13118                              idx++)
13119                                 if (nid == alc861_dac_nids[idx])
13120                                         break;
13121                         sprintf(name, "%s Playback Switch", chname[idx]);
13122                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13123                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13124                                                               HDA_OUTPUT));
13125                         if (err < 0)
13126                                 return err;
13127                 }
13128         }
13129         return 0;
13130 }
13131
13132 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
13133 {
13134         int err;
13135         hda_nid_t nid;
13136
13137         if (!pin)
13138                 return 0;
13139
13140         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
13141                 nid = 0x03;
13142                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13143                                   "Headphone Playback Switch",
13144                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13145                 if (err < 0)
13146                         return err;
13147                 spec->multiout.hp_nid = nid;
13148         }
13149         return 0;
13150 }
13151
13152 /* create playback/capture controls for input pins */
13153 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
13154                                                 const struct auto_pin_cfg *cfg)
13155 {
13156         struct hda_input_mux *imux = &spec->private_imux;
13157         int i, err, idx, idx1;
13158
13159         for (i = 0; i < AUTO_PIN_LAST; i++) {
13160                 switch (cfg->input_pins[i]) {
13161                 case 0x0c:
13162                         idx1 = 1;
13163                         idx = 2;        /* Line In */
13164                         break;
13165                 case 0x0f:
13166                         idx1 = 2;
13167                         idx = 2;        /* Line In */
13168                         break;
13169                 case 0x0d:
13170                         idx1 = 0;
13171                         idx = 1;        /* Mic In */
13172                         break;
13173                 case 0x10:
13174                         idx1 = 3;
13175                         idx = 1;        /* Mic In */
13176                         break;
13177                 case 0x11:
13178                         idx1 = 4;
13179                         idx = 0;        /* CD */
13180                         break;
13181                 default:
13182                         continue;
13183                 }
13184
13185                 err = new_analog_input(spec, cfg->input_pins[i],
13186                                        auto_pin_cfg_labels[i], idx, 0x15);
13187                 if (err < 0)
13188                         return err;
13189
13190                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
13191                 imux->items[imux->num_items].index = idx1;
13192                 imux->num_items++;
13193         }
13194         return 0;
13195 }
13196
13197 static struct snd_kcontrol_new alc861_capture_mixer[] = {
13198         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
13199         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
13200
13201         {
13202                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13203                 /* The multiple "Capture Source" controls confuse alsamixer
13204                  * So call somewhat different..
13205                  */
13206                 /* .name = "Capture Source", */
13207                 .name = "Input Source",
13208                 .count = 1,
13209                 .info = alc_mux_enum_info,
13210                 .get = alc_mux_enum_get,
13211                 .put = alc_mux_enum_put,
13212         },
13213         { } /* end */
13214 };
13215
13216 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
13217                                               hda_nid_t nid,
13218                                               int pin_type, int dac_idx)
13219 {
13220         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
13221                             pin_type);
13222         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13223                             AMP_OUT_UNMUTE);
13224 }
13225
13226 static void alc861_auto_init_multi_out(struct hda_codec *codec)
13227 {
13228         struct alc_spec *spec = codec->spec;
13229         int i;
13230
13231         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
13232         for (i = 0; i < spec->autocfg.line_outs; i++) {
13233                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13234                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13235                 if (nid)
13236                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
13237                                                           spec->multiout.dac_nids[i]);
13238         }
13239 }
13240
13241 static void alc861_auto_init_hp_out(struct hda_codec *codec)
13242 {
13243         struct alc_spec *spec = codec->spec;
13244         hda_nid_t pin;
13245
13246         pin = spec->autocfg.hp_pins[0];
13247         if (pin) /* connect to front */
13248                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
13249                                                   spec->multiout.dac_nids[0]);
13250         pin = spec->autocfg.speaker_pins[0];
13251         if (pin)
13252                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13253 }
13254
13255 static void alc861_auto_init_analog_input(struct hda_codec *codec)
13256 {
13257         struct alc_spec *spec = codec->spec;
13258         int i;
13259
13260         for (i = 0; i < AUTO_PIN_LAST; i++) {
13261                 hda_nid_t nid = spec->autocfg.input_pins[i];
13262                 if (nid >= 0x0c && nid <= 0x11) {
13263                         snd_hda_codec_write(codec, nid, 0,
13264                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
13265                                             i <= AUTO_PIN_FRONT_MIC ?
13266                                             PIN_VREF80 : PIN_IN);
13267                 }
13268         }
13269 }
13270
13271 /* parse the BIOS configuration and set up the alc_spec */
13272 /* return 1 if successful, 0 if the proper config is not found,
13273  * or a negative error code
13274  */
13275 static int alc861_parse_auto_config(struct hda_codec *codec)
13276 {
13277         struct alc_spec *spec = codec->spec;
13278         int err;
13279         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
13280
13281         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13282                                            alc861_ignore);
13283         if (err < 0)
13284                 return err;
13285         if (!spec->autocfg.line_outs)
13286                 return 0; /* can't find valid BIOS pin config */
13287
13288         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
13289         if (err < 0)
13290                 return err;
13291         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
13292         if (err < 0)
13293                 return err;
13294         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
13295         if (err < 0)
13296                 return err;
13297         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
13298         if (err < 0)
13299                 return err;
13300
13301         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13302
13303         if (spec->autocfg.dig_out_pin)
13304                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
13305
13306         if (spec->kctl_alloc)
13307                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
13308
13309         spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs;
13310
13311         spec->num_mux_defs = 1;
13312         spec->input_mux = &spec->private_imux;
13313
13314         spec->adc_nids = alc861_adc_nids;
13315         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
13316         spec->mixers[spec->num_mixers] = alc861_capture_mixer;
13317         spec->num_mixers++;
13318
13319         return 1;
13320 }
13321
13322 /* additional initialization for auto-configuration model */
13323 static void alc861_auto_init(struct hda_codec *codec)
13324 {
13325         struct alc_spec *spec = codec->spec;
13326         alc861_auto_init_multi_out(codec);
13327         alc861_auto_init_hp_out(codec);
13328         alc861_auto_init_analog_input(codec);
13329         if (spec->unsol_event)
13330                 alc_inithook(codec);
13331 }
13332
13333 #ifdef CONFIG_SND_HDA_POWER_SAVE
13334 static struct hda_amp_list alc861_loopbacks[] = {
13335         { 0x15, HDA_INPUT, 0 },
13336         { 0x15, HDA_INPUT, 1 },
13337         { 0x15, HDA_INPUT, 2 },
13338         { 0x15, HDA_INPUT, 3 },
13339         { } /* end */
13340 };
13341 #endif
13342
13343
13344 /*
13345  * configuration and preset
13346  */
13347 static const char *alc861_models[ALC861_MODEL_LAST] = {
13348         [ALC861_3ST]            = "3stack",
13349         [ALC660_3ST]            = "3stack-660",
13350         [ALC861_3ST_DIG]        = "3stack-dig",
13351         [ALC861_6ST_DIG]        = "6stack-dig",
13352         [ALC861_UNIWILL_M31]    = "uniwill-m31",
13353         [ALC861_TOSHIBA]        = "toshiba",
13354         [ALC861_ASUS]           = "asus",
13355         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
13356         [ALC861_AUTO]           = "auto",
13357 };
13358
13359 static struct snd_pci_quirk alc861_cfg_tbl[] = {
13360         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
13361         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13362         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13363         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
13364         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
13365         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
13366         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
13367         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
13368          *        Any other models that need this preset?
13369          */
13370         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
13371         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
13372         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
13373         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
13374         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
13375         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
13376         /* FIXME: the below seems conflict */
13377         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
13378         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
13379         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
13380         {}
13381 };
13382
13383 static struct alc_config_preset alc861_presets[] = {
13384         [ALC861_3ST] = {
13385                 .mixers = { alc861_3ST_mixer },
13386                 .init_verbs = { alc861_threestack_init_verbs },
13387                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13388                 .dac_nids = alc861_dac_nids,
13389                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13390                 .channel_mode = alc861_threestack_modes,
13391                 .need_dac_fix = 1,
13392                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13393                 .adc_nids = alc861_adc_nids,
13394                 .input_mux = &alc861_capture_source,
13395         },
13396         [ALC861_3ST_DIG] = {
13397                 .mixers = { alc861_base_mixer },
13398                 .init_verbs = { alc861_threestack_init_verbs },
13399                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13400                 .dac_nids = alc861_dac_nids,
13401                 .dig_out_nid = ALC861_DIGOUT_NID,
13402                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13403                 .channel_mode = alc861_threestack_modes,
13404                 .need_dac_fix = 1,
13405                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13406                 .adc_nids = alc861_adc_nids,
13407                 .input_mux = &alc861_capture_source,
13408         },
13409         [ALC861_6ST_DIG] = {
13410                 .mixers = { alc861_base_mixer },
13411                 .init_verbs = { alc861_base_init_verbs },
13412                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13413                 .dac_nids = alc861_dac_nids,
13414                 .dig_out_nid = ALC861_DIGOUT_NID,
13415                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
13416                 .channel_mode = alc861_8ch_modes,
13417                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13418                 .adc_nids = alc861_adc_nids,
13419                 .input_mux = &alc861_capture_source,
13420         },
13421         [ALC660_3ST] = {
13422                 .mixers = { alc861_3ST_mixer },
13423                 .init_verbs = { alc861_threestack_init_verbs },
13424                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
13425                 .dac_nids = alc660_dac_nids,
13426                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13427                 .channel_mode = alc861_threestack_modes,
13428                 .need_dac_fix = 1,
13429                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13430                 .adc_nids = alc861_adc_nids,
13431                 .input_mux = &alc861_capture_source,
13432         },
13433         [ALC861_UNIWILL_M31] = {
13434                 .mixers = { alc861_uniwill_m31_mixer },
13435                 .init_verbs = { alc861_uniwill_m31_init_verbs },
13436                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13437                 .dac_nids = alc861_dac_nids,
13438                 .dig_out_nid = ALC861_DIGOUT_NID,
13439                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
13440                 .channel_mode = alc861_uniwill_m31_modes,
13441                 .need_dac_fix = 1,
13442                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13443                 .adc_nids = alc861_adc_nids,
13444                 .input_mux = &alc861_capture_source,
13445         },
13446         [ALC861_TOSHIBA] = {
13447                 .mixers = { alc861_toshiba_mixer },
13448                 .init_verbs = { alc861_base_init_verbs,
13449                                 alc861_toshiba_init_verbs },
13450                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13451                 .dac_nids = alc861_dac_nids,
13452                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13453                 .channel_mode = alc883_3ST_2ch_modes,
13454                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13455                 .adc_nids = alc861_adc_nids,
13456                 .input_mux = &alc861_capture_source,
13457                 .unsol_event = alc861_toshiba_unsol_event,
13458                 .init_hook = alc861_toshiba_automute,
13459         },
13460         [ALC861_ASUS] = {
13461                 .mixers = { alc861_asus_mixer },
13462                 .init_verbs = { alc861_asus_init_verbs },
13463                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13464                 .dac_nids = alc861_dac_nids,
13465                 .dig_out_nid = ALC861_DIGOUT_NID,
13466                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
13467                 .channel_mode = alc861_asus_modes,
13468                 .need_dac_fix = 1,
13469                 .hp_nid = 0x06,
13470                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13471                 .adc_nids = alc861_adc_nids,
13472                 .input_mux = &alc861_capture_source,
13473         },
13474         [ALC861_ASUS_LAPTOP] = {
13475                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
13476                 .init_verbs = { alc861_asus_init_verbs,
13477                                 alc861_asus_laptop_init_verbs },
13478                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13479                 .dac_nids = alc861_dac_nids,
13480                 .dig_out_nid = ALC861_DIGOUT_NID,
13481                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13482                 .channel_mode = alc883_3ST_2ch_modes,
13483                 .need_dac_fix = 1,
13484                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13485                 .adc_nids = alc861_adc_nids,
13486                 .input_mux = &alc861_capture_source,
13487         },
13488 };
13489
13490
13491 static int patch_alc861(struct hda_codec *codec)
13492 {
13493         struct alc_spec *spec;
13494         int board_config;
13495         int err;
13496
13497         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13498         if (spec == NULL)
13499                 return -ENOMEM;
13500
13501         codec->spec = spec;
13502
13503         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
13504                                                   alc861_models,
13505                                                   alc861_cfg_tbl);
13506
13507         if (board_config < 0) {
13508                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
13509                        "trying auto-probe from BIOS...\n");
13510                 board_config = ALC861_AUTO;
13511         }
13512
13513         if (board_config == ALC861_AUTO) {
13514                 /* automatic parse from the BIOS config */
13515                 err = alc861_parse_auto_config(codec);
13516                 if (err < 0) {
13517                         alc_free(codec);
13518                         return err;
13519                 } else if (!err) {
13520                         printk(KERN_INFO
13521                                "hda_codec: Cannot set up configuration "
13522                                "from BIOS.  Using base mode...\n");
13523                    board_config = ALC861_3ST_DIG;
13524                 }
13525         }
13526
13527         if (board_config != ALC861_AUTO)
13528                 setup_preset(spec, &alc861_presets[board_config]);
13529
13530         spec->stream_name_analog = "ALC861 Analog";
13531         spec->stream_analog_playback = &alc861_pcm_analog_playback;
13532         spec->stream_analog_capture = &alc861_pcm_analog_capture;
13533
13534         spec->stream_name_digital = "ALC861 Digital";
13535         spec->stream_digital_playback = &alc861_pcm_digital_playback;
13536         spec->stream_digital_capture = &alc861_pcm_digital_capture;
13537
13538         spec->vmaster_nid = 0x03;
13539
13540         codec->patch_ops = alc_patch_ops;
13541         if (board_config == ALC861_AUTO)
13542                 spec->init_hook = alc861_auto_init;
13543 #ifdef CONFIG_SND_HDA_POWER_SAVE
13544         if (!spec->loopback.amplist)
13545                 spec->loopback.amplist = alc861_loopbacks;
13546 #endif
13547
13548         return 0;
13549 }
13550
13551 /*
13552  * ALC861-VD support
13553  *
13554  * Based on ALC882
13555  *
13556  * In addition, an independent DAC
13557  */
13558 #define ALC861VD_DIGOUT_NID     0x06
13559
13560 static hda_nid_t alc861vd_dac_nids[4] = {
13561         /* front, surr, clfe, side surr */
13562         0x02, 0x03, 0x04, 0x05
13563 };
13564
13565 /* dac_nids for ALC660vd are in a different order - according to
13566  * Realtek's driver.
13567  * This should probably tesult in a different mixer for 6stack models
13568  * of ALC660vd codecs, but for now there is only 3stack mixer
13569  * - and it is the same as in 861vd.
13570  * adc_nids in ALC660vd are (is) the same as in 861vd
13571  */
13572 static hda_nid_t alc660vd_dac_nids[3] = {
13573         /* front, rear, clfe, rear_surr */
13574         0x02, 0x04, 0x03
13575 };
13576
13577 static hda_nid_t alc861vd_adc_nids[1] = {
13578         /* ADC0 */
13579         0x09,
13580 };
13581
13582 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
13583
13584 /* input MUX */
13585 /* FIXME: should be a matrix-type input source selection */
13586 static struct hda_input_mux alc861vd_capture_source = {
13587         .num_items = 4,
13588         .items = {
13589                 { "Mic", 0x0 },
13590                 { "Front Mic", 0x1 },
13591                 { "Line", 0x2 },
13592                 { "CD", 0x4 },
13593         },
13594 };
13595
13596 static struct hda_input_mux alc861vd_dallas_capture_source = {
13597         .num_items = 2,
13598         .items = {
13599                 { "Ext Mic", 0x0 },
13600                 { "Int Mic", 0x1 },
13601         },
13602 };
13603
13604 static struct hda_input_mux alc861vd_hp_capture_source = {
13605         .num_items = 2,
13606         .items = {
13607                 { "Front Mic", 0x0 },
13608                 { "ATAPI Mic", 0x1 },
13609         },
13610 };
13611
13612 #define alc861vd_mux_enum_info alc_mux_enum_info
13613 #define alc861vd_mux_enum_get alc_mux_enum_get
13614 /* ALC861VD has the ALC882-type input selection (but has only one ADC) */
13615 #define alc861vd_mux_enum_put alc882_mux_enum_put
13616
13617 /*
13618  * 2ch mode
13619  */
13620 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
13621         { 2, NULL }
13622 };
13623
13624 /*
13625  * 6ch mode
13626  */
13627 static struct hda_verb alc861vd_6stack_ch6_init[] = {
13628         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13629         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13630         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13631         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13632         { } /* end */
13633 };
13634
13635 /*
13636  * 8ch mode
13637  */
13638 static struct hda_verb alc861vd_6stack_ch8_init[] = {
13639         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13640         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13641         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13642         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13643         { } /* end */
13644 };
13645
13646 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
13647         { 6, alc861vd_6stack_ch6_init },
13648         { 8, alc861vd_6stack_ch8_init },
13649 };
13650
13651 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
13652         {
13653                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13654                 .name = "Channel Mode",
13655                 .info = alc_ch_mode_info,
13656                 .get = alc_ch_mode_get,
13657                 .put = alc_ch_mode_put,
13658         },
13659         { } /* end */
13660 };
13661
13662 static struct snd_kcontrol_new alc861vd_capture_mixer[] = {
13663         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
13664         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
13665
13666         {
13667                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13668                 /* The multiple "Capture Source" controls confuse alsamixer
13669                  * So call somewhat different..
13670                  */
13671                 /* .name = "Capture Source", */
13672                 .name = "Input Source",
13673                 .count = 1,
13674                 .info = alc861vd_mux_enum_info,
13675                 .get = alc861vd_mux_enum_get,
13676                 .put = alc861vd_mux_enum_put,
13677         },
13678         { } /* end */
13679 };
13680
13681 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
13682  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
13683  */
13684 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
13685         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13686         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13687
13688         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13689         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
13690
13691         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
13692                                 HDA_OUTPUT),
13693         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
13694                                 HDA_OUTPUT),
13695         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
13696         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
13697
13698         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
13699         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
13700
13701         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13702
13703         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13704         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13705         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13706
13707         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13708         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13709         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13710
13711         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13712         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13713
13714         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13715         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13716
13717         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13718         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13719
13720         { } /* end */
13721 };
13722
13723 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
13724         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13725         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13726
13727         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13728
13729         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13730         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13731         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13732
13733         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13734         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13735         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13736
13737         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13738         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13739
13740         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13741         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13742
13743         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13744         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13745
13746         { } /* end */
13747 };
13748
13749 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
13750         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13751         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
13752         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13753
13754         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13755
13756         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13757         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13758         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13759
13760         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13761         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13762         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13763
13764         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13765         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13766
13767         { } /* end */
13768 };
13769
13770 /* Pin assignment: Speaker=0x14, HP = 0x15,
13771  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
13772  */
13773 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
13774         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13775         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
13776         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13777         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
13778         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
13779         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13780         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13781         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
13782         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13783         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13784         HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
13785         HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
13786         { } /* end */
13787 };
13788
13789 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
13790  *                 Front Mic=0x18, ATAPI Mic = 0x19,
13791  */
13792 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
13793         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13794         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13795         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13796         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
13797         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13798         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13799         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13800         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13801
13802         { } /* end */
13803 };
13804
13805 /*
13806  * generic initialization of ADC, input mixers and output mixers
13807  */
13808 static struct hda_verb alc861vd_volume_init_verbs[] = {
13809         /*
13810          * Unmute ADC0 and set the default input to mic-in
13811          */
13812         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
13813         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13814
13815         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
13816          * the analog-loopback mixer widget
13817          */
13818         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
13819         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13820         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13821         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13822         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13823         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13824
13825         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
13826         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13827         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13828         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13829         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
13830
13831         /*
13832          * Set up output mixers (0x02 - 0x05)
13833          */
13834         /* set vol=0 to output mixers */
13835         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13836         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13837         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13838         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13839
13840         /* set up input amps for analog loopback */
13841         /* Amp Indices: DAC = 0, mixer = 1 */
13842         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13843         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13844         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13845         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13846         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13847         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13848         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13849         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13850
13851         { }
13852 };
13853
13854 /*
13855  * 3-stack pin configuration:
13856  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
13857  */
13858 static struct hda_verb alc861vd_3stack_init_verbs[] = {
13859         /*
13860          * Set pin mode and muting
13861          */
13862         /* set front pin widgets 0x14 for output */
13863         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13864         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13865         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13866
13867         /* Mic (rear) pin: input vref at 80% */
13868         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13869         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13870         /* Front Mic pin: input vref at 80% */
13871         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13872         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13873         /* Line In pin: input */
13874         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13875         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13876         /* Line-2 In: Headphone output (output 0 - 0x0c) */
13877         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13878         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13879         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13880         /* CD pin widget for input */
13881         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13882
13883         { }
13884 };
13885
13886 /*
13887  * 6-stack pin configuration:
13888  */
13889 static struct hda_verb alc861vd_6stack_init_verbs[] = {
13890         /*
13891          * Set pin mode and muting
13892          */
13893         /* set front pin widgets 0x14 for output */
13894         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13895         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13896         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13897
13898         /* Rear Pin: output 1 (0x0d) */
13899         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13900         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13901         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13902         /* CLFE Pin: output 2 (0x0e) */
13903         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13904         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13905         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
13906         /* Side Pin: output 3 (0x0f) */
13907         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13908         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13909         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
13910
13911         /* Mic (rear) pin: input vref at 80% */
13912         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13913         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13914         /* Front Mic pin: input vref at 80% */
13915         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13916         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13917         /* Line In pin: input */
13918         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13919         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13920         /* Line-2 In: Headphone output (output 0 - 0x0c) */
13921         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13922         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13923         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13924         /* CD pin widget for input */
13925         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13926
13927         { }
13928 };
13929
13930 static struct hda_verb alc861vd_eapd_verbs[] = {
13931         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13932         { }
13933 };
13934
13935 static struct hda_verb alc660vd_eapd_verbs[] = {
13936         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13937         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
13938         { }
13939 };
13940
13941 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
13942         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13943         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13944         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
13945         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13946         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13947         {}
13948 };
13949
13950 /* toggle speaker-output according to the hp-jack state */
13951 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
13952 {
13953         unsigned int present;
13954         unsigned char bits;
13955
13956         present = snd_hda_codec_read(codec, 0x1b, 0,
13957                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13958         bits = present ? HDA_AMP_MUTE : 0;
13959         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
13960                                  HDA_AMP_MUTE, bits);
13961 }
13962
13963 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
13964 {
13965         unsigned int present;
13966         unsigned char bits;
13967
13968         present = snd_hda_codec_read(codec, 0x18, 0,
13969                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13970         bits = present ? HDA_AMP_MUTE : 0;
13971         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
13972                                  HDA_AMP_MUTE, bits);
13973 }
13974
13975 static void alc861vd_lenovo_automute(struct hda_codec *codec)
13976 {
13977         alc861vd_lenovo_hp_automute(codec);
13978         alc861vd_lenovo_mic_automute(codec);
13979 }
13980
13981 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
13982                                         unsigned int res)
13983 {
13984         switch (res >> 26) {
13985         case ALC880_HP_EVENT:
13986                 alc861vd_lenovo_hp_automute(codec);
13987                 break;
13988         case ALC880_MIC_EVENT:
13989                 alc861vd_lenovo_mic_automute(codec);
13990                 break;
13991         }
13992 }
13993
13994 static struct hda_verb alc861vd_dallas_verbs[] = {
13995         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13996         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13997         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13998         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13999
14000         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14001         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14002         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14003         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14004         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14005         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14006         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14007         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14008
14009         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14010         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14011         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14012         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14013         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14014         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14015         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14016         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14017
14018         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14019         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14020         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14021         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14022         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14023         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14024         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14025         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14026
14027         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14028         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14029         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14030         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14031
14032         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14033         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14034         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14035
14036         { } /* end */
14037 };
14038
14039 /* toggle speaker-output according to the hp-jack state */
14040 static void alc861vd_dallas_automute(struct hda_codec *codec)
14041 {
14042         unsigned int present;
14043
14044         present = snd_hda_codec_read(codec, 0x15, 0,
14045                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14046         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14047                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14048 }
14049
14050 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
14051 {
14052         if ((res >> 26) == ALC880_HP_EVENT)
14053                 alc861vd_dallas_automute(codec);
14054 }
14055
14056 #ifdef CONFIG_SND_HDA_POWER_SAVE
14057 #define alc861vd_loopbacks      alc880_loopbacks
14058 #endif
14059
14060 /* pcm configuration: identiacal with ALC880 */
14061 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
14062 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
14063 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
14064 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
14065
14066 /*
14067  * configuration and preset
14068  */
14069 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
14070         [ALC660VD_3ST]          = "3stack-660",
14071         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
14072         [ALC861VD_3ST]          = "3stack",
14073         [ALC861VD_3ST_DIG]      = "3stack-digout",
14074         [ALC861VD_6ST_DIG]      = "6stack-digout",
14075         [ALC861VD_LENOVO]       = "lenovo",
14076         [ALC861VD_DALLAS]       = "dallas",
14077         [ALC861VD_HP]           = "hp",
14078         [ALC861VD_AUTO]         = "auto",
14079 };
14080
14081 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
14082         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
14083         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
14084         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
14085         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
14086         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC861VD_LENOVO),
14087         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
14088         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
14089         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
14090         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
14091         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
14092         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
14093         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
14094         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
14095         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
14096         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
14097         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 N200", ALC861VD_LENOVO),
14098         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
14099         {}
14100 };
14101
14102 static struct alc_config_preset alc861vd_presets[] = {
14103         [ALC660VD_3ST] = {
14104                 .mixers = { alc861vd_3st_mixer },
14105                 .init_verbs = { alc861vd_volume_init_verbs,
14106                                  alc861vd_3stack_init_verbs },
14107                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14108                 .dac_nids = alc660vd_dac_nids,
14109                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14110                 .channel_mode = alc861vd_3stack_2ch_modes,
14111                 .input_mux = &alc861vd_capture_source,
14112         },
14113         [ALC660VD_3ST_DIG] = {
14114                 .mixers = { alc861vd_3st_mixer },
14115                 .init_verbs = { alc861vd_volume_init_verbs,
14116                                  alc861vd_3stack_init_verbs },
14117                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14118                 .dac_nids = alc660vd_dac_nids,
14119                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14120                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14121                 .channel_mode = alc861vd_3stack_2ch_modes,
14122                 .input_mux = &alc861vd_capture_source,
14123         },
14124         [ALC861VD_3ST] = {
14125                 .mixers = { alc861vd_3st_mixer },
14126                 .init_verbs = { alc861vd_volume_init_verbs,
14127                                  alc861vd_3stack_init_verbs },
14128                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14129                 .dac_nids = alc861vd_dac_nids,
14130                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14131                 .channel_mode = alc861vd_3stack_2ch_modes,
14132                 .input_mux = &alc861vd_capture_source,
14133         },
14134         [ALC861VD_3ST_DIG] = {
14135                 .mixers = { alc861vd_3st_mixer },
14136                 .init_verbs = { alc861vd_volume_init_verbs,
14137                                  alc861vd_3stack_init_verbs },
14138                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14139                 .dac_nids = alc861vd_dac_nids,
14140                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14141                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14142                 .channel_mode = alc861vd_3stack_2ch_modes,
14143                 .input_mux = &alc861vd_capture_source,
14144         },
14145         [ALC861VD_6ST_DIG] = {
14146                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
14147                 .init_verbs = { alc861vd_volume_init_verbs,
14148                                 alc861vd_6stack_init_verbs },
14149                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14150                 .dac_nids = alc861vd_dac_nids,
14151                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14152                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
14153                 .channel_mode = alc861vd_6stack_modes,
14154                 .input_mux = &alc861vd_capture_source,
14155         },
14156         [ALC861VD_LENOVO] = {
14157                 .mixers = { alc861vd_lenovo_mixer },
14158                 .init_verbs = { alc861vd_volume_init_verbs,
14159                                 alc861vd_3stack_init_verbs,
14160                                 alc861vd_eapd_verbs,
14161                                 alc861vd_lenovo_unsol_verbs },
14162                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14163                 .dac_nids = alc660vd_dac_nids,
14164                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14165                 .channel_mode = alc861vd_3stack_2ch_modes,
14166                 .input_mux = &alc861vd_capture_source,
14167                 .unsol_event = alc861vd_lenovo_unsol_event,
14168                 .init_hook = alc861vd_lenovo_automute,
14169         },
14170         [ALC861VD_DALLAS] = {
14171                 .mixers = { alc861vd_dallas_mixer },
14172                 .init_verbs = { alc861vd_dallas_verbs },
14173                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14174                 .dac_nids = alc861vd_dac_nids,
14175                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14176                 .channel_mode = alc861vd_3stack_2ch_modes,
14177                 .input_mux = &alc861vd_dallas_capture_source,
14178                 .unsol_event = alc861vd_dallas_unsol_event,
14179                 .init_hook = alc861vd_dallas_automute,
14180         },
14181         [ALC861VD_HP] = {
14182                 .mixers = { alc861vd_hp_mixer },
14183                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
14184                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14185                 .dac_nids = alc861vd_dac_nids,
14186                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14187                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14188                 .channel_mode = alc861vd_3stack_2ch_modes,
14189                 .input_mux = &alc861vd_hp_capture_source,
14190                 .unsol_event = alc861vd_dallas_unsol_event,
14191                 .init_hook = alc861vd_dallas_automute,
14192         },
14193 };
14194
14195 /*
14196  * BIOS auto configuration
14197  */
14198 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
14199                                 hda_nid_t nid, int pin_type, int dac_idx)
14200 {
14201         alc_set_pin_output(codec, nid, pin_type);
14202 }
14203
14204 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
14205 {
14206         struct alc_spec *spec = codec->spec;
14207         int i;
14208
14209         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
14210         for (i = 0; i <= HDA_SIDE; i++) {
14211                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14212                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14213                 if (nid)
14214                         alc861vd_auto_set_output_and_unmute(codec, nid,
14215                                                             pin_type, i);
14216         }
14217 }
14218
14219
14220 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
14221 {
14222         struct alc_spec *spec = codec->spec;
14223         hda_nid_t pin;
14224
14225         pin = spec->autocfg.hp_pins[0];
14226         if (pin) /* connect to front and  use dac 0 */
14227                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
14228         pin = spec->autocfg.speaker_pins[0];
14229         if (pin)
14230                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14231 }
14232
14233 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
14234 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
14235
14236 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
14237 {
14238         struct alc_spec *spec = codec->spec;
14239         int i;
14240
14241         for (i = 0; i < AUTO_PIN_LAST; i++) {
14242                 hda_nid_t nid = spec->autocfg.input_pins[i];
14243                 if (alc861vd_is_input_pin(nid)) {
14244                         snd_hda_codec_write(codec, nid, 0,
14245                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
14246                                         i <= AUTO_PIN_FRONT_MIC ?
14247                                                         PIN_VREF80 : PIN_IN);
14248                         if (nid != ALC861VD_PIN_CD_NID)
14249                                 snd_hda_codec_write(codec, nid, 0,
14250                                                 AC_VERB_SET_AMP_GAIN_MUTE,
14251                                                 AMP_OUT_MUTE);
14252                 }
14253         }
14254 }
14255
14256 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
14257
14258 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
14259 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
14260
14261 /* add playback controls from the parsed DAC table */
14262 /* Based on ALC880 version. But ALC861VD has separate,
14263  * different NIDs for mute/unmute switch and volume control */
14264 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
14265                                              const struct auto_pin_cfg *cfg)
14266 {
14267         char name[32];
14268         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
14269         hda_nid_t nid_v, nid_s;
14270         int i, err;
14271
14272         for (i = 0; i < cfg->line_outs; i++) {
14273                 if (!spec->multiout.dac_nids[i])
14274                         continue;
14275                 nid_v = alc861vd_idx_to_mixer_vol(
14276                                 alc880_dac_to_idx(
14277                                         spec->multiout.dac_nids[i]));
14278                 nid_s = alc861vd_idx_to_mixer_switch(
14279                                 alc880_dac_to_idx(
14280                                         spec->multiout.dac_nids[i]));
14281
14282                 if (i == 2) {
14283                         /* Center/LFE */
14284                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14285                                           "Center Playback Volume",
14286                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
14287                                                               HDA_OUTPUT));
14288                         if (err < 0)
14289                                 return err;
14290                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14291                                           "LFE Playback Volume",
14292                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
14293                                                               HDA_OUTPUT));
14294                         if (err < 0)
14295                                 return err;
14296                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14297                                           "Center Playback Switch",
14298                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
14299                                                               HDA_INPUT));
14300                         if (err < 0)
14301                                 return err;
14302                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14303                                           "LFE Playback Switch",
14304                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
14305                                                               HDA_INPUT));
14306                         if (err < 0)
14307                                 return err;
14308                 } else {
14309                         sprintf(name, "%s Playback Volume", chname[i]);
14310                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14311                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
14312                                                               HDA_OUTPUT));
14313                         if (err < 0)
14314                                 return err;
14315                         sprintf(name, "%s Playback Switch", chname[i]);
14316                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14317                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
14318                                                               HDA_INPUT));
14319                         if (err < 0)
14320                                 return err;
14321                 }
14322         }
14323         return 0;
14324 }
14325
14326 /* add playback controls for speaker and HP outputs */
14327 /* Based on ALC880 version. But ALC861VD has separate,
14328  * different NIDs for mute/unmute switch and volume control */
14329 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
14330                                         hda_nid_t pin, const char *pfx)
14331 {
14332         hda_nid_t nid_v, nid_s;
14333         int err;
14334         char name[32];
14335
14336         if (!pin)
14337                 return 0;
14338
14339         if (alc880_is_fixed_pin(pin)) {
14340                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14341                 /* specify the DAC as the extra output */
14342                 if (!spec->multiout.hp_nid)
14343                         spec->multiout.hp_nid = nid_v;
14344                 else
14345                         spec->multiout.extra_out_nid[0] = nid_v;
14346                 /* control HP volume/switch on the output mixer amp */
14347                 nid_v = alc861vd_idx_to_mixer_vol(
14348                                 alc880_fixed_pin_idx(pin));
14349                 nid_s = alc861vd_idx_to_mixer_switch(
14350                                 alc880_fixed_pin_idx(pin));
14351
14352                 sprintf(name, "%s Playback Volume", pfx);
14353                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14354                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
14355                 if (err < 0)
14356                         return err;
14357                 sprintf(name, "%s Playback Switch", pfx);
14358                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14359                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
14360                 if (err < 0)
14361                         return err;
14362         } else if (alc880_is_multi_pin(pin)) {
14363                 /* set manual connection */
14364                 /* we have only a switch on HP-out PIN */
14365                 sprintf(name, "%s Playback Switch", pfx);
14366                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14367                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
14368                 if (err < 0)
14369                         return err;
14370         }
14371         return 0;
14372 }
14373
14374 /* parse the BIOS configuration and set up the alc_spec
14375  * return 1 if successful, 0 if the proper config is not found,
14376  * or a negative error code
14377  * Based on ALC880 version - had to change it to override
14378  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
14379 static int alc861vd_parse_auto_config(struct hda_codec *codec)
14380 {
14381         struct alc_spec *spec = codec->spec;
14382         int err;
14383         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
14384
14385         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14386                                            alc861vd_ignore);
14387         if (err < 0)
14388                 return err;
14389         if (!spec->autocfg.line_outs)
14390                 return 0; /* can't find valid BIOS pin config */
14391
14392         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
14393         if (err < 0)
14394                 return err;
14395         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
14396         if (err < 0)
14397                 return err;
14398         err = alc861vd_auto_create_extra_out(spec,
14399                                              spec->autocfg.speaker_pins[0],
14400                                              "Speaker");
14401         if (err < 0)
14402                 return err;
14403         err = alc861vd_auto_create_extra_out(spec,
14404                                              spec->autocfg.hp_pins[0],
14405                                              "Headphone");
14406         if (err < 0)
14407                 return err;
14408         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
14409         if (err < 0)
14410                 return err;
14411
14412         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14413
14414         if (spec->autocfg.dig_out_pin)
14415                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
14416
14417         if (spec->kctl_alloc)
14418                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
14419
14420         spec->init_verbs[spec->num_init_verbs++]
14421                 = alc861vd_volume_init_verbs;
14422
14423         spec->num_mux_defs = 1;
14424         spec->input_mux = &spec->private_imux;
14425
14426         err = alc_auto_add_mic_boost(codec);
14427         if (err < 0)
14428                 return err;
14429
14430         return 1;
14431 }
14432
14433 /* additional initialization for auto-configuration model */
14434 static void alc861vd_auto_init(struct hda_codec *codec)
14435 {
14436         struct alc_spec *spec = codec->spec;
14437         alc861vd_auto_init_multi_out(codec);
14438         alc861vd_auto_init_hp_out(codec);
14439         alc861vd_auto_init_analog_input(codec);
14440         alc861vd_auto_init_input_src(codec);
14441         if (spec->unsol_event)
14442                 alc_inithook(codec);
14443 }
14444
14445 static int patch_alc861vd(struct hda_codec *codec)
14446 {
14447         struct alc_spec *spec;
14448         int err, board_config;
14449
14450         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14451         if (spec == NULL)
14452                 return -ENOMEM;
14453
14454         codec->spec = spec;
14455
14456         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
14457                                                   alc861vd_models,
14458                                                   alc861vd_cfg_tbl);
14459
14460         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
14461                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
14462                         "ALC861VD, trying auto-probe from BIOS...\n");
14463                 board_config = ALC861VD_AUTO;
14464         }
14465
14466         if (board_config == ALC861VD_AUTO) {
14467                 /* automatic parse from the BIOS config */
14468                 err = alc861vd_parse_auto_config(codec);
14469                 if (err < 0) {
14470                         alc_free(codec);
14471                         return err;
14472                 } else if (!err) {
14473                         printk(KERN_INFO
14474                                "hda_codec: Cannot set up configuration "
14475                                "from BIOS.  Using base mode...\n");
14476                         board_config = ALC861VD_3ST;
14477                 }
14478         }
14479
14480         if (board_config != ALC861VD_AUTO)
14481                 setup_preset(spec, &alc861vd_presets[board_config]);
14482
14483         if (codec->vendor_id == 0x10ec0660) {
14484                 spec->stream_name_analog = "ALC660-VD Analog";
14485                 spec->stream_name_digital = "ALC660-VD Digital";
14486                 /* always turn on EAPD */
14487                 spec->init_verbs[spec->num_init_verbs++] = alc660vd_eapd_verbs;
14488         } else {
14489                 spec->stream_name_analog = "ALC861VD Analog";
14490                 spec->stream_name_digital = "ALC861VD Digital";
14491         }
14492
14493         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
14494         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
14495
14496         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
14497         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
14498
14499         spec->adc_nids = alc861vd_adc_nids;
14500         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
14501         spec->capsrc_nids = alc861vd_capsrc_nids;
14502
14503         spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
14504         spec->num_mixers++;
14505
14506         spec->vmaster_nid = 0x02;
14507
14508         codec->patch_ops = alc_patch_ops;
14509
14510         if (board_config == ALC861VD_AUTO)
14511                 spec->init_hook = alc861vd_auto_init;
14512 #ifdef CONFIG_SND_HDA_POWER_SAVE
14513         if (!spec->loopback.amplist)
14514                 spec->loopback.amplist = alc861vd_loopbacks;
14515 #endif
14516
14517         return 0;
14518 }
14519
14520 /*
14521  * ALC662 support
14522  *
14523  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
14524  * configuration.  Each pin widget can choose any input DACs and a mixer.
14525  * Each ADC is connected from a mixer of all inputs.  This makes possible
14526  * 6-channel independent captures.
14527  *
14528  * In addition, an independent DAC for the multi-playback (not used in this
14529  * driver yet).
14530  */
14531 #define ALC662_DIGOUT_NID       0x06
14532 #define ALC662_DIGIN_NID        0x0a
14533
14534 static hda_nid_t alc662_dac_nids[4] = {
14535         /* front, rear, clfe, rear_surr */
14536         0x02, 0x03, 0x04
14537 };
14538
14539 static hda_nid_t alc662_adc_nids[1] = {
14540         /* ADC1-2 */
14541         0x09,
14542 };
14543
14544 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
14545
14546 /* input MUX */
14547 /* FIXME: should be a matrix-type input source selection */
14548 static struct hda_input_mux alc662_capture_source = {
14549         .num_items = 4,
14550         .items = {
14551                 { "Mic", 0x0 },
14552                 { "Front Mic", 0x1 },
14553                 { "Line", 0x2 },
14554                 { "CD", 0x4 },
14555         },
14556 };
14557
14558 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
14559         .num_items = 2,
14560         .items = {
14561                 { "Mic", 0x1 },
14562                 { "Line", 0x2 },
14563         },
14564 };
14565
14566 static struct hda_input_mux alc662_eeepc_capture_source = {
14567         .num_items = 2,
14568         .items = {
14569                 { "i-Mic", 0x1 },
14570                 { "e-Mic", 0x0 },
14571         },
14572 };
14573
14574 static struct hda_input_mux alc663_capture_source = {
14575         .num_items = 3,
14576         .items = {
14577                 { "Mic", 0x0 },
14578                 { "Front Mic", 0x1 },
14579                 { "Line", 0x2 },
14580         },
14581 };
14582
14583 static struct hda_input_mux alc663_m51va_capture_source = {
14584         .num_items = 2,
14585         .items = {
14586                 { "Ext-Mic", 0x0 },
14587                 { "D-Mic", 0x9 },
14588         },
14589 };
14590
14591 #define alc662_mux_enum_info alc_mux_enum_info
14592 #define alc662_mux_enum_get alc_mux_enum_get
14593 #define alc662_mux_enum_put alc882_mux_enum_put
14594
14595 /*
14596  * 2ch mode
14597  */
14598 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
14599         { 2, NULL }
14600 };
14601
14602 /*
14603  * 2ch mode
14604  */
14605 static struct hda_verb alc662_3ST_ch2_init[] = {
14606         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
14607         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14608         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
14609         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14610         { } /* end */
14611 };
14612
14613 /*
14614  * 6ch mode
14615  */
14616 static struct hda_verb alc662_3ST_ch6_init[] = {
14617         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14618         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14619         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
14620         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14621         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14622         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
14623         { } /* end */
14624 };
14625
14626 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
14627         { 2, alc662_3ST_ch2_init },
14628         { 6, alc662_3ST_ch6_init },
14629 };
14630
14631 /*
14632  * 2ch mode
14633  */
14634 static struct hda_verb alc662_sixstack_ch6_init[] = {
14635         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14636         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14637         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14638         { } /* end */
14639 };
14640
14641 /*
14642  * 6ch mode
14643  */
14644 static struct hda_verb alc662_sixstack_ch8_init[] = {
14645         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14646         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14647         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14648         { } /* end */
14649 };
14650
14651 static struct hda_channel_mode alc662_5stack_modes[2] = {
14652         { 2, alc662_sixstack_ch6_init },
14653         { 6, alc662_sixstack_ch8_init },
14654 };
14655
14656 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14657  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14658  */
14659
14660 static struct snd_kcontrol_new alc662_base_mixer[] = {
14661         /* output mixer control */
14662         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
14663         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14664         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
14665         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
14666         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14667         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14668         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
14669         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
14670         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14671
14672         /*Input mixer control */
14673         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
14674         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
14675         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
14676         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
14677         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
14678         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
14679         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
14680         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
14681         { } /* end */
14682 };
14683
14684 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
14685         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14686         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14687         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14688         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14689         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14690         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14691         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14692         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14693         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14694         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14695         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14696         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14697         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14698         { } /* end */
14699 };
14700
14701 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
14702         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14703         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14704         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14705         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
14706         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14707         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14708         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
14709         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
14710         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14711         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14712         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14713         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14714         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14715         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14716         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14717         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14718         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14719         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14720         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14721         { } /* end */
14722 };
14723
14724 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
14725         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14726         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
14727         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14728         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
14729         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14730         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14731         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14732         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14733         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14734         { } /* end */
14735 };
14736
14737 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
14738         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14739
14740         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14741         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14742
14743         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
14744         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14745         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14746
14747         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
14748         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14749         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14750         { } /* end */
14751 };
14752
14753 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
14754         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14755         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14756         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14757         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
14758         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14759         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14760         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
14761         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
14762         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14763         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
14764         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14765         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14766         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14767         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14768         { } /* end */
14769 };
14770
14771 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
14772         .ops = &snd_hda_bind_vol,
14773         .values = {
14774                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
14775                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
14776                 0
14777         },
14778 };
14779
14780 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
14781         .ops = &snd_hda_bind_sw,
14782         .values = {
14783                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14784                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
14785                 0
14786         },
14787 };
14788
14789 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
14790         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14791         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
14792         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14793         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14794         { } /* end */
14795 };
14796
14797 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
14798         .ops = &snd_hda_bind_sw,
14799         .values = {
14800                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14801                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
14802                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
14803                 0
14804         },
14805 };
14806
14807 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
14808         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14809         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
14810         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14811         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14812         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14813         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14814
14815         { } /* end */
14816 };
14817
14818 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
14819         .ops = &snd_hda_bind_sw,
14820         .values = {
14821                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14822                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
14823                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
14824                 0
14825         },
14826 };
14827
14828 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
14829         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14830         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
14831         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14832         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14833         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14834         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14835         { } /* end */
14836 };
14837
14838 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
14839         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14840         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14841         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14842         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14843         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14844         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14845         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14846         { } /* end */
14847 };
14848
14849 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
14850         .ops = &snd_hda_bind_vol,
14851         .values = {
14852                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
14853                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
14854                 0
14855         },
14856 };
14857
14858 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
14859         .ops = &snd_hda_bind_sw,
14860         .values = {
14861                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14862                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
14863                 0
14864         },
14865 };
14866
14867 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
14868         HDA_BIND_VOL("Master Playback Volume",
14869                                 &alc663_asus_two_bind_master_vol),
14870         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
14871         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14872         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
14873         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14874         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14875         { } /* end */
14876 };
14877
14878 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
14879         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14880         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
14881         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14882         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
14883         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14884         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14885         { } /* end */
14886 };
14887
14888 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
14889         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14890         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14891         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14892         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
14893         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
14894
14895         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14896         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14897         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14898         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14899         { } /* end */
14900 };
14901
14902 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
14903         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14904         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14905         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
14906
14907         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14908         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14909         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14910         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14911         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14912         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14913         { } /* end */
14914 };
14915
14916 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
14917         {
14918                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14919                 .name = "Channel Mode",
14920                 .info = alc_ch_mode_info,
14921                 .get = alc_ch_mode_get,
14922                 .put = alc_ch_mode_put,
14923         },
14924         { } /* end */
14925 };
14926
14927 static struct hda_verb alc662_init_verbs[] = {
14928         /* ADC: mute amp left and right */
14929         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14930         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14931         /* Front mixer: unmute input/output amp left and right (volume = 0) */
14932
14933         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14934         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14935         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14936         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14937         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14938
14939         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14940         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14941         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14942         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14943         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14944         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14945
14946         /* Front Pin: output 0 (0x0c) */
14947         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14948         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14949
14950         /* Rear Pin: output 1 (0x0d) */
14951         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14952         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14953
14954         /* CLFE Pin: output 2 (0x0e) */
14955         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14956         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14957
14958         /* Mic (rear) pin: input vref at 80% */
14959         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14960         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14961         /* Front Mic pin: input vref at 80% */
14962         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14963         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14964         /* Line In pin: input */
14965         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14966         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14967         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14968         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14969         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14970         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14971         /* CD pin widget for input */
14972         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14973
14974         /* FIXME: use matrix-type input source selection */
14975         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
14976         /* Input mixer */
14977         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14978         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14979         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14980         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14981
14982         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14983         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14984         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14985         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14986
14987         /* always trun on EAPD */
14988         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14989         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
14990
14991         { }
14992 };
14993
14994 static struct hda_verb alc662_sue_init_verbs[] = {
14995         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
14996         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
14997         {}
14998 };
14999
15000 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
15001         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15002         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15003         {}
15004 };
15005
15006 /* Set Unsolicited Event*/
15007 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
15008         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15009         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15010         {}
15011 };
15012
15013 /*
15014  * generic initialization of ADC, input mixers and output mixers
15015  */
15016 static struct hda_verb alc662_auto_init_verbs[] = {
15017         /*
15018          * Unmute ADC and set the default input to mic-in
15019          */
15020         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15021         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15022
15023         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
15024          * mixer widget
15025          * Note: PASD motherboards uses the Line In 2 as the input for front
15026          * panel mic (mic 2)
15027          */
15028         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
15029         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15030         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15031         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15032         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15033         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15034
15035         /*
15036          * Set up output mixers (0x0c - 0x0f)
15037          */
15038         /* set vol=0 to output mixers */
15039         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15040         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15041         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15042
15043         /* set up input amps for analog loopback */
15044         /* Amp Indices: DAC = 0, mixer = 1 */
15045         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15046         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15047         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15048         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15049         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15050         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15051
15052
15053         /* FIXME: use matrix-type input source selection */
15054         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15055         /* Input mixer */
15056         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15057         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15058         { }
15059 };
15060
15061 /* additional verbs for ALC663 */
15062 static struct hda_verb alc663_auto_init_verbs[] = {
15063         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15064         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15065         { }
15066 };
15067
15068 static struct hda_verb alc663_m51va_init_verbs[] = {
15069         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15070         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15071         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15072         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15073         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15074         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15075         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
15076         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15077         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15078         {}
15079 };
15080
15081 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
15082         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15083         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15084         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15085         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15086         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15087         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15088         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15089         {}
15090 };
15091
15092 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
15093         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15094         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15095         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15096         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15097         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15098         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15099         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15100         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15101         {}
15102 };
15103
15104 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
15105         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15106         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15107         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15108         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15109         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15110         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15111         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15112         {}
15113 };
15114
15115 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
15116         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15117         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15118         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15119         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15120         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15121         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15122         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15123         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15124         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15125         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15126         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15127         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15128         {}
15129 };
15130
15131 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
15132         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15133         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15134         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15135         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15136         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15137         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15138         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15139         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15140         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15141         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15142         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15143         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15144         {}
15145 };
15146
15147 static struct hda_verb alc663_g71v_init_verbs[] = {
15148         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15149         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
15150         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
15151
15152         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15153         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15154         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15155
15156         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15157         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
15158         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15159         {}
15160 };
15161
15162 static struct hda_verb alc663_g50v_init_verbs[] = {
15163         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15164         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15165         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15166
15167         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15168         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15169         {}
15170 };
15171
15172 static struct hda_verb alc662_ecs_init_verbs[] = {
15173         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
15174         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15175         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15176         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15177         {}
15178 };
15179
15180 /* capture mixer elements */
15181 static struct snd_kcontrol_new alc662_capture_mixer[] = {
15182         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
15183         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
15184         {
15185                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15186                 /* The multiple "Capture Source" controls confuse alsamixer
15187                  * So call somewhat different..
15188                  */
15189                 /* .name = "Capture Source", */
15190                 .name = "Input Source",
15191                 .count = 1,
15192                 .info = alc662_mux_enum_info,
15193                 .get = alc662_mux_enum_get,
15194                 .put = alc662_mux_enum_put,
15195         },
15196         { } /* end */
15197 };
15198
15199 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
15200         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
15201         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
15202         { } /* end */
15203 };
15204
15205 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
15206 {
15207         unsigned int present;
15208         unsigned char bits;
15209
15210         present = snd_hda_codec_read(codec, 0x14, 0,
15211                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15212         bits = present ? HDA_AMP_MUTE : 0;
15213         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15214                                  HDA_AMP_MUTE, bits);
15215 }
15216
15217 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
15218 {
15219         unsigned int present;
15220         unsigned char bits;
15221
15222         present = snd_hda_codec_read(codec, 0x1b, 0,
15223                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15224         bits = present ? HDA_AMP_MUTE : 0;
15225         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15226                                  HDA_AMP_MUTE, bits);
15227         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15228                                  HDA_AMP_MUTE, bits);
15229 }
15230
15231 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
15232                                            unsigned int res)
15233 {
15234         if ((res >> 26) == ALC880_HP_EVENT)
15235                 alc662_lenovo_101e_all_automute(codec);
15236         if ((res >> 26) == ALC880_FRONT_EVENT)
15237                 alc662_lenovo_101e_ispeaker_automute(codec);
15238 }
15239
15240 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
15241 {
15242         unsigned int present;
15243
15244         present = snd_hda_codec_read(codec, 0x18, 0,
15245                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15246         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15247                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15248         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15249                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15250         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15251                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15252         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15253                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15254 }
15255
15256 /* unsolicited event for HP jack sensing */
15257 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
15258                                      unsigned int res)
15259 {
15260         if ((res >> 26) == ALC880_HP_EVENT)
15261                 alc262_hippo1_automute( codec );
15262
15263         if ((res >> 26) == ALC880_MIC_EVENT)
15264                 alc662_eeepc_mic_automute(codec);
15265 }
15266
15267 static void alc662_eeepc_inithook(struct hda_codec *codec)
15268 {
15269         alc262_hippo1_automute( codec );
15270         alc662_eeepc_mic_automute(codec);
15271 }
15272
15273 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
15274 {
15275         unsigned int mute;
15276         unsigned int present;
15277
15278         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
15279         present = snd_hda_codec_read(codec, 0x14, 0,
15280                                      AC_VERB_GET_PIN_SENSE, 0);
15281         present = (present & 0x80000000) != 0;
15282         if (present) {
15283                 /* mute internal speaker */
15284                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15285                                         HDA_AMP_MUTE, HDA_AMP_MUTE);
15286         } else {
15287                 /* unmute internal speaker if necessary */
15288                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
15289                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15290                                         HDA_AMP_MUTE, mute);
15291         }
15292 }
15293
15294 /* unsolicited event for HP jack sensing */
15295 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
15296                                           unsigned int res)
15297 {
15298         if ((res >> 26) == ALC880_HP_EVENT)
15299                 alc662_eeepc_ep20_automute(codec);
15300 }
15301
15302 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
15303 {
15304         alc662_eeepc_ep20_automute(codec);
15305 }
15306
15307 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
15308 {
15309         unsigned int present;
15310         unsigned char bits;
15311
15312         present = snd_hda_codec_read(codec, 0x21, 0,
15313                         AC_VERB_GET_PIN_SENSE, 0)
15314                         & AC_PINSENSE_PRESENCE;
15315         bits = present ? HDA_AMP_MUTE : 0;
15316         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15317                                 AMP_IN_MUTE(0), bits);
15318         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15319                                 AMP_IN_MUTE(0), bits);
15320 }
15321
15322 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
15323 {
15324         unsigned int present;
15325         unsigned char bits;
15326
15327         present = snd_hda_codec_read(codec, 0x21, 0,
15328                         AC_VERB_GET_PIN_SENSE, 0)
15329                         & AC_PINSENSE_PRESENCE;
15330         bits = present ? HDA_AMP_MUTE : 0;
15331         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15332                                 AMP_IN_MUTE(0), bits);
15333         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15334                                 AMP_IN_MUTE(0), bits);
15335         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15336                                 AMP_IN_MUTE(0), bits);
15337         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15338                                 AMP_IN_MUTE(0), bits);
15339 }
15340
15341 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
15342 {
15343         unsigned int present;
15344         unsigned char bits;
15345
15346         present = snd_hda_codec_read(codec, 0x15, 0,
15347                         AC_VERB_GET_PIN_SENSE, 0)
15348                         & AC_PINSENSE_PRESENCE;
15349         bits = present ? HDA_AMP_MUTE : 0;
15350         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15351                                 AMP_IN_MUTE(0), bits);
15352         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15353                                 AMP_IN_MUTE(0), bits);
15354         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15355                                 AMP_IN_MUTE(0), bits);
15356         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15357                                 AMP_IN_MUTE(0), bits);
15358 }
15359
15360 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
15361 {
15362         unsigned int present;
15363         unsigned char bits;
15364
15365         present = snd_hda_codec_read(codec, 0x1b, 0,
15366                         AC_VERB_GET_PIN_SENSE, 0)
15367                         & AC_PINSENSE_PRESENCE;
15368         bits = present ? 0 : PIN_OUT;
15369         snd_hda_codec_write(codec, 0x14, 0,
15370                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
15371 }
15372
15373 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
15374 {
15375         unsigned int present1, present2;
15376
15377         present1 = snd_hda_codec_read(codec, 0x21, 0,
15378                         AC_VERB_GET_PIN_SENSE, 0)
15379                         & AC_PINSENSE_PRESENCE;
15380         present2 = snd_hda_codec_read(codec, 0x15, 0,
15381                         AC_VERB_GET_PIN_SENSE, 0)
15382                         & AC_PINSENSE_PRESENCE;
15383
15384         if (present1 || present2) {
15385                 snd_hda_codec_write_cache(codec, 0x14, 0,
15386                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
15387         } else {
15388                 snd_hda_codec_write_cache(codec, 0x14, 0,
15389                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
15390         }
15391 }
15392
15393 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
15394 {
15395         unsigned int present1, present2;
15396
15397         present1 = snd_hda_codec_read(codec, 0x1b, 0,
15398                                 AC_VERB_GET_PIN_SENSE, 0)
15399                                 & AC_PINSENSE_PRESENCE;
15400         present2 = snd_hda_codec_read(codec, 0x15, 0,
15401                                 AC_VERB_GET_PIN_SENSE, 0)
15402                                 & AC_PINSENSE_PRESENCE;
15403
15404         if (present1 || present2) {
15405                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15406                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15407                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15408                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15409         } else {
15410                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15411                                 AMP_IN_MUTE(0), 0);
15412                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15413                                 AMP_IN_MUTE(0), 0);
15414         }
15415 }
15416
15417 static void alc663_m51va_mic_automute(struct hda_codec *codec)
15418 {
15419         unsigned int present;
15420
15421         present = snd_hda_codec_read(codec, 0x18, 0,
15422                         AC_VERB_GET_PIN_SENSE, 0)
15423                         & AC_PINSENSE_PRESENCE;
15424         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15425                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15426         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15427                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15428         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15429                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15430         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15431                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15432 }
15433
15434 static void alc663_m51va_unsol_event(struct hda_codec *codec,
15435                                            unsigned int res)
15436 {
15437         switch (res >> 26) {
15438         case ALC880_HP_EVENT:
15439                 alc663_m51va_speaker_automute(codec);
15440                 break;
15441         case ALC880_MIC_EVENT:
15442                 alc663_m51va_mic_automute(codec);
15443                 break;
15444         }
15445 }
15446
15447 static void alc663_m51va_inithook(struct hda_codec *codec)
15448 {
15449         alc663_m51va_speaker_automute(codec);
15450         alc663_m51va_mic_automute(codec);
15451 }
15452
15453 /* ***************** Mode1 ******************************/
15454 static void alc663_mode1_unsol_event(struct hda_codec *codec,
15455                                            unsigned int res)
15456 {
15457         switch (res >> 26) {
15458         case ALC880_HP_EVENT:
15459                 alc663_m51va_speaker_automute(codec);
15460                 break;
15461         case ALC880_MIC_EVENT:
15462                 alc662_eeepc_mic_automute(codec);
15463                 break;
15464         }
15465 }
15466
15467 static void alc663_mode1_inithook(struct hda_codec *codec)
15468 {
15469         alc663_m51va_speaker_automute(codec);
15470         alc662_eeepc_mic_automute(codec);
15471 }
15472 /* ***************** Mode2 ******************************/
15473 static void alc662_mode2_unsol_event(struct hda_codec *codec,
15474                                            unsigned int res)
15475 {
15476         switch (res >> 26) {
15477         case ALC880_HP_EVENT:
15478                 alc662_f5z_speaker_automute(codec);
15479                 break;
15480         case ALC880_MIC_EVENT:
15481                 alc662_eeepc_mic_automute(codec);
15482                 break;
15483         }
15484 }
15485
15486 static void alc662_mode2_inithook(struct hda_codec *codec)
15487 {
15488         alc662_f5z_speaker_automute(codec);
15489         alc662_eeepc_mic_automute(codec);
15490 }
15491 /* ***************** Mode3 ******************************/
15492 static void alc663_mode3_unsol_event(struct hda_codec *codec,
15493                                            unsigned int res)
15494 {
15495         switch (res >> 26) {
15496         case ALC880_HP_EVENT:
15497                 alc663_two_hp_m1_speaker_automute(codec);
15498                 break;
15499         case ALC880_MIC_EVENT:
15500                 alc662_eeepc_mic_automute(codec);
15501                 break;
15502         }
15503 }
15504
15505 static void alc663_mode3_inithook(struct hda_codec *codec)
15506 {
15507         alc663_two_hp_m1_speaker_automute(codec);
15508         alc662_eeepc_mic_automute(codec);
15509 }
15510 /* ***************** Mode4 ******************************/
15511 static void alc663_mode4_unsol_event(struct hda_codec *codec,
15512                                            unsigned int res)
15513 {
15514         switch (res >> 26) {
15515         case ALC880_HP_EVENT:
15516                 alc663_21jd_two_speaker_automute(codec);
15517                 break;
15518         case ALC880_MIC_EVENT:
15519                 alc662_eeepc_mic_automute(codec);
15520                 break;
15521         }
15522 }
15523
15524 static void alc663_mode4_inithook(struct hda_codec *codec)
15525 {
15526         alc663_21jd_two_speaker_automute(codec);
15527         alc662_eeepc_mic_automute(codec);
15528 }
15529 /* ***************** Mode5 ******************************/
15530 static void alc663_mode5_unsol_event(struct hda_codec *codec,
15531                                            unsigned int res)
15532 {
15533         switch (res >> 26) {
15534         case ALC880_HP_EVENT:
15535                 alc663_15jd_two_speaker_automute(codec);
15536                 break;
15537         case ALC880_MIC_EVENT:
15538                 alc662_eeepc_mic_automute(codec);
15539                 break;
15540         }
15541 }
15542
15543 static void alc663_mode5_inithook(struct hda_codec *codec)
15544 {
15545         alc663_15jd_two_speaker_automute(codec);
15546         alc662_eeepc_mic_automute(codec);
15547 }
15548 /* ***************** Mode6 ******************************/
15549 static void alc663_mode6_unsol_event(struct hda_codec *codec,
15550                                            unsigned int res)
15551 {
15552         switch (res >> 26) {
15553         case ALC880_HP_EVENT:
15554                 alc663_two_hp_m2_speaker_automute(codec);
15555                 break;
15556         case ALC880_MIC_EVENT:
15557                 alc662_eeepc_mic_automute(codec);
15558                 break;
15559         }
15560 }
15561
15562 static void alc663_mode6_inithook(struct hda_codec *codec)
15563 {
15564         alc663_two_hp_m2_speaker_automute(codec);
15565         alc662_eeepc_mic_automute(codec);
15566 }
15567
15568 static void alc663_g71v_hp_automute(struct hda_codec *codec)
15569 {
15570         unsigned int present;
15571         unsigned char bits;
15572
15573         present = snd_hda_codec_read(codec, 0x21, 0,
15574                                      AC_VERB_GET_PIN_SENSE, 0)
15575                 & AC_PINSENSE_PRESENCE;
15576         bits = present ? HDA_AMP_MUTE : 0;
15577         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15578                                  HDA_AMP_MUTE, bits);
15579         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15580                                  HDA_AMP_MUTE, bits);
15581 }
15582
15583 static void alc663_g71v_front_automute(struct hda_codec *codec)
15584 {
15585         unsigned int present;
15586         unsigned char bits;
15587
15588         present = snd_hda_codec_read(codec, 0x15, 0,
15589                                      AC_VERB_GET_PIN_SENSE, 0)
15590                 & AC_PINSENSE_PRESENCE;
15591         bits = present ? HDA_AMP_MUTE : 0;
15592         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15593                                  HDA_AMP_MUTE, bits);
15594 }
15595
15596 static void alc663_g71v_unsol_event(struct hda_codec *codec,
15597                                            unsigned int res)
15598 {
15599         switch (res >> 26) {
15600         case ALC880_HP_EVENT:
15601                 alc663_g71v_hp_automute(codec);
15602                 break;
15603         case ALC880_FRONT_EVENT:
15604                 alc663_g71v_front_automute(codec);
15605                 break;
15606         case ALC880_MIC_EVENT:
15607                 alc662_eeepc_mic_automute(codec);
15608                 break;
15609         }
15610 }
15611
15612 static void alc663_g71v_inithook(struct hda_codec *codec)
15613 {
15614         alc663_g71v_front_automute(codec);
15615         alc663_g71v_hp_automute(codec);
15616         alc662_eeepc_mic_automute(codec);
15617 }
15618
15619 static void alc663_g50v_unsol_event(struct hda_codec *codec,
15620                                            unsigned int res)
15621 {
15622         switch (res >> 26) {
15623         case ALC880_HP_EVENT:
15624                 alc663_m51va_speaker_automute(codec);
15625                 break;
15626         case ALC880_MIC_EVENT:
15627                 alc662_eeepc_mic_automute(codec);
15628                 break;
15629         }
15630 }
15631
15632 static void alc663_g50v_inithook(struct hda_codec *codec)
15633 {
15634         alc663_m51va_speaker_automute(codec);
15635         alc662_eeepc_mic_automute(codec);
15636 }
15637
15638 /* bind hp and internal speaker mute (with plug check) */
15639 static int alc662_ecs_master_sw_put(struct snd_kcontrol *kcontrol,
15640                                      struct snd_ctl_elem_value *ucontrol)
15641 {
15642         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
15643         long *valp = ucontrol->value.integer.value;
15644         int change;
15645
15646         change = snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
15647                                           HDA_AMP_MUTE,
15648                                           valp[0] ? 0 : HDA_AMP_MUTE);
15649         change |= snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
15650                                            HDA_AMP_MUTE,
15651                                            valp[1] ? 0 : HDA_AMP_MUTE);
15652         if (change)
15653                 alc262_hippo1_automute(codec);
15654         return change;
15655 }
15656
15657 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
15658         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15659         {
15660                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15661                 .name = "Master Playback Switch",
15662                 .info = snd_hda_mixer_amp_switch_info,
15663                 .get = snd_hda_mixer_amp_switch_get,
15664                 .put = alc662_ecs_master_sw_put,
15665                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15666         },
15667
15668         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
15669         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
15670         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
15671
15672         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15673         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15674         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15675         { } /* end */
15676 };
15677
15678 #ifdef CONFIG_SND_HDA_POWER_SAVE
15679 #define alc662_loopbacks        alc880_loopbacks
15680 #endif
15681
15682
15683 /* pcm configuration: identiacal with ALC880 */
15684 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
15685 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
15686 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
15687 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
15688
15689 /*
15690  * configuration and preset
15691  */
15692 static const char *alc662_models[ALC662_MODEL_LAST] = {
15693         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
15694         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
15695         [ALC662_3ST_6ch]        = "3stack-6ch",
15696         [ALC662_5ST_DIG]        = "6stack-dig",
15697         [ALC662_LENOVO_101E]    = "lenovo-101e",
15698         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
15699         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
15700         [ALC662_ECS] = "ecs",
15701         [ALC663_ASUS_M51VA] = "m51va",
15702         [ALC663_ASUS_G71V] = "g71v",
15703         [ALC663_ASUS_H13] = "h13",
15704         [ALC663_ASUS_G50V] = "g50v",
15705         [ALC663_ASUS_MODE1] = "asus-mode1",
15706         [ALC662_ASUS_MODE2] = "asus-mode2",
15707         [ALC663_ASUS_MODE3] = "asus-mode3",
15708         [ALC663_ASUS_MODE4] = "asus-mode4",
15709         [ALC663_ASUS_MODE5] = "asus-mode5",
15710         [ALC663_ASUS_MODE6] = "asus-mode6",
15711         [ALC662_AUTO]           = "auto",
15712 };
15713
15714 static struct snd_pci_quirk alc662_cfg_tbl[] = {
15715         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
15716         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
15717         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
15718         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
15719         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
15720         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
15721         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),
15722         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
15723         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
15724         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
15725         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),
15726         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
15727         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
15728         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
15729         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
15730         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
15731         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
15732         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
15733         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
15734         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
15735         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
15736         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
15737         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
15738         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
15739         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
15740         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
15741         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
15742         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
15743         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
15744         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
15745         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
15746         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
15747         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
15748         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
15749         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
15750         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
15751         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
15752         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
15753                       ALC662_3ST_6ch_DIG),
15754         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
15755         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
15756         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
15757         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
15758                       ALC662_3ST_6ch_DIG),
15759         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
15760         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
15761                                         ALC662_3ST_6ch_DIG),
15762         SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13),
15763         SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13),
15764         SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13),
15765         {}
15766 };
15767
15768 static struct alc_config_preset alc662_presets[] = {
15769         [ALC662_3ST_2ch_DIG] = {
15770                 .mixers = { alc662_3ST_2ch_mixer, alc662_capture_mixer },
15771                 .init_verbs = { alc662_init_verbs },
15772                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15773                 .dac_nids = alc662_dac_nids,
15774                 .dig_out_nid = ALC662_DIGOUT_NID,
15775                 .dig_in_nid = ALC662_DIGIN_NID,
15776                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15777                 .channel_mode = alc662_3ST_2ch_modes,
15778                 .input_mux = &alc662_capture_source,
15779         },
15780         [ALC662_3ST_6ch_DIG] = {
15781                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
15782                             alc662_capture_mixer },
15783                 .init_verbs = { alc662_init_verbs },
15784                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15785                 .dac_nids = alc662_dac_nids,
15786                 .dig_out_nid = ALC662_DIGOUT_NID,
15787                 .dig_in_nid = ALC662_DIGIN_NID,
15788                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
15789                 .channel_mode = alc662_3ST_6ch_modes,
15790                 .need_dac_fix = 1,
15791                 .input_mux = &alc662_capture_source,
15792         },
15793         [ALC662_3ST_6ch] = {
15794                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
15795                             alc662_capture_mixer },
15796                 .init_verbs = { alc662_init_verbs },
15797                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15798                 .dac_nids = alc662_dac_nids,
15799                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
15800                 .channel_mode = alc662_3ST_6ch_modes,
15801                 .need_dac_fix = 1,
15802                 .input_mux = &alc662_capture_source,
15803         },
15804         [ALC662_5ST_DIG] = {
15805                 .mixers = { alc662_base_mixer, alc662_chmode_mixer,
15806                             alc662_capture_mixer },
15807                 .init_verbs = { alc662_init_verbs },
15808                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15809                 .dac_nids = alc662_dac_nids,
15810                 .dig_out_nid = ALC662_DIGOUT_NID,
15811                 .dig_in_nid = ALC662_DIGIN_NID,
15812                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
15813                 .channel_mode = alc662_5stack_modes,
15814                 .input_mux = &alc662_capture_source,
15815         },
15816         [ALC662_LENOVO_101E] = {
15817                 .mixers = { alc662_lenovo_101e_mixer, alc662_capture_mixer },
15818                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
15819                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15820                 .dac_nids = alc662_dac_nids,
15821                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15822                 .channel_mode = alc662_3ST_2ch_modes,
15823                 .input_mux = &alc662_lenovo_101e_capture_source,
15824                 .unsol_event = alc662_lenovo_101e_unsol_event,
15825                 .init_hook = alc662_lenovo_101e_all_automute,
15826         },
15827         [ALC662_ASUS_EEEPC_P701] = {
15828                 .mixers = { alc662_eeepc_p701_mixer, alc662_capture_mixer },
15829                 .init_verbs = { alc662_init_verbs,
15830                                 alc662_eeepc_sue_init_verbs },
15831                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15832                 .dac_nids = alc662_dac_nids,
15833                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15834                 .channel_mode = alc662_3ST_2ch_modes,
15835                 .input_mux = &alc662_eeepc_capture_source,
15836                 .unsol_event = alc662_eeepc_unsol_event,
15837                 .init_hook = alc662_eeepc_inithook,
15838         },
15839         [ALC662_ASUS_EEEPC_EP20] = {
15840                 .mixers = { alc662_eeepc_ep20_mixer, alc662_capture_mixer,
15841                             alc662_chmode_mixer },
15842                 .init_verbs = { alc662_init_verbs,
15843                                 alc662_eeepc_ep20_sue_init_verbs },
15844                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15845                 .dac_nids = alc662_dac_nids,
15846                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
15847                 .channel_mode = alc662_3ST_6ch_modes,
15848                 .input_mux = &alc662_lenovo_101e_capture_source,
15849                 .unsol_event = alc662_eeepc_ep20_unsol_event,
15850                 .init_hook = alc662_eeepc_ep20_inithook,
15851         },
15852         [ALC662_ECS] = {
15853                 .mixers = { alc662_ecs_mixer, alc662_capture_mixer },
15854                 .init_verbs = { alc662_init_verbs,
15855                                 alc662_ecs_init_verbs },
15856                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15857                 .dac_nids = alc662_dac_nids,
15858                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15859                 .channel_mode = alc662_3ST_2ch_modes,
15860                 .input_mux = &alc662_eeepc_capture_source,
15861                 .unsol_event = alc662_eeepc_unsol_event,
15862                 .init_hook = alc662_eeepc_inithook,
15863         },
15864         [ALC663_ASUS_M51VA] = {
15865                 .mixers = { alc663_m51va_mixer, alc662_capture_mixer},
15866                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
15867                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15868                 .dac_nids = alc662_dac_nids,
15869                 .dig_out_nid = ALC662_DIGOUT_NID,
15870                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15871                 .channel_mode = alc662_3ST_2ch_modes,
15872                 .input_mux = &alc663_m51va_capture_source,
15873                 .unsol_event = alc663_m51va_unsol_event,
15874                 .init_hook = alc663_m51va_inithook,
15875         },
15876         [ALC663_ASUS_G71V] = {
15877                 .mixers = { alc663_g71v_mixer, alc662_capture_mixer},
15878                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
15879                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15880                 .dac_nids = alc662_dac_nids,
15881                 .dig_out_nid = ALC662_DIGOUT_NID,
15882                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15883                 .channel_mode = alc662_3ST_2ch_modes,
15884                 .input_mux = &alc662_eeepc_capture_source,
15885                 .unsol_event = alc663_g71v_unsol_event,
15886                 .init_hook = alc663_g71v_inithook,
15887         },
15888         [ALC663_ASUS_H13] = {
15889                 .mixers = { alc663_m51va_mixer, alc662_capture_mixer},
15890                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
15891                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15892                 .dac_nids = alc662_dac_nids,
15893                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15894                 .channel_mode = alc662_3ST_2ch_modes,
15895                 .input_mux = &alc663_m51va_capture_source,
15896                 .unsol_event = alc663_m51va_unsol_event,
15897                 .init_hook = alc663_m51va_inithook,
15898         },
15899         [ALC663_ASUS_G50V] = {
15900                 .mixers = { alc663_g50v_mixer, alc662_capture_mixer},
15901                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
15902                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15903                 .dac_nids = alc662_dac_nids,
15904                 .dig_out_nid = ALC662_DIGOUT_NID,
15905                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
15906                 .channel_mode = alc662_3ST_6ch_modes,
15907                 .input_mux = &alc663_capture_source,
15908                 .unsol_event = alc663_g50v_unsol_event,
15909                 .init_hook = alc663_g50v_inithook,
15910         },
15911         [ALC663_ASUS_MODE1] = {
15912                 .mixers = { alc663_m51va_mixer, alc662_auto_capture_mixer },
15913                 .init_verbs = { alc662_init_verbs,
15914                                 alc663_21jd_amic_init_verbs },
15915                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15916                 .hp_nid = 0x03,
15917                 .dac_nids = alc662_dac_nids,
15918                 .dig_out_nid = ALC662_DIGOUT_NID,
15919                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15920                 .channel_mode = alc662_3ST_2ch_modes,
15921                 .input_mux = &alc662_eeepc_capture_source,
15922                 .unsol_event = alc663_mode1_unsol_event,
15923                 .init_hook = alc663_mode1_inithook,
15924         },
15925         [ALC662_ASUS_MODE2] = {
15926                 .mixers = { alc662_1bjd_mixer, alc662_auto_capture_mixer },
15927                 .init_verbs = { alc662_init_verbs,
15928                                 alc662_1bjd_amic_init_verbs },
15929                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15930                 .dac_nids = alc662_dac_nids,
15931                 .dig_out_nid = ALC662_DIGOUT_NID,
15932                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15933                 .channel_mode = alc662_3ST_2ch_modes,
15934                 .input_mux = &alc662_eeepc_capture_source,
15935                 .unsol_event = alc662_mode2_unsol_event,
15936                 .init_hook = alc662_mode2_inithook,
15937         },
15938         [ALC663_ASUS_MODE3] = {
15939                 .mixers = { alc663_two_hp_m1_mixer, alc662_auto_capture_mixer },
15940                 .init_verbs = { alc662_init_verbs,
15941                                 alc663_two_hp_amic_m1_init_verbs },
15942                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15943                 .hp_nid = 0x03,
15944                 .dac_nids = alc662_dac_nids,
15945                 .dig_out_nid = ALC662_DIGOUT_NID,
15946                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15947                 .channel_mode = alc662_3ST_2ch_modes,
15948                 .input_mux = &alc662_eeepc_capture_source,
15949                 .unsol_event = alc663_mode3_unsol_event,
15950                 .init_hook = alc663_mode3_inithook,
15951         },
15952         [ALC663_ASUS_MODE4] = {
15953                 .mixers = { alc663_asus_21jd_clfe_mixer,
15954                                 alc662_auto_capture_mixer},
15955                 .init_verbs = { alc662_init_verbs,
15956                                 alc663_21jd_amic_init_verbs},
15957                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15958                 .hp_nid = 0x03,
15959                 .dac_nids = alc662_dac_nids,
15960                 .dig_out_nid = ALC662_DIGOUT_NID,
15961                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15962                 .channel_mode = alc662_3ST_2ch_modes,
15963                 .input_mux = &alc662_eeepc_capture_source,
15964                 .unsol_event = alc663_mode4_unsol_event,
15965                 .init_hook = alc663_mode4_inithook,
15966         },
15967         [ALC663_ASUS_MODE5] = {
15968                 .mixers = { alc663_asus_15jd_clfe_mixer,
15969                                 alc662_auto_capture_mixer },
15970                 .init_verbs = { alc662_init_verbs,
15971                                 alc663_15jd_amic_init_verbs },
15972                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15973                 .hp_nid = 0x03,
15974                 .dac_nids = alc662_dac_nids,
15975                 .dig_out_nid = ALC662_DIGOUT_NID,
15976                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15977                 .channel_mode = alc662_3ST_2ch_modes,
15978                 .input_mux = &alc662_eeepc_capture_source,
15979                 .unsol_event = alc663_mode5_unsol_event,
15980                 .init_hook = alc663_mode5_inithook,
15981         },
15982         [ALC663_ASUS_MODE6] = {
15983                 .mixers = { alc663_two_hp_m2_mixer, alc662_auto_capture_mixer },
15984                 .init_verbs = { alc662_init_verbs,
15985                                 alc663_two_hp_amic_m2_init_verbs },
15986                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15987                 .hp_nid = 0x03,
15988                 .dac_nids = alc662_dac_nids,
15989                 .dig_out_nid = ALC662_DIGOUT_NID,
15990                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15991                 .channel_mode = alc662_3ST_2ch_modes,
15992                 .input_mux = &alc662_eeepc_capture_source,
15993                 .unsol_event = alc663_mode6_unsol_event,
15994                 .init_hook = alc663_mode6_inithook,
15995         },
15996 };
15997
15998
15999 /*
16000  * BIOS auto configuration
16001  */
16002
16003 /* add playback controls from the parsed DAC table */
16004 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
16005                                              const struct auto_pin_cfg *cfg)
16006 {
16007         char name[32];
16008         static const char *chname[4] = {
16009                 "Front", "Surround", NULL /*CLFE*/, "Side"
16010         };
16011         hda_nid_t nid;
16012         int i, err;
16013
16014         for (i = 0; i < cfg->line_outs; i++) {
16015                 if (!spec->multiout.dac_nids[i])
16016                         continue;
16017                 nid = alc880_idx_to_dac(i);
16018                 if (i == 2) {
16019                         /* Center/LFE */
16020                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16021                                           "Center Playback Volume",
16022                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
16023                                                               HDA_OUTPUT));
16024                         if (err < 0)
16025                                 return err;
16026                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16027                                           "LFE Playback Volume",
16028                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
16029                                                               HDA_OUTPUT));
16030                         if (err < 0)
16031                                 return err;
16032                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16033                                           "Center Playback Switch",
16034                                           HDA_COMPOSE_AMP_VAL(0x0e, 1, 0,
16035                                                               HDA_INPUT));
16036                         if (err < 0)
16037                                 return err;
16038                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16039                                           "LFE Playback Switch",
16040                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
16041                                                               HDA_INPUT));
16042                         if (err < 0)
16043                                 return err;
16044                 } else {
16045                         sprintf(name, "%s Playback Volume", chname[i]);
16046                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16047                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
16048                                                               HDA_OUTPUT));
16049                         if (err < 0)
16050                                 return err;
16051                         sprintf(name, "%s Playback Switch", chname[i]);
16052                         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16053                                 HDA_COMPOSE_AMP_VAL(alc880_idx_to_mixer(i),
16054                                                     3, 0, HDA_INPUT));
16055                         if (err < 0)
16056                                 return err;
16057                 }
16058         }
16059         return 0;
16060 }
16061
16062 /* add playback controls for speaker and HP outputs */
16063 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
16064                                         const char *pfx)
16065 {
16066         hda_nid_t nid;
16067         int err;
16068         char name[32];
16069
16070         if (!pin)
16071                 return 0;
16072
16073         if (pin == 0x17) {
16074                 /* ALC663 has a mono output pin on 0x17 */
16075                 sprintf(name, "%s Playback Switch", pfx);
16076                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16077                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
16078                 return err;
16079         }
16080
16081         if (alc880_is_fixed_pin(pin)) {
16082                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16083                 /* printk("DAC nid=%x\n",nid); */
16084                 /* specify the DAC as the extra output */
16085                 if (!spec->multiout.hp_nid)
16086                         spec->multiout.hp_nid = nid;
16087                 else
16088                         spec->multiout.extra_out_nid[0] = nid;
16089                 /* control HP volume/switch on the output mixer amp */
16090                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16091                 sprintf(name, "%s Playback Volume", pfx);
16092                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16093                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
16094                 if (err < 0)
16095                         return err;
16096                 sprintf(name, "%s Playback Switch", pfx);
16097                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
16098                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
16099                 if (err < 0)
16100                         return err;
16101         } else if (alc880_is_multi_pin(pin)) {
16102                 /* set manual connection */
16103                 /* we have only a switch on HP-out PIN */
16104                 sprintf(name, "%s Playback Switch", pfx);
16105                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16106                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
16107                 if (err < 0)
16108                         return err;
16109         }
16110         return 0;
16111 }
16112
16113 /* create playback/capture controls for input pins */
16114 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
16115                                                 const struct auto_pin_cfg *cfg)
16116 {
16117         struct hda_input_mux *imux = &spec->private_imux;
16118         int i, err, idx;
16119
16120         for (i = 0; i < AUTO_PIN_LAST; i++) {
16121                 if (alc880_is_input_pin(cfg->input_pins[i])) {
16122                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
16123                         err = new_analog_input(spec, cfg->input_pins[i],
16124                                                auto_pin_cfg_labels[i],
16125                                                idx, 0x0b);
16126                         if (err < 0)
16127                                 return err;
16128                         imux->items[imux->num_items].label =
16129                                 auto_pin_cfg_labels[i];
16130                         imux->items[imux->num_items].index =
16131                                 alc880_input_pin_idx(cfg->input_pins[i]);
16132                         imux->num_items++;
16133                 }
16134         }
16135         return 0;
16136 }
16137
16138 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
16139                                               hda_nid_t nid, int pin_type,
16140                                               int dac_idx)
16141 {
16142         alc_set_pin_output(codec, nid, pin_type);
16143         /* need the manual connection? */
16144         if (alc880_is_multi_pin(nid)) {
16145                 struct alc_spec *spec = codec->spec;
16146                 int idx = alc880_multi_pin_idx(nid);
16147                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
16148                                     AC_VERB_SET_CONNECT_SEL,
16149                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
16150         }
16151 }
16152
16153 static void alc662_auto_init_multi_out(struct hda_codec *codec)
16154 {
16155         struct alc_spec *spec = codec->spec;
16156         int i;
16157
16158         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
16159         for (i = 0; i <= HDA_SIDE; i++) {
16160                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
16161                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
16162                 if (nid)
16163                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
16164                                                           i);
16165         }
16166 }
16167
16168 static void alc662_auto_init_hp_out(struct hda_codec *codec)
16169 {
16170         struct alc_spec *spec = codec->spec;
16171         hda_nid_t pin;
16172
16173         pin = spec->autocfg.hp_pins[0];
16174         if (pin) /* connect to front */
16175                 /* use dac 0 */
16176                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
16177         pin = spec->autocfg.speaker_pins[0];
16178         if (pin)
16179                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
16180 }
16181
16182 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
16183 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
16184
16185 static void alc662_auto_init_analog_input(struct hda_codec *codec)
16186 {
16187         struct alc_spec *spec = codec->spec;
16188         int i;
16189
16190         for (i = 0; i < AUTO_PIN_LAST; i++) {
16191                 hda_nid_t nid = spec->autocfg.input_pins[i];
16192                 if (alc662_is_input_pin(nid)) {
16193                         snd_hda_codec_write(codec, nid, 0,
16194                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
16195                                             (i <= AUTO_PIN_FRONT_MIC ?
16196                                              PIN_VREF80 : PIN_IN));
16197                         if (nid != ALC662_PIN_CD_NID)
16198                                 snd_hda_codec_write(codec, nid, 0,
16199                                                     AC_VERB_SET_AMP_GAIN_MUTE,
16200                                                     AMP_OUT_MUTE);
16201                 }
16202         }
16203 }
16204
16205 #define alc662_auto_init_input_src      alc882_auto_init_input_src
16206
16207 static int alc662_parse_auto_config(struct hda_codec *codec)
16208 {
16209         struct alc_spec *spec = codec->spec;
16210         int err;
16211         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
16212
16213         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
16214                                            alc662_ignore);
16215         if (err < 0)
16216                 return err;
16217         if (!spec->autocfg.line_outs)
16218                 return 0; /* can't find valid BIOS pin config */
16219
16220         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
16221         if (err < 0)
16222                 return err;
16223         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
16224         if (err < 0)
16225                 return err;
16226         err = alc662_auto_create_extra_out(spec,
16227                                            spec->autocfg.speaker_pins[0],
16228                                            "Speaker");
16229         if (err < 0)
16230                 return err;
16231         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
16232                                            "Headphone");
16233         if (err < 0)
16234                 return err;
16235         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
16236         if (err < 0)
16237                 return err;
16238
16239         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
16240
16241         if (spec->autocfg.dig_out_pin)
16242                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
16243
16244         if (spec->kctl_alloc)
16245                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
16246
16247         spec->num_mux_defs = 1;
16248         spec->input_mux = &spec->private_imux;
16249
16250         spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs;
16251         if (codec->vendor_id == 0x10ec0663)
16252                 spec->init_verbs[spec->num_init_verbs++] =
16253                         alc663_auto_init_verbs;
16254
16255         err = alc_auto_add_mic_boost(codec);
16256         if (err < 0)
16257                 return err;
16258
16259         spec->mixers[spec->num_mixers] = alc662_capture_mixer;
16260         spec->num_mixers++;
16261         return 1;
16262 }
16263
16264 /* additional initialization for auto-configuration model */
16265 static void alc662_auto_init(struct hda_codec *codec)
16266 {
16267         struct alc_spec *spec = codec->spec;
16268         alc662_auto_init_multi_out(codec);
16269         alc662_auto_init_hp_out(codec);
16270         alc662_auto_init_analog_input(codec);
16271         alc662_auto_init_input_src(codec);
16272         if (spec->unsol_event)
16273                 alc_inithook(codec);
16274 }
16275
16276 static int patch_alc662(struct hda_codec *codec)
16277 {
16278         struct alc_spec *spec;
16279         int err, board_config;
16280
16281         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
16282         if (!spec)
16283                 return -ENOMEM;
16284
16285         codec->spec = spec;
16286
16287         alc_fix_pll_init(codec, 0x20, 0x04, 15);
16288
16289         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
16290                                                   alc662_models,
16291                                                   alc662_cfg_tbl);
16292         if (board_config < 0) {
16293                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
16294                        "trying auto-probe from BIOS...\n");
16295                 board_config = ALC662_AUTO;
16296         }
16297
16298         if (board_config == ALC662_AUTO) {
16299                 /* automatic parse from the BIOS config */
16300                 err = alc662_parse_auto_config(codec);
16301                 if (err < 0) {
16302                         alc_free(codec);
16303                         return err;
16304                 } else if (!err) {
16305                         printk(KERN_INFO
16306                                "hda_codec: Cannot set up configuration "
16307                                "from BIOS.  Using base mode...\n");
16308                         board_config = ALC662_3ST_2ch_DIG;
16309                 }
16310         }
16311
16312         if (board_config != ALC662_AUTO)
16313                 setup_preset(spec, &alc662_presets[board_config]);
16314
16315         if (codec->vendor_id == 0x10ec0663) {
16316                 spec->stream_name_analog = "ALC663 Analog";
16317                 spec->stream_name_digital = "ALC663 Digital";
16318         } else if (codec->vendor_id == 0x10ec0272) {
16319                 spec->stream_name_analog = "ALC272 Analog";
16320                 spec->stream_name_digital = "ALC272 Digital";
16321         } else {
16322                 spec->stream_name_analog = "ALC662 Analog";
16323                 spec->stream_name_digital = "ALC662 Digital";
16324         }
16325
16326         spec->stream_analog_playback = &alc662_pcm_analog_playback;
16327         spec->stream_analog_capture = &alc662_pcm_analog_capture;
16328
16329         spec->stream_digital_playback = &alc662_pcm_digital_playback;
16330         spec->stream_digital_capture = &alc662_pcm_digital_capture;
16331
16332         spec->adc_nids = alc662_adc_nids;
16333         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
16334         spec->capsrc_nids = alc662_capsrc_nids;
16335
16336         spec->vmaster_nid = 0x02;
16337
16338         codec->patch_ops = alc_patch_ops;
16339         if (board_config == ALC662_AUTO)
16340                 spec->init_hook = alc662_auto_init;
16341 #ifdef CONFIG_SND_HDA_POWER_SAVE
16342         if (!spec->loopback.amplist)
16343                 spec->loopback.amplist = alc662_loopbacks;
16344 #endif
16345
16346         return 0;
16347 }
16348
16349 /*
16350  * patch entries
16351  */
16352 struct hda_codec_preset snd_hda_preset_realtek[] = {
16353         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
16354         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
16355         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
16356         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
16357         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
16358         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
16359         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
16360           .patch = patch_alc861 },
16361         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
16362         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
16363         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
16364         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
16365           .patch = patch_alc883 },
16366         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
16367           .patch = patch_alc662 },
16368         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
16369         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
16370         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
16371         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
16372         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
16373           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16374         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
16375           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16376         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
16377         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc883 },
16378         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
16379         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
16380           .patch = patch_alc883 },
16381         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
16382         {} /* terminator */
16383 };