]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - sound/pci/hda/patch_realtek.c
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wirel...
[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 #ifdef SND_HDA_NEEDS_RESUME
312 #define ALC_MAX_PINS    16
313         unsigned int num_pins;
314         hda_nid_t pin_nids[ALC_MAX_PINS];
315         unsigned int pin_cfgs[ALC_MAX_PINS];
316 #endif
317 };
318
319 /*
320  * configuration template - to be copied to the spec instance
321  */
322 struct alc_config_preset {
323         struct snd_kcontrol_new *mixers[5]; /* should be identical size
324                                              * with spec
325                                              */
326         const struct hda_verb *init_verbs[5];
327         unsigned int num_dacs;
328         hda_nid_t *dac_nids;
329         hda_nid_t dig_out_nid;          /* optional */
330         hda_nid_t hp_nid;               /* optional */
331         unsigned int num_adc_nids;
332         hda_nid_t *adc_nids;
333         hda_nid_t *capsrc_nids;
334         hda_nid_t dig_in_nid;
335         unsigned int num_channel_mode;
336         const struct hda_channel_mode *channel_mode;
337         int need_dac_fix;
338         unsigned int num_mux_defs;
339         const struct hda_input_mux *input_mux;
340         void (*unsol_event)(struct hda_codec *, unsigned int);
341         void (*init_hook)(struct hda_codec *);
342 #ifdef CONFIG_SND_HDA_POWER_SAVE
343         struct hda_amp_list *loopbacks;
344 #endif
345 };
346
347
348 /*
349  * input MUX handling
350  */
351 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
352                              struct snd_ctl_elem_info *uinfo)
353 {
354         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
355         struct alc_spec *spec = codec->spec;
356         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
357         if (mux_idx >= spec->num_mux_defs)
358                 mux_idx = 0;
359         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
360 }
361
362 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
363                             struct snd_ctl_elem_value *ucontrol)
364 {
365         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
366         struct alc_spec *spec = codec->spec;
367         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
368
369         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
370         return 0;
371 }
372
373 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
374                             struct snd_ctl_elem_value *ucontrol)
375 {
376         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
377         struct alc_spec *spec = codec->spec;
378         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
379         unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
380         hda_nid_t nid = spec->capsrc_nids ?
381                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
382         return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
383                                      nid, &spec->cur_mux[adc_idx]);
384 }
385
386
387 /*
388  * channel mode setting
389  */
390 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
391                             struct snd_ctl_elem_info *uinfo)
392 {
393         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
394         struct alc_spec *spec = codec->spec;
395         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
396                                     spec->num_channel_mode);
397 }
398
399 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
400                            struct snd_ctl_elem_value *ucontrol)
401 {
402         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
403         struct alc_spec *spec = codec->spec;
404         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
405                                    spec->num_channel_mode,
406                                    spec->multiout.max_channels);
407 }
408
409 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
410                            struct snd_ctl_elem_value *ucontrol)
411 {
412         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
413         struct alc_spec *spec = codec->spec;
414         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
415                                       spec->num_channel_mode,
416                                       &spec->multiout.max_channels);
417         if (err >= 0 && spec->need_dac_fix)
418                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
419         return err;
420 }
421
422 /*
423  * Control the mode of pin widget settings via the mixer.  "pc" is used
424  * instead of "%" to avoid consequences of accidently treating the % as
425  * being part of a format specifier.  Maximum allowed length of a value is
426  * 63 characters plus NULL terminator.
427  *
428  * Note: some retasking pin complexes seem to ignore requests for input
429  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
430  * are requested.  Therefore order this list so that this behaviour will not
431  * cause problems when mixer clients move through the enum sequentially.
432  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
433  * March 2006.
434  */
435 static char *alc_pin_mode_names[] = {
436         "Mic 50pc bias", "Mic 80pc bias",
437         "Line in", "Line out", "Headphone out",
438 };
439 static unsigned char alc_pin_mode_values[] = {
440         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
441 };
442 /* The control can present all 5 options, or it can limit the options based
443  * in the pin being assumed to be exclusively an input or an output pin.  In
444  * addition, "input" pins may or may not process the mic bias option
445  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
446  * accept requests for bias as of chip versions up to March 2006) and/or
447  * wiring in the computer.
448  */
449 #define ALC_PIN_DIR_IN              0x00
450 #define ALC_PIN_DIR_OUT             0x01
451 #define ALC_PIN_DIR_INOUT           0x02
452 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
453 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
454
455 /* Info about the pin modes supported by the different pin direction modes.
456  * For each direction the minimum and maximum values are given.
457  */
458 static signed char alc_pin_mode_dir_info[5][2] = {
459         { 0, 2 },    /* ALC_PIN_DIR_IN */
460         { 3, 4 },    /* ALC_PIN_DIR_OUT */
461         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
462         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
463         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
464 };
465 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
466 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
467 #define alc_pin_mode_n_items(_dir) \
468         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
469
470 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
471                              struct snd_ctl_elem_info *uinfo)
472 {
473         unsigned int item_num = uinfo->value.enumerated.item;
474         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
475
476         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
477         uinfo->count = 1;
478         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
479
480         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
481                 item_num = alc_pin_mode_min(dir);
482         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
483         return 0;
484 }
485
486 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
487                             struct snd_ctl_elem_value *ucontrol)
488 {
489         unsigned int i;
490         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
491         hda_nid_t nid = kcontrol->private_value & 0xffff;
492         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
493         long *valp = ucontrol->value.integer.value;
494         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
495                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
496                                                  0x00);
497
498         /* Find enumerated value for current pinctl setting */
499         i = alc_pin_mode_min(dir);
500         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
501                 i++;
502         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
503         return 0;
504 }
505
506 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
507                             struct snd_ctl_elem_value *ucontrol)
508 {
509         signed int change;
510         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
511         hda_nid_t nid = kcontrol->private_value & 0xffff;
512         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
513         long val = *ucontrol->value.integer.value;
514         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
515                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
516                                                  0x00);
517
518         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
519                 val = alc_pin_mode_min(dir);
520
521         change = pinctl != alc_pin_mode_values[val];
522         if (change) {
523                 /* Set pin mode to that requested */
524                 snd_hda_codec_write_cache(codec, nid, 0,
525                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
526                                           alc_pin_mode_values[val]);
527
528                 /* Also enable the retasking pin's input/output as required
529                  * for the requested pin mode.  Enum values of 2 or less are
530                  * input modes.
531                  *
532                  * Dynamically switching the input/output buffers probably
533                  * reduces noise slightly (particularly on input) so we'll
534                  * do it.  However, having both input and output buffers
535                  * enabled simultaneously doesn't seem to be problematic if
536                  * this turns out to be necessary in the future.
537                  */
538                 if (val <= 2) {
539                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
540                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
541                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
542                                                  HDA_AMP_MUTE, 0);
543                 } else {
544                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
545                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
546                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
547                                                  HDA_AMP_MUTE, 0);
548                 }
549         }
550         return change;
551 }
552
553 #define ALC_PIN_MODE(xname, nid, dir) \
554         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
555           .info = alc_pin_mode_info, \
556           .get = alc_pin_mode_get, \
557           .put = alc_pin_mode_put, \
558           .private_value = nid | (dir<<16) }
559
560 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
561  * together using a mask with more than one bit set.  This control is
562  * currently used only by the ALC260 test model.  At this stage they are not
563  * needed for any "production" models.
564  */
565 #ifdef CONFIG_SND_DEBUG
566 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
567
568 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
569                              struct snd_ctl_elem_value *ucontrol)
570 {
571         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
572         hda_nid_t nid = kcontrol->private_value & 0xffff;
573         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
574         long *valp = ucontrol->value.integer.value;
575         unsigned int val = snd_hda_codec_read(codec, nid, 0,
576                                               AC_VERB_GET_GPIO_DATA, 0x00);
577
578         *valp = (val & mask) != 0;
579         return 0;
580 }
581 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
582                              struct snd_ctl_elem_value *ucontrol)
583 {
584         signed int change;
585         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
586         hda_nid_t nid = kcontrol->private_value & 0xffff;
587         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
588         long val = *ucontrol->value.integer.value;
589         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
590                                                     AC_VERB_GET_GPIO_DATA,
591                                                     0x00);
592
593         /* Set/unset the masked GPIO bit(s) as needed */
594         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
595         if (val == 0)
596                 gpio_data &= ~mask;
597         else
598                 gpio_data |= mask;
599         snd_hda_codec_write_cache(codec, nid, 0,
600                                   AC_VERB_SET_GPIO_DATA, gpio_data);
601
602         return change;
603 }
604 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
605         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
606           .info = alc_gpio_data_info, \
607           .get = alc_gpio_data_get, \
608           .put = alc_gpio_data_put, \
609           .private_value = nid | (mask<<16) }
610 #endif   /* CONFIG_SND_DEBUG */
611
612 /* A switch control to allow the enabling of the digital IO pins on the
613  * ALC260.  This is incredibly simplistic; the intention of this control is
614  * to provide something in the test model allowing digital outputs to be
615  * identified if present.  If models are found which can utilise these
616  * outputs a more complete mixer control can be devised for those models if
617  * necessary.
618  */
619 #ifdef CONFIG_SND_DEBUG
620 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
621
622 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
623                               struct snd_ctl_elem_value *ucontrol)
624 {
625         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
626         hda_nid_t nid = kcontrol->private_value & 0xffff;
627         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
628         long *valp = ucontrol->value.integer.value;
629         unsigned int val = snd_hda_codec_read(codec, nid, 0,
630                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
631
632         *valp = (val & mask) != 0;
633         return 0;
634 }
635 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
636                               struct snd_ctl_elem_value *ucontrol)
637 {
638         signed int change;
639         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
640         hda_nid_t nid = kcontrol->private_value & 0xffff;
641         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
642         long val = *ucontrol->value.integer.value;
643         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
644                                                     AC_VERB_GET_DIGI_CONVERT_1,
645                                                     0x00);
646
647         /* Set/unset the masked control bit(s) as needed */
648         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
649         if (val==0)
650                 ctrl_data &= ~mask;
651         else
652                 ctrl_data |= mask;
653         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
654                                   ctrl_data);
655
656         return change;
657 }
658 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
659         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
660           .info = alc_spdif_ctrl_info, \
661           .get = alc_spdif_ctrl_get, \
662           .put = alc_spdif_ctrl_put, \
663           .private_value = nid | (mask<<16) }
664 #endif   /* CONFIG_SND_DEBUG */
665
666 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
667  * Again, this is only used in the ALC26x test models to help identify when
668  * the EAPD line must be asserted for features to work.
669  */
670 #ifdef CONFIG_SND_DEBUG
671 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
672
673 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
674                               struct snd_ctl_elem_value *ucontrol)
675 {
676         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
677         hda_nid_t nid = kcontrol->private_value & 0xffff;
678         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
679         long *valp = ucontrol->value.integer.value;
680         unsigned int val = snd_hda_codec_read(codec, nid, 0,
681                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
682
683         *valp = (val & mask) != 0;
684         return 0;
685 }
686
687 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
688                               struct snd_ctl_elem_value *ucontrol)
689 {
690         int change;
691         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
692         hda_nid_t nid = kcontrol->private_value & 0xffff;
693         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
694         long val = *ucontrol->value.integer.value;
695         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
696                                                     AC_VERB_GET_EAPD_BTLENABLE,
697                                                     0x00);
698
699         /* Set/unset the masked control bit(s) as needed */
700         change = (!val ? 0 : mask) != (ctrl_data & mask);
701         if (!val)
702                 ctrl_data &= ~mask;
703         else
704                 ctrl_data |= mask;
705         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
706                                   ctrl_data);
707
708         return change;
709 }
710
711 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
712         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
713           .info = alc_eapd_ctrl_info, \
714           .get = alc_eapd_ctrl_get, \
715           .put = alc_eapd_ctrl_put, \
716           .private_value = nid | (mask<<16) }
717 #endif   /* CONFIG_SND_DEBUG */
718
719 /*
720  * set up from the preset table
721  */
722 static void setup_preset(struct alc_spec *spec,
723                          const struct alc_config_preset *preset)
724 {
725         int i;
726
727         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
728                 spec->mixers[spec->num_mixers++] = preset->mixers[i];
729         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
730              i++)
731                 spec->init_verbs[spec->num_init_verbs++] =
732                         preset->init_verbs[i];
733
734         spec->channel_mode = preset->channel_mode;
735         spec->num_channel_mode = preset->num_channel_mode;
736         spec->need_dac_fix = preset->need_dac_fix;
737
738         spec->multiout.max_channels = spec->channel_mode[0].channels;
739
740         spec->multiout.num_dacs = preset->num_dacs;
741         spec->multiout.dac_nids = preset->dac_nids;
742         spec->multiout.dig_out_nid = preset->dig_out_nid;
743         spec->multiout.hp_nid = preset->hp_nid;
744
745         spec->num_mux_defs = preset->num_mux_defs;
746         if (!spec->num_mux_defs)
747                 spec->num_mux_defs = 1;
748         spec->input_mux = preset->input_mux;
749
750         spec->num_adc_nids = preset->num_adc_nids;
751         spec->adc_nids = preset->adc_nids;
752         spec->capsrc_nids = preset->capsrc_nids;
753         spec->dig_in_nid = preset->dig_in_nid;
754
755         spec->unsol_event = preset->unsol_event;
756         spec->init_hook = preset->init_hook;
757 #ifdef CONFIG_SND_HDA_POWER_SAVE
758         spec->loopback.amplist = preset->loopbacks;
759 #endif
760 }
761
762 /* Enable GPIO mask and set output */
763 static struct hda_verb alc_gpio1_init_verbs[] = {
764         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
765         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
766         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
767         { }
768 };
769
770 static struct hda_verb alc_gpio2_init_verbs[] = {
771         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
772         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
773         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
774         { }
775 };
776
777 static struct hda_verb alc_gpio3_init_verbs[] = {
778         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
779         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
780         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
781         { }
782 };
783
784 /*
785  * Fix hardware PLL issue
786  * On some codecs, the analog PLL gating control must be off while
787  * the default value is 1.
788  */
789 static void alc_fix_pll(struct hda_codec *codec)
790 {
791         struct alc_spec *spec = codec->spec;
792         unsigned int val;
793
794         if (!spec->pll_nid)
795                 return;
796         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
797                             spec->pll_coef_idx);
798         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
799                                  AC_VERB_GET_PROC_COEF, 0);
800         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
801                             spec->pll_coef_idx);
802         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
803                             val & ~(1 << spec->pll_coef_bit));
804 }
805
806 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
807                              unsigned int coef_idx, unsigned int coef_bit)
808 {
809         struct alc_spec *spec = codec->spec;
810         spec->pll_nid = nid;
811         spec->pll_coef_idx = coef_idx;
812         spec->pll_coef_bit = coef_bit;
813         alc_fix_pll(codec);
814 }
815
816 static void alc_sku_automute(struct hda_codec *codec)
817 {
818         struct alc_spec *spec = codec->spec;
819         unsigned int present;
820         unsigned int hp_nid = spec->autocfg.hp_pins[0];
821         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
822
823         /* need to execute and sync at first */
824         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
825         present = snd_hda_codec_read(codec, hp_nid, 0,
826                                      AC_VERB_GET_PIN_SENSE, 0);
827         spec->jack_present = (present & 0x80000000) != 0;
828         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
829                             spec->jack_present ? 0 : PIN_OUT);
830 }
831
832 static void alc_mic_automute(struct hda_codec *codec)
833 {
834         struct alc_spec *spec = codec->spec;
835         unsigned int present;
836         unsigned int mic_nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
837         unsigned int fmic_nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
838         unsigned int mix_nid = spec->capsrc_nids[0];
839         unsigned int capsrc_idx_mic, capsrc_idx_fmic;
840
841         capsrc_idx_mic = mic_nid - 0x18;
842         capsrc_idx_fmic = fmic_nid - 0x18;
843         present = snd_hda_codec_read(codec, mic_nid, 0,
844                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
845         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
846                     0x7000 | (capsrc_idx_mic << 8) | (present ? 0 : 0x80));
847         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
848                     0x7000 | (capsrc_idx_fmic << 8) | (present ? 0x80 : 0));
849         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, capsrc_idx_fmic,
850                          HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
851 }
852
853 /* unsolicited event for HP jack sensing */
854 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
855 {
856         if (codec->vendor_id == 0x10ec0880)
857                 res >>= 28;
858         else
859                 res >>= 26;
860         if (res == ALC880_HP_EVENT)
861                 alc_sku_automute(codec);
862
863         if (res == ALC880_MIC_EVENT)
864                 alc_mic_automute(codec);
865 }
866
867 static void alc_inithook(struct hda_codec *codec)
868 {
869         alc_sku_automute(codec);
870         alc_mic_automute(codec);
871 }
872
873 /* additional initialization for ALC888 variants */
874 static void alc888_coef_init(struct hda_codec *codec)
875 {
876         unsigned int tmp;
877
878         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
879         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
880         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
881         if ((tmp & 0xf0) == 2)
882                 /* alc888S-VC */
883                 snd_hda_codec_read(codec, 0x20, 0,
884                                    AC_VERB_SET_PROC_COEF, 0x830);
885          else
886                  /* alc888-VB */
887                  snd_hda_codec_read(codec, 0x20, 0,
888                                     AC_VERB_SET_PROC_COEF, 0x3030);
889 }
890
891 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
892  *      31 ~ 16 :       Manufacture ID
893  *      15 ~ 8  :       SKU ID
894  *      7  ~ 0  :       Assembly ID
895  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
896  */
897 static void alc_subsystem_id(struct hda_codec *codec,
898                              unsigned int porta, unsigned int porte,
899                              unsigned int portd)
900 {
901         unsigned int ass, tmp, i;
902         unsigned nid;
903         struct alc_spec *spec = codec->spec;
904
905         ass = codec->subsystem_id & 0xffff;
906         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
907                 goto do_sku;
908
909         /*
910          * 31~30        : port conetcivity
911          * 29~21        : reserve
912          * 20           : PCBEEP input
913          * 19~16        : Check sum (15:1)
914          * 15~1         : Custom
915          * 0            : override
916         */
917         nid = 0x1d;
918         if (codec->vendor_id == 0x10ec0260)
919                 nid = 0x17;
920         ass = snd_hda_codec_read(codec, nid, 0,
921                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
922         if (!(ass & 1) && !(ass & 0x100000))
923                 return;
924         if ((ass >> 30) != 1)   /* no physical connection */
925                 return;
926
927         /* check sum */
928         tmp = 0;
929         for (i = 1; i < 16; i++) {
930                 if ((ass >> i) & 1)
931                         tmp++;
932         }
933         if (((ass >> 16) & 0xf) != tmp)
934                 return;
935 do_sku:
936         /*
937          * 0 : override
938          * 1 :  Swap Jack
939          * 2 : 0 --> Desktop, 1 --> Laptop
940          * 3~5 : External Amplifier control
941          * 7~6 : Reserved
942         */
943         tmp = (ass & 0x38) >> 3;        /* external Amp control */
944         switch (tmp) {
945         case 1:
946                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
947                 break;
948         case 3:
949                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
950                 break;
951         case 7:
952                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
953                 break;
954         case 5: /* set EAPD output high */
955                 switch (codec->vendor_id) {
956                 case 0x10ec0260:
957                         snd_hda_codec_write(codec, 0x0f, 0,
958                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
959                         snd_hda_codec_write(codec, 0x10, 0,
960                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
961                         break;
962                 case 0x10ec0262:
963                 case 0x10ec0267:
964                 case 0x10ec0268:
965                 case 0x10ec0269:
966                 case 0x10ec0660:
967                 case 0x10ec0662:
968                 case 0x10ec0663:
969                 case 0x10ec0862:
970                 case 0x10ec0889:
971                         snd_hda_codec_write(codec, 0x14, 0,
972                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
973                         snd_hda_codec_write(codec, 0x15, 0,
974                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
975                         break;
976                 }
977                 switch (codec->vendor_id) {
978                 case 0x10ec0260:
979                         snd_hda_codec_write(codec, 0x1a, 0,
980                                             AC_VERB_SET_COEF_INDEX, 7);
981                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
982                                                  AC_VERB_GET_PROC_COEF, 0);
983                         snd_hda_codec_write(codec, 0x1a, 0,
984                                             AC_VERB_SET_COEF_INDEX, 7);
985                         snd_hda_codec_write(codec, 0x1a, 0,
986                                             AC_VERB_SET_PROC_COEF,
987                                             tmp | 0x2010);
988                         break;
989                 case 0x10ec0262:
990                 case 0x10ec0880:
991                 case 0x10ec0882:
992                 case 0x10ec0883:
993                 case 0x10ec0885:
994                 case 0x10ec0889:
995                         snd_hda_codec_write(codec, 0x20, 0,
996                                             AC_VERB_SET_COEF_INDEX, 7);
997                         tmp = snd_hda_codec_read(codec, 0x20, 0,
998                                                  AC_VERB_GET_PROC_COEF, 0);
999                         snd_hda_codec_write(codec, 0x20, 0,
1000                                             AC_VERB_SET_COEF_INDEX, 7);
1001                         snd_hda_codec_write(codec, 0x20, 0,
1002                                             AC_VERB_SET_PROC_COEF,
1003                                             tmp | 0x2010);
1004                         break;
1005                 case 0x10ec0888:
1006                         /*alc888_coef_init(codec);*/ /* called in alc_init() */
1007                         break;
1008                 case 0x10ec0267:
1009                 case 0x10ec0268:
1010                         snd_hda_codec_write(codec, 0x20, 0,
1011                                             AC_VERB_SET_COEF_INDEX, 7);
1012                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1013                                                  AC_VERB_GET_PROC_COEF, 0);
1014                         snd_hda_codec_write(codec, 0x20, 0,
1015                                             AC_VERB_SET_COEF_INDEX, 7);
1016                         snd_hda_codec_write(codec, 0x20, 0,
1017                                             AC_VERB_SET_PROC_COEF,
1018                                             tmp | 0x3000);
1019                         break;
1020                 }
1021         default:
1022                 break;
1023         }
1024
1025         /* is laptop or Desktop and enable the function "Mute internal speaker
1026          * when the external headphone out jack is plugged"
1027          */
1028         if (!(ass & 0x8000))
1029                 return;
1030         /*
1031          * 10~8 : Jack location
1032          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1033          * 14~13: Resvered
1034          * 15   : 1 --> enable the function "Mute internal speaker
1035          *              when the external headphone out jack is plugged"
1036          */
1037         if (!spec->autocfg.speaker_pins[0]) {
1038                 if (spec->autocfg.line_out_pins[0])
1039                         spec->autocfg.speaker_pins[0] =
1040                                 spec->autocfg.line_out_pins[0];
1041                 else
1042                         return;
1043         }
1044
1045         if (!spec->autocfg.hp_pins[0]) {
1046                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1047                 if (tmp == 0)
1048                         spec->autocfg.hp_pins[0] = porta;
1049                 else if (tmp == 1)
1050                         spec->autocfg.hp_pins[0] = porte;
1051                 else if (tmp == 2)
1052                         spec->autocfg.hp_pins[0] = portd;
1053                 else
1054                         return;
1055         }
1056         if (spec->autocfg.hp_pins[0])
1057                 snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1058                         AC_VERB_SET_UNSOLICITED_ENABLE,
1059                         AC_USRSP_EN | ALC880_HP_EVENT);
1060
1061         if (spec->autocfg.input_pins[AUTO_PIN_MIC] &&
1062                 spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC])
1063                 snd_hda_codec_write(codec,
1064                         spec->autocfg.input_pins[AUTO_PIN_MIC], 0,
1065                         AC_VERB_SET_UNSOLICITED_ENABLE,
1066                         AC_USRSP_EN | ALC880_MIC_EVENT);
1067
1068         spec->unsol_event = alc_sku_unsol_event;
1069 }
1070
1071 /*
1072  * Fix-up pin default configurations
1073  */
1074
1075 struct alc_pincfg {
1076         hda_nid_t nid;
1077         u32 val;
1078 };
1079
1080 static void alc_fix_pincfg(struct hda_codec *codec,
1081                            const struct snd_pci_quirk *quirk,
1082                            const struct alc_pincfg **pinfix)
1083 {
1084         const struct alc_pincfg *cfg;
1085
1086         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1087         if (!quirk)
1088                 return;
1089
1090         cfg = pinfix[quirk->value];
1091         for (; cfg->nid; cfg++) {
1092                 int i;
1093                 u32 val = cfg->val;
1094                 for (i = 0; i < 4; i++) {
1095                         snd_hda_codec_write(codec, cfg->nid, 0,
1096                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
1097                                     val & 0xff);
1098                         val >>= 8;
1099                 }
1100         }
1101 }
1102
1103 /*
1104  * ALC880 3-stack model
1105  *
1106  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1107  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1108  *                 F-Mic = 0x1b, HP = 0x19
1109  */
1110
1111 static hda_nid_t alc880_dac_nids[4] = {
1112         /* front, rear, clfe, rear_surr */
1113         0x02, 0x05, 0x04, 0x03
1114 };
1115
1116 static hda_nid_t alc880_adc_nids[3] = {
1117         /* ADC0-2 */
1118         0x07, 0x08, 0x09,
1119 };
1120
1121 /* The datasheet says the node 0x07 is connected from inputs,
1122  * but it shows zero connection in the real implementation on some devices.
1123  * Note: this is a 915GAV bug, fixed on 915GLV
1124  */
1125 static hda_nid_t alc880_adc_nids_alt[2] = {
1126         /* ADC1-2 */
1127         0x08, 0x09,
1128 };
1129
1130 #define ALC880_DIGOUT_NID       0x06
1131 #define ALC880_DIGIN_NID        0x0a
1132
1133 static struct hda_input_mux alc880_capture_source = {
1134         .num_items = 4,
1135         .items = {
1136                 { "Mic", 0x0 },
1137                 { "Front Mic", 0x3 },
1138                 { "Line", 0x2 },
1139                 { "CD", 0x4 },
1140         },
1141 };
1142
1143 /* channel source setting (2/6 channel selection for 3-stack) */
1144 /* 2ch mode */
1145 static struct hda_verb alc880_threestack_ch2_init[] = {
1146         /* set line-in to input, mute it */
1147         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1148         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1149         /* set mic-in to input vref 80%, mute it */
1150         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1151         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1152         { } /* end */
1153 };
1154
1155 /* 6ch mode */
1156 static struct hda_verb alc880_threestack_ch6_init[] = {
1157         /* set line-in to output, unmute it */
1158         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1159         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1160         /* set mic-in to output, unmute it */
1161         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1162         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1163         { } /* end */
1164 };
1165
1166 static struct hda_channel_mode alc880_threestack_modes[2] = {
1167         { 2, alc880_threestack_ch2_init },
1168         { 6, alc880_threestack_ch6_init },
1169 };
1170
1171 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1172         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1173         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1174         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1175         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1176         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1177         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1178         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1179         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1180         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1181         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1182         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1183         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1184         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1185         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1186         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1187         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1188         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1189         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1190         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1191         {
1192                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1193                 .name = "Channel Mode",
1194                 .info = alc_ch_mode_info,
1195                 .get = alc_ch_mode_get,
1196                 .put = alc_ch_mode_put,
1197         },
1198         { } /* end */
1199 };
1200
1201 /* capture mixer elements */
1202 static struct snd_kcontrol_new alc880_capture_mixer[] = {
1203         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
1204         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
1205         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
1206         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
1207         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
1208         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
1209         {
1210                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1211                 /* The multiple "Capture Source" controls confuse alsamixer
1212                  * So call somewhat different..
1213                  */
1214                 /* .name = "Capture Source", */
1215                 .name = "Input Source",
1216                 .count = 3,
1217                 .info = alc_mux_enum_info,
1218                 .get = alc_mux_enum_get,
1219                 .put = alc_mux_enum_put,
1220         },
1221         { } /* end */
1222 };
1223
1224 /* capture mixer elements (in case NID 0x07 not available) */
1225 static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
1226         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1227         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1228         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
1229         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
1230         {
1231                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1232                 /* The multiple "Capture Source" controls confuse alsamixer
1233                  * So call somewhat different..
1234                  */
1235                 /* .name = "Capture Source", */
1236                 .name = "Input Source",
1237                 .count = 2,
1238                 .info = alc_mux_enum_info,
1239                 .get = alc_mux_enum_get,
1240                 .put = alc_mux_enum_put,
1241         },
1242         { } /* end */
1243 };
1244
1245
1246
1247 /*
1248  * ALC880 5-stack model
1249  *
1250  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1251  *      Side = 0x02 (0xd)
1252  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1253  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1254  */
1255
1256 /* additional mixers to alc880_three_stack_mixer */
1257 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1258         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1259         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1260         { } /* end */
1261 };
1262
1263 /* channel source setting (6/8 channel selection for 5-stack) */
1264 /* 6ch mode */
1265 static struct hda_verb alc880_fivestack_ch6_init[] = {
1266         /* set line-in to input, mute it */
1267         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1268         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1269         { } /* end */
1270 };
1271
1272 /* 8ch mode */
1273 static struct hda_verb alc880_fivestack_ch8_init[] = {
1274         /* set line-in to output, unmute it */
1275         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1276         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1277         { } /* end */
1278 };
1279
1280 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1281         { 6, alc880_fivestack_ch6_init },
1282         { 8, alc880_fivestack_ch8_init },
1283 };
1284
1285
1286 /*
1287  * ALC880 6-stack model
1288  *
1289  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1290  *      Side = 0x05 (0x0f)
1291  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1292  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1293  */
1294
1295 static hda_nid_t alc880_6st_dac_nids[4] = {
1296         /* front, rear, clfe, rear_surr */
1297         0x02, 0x03, 0x04, 0x05
1298 };
1299
1300 static struct hda_input_mux alc880_6stack_capture_source = {
1301         .num_items = 4,
1302         .items = {
1303                 { "Mic", 0x0 },
1304                 { "Front Mic", 0x1 },
1305                 { "Line", 0x2 },
1306                 { "CD", 0x4 },
1307         },
1308 };
1309
1310 /* fixed 8-channels */
1311 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1312         { 8, NULL },
1313 };
1314
1315 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1316         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1317         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1318         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1319         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1320         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1321         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1322         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1323         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1324         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1325         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1326         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1327         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1328         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1329         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1330         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1331         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1332         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1333         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1334         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1335         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1336         {
1337                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1338                 .name = "Channel Mode",
1339                 .info = alc_ch_mode_info,
1340                 .get = alc_ch_mode_get,
1341                 .put = alc_ch_mode_put,
1342         },
1343         { } /* end */
1344 };
1345
1346
1347 /*
1348  * ALC880 W810 model
1349  *
1350  * W810 has rear IO for:
1351  * Front (DAC 02)
1352  * Surround (DAC 03)
1353  * Center/LFE (DAC 04)
1354  * Digital out (06)
1355  *
1356  * The system also has a pair of internal speakers, and a headphone jack.
1357  * These are both connected to Line2 on the codec, hence to DAC 02.
1358  *
1359  * There is a variable resistor to control the speaker or headphone
1360  * volume. This is a hardware-only device without a software API.
1361  *
1362  * Plugging headphones in will disable the internal speakers. This is
1363  * implemented in hardware, not via the driver using jack sense. In
1364  * a similar fashion, plugging into the rear socket marked "front" will
1365  * disable both the speakers and headphones.
1366  *
1367  * For input, there's a microphone jack, and an "audio in" jack.
1368  * These may not do anything useful with this driver yet, because I
1369  * haven't setup any initialization verbs for these yet...
1370  */
1371
1372 static hda_nid_t alc880_w810_dac_nids[3] = {
1373         /* front, rear/surround, clfe */
1374         0x02, 0x03, 0x04
1375 };
1376
1377 /* fixed 6 channels */
1378 static struct hda_channel_mode alc880_w810_modes[1] = {
1379         { 6, NULL }
1380 };
1381
1382 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1383 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1384         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1385         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1386         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1387         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1388         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1389         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1390         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1391         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1392         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1393         { } /* end */
1394 };
1395
1396
1397 /*
1398  * Z710V model
1399  *
1400  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1401  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1402  *                 Line = 0x1a
1403  */
1404
1405 static hda_nid_t alc880_z71v_dac_nids[1] = {
1406         0x02
1407 };
1408 #define ALC880_Z71V_HP_DAC      0x03
1409
1410 /* fixed 2 channels */
1411 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1412         { 2, NULL }
1413 };
1414
1415 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1416         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1417         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1418         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1419         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1420         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1421         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1422         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1423         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1424         { } /* end */
1425 };
1426
1427
1428 /*
1429  * ALC880 F1734 model
1430  *
1431  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1432  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1433  */
1434
1435 static hda_nid_t alc880_f1734_dac_nids[1] = {
1436         0x03
1437 };
1438 #define ALC880_F1734_HP_DAC     0x02
1439
1440 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1441         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1442         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1443         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1444         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1445         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1446         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1447         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1448         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1449         { } /* end */
1450 };
1451
1452 static struct hda_input_mux alc880_f1734_capture_source = {
1453         .num_items = 2,
1454         .items = {
1455                 { "Mic", 0x1 },
1456                 { "CD", 0x4 },
1457         },
1458 };
1459
1460
1461 /*
1462  * ALC880 ASUS model
1463  *
1464  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1465  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1466  *  Mic = 0x18, Line = 0x1a
1467  */
1468
1469 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1470 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1471
1472 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1473         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1474         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1475         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1476         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1477         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1478         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1479         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1480         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1481         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1482         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1483         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1484         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1485         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1486         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1487         {
1488                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1489                 .name = "Channel Mode",
1490                 .info = alc_ch_mode_info,
1491                 .get = alc_ch_mode_get,
1492                 .put = alc_ch_mode_put,
1493         },
1494         { } /* end */
1495 };
1496
1497 /*
1498  * ALC880 ASUS W1V model
1499  *
1500  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1501  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1502  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1503  */
1504
1505 /* additional mixers to alc880_asus_mixer */
1506 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1507         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1508         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1509         { } /* end */
1510 };
1511
1512 /* additional mixers to alc880_asus_mixer */
1513 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1514         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1515         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1516         { } /* end */
1517 };
1518
1519 /* TCL S700 */
1520 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1521         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1522         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1523         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1524         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1525         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1526         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1527         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1528         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1529         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1530         {
1531                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1532                 /* The multiple "Capture Source" controls confuse alsamixer
1533                  * So call somewhat different..
1534                  */
1535                 /* .name = "Capture Source", */
1536                 .name = "Input Source",
1537                 .count = 1,
1538                 .info = alc_mux_enum_info,
1539                 .get = alc_mux_enum_get,
1540                 .put = alc_mux_enum_put,
1541         },
1542         { } /* end */
1543 };
1544
1545 /* Uniwill */
1546 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1547         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1548         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1549         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1550         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1551         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1552         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1553         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1554         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1555         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1556         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1557         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1558         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1559         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1560         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1561         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1562         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1563         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1564         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1565         {
1566                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1567                 .name = "Channel Mode",
1568                 .info = alc_ch_mode_info,
1569                 .get = alc_ch_mode_get,
1570                 .put = alc_ch_mode_put,
1571         },
1572         { } /* end */
1573 };
1574
1575 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1576         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1577         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1578         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1579         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1580         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1581         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1582         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1583         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1584         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1585         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1586         { } /* end */
1587 };
1588
1589 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1590         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1591         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1592         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1593         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1594         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1595         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1596         { } /* end */
1597 };
1598
1599 /*
1600  * virtual master controls
1601  */
1602
1603 /*
1604  * slave controls for virtual master
1605  */
1606 static const char *alc_slave_vols[] = {
1607         "Front Playback Volume",
1608         "Surround Playback Volume",
1609         "Center Playback Volume",
1610         "LFE Playback Volume",
1611         "Side Playback Volume",
1612         "Headphone Playback Volume",
1613         "Speaker Playback Volume",
1614         "Mono Playback Volume",
1615         "Line-Out Playback Volume",
1616         NULL,
1617 };
1618
1619 static const char *alc_slave_sws[] = {
1620         "Front Playback Switch",
1621         "Surround Playback Switch",
1622         "Center Playback Switch",
1623         "LFE Playback Switch",
1624         "Side Playback Switch",
1625         "Headphone Playback Switch",
1626         "Speaker Playback Switch",
1627         "Mono Playback Switch",
1628         "IEC958 Playback Switch",
1629         NULL,
1630 };
1631
1632 /*
1633  * build control elements
1634  */
1635 static int alc_build_controls(struct hda_codec *codec)
1636 {
1637         struct alc_spec *spec = codec->spec;
1638         int err;
1639         int i;
1640
1641         for (i = 0; i < spec->num_mixers; i++) {
1642                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1643                 if (err < 0)
1644                         return err;
1645         }
1646
1647         if (spec->multiout.dig_out_nid) {
1648                 err = snd_hda_create_spdif_out_ctls(codec,
1649                                                     spec->multiout.dig_out_nid);
1650                 if (err < 0)
1651                         return err;
1652                 err = snd_hda_create_spdif_share_sw(codec,
1653                                                     &spec->multiout);
1654                 if (err < 0)
1655                         return err;
1656                 spec->multiout.share_spdif = 1;
1657         }
1658         if (spec->dig_in_nid) {
1659                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1660                 if (err < 0)
1661                         return err;
1662         }
1663
1664         /* if we have no master control, let's create it */
1665         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1666                 unsigned int vmaster_tlv[4];
1667                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1668                                         HDA_OUTPUT, vmaster_tlv);
1669                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1670                                           vmaster_tlv, alc_slave_vols);
1671                 if (err < 0)
1672                         return err;
1673         }
1674         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1675                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1676                                           NULL, alc_slave_sws);
1677                 if (err < 0)
1678                         return err;
1679         }
1680
1681         return 0;
1682 }
1683
1684
1685 /*
1686  * initialize the codec volumes, etc
1687  */
1688
1689 /*
1690  * generic initialization of ADC, input mixers and output mixers
1691  */
1692 static struct hda_verb alc880_volume_init_verbs[] = {
1693         /*
1694          * Unmute ADC0-2 and set the default input to mic-in
1695          */
1696         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
1697         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1698         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
1699         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1700         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1701         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1702
1703         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1704          * mixer widget
1705          * Note: PASD motherboards uses the Line In 2 as the input for front
1706          * panel mic (mic 2)
1707          */
1708         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
1709         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1710         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1711         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1712         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1713         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1714         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1715         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1716
1717         /*
1718          * Set up output mixers (0x0c - 0x0f)
1719          */
1720         /* set vol=0 to output mixers */
1721         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1722         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1723         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1724         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1725         /* set up input amps for analog loopback */
1726         /* Amp Indices: DAC = 0, mixer = 1 */
1727         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1728         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1729         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1730         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1731         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1732         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1733         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1734         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1735
1736         { }
1737 };
1738
1739 /*
1740  * 3-stack pin configuration:
1741  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
1742  */
1743 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
1744         /*
1745          * preset connection lists of input pins
1746          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1747          */
1748         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1749         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1750         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1751
1752         /*
1753          * Set pin mode and muting
1754          */
1755         /* set front pin widgets 0x14 for output */
1756         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1757         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1758         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1759         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1760         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1761         /* Mic2 (as headphone out) for HP output */
1762         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1763         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1764         /* Line In pin widget for input */
1765         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1766         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1767         /* Line2 (as front mic) pin widget for input and vref at 80% */
1768         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1769         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1770         /* CD pin widget for input */
1771         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1772
1773         { }
1774 };
1775
1776 /*
1777  * 5-stack pin configuration:
1778  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
1779  * line-in/side = 0x1a, f-mic = 0x1b
1780  */
1781 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
1782         /*
1783          * preset connection lists of input pins
1784          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1785          */
1786         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1787         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1788
1789         /*
1790          * Set pin mode and muting
1791          */
1792         /* set pin widgets 0x14-0x17 for output */
1793         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1794         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1795         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1796         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1797         /* unmute pins for output (no gain on this amp) */
1798         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1799         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1800         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1801         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1802
1803         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1804         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1805         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1806         /* Mic2 (as headphone out) for HP output */
1807         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1808         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1809         /* Line In pin widget for input */
1810         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1811         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1812         /* Line2 (as front mic) pin widget for input and vref at 80% */
1813         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1814         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1815         /* CD pin widget for input */
1816         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1817
1818         { }
1819 };
1820
1821 /*
1822  * W810 pin configuration:
1823  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
1824  */
1825 static struct hda_verb alc880_pin_w810_init_verbs[] = {
1826         /* hphone/speaker input selector: front DAC */
1827         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1828
1829         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1830         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1831         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1832         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1833         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1834         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1835
1836         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1837         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1838
1839         { }
1840 };
1841
1842 /*
1843  * Z71V pin configuration:
1844  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
1845  */
1846 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
1847         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1848         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1849         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1850         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1851
1852         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1853         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1854         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1855         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1856
1857         { }
1858 };
1859
1860 /*
1861  * 6-stack pin configuration:
1862  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
1863  * f-mic = 0x19, line = 0x1a, HP = 0x1b
1864  */
1865 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1866         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1867
1868         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1869         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1870         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1871         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1872         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1873         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1874         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1875         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1876
1877         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1878         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1879         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1880         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1881         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1882         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1883         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1884         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1885         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1886
1887         { }
1888 };
1889
1890 /*
1891  * Uniwill pin configuration:
1892  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
1893  * line = 0x1a
1894  */
1895 static struct hda_verb alc880_uniwill_init_verbs[] = {
1896         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1897
1898         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1899         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1900         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1901         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1902         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1903         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1904         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1905         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1906         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1907         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1908         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1909         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1910         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1911         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1912
1913         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1914         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1915         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1916         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1917         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1918         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1919         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
1920         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
1921         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1922
1923         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1924         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
1925
1926         { }
1927 };
1928
1929 /*
1930 * Uniwill P53
1931 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
1932  */
1933 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
1934         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1935
1936         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1937         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1938         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1939         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1940         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1941         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1942         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1943         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1944         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1945         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1946         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1947         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1948
1949         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1950         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1951         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1952         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1953         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1954         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1955
1956         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1957         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
1958
1959         { }
1960 };
1961
1962 static struct hda_verb alc880_beep_init_verbs[] = {
1963         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
1964         { }
1965 };
1966
1967 /* toggle speaker-output according to the hp-jack state */
1968 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
1969 {
1970         unsigned int present;
1971         unsigned char bits;
1972
1973         present = snd_hda_codec_read(codec, 0x14, 0,
1974                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1975         bits = present ? HDA_AMP_MUTE : 0;
1976         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1977                                  HDA_AMP_MUTE, bits);
1978         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
1979                                  HDA_AMP_MUTE, bits);
1980 }
1981
1982 /* auto-toggle front mic */
1983 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
1984 {
1985         unsigned int present;
1986         unsigned char bits;
1987
1988         present = snd_hda_codec_read(codec, 0x18, 0,
1989                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1990         bits = present ? HDA_AMP_MUTE : 0;
1991         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
1992 }
1993
1994 static void alc880_uniwill_automute(struct hda_codec *codec)
1995 {
1996         alc880_uniwill_hp_automute(codec);
1997         alc880_uniwill_mic_automute(codec);
1998 }
1999
2000 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2001                                        unsigned int res)
2002 {
2003         /* Looks like the unsol event is incompatible with the standard
2004          * definition.  4bit tag is placed at 28 bit!
2005          */
2006         switch (res >> 28) {
2007         case ALC880_HP_EVENT:
2008                 alc880_uniwill_hp_automute(codec);
2009                 break;
2010         case ALC880_MIC_EVENT:
2011                 alc880_uniwill_mic_automute(codec);
2012                 break;
2013         }
2014 }
2015
2016 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
2017 {
2018         unsigned int present;
2019         unsigned char bits;
2020
2021         present = snd_hda_codec_read(codec, 0x14, 0,
2022                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2023         bits = present ? HDA_AMP_MUTE : 0;
2024         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
2025 }
2026
2027 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2028 {
2029         unsigned int present;
2030
2031         present = snd_hda_codec_read(codec, 0x21, 0,
2032                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2033         present &= HDA_AMP_VOLMASK;
2034         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2035                                  HDA_AMP_VOLMASK, present);
2036         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2037                                  HDA_AMP_VOLMASK, present);
2038 }
2039
2040 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2041                                            unsigned int res)
2042 {
2043         /* Looks like the unsol event is incompatible with the standard
2044          * definition.  4bit tag is placed at 28 bit!
2045          */
2046         if ((res >> 28) == ALC880_HP_EVENT)
2047                 alc880_uniwill_p53_hp_automute(codec);
2048         if ((res >> 28) == ALC880_DCVOL_EVENT)
2049                 alc880_uniwill_p53_dcvol_automute(codec);
2050 }
2051
2052 /*
2053  * F1734 pin configuration:
2054  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2055  */
2056 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2057         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2058         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2059         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2060         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2061         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2062
2063         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2064         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2065         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2066         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2067
2068         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2069         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2070         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2071         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2072         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2073         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2074         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2075         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2076         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2077
2078         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2079         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2080
2081         { }
2082 };
2083
2084 /*
2085  * ASUS pin configuration:
2086  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2087  */
2088 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2089         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2090         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2091         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2092         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2093
2094         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2095         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2096         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2097         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2098         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2099         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2100         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2101         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2102
2103         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2104         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2105         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2106         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2107         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2108         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2109         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2110         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2111         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2112
2113         { }
2114 };
2115
2116 /* Enable GPIO mask and set output */
2117 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2118 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2119
2120 /* Clevo m520g init */
2121 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2122         /* headphone output */
2123         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2124         /* line-out */
2125         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2126         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2127         /* Line-in */
2128         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2129         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2130         /* CD */
2131         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2132         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2133         /* Mic1 (rear panel) */
2134         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2135         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2136         /* Mic2 (front panel) */
2137         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2138         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2139         /* headphone */
2140         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2141         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2142         /* change to EAPD mode */
2143         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2144         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2145
2146         { }
2147 };
2148
2149 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2150         /* change to EAPD mode */
2151         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2152         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2153
2154         /* Headphone output */
2155         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2156         /* Front output*/
2157         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2158         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2159
2160         /* Line In pin widget for input */
2161         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2162         /* CD pin widget for input */
2163         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2164         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2165         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2166
2167         /* change to EAPD mode */
2168         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2169         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2170
2171         { }
2172 };
2173
2174 /*
2175  * LG m1 express dual
2176  *
2177  * Pin assignment:
2178  *   Rear Line-In/Out (blue): 0x14
2179  *   Build-in Mic-In: 0x15
2180  *   Speaker-out: 0x17
2181  *   HP-Out (green): 0x1b
2182  *   Mic-In/Out (red): 0x19
2183  *   SPDIF-Out: 0x1e
2184  */
2185
2186 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2187 static hda_nid_t alc880_lg_dac_nids[3] = {
2188         0x05, 0x02, 0x03
2189 };
2190
2191 /* seems analog CD is not working */
2192 static struct hda_input_mux alc880_lg_capture_source = {
2193         .num_items = 3,
2194         .items = {
2195                 { "Mic", 0x1 },
2196                 { "Line", 0x5 },
2197                 { "Internal Mic", 0x6 },
2198         },
2199 };
2200
2201 /* 2,4,6 channel modes */
2202 static struct hda_verb alc880_lg_ch2_init[] = {
2203         /* set line-in and mic-in to input */
2204         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2205         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2206         { }
2207 };
2208
2209 static struct hda_verb alc880_lg_ch4_init[] = {
2210         /* set line-in to out and mic-in to input */
2211         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2212         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2213         { }
2214 };
2215
2216 static struct hda_verb alc880_lg_ch6_init[] = {
2217         /* set line-in and mic-in to output */
2218         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2219         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2220         { }
2221 };
2222
2223 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2224         { 2, alc880_lg_ch2_init },
2225         { 4, alc880_lg_ch4_init },
2226         { 6, alc880_lg_ch6_init },
2227 };
2228
2229 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2230         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2231         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2232         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2233         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2234         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2235         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2236         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2237         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2238         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2239         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2240         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2241         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2242         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2243         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2244         {
2245                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2246                 .name = "Channel Mode",
2247                 .info = alc_ch_mode_info,
2248                 .get = alc_ch_mode_get,
2249                 .put = alc_ch_mode_put,
2250         },
2251         { } /* end */
2252 };
2253
2254 static struct hda_verb alc880_lg_init_verbs[] = {
2255         /* set capture source to mic-in */
2256         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2257         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2258         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2259         /* mute all amp mixer inputs */
2260         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2261         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2262         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2263         /* line-in to input */
2264         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2265         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2266         /* built-in mic */
2267         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2268         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2269         /* speaker-out */
2270         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2271         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2272         /* mic-in to input */
2273         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2274         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2275         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2276         /* HP-out */
2277         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2278         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2279         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2280         /* jack sense */
2281         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2282         { }
2283 };
2284
2285 /* toggle speaker-output according to the hp-jack state */
2286 static void alc880_lg_automute(struct hda_codec *codec)
2287 {
2288         unsigned int present;
2289         unsigned char bits;
2290
2291         present = snd_hda_codec_read(codec, 0x1b, 0,
2292                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2293         bits = present ? HDA_AMP_MUTE : 0;
2294         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2295                                  HDA_AMP_MUTE, bits);
2296 }
2297
2298 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2299 {
2300         /* Looks like the unsol event is incompatible with the standard
2301          * definition.  4bit tag is placed at 28 bit!
2302          */
2303         if ((res >> 28) == 0x01)
2304                 alc880_lg_automute(codec);
2305 }
2306
2307 /*
2308  * LG LW20
2309  *
2310  * Pin assignment:
2311  *   Speaker-out: 0x14
2312  *   Mic-In: 0x18
2313  *   Built-in Mic-In: 0x19
2314  *   Line-In: 0x1b
2315  *   HP-Out: 0x1a
2316  *   SPDIF-Out: 0x1e
2317  */
2318
2319 static struct hda_input_mux alc880_lg_lw_capture_source = {
2320         .num_items = 3,
2321         .items = {
2322                 { "Mic", 0x0 },
2323                 { "Internal Mic", 0x1 },
2324                 { "Line In", 0x2 },
2325         },
2326 };
2327
2328 #define alc880_lg_lw_modes alc880_threestack_modes
2329
2330 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2331         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2332         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2333         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2334         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2335         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2336         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2337         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2338         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2339         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2340         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2341         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2342         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2343         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2344         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2345         {
2346                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2347                 .name = "Channel Mode",
2348                 .info = alc_ch_mode_info,
2349                 .get = alc_ch_mode_get,
2350                 .put = alc_ch_mode_put,
2351         },
2352         { } /* end */
2353 };
2354
2355 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2356         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2357         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2358         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2359
2360         /* set capture source to mic-in */
2361         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2362         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2363         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2364         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2365         /* speaker-out */
2366         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2367         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2368         /* HP-out */
2369         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2370         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2371         /* mic-in to input */
2372         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2373         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2374         /* built-in mic */
2375         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2376         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2377         /* jack sense */
2378         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2379         { }
2380 };
2381
2382 /* toggle speaker-output according to the hp-jack state */
2383 static void alc880_lg_lw_automute(struct hda_codec *codec)
2384 {
2385         unsigned int present;
2386         unsigned char bits;
2387
2388         present = snd_hda_codec_read(codec, 0x1b, 0,
2389                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2390         bits = present ? HDA_AMP_MUTE : 0;
2391         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2392                                  HDA_AMP_MUTE, bits);
2393 }
2394
2395 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2396 {
2397         /* Looks like the unsol event is incompatible with the standard
2398          * definition.  4bit tag is placed at 28 bit!
2399          */
2400         if ((res >> 28) == 0x01)
2401                 alc880_lg_lw_automute(codec);
2402 }
2403
2404 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2405         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2406         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2407         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2408         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2409         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2410         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2411         { } /* end */
2412 };
2413
2414 static struct hda_input_mux alc880_medion_rim_capture_source = {
2415         .num_items = 2,
2416         .items = {
2417                 { "Mic", 0x0 },
2418                 { "Internal Mic", 0x1 },
2419         },
2420 };
2421
2422 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2423         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2424
2425         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2426         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2427
2428         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2429         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2430         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2431         /* Mic2 (as headphone out) for HP output */
2432         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2433         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2434         /* Internal Speaker */
2435         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2436         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2437
2438         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2439         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2440
2441         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2442         { }
2443 };
2444
2445 /* toggle speaker-output according to the hp-jack state */
2446 static void alc880_medion_rim_automute(struct hda_codec *codec)
2447 {
2448         unsigned int present;
2449         unsigned char bits;
2450
2451         present = snd_hda_codec_read(codec, 0x14, 0,
2452                                      AC_VERB_GET_PIN_SENSE, 0)
2453                 & AC_PINSENSE_PRESENCE;
2454         bits = present ? HDA_AMP_MUTE : 0;
2455         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2456                                  HDA_AMP_MUTE, bits);
2457         if (present)
2458                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2459         else
2460                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2461 }
2462
2463 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2464                                           unsigned int res)
2465 {
2466         /* Looks like the unsol event is incompatible with the standard
2467          * definition.  4bit tag is placed at 28 bit!
2468          */
2469         if ((res >> 28) == ALC880_HP_EVENT)
2470                 alc880_medion_rim_automute(codec);
2471 }
2472
2473 #ifdef CONFIG_SND_HDA_POWER_SAVE
2474 static struct hda_amp_list alc880_loopbacks[] = {
2475         { 0x0b, HDA_INPUT, 0 },
2476         { 0x0b, HDA_INPUT, 1 },
2477         { 0x0b, HDA_INPUT, 2 },
2478         { 0x0b, HDA_INPUT, 3 },
2479         { 0x0b, HDA_INPUT, 4 },
2480         { } /* end */
2481 };
2482
2483 static struct hda_amp_list alc880_lg_loopbacks[] = {
2484         { 0x0b, HDA_INPUT, 1 },
2485         { 0x0b, HDA_INPUT, 6 },
2486         { 0x0b, HDA_INPUT, 7 },
2487         { } /* end */
2488 };
2489 #endif
2490
2491 /*
2492  * Common callbacks
2493  */
2494
2495 static int alc_init(struct hda_codec *codec)
2496 {
2497         struct alc_spec *spec = codec->spec;
2498         unsigned int i;
2499
2500         alc_fix_pll(codec);
2501         if (codec->vendor_id == 0x10ec0888)
2502                 alc888_coef_init(codec);
2503
2504         for (i = 0; i < spec->num_init_verbs; i++)
2505                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2506
2507         if (spec->init_hook)
2508                 spec->init_hook(codec);
2509
2510         return 0;
2511 }
2512
2513 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2514 {
2515         struct alc_spec *spec = codec->spec;
2516
2517         if (spec->unsol_event)
2518                 spec->unsol_event(codec, res);
2519 }
2520
2521 #ifdef CONFIG_SND_HDA_POWER_SAVE
2522 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2523 {
2524         struct alc_spec *spec = codec->spec;
2525         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2526 }
2527 #endif
2528
2529 /*
2530  * Analog playback callbacks
2531  */
2532 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2533                                     struct hda_codec *codec,
2534                                     struct snd_pcm_substream *substream)
2535 {
2536         struct alc_spec *spec = codec->spec;
2537         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2538                                              hinfo);
2539 }
2540
2541 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2542                                        struct hda_codec *codec,
2543                                        unsigned int stream_tag,
2544                                        unsigned int format,
2545                                        struct snd_pcm_substream *substream)
2546 {
2547         struct alc_spec *spec = codec->spec;
2548         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2549                                                 stream_tag, format, substream);
2550 }
2551
2552 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2553                                        struct hda_codec *codec,
2554                                        struct snd_pcm_substream *substream)
2555 {
2556         struct alc_spec *spec = codec->spec;
2557         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2558 }
2559
2560 /*
2561  * Digital out
2562  */
2563 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2564                                         struct hda_codec *codec,
2565                                         struct snd_pcm_substream *substream)
2566 {
2567         struct alc_spec *spec = codec->spec;
2568         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2569 }
2570
2571 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2572                                            struct hda_codec *codec,
2573                                            unsigned int stream_tag,
2574                                            unsigned int format,
2575                                            struct snd_pcm_substream *substream)
2576 {
2577         struct alc_spec *spec = codec->spec;
2578         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2579                                              stream_tag, format, substream);
2580 }
2581
2582 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2583                                          struct hda_codec *codec,
2584                                          struct snd_pcm_substream *substream)
2585 {
2586         struct alc_spec *spec = codec->spec;
2587         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2588 }
2589
2590 /*
2591  * Analog capture
2592  */
2593 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2594                                       struct hda_codec *codec,
2595                                       unsigned int stream_tag,
2596                                       unsigned int format,
2597                                       struct snd_pcm_substream *substream)
2598 {
2599         struct alc_spec *spec = codec->spec;
2600
2601         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2602                                    stream_tag, 0, format);
2603         return 0;
2604 }
2605
2606 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2607                                       struct hda_codec *codec,
2608                                       struct snd_pcm_substream *substream)
2609 {
2610         struct alc_spec *spec = codec->spec;
2611
2612         snd_hda_codec_cleanup_stream(codec,
2613                                      spec->adc_nids[substream->number + 1]);
2614         return 0;
2615 }
2616
2617
2618 /*
2619  */
2620 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2621         .substreams = 1,
2622         .channels_min = 2,
2623         .channels_max = 8,
2624         /* NID is set in alc_build_pcms */
2625         .ops = {
2626                 .open = alc880_playback_pcm_open,
2627                 .prepare = alc880_playback_pcm_prepare,
2628                 .cleanup = alc880_playback_pcm_cleanup
2629         },
2630 };
2631
2632 static struct hda_pcm_stream alc880_pcm_analog_capture = {
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_playback = {
2640         .substreams = 1,
2641         .channels_min = 2,
2642         .channels_max = 2,
2643         /* NID is set in alc_build_pcms */
2644 };
2645
2646 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
2647         .substreams = 2, /* can be overridden */
2648         .channels_min = 2,
2649         .channels_max = 2,
2650         /* NID is set in alc_build_pcms */
2651         .ops = {
2652                 .prepare = alc880_alt_capture_pcm_prepare,
2653                 .cleanup = alc880_alt_capture_pcm_cleanup
2654         },
2655 };
2656
2657 static struct hda_pcm_stream alc880_pcm_digital_playback = {
2658         .substreams = 1,
2659         .channels_min = 2,
2660         .channels_max = 2,
2661         /* NID is set in alc_build_pcms */
2662         .ops = {
2663                 .open = alc880_dig_playback_pcm_open,
2664                 .close = alc880_dig_playback_pcm_close,
2665                 .prepare = alc880_dig_playback_pcm_prepare
2666         },
2667 };
2668
2669 static struct hda_pcm_stream alc880_pcm_digital_capture = {
2670         .substreams = 1,
2671         .channels_min = 2,
2672         .channels_max = 2,
2673         /* NID is set in alc_build_pcms */
2674 };
2675
2676 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2677 static struct hda_pcm_stream alc_pcm_null_stream = {
2678         .substreams = 0,
2679         .channels_min = 0,
2680         .channels_max = 0,
2681 };
2682
2683 static int alc_build_pcms(struct hda_codec *codec)
2684 {
2685         struct alc_spec *spec = codec->spec;
2686         struct hda_pcm *info = spec->pcm_rec;
2687         int i;
2688
2689         codec->num_pcms = 1;
2690         codec->pcm_info = info;
2691
2692         info->name = spec->stream_name_analog;
2693         if (spec->stream_analog_playback) {
2694                 if (snd_BUG_ON(!spec->multiout.dac_nids))
2695                         return -EINVAL;
2696                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
2697                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2698         }
2699         if (spec->stream_analog_capture) {
2700                 if (snd_BUG_ON(!spec->adc_nids))
2701                         return -EINVAL;
2702                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2703                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2704         }
2705
2706         if (spec->channel_mode) {
2707                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2708                 for (i = 0; i < spec->num_channel_mode; i++) {
2709                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2710                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2711                         }
2712                 }
2713         }
2714
2715         /* SPDIF for stream index #1 */
2716         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2717                 codec->num_pcms = 2;
2718                 info = spec->pcm_rec + 1;
2719                 info->name = spec->stream_name_digital;
2720                 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2721                 if (spec->multiout.dig_out_nid &&
2722                     spec->stream_digital_playback) {
2723                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
2724                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2725                 }
2726                 if (spec->dig_in_nid &&
2727                     spec->stream_digital_capture) {
2728                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
2729                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2730                 }
2731                 /* FIXME: do we need this for all Realtek codec models? */
2732                 codec->spdif_status_reset = 1;
2733         }
2734
2735         /* If the use of more than one ADC is requested for the current
2736          * model, configure a second analog capture-only PCM.
2737          */
2738         /* Additional Analaog capture for index #2 */
2739         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
2740             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
2741                 codec->num_pcms = 3;
2742                 info = spec->pcm_rec + 2;
2743                 info->name = spec->stream_name_analog;
2744                 if (spec->alt_dac_nid) {
2745                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2746                                 *spec->stream_analog_alt_playback;
2747                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2748                                 spec->alt_dac_nid;
2749                 } else {
2750                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2751                                 alc_pcm_null_stream;
2752                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2753                 }
2754                 if (spec->num_adc_nids > 1) {
2755                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2756                                 *spec->stream_analog_alt_capture;
2757                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2758                                 spec->adc_nids[1];
2759                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2760                                 spec->num_adc_nids - 1;
2761                 } else {
2762                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2763                                 alc_pcm_null_stream;
2764                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2765                 }
2766         }
2767
2768         return 0;
2769 }
2770
2771 static void alc_free(struct hda_codec *codec)
2772 {
2773         struct alc_spec *spec = codec->spec;
2774         unsigned int i;
2775
2776         if (!spec)
2777                 return;
2778
2779         if (spec->kctl_alloc) {
2780                 for (i = 0; i < spec->num_kctl_used; i++)
2781                         kfree(spec->kctl_alloc[i].name);
2782                 kfree(spec->kctl_alloc);
2783         }
2784         kfree(spec);
2785         codec->spec = NULL; /* to be sure */
2786 }
2787
2788 #ifdef SND_HDA_NEEDS_RESUME
2789 static void store_pin_configs(struct hda_codec *codec)
2790 {
2791         struct alc_spec *spec = codec->spec;
2792         hda_nid_t nid, end_nid;
2793
2794         end_nid = codec->start_nid + codec->num_nodes;
2795         for (nid = codec->start_nid; nid < end_nid; nid++) {
2796                 unsigned int wid_caps = get_wcaps(codec, nid);
2797                 unsigned int wid_type =
2798                         (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
2799                 if (wid_type != AC_WID_PIN)
2800                         continue;
2801                 if (spec->num_pins >= ARRAY_SIZE(spec->pin_nids))
2802                         break;
2803                 spec->pin_nids[spec->num_pins] = nid;
2804                 spec->pin_cfgs[spec->num_pins] =
2805                         snd_hda_codec_read(codec, nid, 0,
2806                                            AC_VERB_GET_CONFIG_DEFAULT, 0);
2807                 spec->num_pins++;
2808         }
2809 }
2810
2811 static void resume_pin_configs(struct hda_codec *codec)
2812 {
2813         struct alc_spec *spec = codec->spec;
2814         int i;
2815
2816         for (i = 0; i < spec->num_pins; i++) {
2817                 hda_nid_t pin_nid = spec->pin_nids[i];
2818                 unsigned int pin_config = spec->pin_cfgs[i];
2819                 snd_hda_codec_write(codec, pin_nid, 0,
2820                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
2821                                     pin_config & 0x000000ff);
2822                 snd_hda_codec_write(codec, pin_nid, 0,
2823                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
2824                                     (pin_config & 0x0000ff00) >> 8);
2825                 snd_hda_codec_write(codec, pin_nid, 0,
2826                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
2827                                     (pin_config & 0x00ff0000) >> 16);
2828                 snd_hda_codec_write(codec, pin_nid, 0,
2829                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
2830                                     pin_config >> 24);
2831         }
2832 }
2833
2834 static int alc_resume(struct hda_codec *codec)
2835 {
2836         resume_pin_configs(codec);
2837         codec->patch_ops.init(codec);
2838         snd_hda_codec_resume_amp(codec);
2839         snd_hda_codec_resume_cache(codec);
2840         return 0;
2841 }
2842 #else
2843 #define store_pin_configs(codec)
2844 #endif
2845
2846 /*
2847  */
2848 static struct hda_codec_ops alc_patch_ops = {
2849         .build_controls = alc_build_controls,
2850         .build_pcms = alc_build_pcms,
2851         .init = alc_init,
2852         .free = alc_free,
2853         .unsol_event = alc_unsol_event,
2854 #ifdef SND_HDA_NEEDS_RESUME
2855         .resume = alc_resume,
2856 #endif
2857 #ifdef CONFIG_SND_HDA_POWER_SAVE
2858         .check_power_status = alc_check_power_status,
2859 #endif
2860 };
2861
2862
2863 /*
2864  * Test configuration for debugging
2865  *
2866  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
2867  * enum controls.
2868  */
2869 #ifdef CONFIG_SND_DEBUG
2870 static hda_nid_t alc880_test_dac_nids[4] = {
2871         0x02, 0x03, 0x04, 0x05
2872 };
2873
2874 static struct hda_input_mux alc880_test_capture_source = {
2875         .num_items = 7,
2876         .items = {
2877                 { "In-1", 0x0 },
2878                 { "In-2", 0x1 },
2879                 { "In-3", 0x2 },
2880                 { "In-4", 0x3 },
2881                 { "CD", 0x4 },
2882                 { "Front", 0x5 },
2883                 { "Surround", 0x6 },
2884         },
2885 };
2886
2887 static struct hda_channel_mode alc880_test_modes[4] = {
2888         { 2, NULL },
2889         { 4, NULL },
2890         { 6, NULL },
2891         { 8, NULL },
2892 };
2893
2894 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
2895                                  struct snd_ctl_elem_info *uinfo)
2896 {
2897         static char *texts[] = {
2898                 "N/A", "Line Out", "HP Out",
2899                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
2900         };
2901         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2902         uinfo->count = 1;
2903         uinfo->value.enumerated.items = 8;
2904         if (uinfo->value.enumerated.item >= 8)
2905                 uinfo->value.enumerated.item = 7;
2906         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2907         return 0;
2908 }
2909
2910 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
2911                                 struct snd_ctl_elem_value *ucontrol)
2912 {
2913         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2914         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2915         unsigned int pin_ctl, item = 0;
2916
2917         pin_ctl = snd_hda_codec_read(codec, nid, 0,
2918                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2919         if (pin_ctl & AC_PINCTL_OUT_EN) {
2920                 if (pin_ctl & AC_PINCTL_HP_EN)
2921                         item = 2;
2922                 else
2923                         item = 1;
2924         } else if (pin_ctl & AC_PINCTL_IN_EN) {
2925                 switch (pin_ctl & AC_PINCTL_VREFEN) {
2926                 case AC_PINCTL_VREF_HIZ: item = 3; break;
2927                 case AC_PINCTL_VREF_50:  item = 4; break;
2928                 case AC_PINCTL_VREF_GRD: item = 5; break;
2929                 case AC_PINCTL_VREF_80:  item = 6; break;
2930                 case AC_PINCTL_VREF_100: item = 7; break;
2931                 }
2932         }
2933         ucontrol->value.enumerated.item[0] = item;
2934         return 0;
2935 }
2936
2937 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
2938                                 struct snd_ctl_elem_value *ucontrol)
2939 {
2940         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2941         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2942         static unsigned int ctls[] = {
2943                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
2944                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
2945                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
2946                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
2947                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
2948                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
2949         };
2950         unsigned int old_ctl, new_ctl;
2951
2952         old_ctl = snd_hda_codec_read(codec, nid, 0,
2953                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2954         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
2955         if (old_ctl != new_ctl) {
2956                 int val;
2957                 snd_hda_codec_write_cache(codec, nid, 0,
2958                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
2959                                           new_ctl);
2960                 val = ucontrol->value.enumerated.item[0] >= 3 ?
2961                         HDA_AMP_MUTE : 0;
2962                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
2963                                          HDA_AMP_MUTE, val);
2964                 return 1;
2965         }
2966         return 0;
2967 }
2968
2969 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
2970                                  struct snd_ctl_elem_info *uinfo)
2971 {
2972         static char *texts[] = {
2973                 "Front", "Surround", "CLFE", "Side"
2974         };
2975         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2976         uinfo->count = 1;
2977         uinfo->value.enumerated.items = 4;
2978         if (uinfo->value.enumerated.item >= 4)
2979                 uinfo->value.enumerated.item = 3;
2980         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2981         return 0;
2982 }
2983
2984 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
2985                                 struct snd_ctl_elem_value *ucontrol)
2986 {
2987         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2988         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2989         unsigned int sel;
2990
2991         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
2992         ucontrol->value.enumerated.item[0] = sel & 3;
2993         return 0;
2994 }
2995
2996 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
2997                                 struct snd_ctl_elem_value *ucontrol)
2998 {
2999         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3000         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3001         unsigned int sel;
3002
3003         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3004         if (ucontrol->value.enumerated.item[0] != sel) {
3005                 sel = ucontrol->value.enumerated.item[0] & 3;
3006                 snd_hda_codec_write_cache(codec, nid, 0,
3007                                           AC_VERB_SET_CONNECT_SEL, sel);
3008                 return 1;
3009         }
3010         return 0;
3011 }
3012
3013 #define PIN_CTL_TEST(xname,nid) {                       \
3014                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3015                         .name = xname,                 \
3016                         .info = alc_test_pin_ctl_info, \
3017                         .get = alc_test_pin_ctl_get,   \
3018                         .put = alc_test_pin_ctl_put,   \
3019                         .private_value = nid           \
3020                         }
3021
3022 #define PIN_SRC_TEST(xname,nid) {                       \
3023                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3024                         .name = xname,                 \
3025                         .info = alc_test_pin_src_info, \
3026                         .get = alc_test_pin_src_get,   \
3027                         .put = alc_test_pin_src_put,   \
3028                         .private_value = nid           \
3029                         }
3030
3031 static struct snd_kcontrol_new alc880_test_mixer[] = {
3032         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3033         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3034         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3035         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3036         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3037         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3038         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3039         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3040         PIN_CTL_TEST("Front Pin Mode", 0x14),
3041         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3042         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3043         PIN_CTL_TEST("Side Pin Mode", 0x17),
3044         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3045         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3046         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3047         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3048         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3049         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3050         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3051         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3052         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3053         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3054         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3055         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3056         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3057         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3058         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3059         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3060         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3061         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3062         {
3063                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3064                 .name = "Channel Mode",
3065                 .info = alc_ch_mode_info,
3066                 .get = alc_ch_mode_get,
3067                 .put = alc_ch_mode_put,
3068         },
3069         { } /* end */
3070 };
3071
3072 static struct hda_verb alc880_test_init_verbs[] = {
3073         /* Unmute inputs of 0x0c - 0x0f */
3074         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3075         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3076         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3077         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3078         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3079         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3080         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3081         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3082         /* Vol output for 0x0c-0x0f */
3083         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3084         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3085         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3086         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3087         /* Set output pins 0x14-0x17 */
3088         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3089         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3090         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3091         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3092         /* Unmute output pins 0x14-0x17 */
3093         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3094         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3095         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3096         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3097         /* Set input pins 0x18-0x1c */
3098         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3099         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3100         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3101         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3102         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3103         /* Mute input pins 0x18-0x1b */
3104         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3105         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3106         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3107         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3108         /* ADC set up */
3109         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3110         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3111         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3112         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3113         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3114         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3115         /* Analog input/passthru */
3116         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3117         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3118         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3119         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3120         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3121         { }
3122 };
3123 #endif
3124
3125 /*
3126  */
3127
3128 static const char *alc880_models[ALC880_MODEL_LAST] = {
3129         [ALC880_3ST]            = "3stack",
3130         [ALC880_TCL_S700]       = "tcl",
3131         [ALC880_3ST_DIG]        = "3stack-digout",
3132         [ALC880_CLEVO]          = "clevo",
3133         [ALC880_5ST]            = "5stack",
3134         [ALC880_5ST_DIG]        = "5stack-digout",
3135         [ALC880_W810]           = "w810",
3136         [ALC880_Z71V]           = "z71v",
3137         [ALC880_6ST]            = "6stack",
3138         [ALC880_6ST_DIG]        = "6stack-digout",
3139         [ALC880_ASUS]           = "asus",
3140         [ALC880_ASUS_W1V]       = "asus-w1v",
3141         [ALC880_ASUS_DIG]       = "asus-dig",
3142         [ALC880_ASUS_DIG2]      = "asus-dig2",
3143         [ALC880_UNIWILL_DIG]    = "uniwill",
3144         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3145         [ALC880_FUJITSU]        = "fujitsu",
3146         [ALC880_F1734]          = "F1734",
3147         [ALC880_LG]             = "lg",
3148         [ALC880_LG_LW]          = "lg-lw",
3149         [ALC880_MEDION_RIM]     = "medion",
3150 #ifdef CONFIG_SND_DEBUG
3151         [ALC880_TEST]           = "test",
3152 #endif
3153         [ALC880_AUTO]           = "auto",
3154 };
3155
3156 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3157         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3158         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3159         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3160         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3161         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3162         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3163         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3164         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3165         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3166         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3167         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3168         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3169         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3170         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3171         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3172         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3173         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3174         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3175         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3176         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3177         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3178         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3179         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3180         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3181         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3182         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
3183         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3184         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3185         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3186         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3187         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3188         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3189         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3190         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3191         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3192         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3193         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3194         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3195         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3196         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3197         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3198         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3199         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3200         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3201         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3202         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3203         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3204         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3205         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3206         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3207         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3208         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3209         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3210         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3211         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3212         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3213         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3214         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3215         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3216         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3217         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3218         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3219         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3220         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3221         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3222         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3223         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3224         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3225         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
3226         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3227         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3228         {}
3229 };
3230
3231 /*
3232  * ALC880 codec presets
3233  */
3234 static struct alc_config_preset alc880_presets[] = {
3235         [ALC880_3ST] = {
3236                 .mixers = { alc880_three_stack_mixer },
3237                 .init_verbs = { alc880_volume_init_verbs,
3238                                 alc880_pin_3stack_init_verbs },
3239                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3240                 .dac_nids = alc880_dac_nids,
3241                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3242                 .channel_mode = alc880_threestack_modes,
3243                 .need_dac_fix = 1,
3244                 .input_mux = &alc880_capture_source,
3245         },
3246         [ALC880_3ST_DIG] = {
3247                 .mixers = { alc880_three_stack_mixer },
3248                 .init_verbs = { alc880_volume_init_verbs,
3249                                 alc880_pin_3stack_init_verbs },
3250                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3251                 .dac_nids = alc880_dac_nids,
3252                 .dig_out_nid = ALC880_DIGOUT_NID,
3253                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3254                 .channel_mode = alc880_threestack_modes,
3255                 .need_dac_fix = 1,
3256                 .input_mux = &alc880_capture_source,
3257         },
3258         [ALC880_TCL_S700] = {
3259                 .mixers = { alc880_tcl_s700_mixer },
3260                 .init_verbs = { alc880_volume_init_verbs,
3261                                 alc880_pin_tcl_S700_init_verbs,
3262                                 alc880_gpio2_init_verbs },
3263                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3264                 .dac_nids = alc880_dac_nids,
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_5ST] = {
3271                 .mixers = { alc880_three_stack_mixer,
3272                             alc880_five_stack_mixer},
3273                 .init_verbs = { alc880_volume_init_verbs,
3274                                 alc880_pin_5stack_init_verbs },
3275                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3276                 .dac_nids = alc880_dac_nids,
3277                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3278                 .channel_mode = alc880_fivestack_modes,
3279                 .input_mux = &alc880_capture_source,
3280         },
3281         [ALC880_5ST_DIG] = {
3282                 .mixers = { alc880_three_stack_mixer,
3283                             alc880_five_stack_mixer },
3284                 .init_verbs = { alc880_volume_init_verbs,
3285                                 alc880_pin_5stack_init_verbs },
3286                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3287                 .dac_nids = alc880_dac_nids,
3288                 .dig_out_nid = ALC880_DIGOUT_NID,
3289                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3290                 .channel_mode = alc880_fivestack_modes,
3291                 .input_mux = &alc880_capture_source,
3292         },
3293         [ALC880_6ST] = {
3294                 .mixers = { alc880_six_stack_mixer },
3295                 .init_verbs = { alc880_volume_init_verbs,
3296                                 alc880_pin_6stack_init_verbs },
3297                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3298                 .dac_nids = alc880_6st_dac_nids,
3299                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3300                 .channel_mode = alc880_sixstack_modes,
3301                 .input_mux = &alc880_6stack_capture_source,
3302         },
3303         [ALC880_6ST_DIG] = {
3304                 .mixers = { alc880_six_stack_mixer },
3305                 .init_verbs = { alc880_volume_init_verbs,
3306                                 alc880_pin_6stack_init_verbs },
3307                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3308                 .dac_nids = alc880_6st_dac_nids,
3309                 .dig_out_nid = ALC880_DIGOUT_NID,
3310                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3311                 .channel_mode = alc880_sixstack_modes,
3312                 .input_mux = &alc880_6stack_capture_source,
3313         },
3314         [ALC880_W810] = {
3315                 .mixers = { alc880_w810_base_mixer },
3316                 .init_verbs = { alc880_volume_init_verbs,
3317                                 alc880_pin_w810_init_verbs,
3318                                 alc880_gpio2_init_verbs },
3319                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3320                 .dac_nids = alc880_w810_dac_nids,
3321                 .dig_out_nid = ALC880_DIGOUT_NID,
3322                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3323                 .channel_mode = alc880_w810_modes,
3324                 .input_mux = &alc880_capture_source,
3325         },
3326         [ALC880_Z71V] = {
3327                 .mixers = { alc880_z71v_mixer },
3328                 .init_verbs = { alc880_volume_init_verbs,
3329                                 alc880_pin_z71v_init_verbs },
3330                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3331                 .dac_nids = alc880_z71v_dac_nids,
3332                 .dig_out_nid = ALC880_DIGOUT_NID,
3333                 .hp_nid = 0x03,
3334                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3335                 .channel_mode = alc880_2_jack_modes,
3336                 .input_mux = &alc880_capture_source,
3337         },
3338         [ALC880_F1734] = {
3339                 .mixers = { alc880_f1734_mixer },
3340                 .init_verbs = { alc880_volume_init_verbs,
3341                                 alc880_pin_f1734_init_verbs },
3342                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3343                 .dac_nids = alc880_f1734_dac_nids,
3344                 .hp_nid = 0x02,
3345                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3346                 .channel_mode = alc880_2_jack_modes,
3347                 .input_mux = &alc880_f1734_capture_source,
3348                 .unsol_event = alc880_uniwill_p53_unsol_event,
3349                 .init_hook = alc880_uniwill_p53_hp_automute,
3350         },
3351         [ALC880_ASUS] = {
3352                 .mixers = { alc880_asus_mixer },
3353                 .init_verbs = { alc880_volume_init_verbs,
3354                                 alc880_pin_asus_init_verbs,
3355                                 alc880_gpio1_init_verbs },
3356                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3357                 .dac_nids = alc880_asus_dac_nids,
3358                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3359                 .channel_mode = alc880_asus_modes,
3360                 .need_dac_fix = 1,
3361                 .input_mux = &alc880_capture_source,
3362         },
3363         [ALC880_ASUS_DIG] = {
3364                 .mixers = { alc880_asus_mixer },
3365                 .init_verbs = { alc880_volume_init_verbs,
3366                                 alc880_pin_asus_init_verbs,
3367                                 alc880_gpio1_init_verbs },
3368                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3369                 .dac_nids = alc880_asus_dac_nids,
3370                 .dig_out_nid = ALC880_DIGOUT_NID,
3371                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3372                 .channel_mode = alc880_asus_modes,
3373                 .need_dac_fix = 1,
3374                 .input_mux = &alc880_capture_source,
3375         },
3376         [ALC880_ASUS_DIG2] = {
3377                 .mixers = { alc880_asus_mixer },
3378                 .init_verbs = { alc880_volume_init_verbs,
3379                                 alc880_pin_asus_init_verbs,
3380                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3381                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3382                 .dac_nids = alc880_asus_dac_nids,
3383                 .dig_out_nid = ALC880_DIGOUT_NID,
3384                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3385                 .channel_mode = alc880_asus_modes,
3386                 .need_dac_fix = 1,
3387                 .input_mux = &alc880_capture_source,
3388         },
3389         [ALC880_ASUS_W1V] = {
3390                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3391                 .init_verbs = { alc880_volume_init_verbs,
3392                                 alc880_pin_asus_init_verbs,
3393                                 alc880_gpio1_init_verbs },
3394                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3395                 .dac_nids = alc880_asus_dac_nids,
3396                 .dig_out_nid = ALC880_DIGOUT_NID,
3397                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3398                 .channel_mode = alc880_asus_modes,
3399                 .need_dac_fix = 1,
3400                 .input_mux = &alc880_capture_source,
3401         },
3402         [ALC880_UNIWILL_DIG] = {
3403                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3404                 .init_verbs = { alc880_volume_init_verbs,
3405                                 alc880_pin_asus_init_verbs },
3406                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3407                 .dac_nids = alc880_asus_dac_nids,
3408                 .dig_out_nid = ALC880_DIGOUT_NID,
3409                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3410                 .channel_mode = alc880_asus_modes,
3411                 .need_dac_fix = 1,
3412                 .input_mux = &alc880_capture_source,
3413         },
3414         [ALC880_UNIWILL] = {
3415                 .mixers = { alc880_uniwill_mixer },
3416                 .init_verbs = { alc880_volume_init_verbs,
3417                                 alc880_uniwill_init_verbs },
3418                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3419                 .dac_nids = alc880_asus_dac_nids,
3420                 .dig_out_nid = ALC880_DIGOUT_NID,
3421                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3422                 .channel_mode = alc880_threestack_modes,
3423                 .need_dac_fix = 1,
3424                 .input_mux = &alc880_capture_source,
3425                 .unsol_event = alc880_uniwill_unsol_event,
3426                 .init_hook = alc880_uniwill_automute,
3427         },
3428         [ALC880_UNIWILL_P53] = {
3429                 .mixers = { alc880_uniwill_p53_mixer },
3430                 .init_verbs = { alc880_volume_init_verbs,
3431                                 alc880_uniwill_p53_init_verbs },
3432                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3433                 .dac_nids = alc880_asus_dac_nids,
3434                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3435                 .channel_mode = alc880_threestack_modes,
3436                 .input_mux = &alc880_capture_source,
3437                 .unsol_event = alc880_uniwill_p53_unsol_event,
3438                 .init_hook = alc880_uniwill_p53_hp_automute,
3439         },
3440         [ALC880_FUJITSU] = {
3441                 .mixers = { alc880_fujitsu_mixer,
3442                             alc880_pcbeep_mixer, },
3443                 .init_verbs = { alc880_volume_init_verbs,
3444                                 alc880_uniwill_p53_init_verbs,
3445                                 alc880_beep_init_verbs },
3446                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3447                 .dac_nids = alc880_dac_nids,
3448                 .dig_out_nid = ALC880_DIGOUT_NID,
3449                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3450                 .channel_mode = alc880_2_jack_modes,
3451                 .input_mux = &alc880_capture_source,
3452                 .unsol_event = alc880_uniwill_p53_unsol_event,
3453                 .init_hook = alc880_uniwill_p53_hp_automute,
3454         },
3455         [ALC880_CLEVO] = {
3456                 .mixers = { alc880_three_stack_mixer },
3457                 .init_verbs = { alc880_volume_init_verbs,
3458                                 alc880_pin_clevo_init_verbs },
3459                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3460                 .dac_nids = alc880_dac_nids,
3461                 .hp_nid = 0x03,
3462                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3463                 .channel_mode = alc880_threestack_modes,
3464                 .need_dac_fix = 1,
3465                 .input_mux = &alc880_capture_source,
3466         },
3467         [ALC880_LG] = {
3468                 .mixers = { alc880_lg_mixer },
3469                 .init_verbs = { alc880_volume_init_verbs,
3470                                 alc880_lg_init_verbs },
3471                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3472                 .dac_nids = alc880_lg_dac_nids,
3473                 .dig_out_nid = ALC880_DIGOUT_NID,
3474                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3475                 .channel_mode = alc880_lg_ch_modes,
3476                 .need_dac_fix = 1,
3477                 .input_mux = &alc880_lg_capture_source,
3478                 .unsol_event = alc880_lg_unsol_event,
3479                 .init_hook = alc880_lg_automute,
3480 #ifdef CONFIG_SND_HDA_POWER_SAVE
3481                 .loopbacks = alc880_lg_loopbacks,
3482 #endif
3483         },
3484         [ALC880_LG_LW] = {
3485                 .mixers = { alc880_lg_lw_mixer },
3486                 .init_verbs = { alc880_volume_init_verbs,
3487                                 alc880_lg_lw_init_verbs },
3488                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3489                 .dac_nids = alc880_dac_nids,
3490                 .dig_out_nid = ALC880_DIGOUT_NID,
3491                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3492                 .channel_mode = alc880_lg_lw_modes,
3493                 .input_mux = &alc880_lg_lw_capture_source,
3494                 .unsol_event = alc880_lg_lw_unsol_event,
3495                 .init_hook = alc880_lg_lw_automute,
3496         },
3497         [ALC880_MEDION_RIM] = {
3498                 .mixers = { alc880_medion_rim_mixer },
3499                 .init_verbs = { alc880_volume_init_verbs,
3500                                 alc880_medion_rim_init_verbs,
3501                                 alc_gpio2_init_verbs },
3502                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3503                 .dac_nids = alc880_dac_nids,
3504                 .dig_out_nid = ALC880_DIGOUT_NID,
3505                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3506                 .channel_mode = alc880_2_jack_modes,
3507                 .input_mux = &alc880_medion_rim_capture_source,
3508                 .unsol_event = alc880_medion_rim_unsol_event,
3509                 .init_hook = alc880_medion_rim_automute,
3510         },
3511 #ifdef CONFIG_SND_DEBUG
3512         [ALC880_TEST] = {
3513                 .mixers = { alc880_test_mixer },
3514                 .init_verbs = { alc880_test_init_verbs },
3515                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3516                 .dac_nids = alc880_test_dac_nids,
3517                 .dig_out_nid = ALC880_DIGOUT_NID,
3518                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3519                 .channel_mode = alc880_test_modes,
3520                 .input_mux = &alc880_test_capture_source,
3521         },
3522 #endif
3523 };
3524
3525 /*
3526  * Automatic parse of I/O pins from the BIOS configuration
3527  */
3528
3529 #define NUM_CONTROL_ALLOC       32
3530 #define NUM_VERB_ALLOC          32
3531
3532 enum {
3533         ALC_CTL_WIDGET_VOL,
3534         ALC_CTL_WIDGET_MUTE,
3535         ALC_CTL_BIND_MUTE,
3536 };
3537 static struct snd_kcontrol_new alc880_control_templates[] = {
3538         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3539         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3540         HDA_BIND_MUTE(NULL, 0, 0, 0),
3541 };
3542
3543 /* add dynamic controls */
3544 static int add_control(struct alc_spec *spec, int type, const char *name,
3545                        unsigned long val)
3546 {
3547         struct snd_kcontrol_new *knew;
3548
3549         if (spec->num_kctl_used >= spec->num_kctl_alloc) {
3550                 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
3551
3552                 /* array + terminator */
3553                 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
3554                 if (!knew)
3555                         return -ENOMEM;
3556                 if (spec->kctl_alloc) {
3557                         memcpy(knew, spec->kctl_alloc,
3558                                sizeof(*knew) * spec->num_kctl_alloc);
3559                         kfree(spec->kctl_alloc);
3560                 }
3561                 spec->kctl_alloc = knew;
3562                 spec->num_kctl_alloc = num;
3563         }
3564
3565         knew = &spec->kctl_alloc[spec->num_kctl_used];
3566         *knew = alc880_control_templates[type];
3567         knew->name = kstrdup(name, GFP_KERNEL);
3568         if (!knew->name)
3569                 return -ENOMEM;
3570         knew->private_value = val;
3571         spec->num_kctl_used++;
3572         return 0;
3573 }
3574
3575 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3576 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3577 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3578 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3579 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3580 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3581 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3582 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3583 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3584 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3585 #define ALC880_PIN_CD_NID               0x1c
3586
3587 /* fill in the dac_nids table from the parsed pin configuration */
3588 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3589                                      const struct auto_pin_cfg *cfg)
3590 {
3591         hda_nid_t nid;
3592         int assigned[4];
3593         int i, j;
3594
3595         memset(assigned, 0, sizeof(assigned));
3596         spec->multiout.dac_nids = spec->private_dac_nids;
3597
3598         /* check the pins hardwired to audio widget */
3599         for (i = 0; i < cfg->line_outs; i++) {
3600                 nid = cfg->line_out_pins[i];
3601                 if (alc880_is_fixed_pin(nid)) {
3602                         int idx = alc880_fixed_pin_idx(nid);
3603                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3604                         assigned[idx] = 1;
3605                 }
3606         }
3607         /* left pins can be connect to any audio widget */
3608         for (i = 0; i < cfg->line_outs; i++) {
3609                 nid = cfg->line_out_pins[i];
3610                 if (alc880_is_fixed_pin(nid))
3611                         continue;
3612                 /* search for an empty channel */
3613                 for (j = 0; j < cfg->line_outs; j++) {
3614                         if (!assigned[j]) {
3615                                 spec->multiout.dac_nids[i] =
3616                                         alc880_idx_to_dac(j);
3617                                 assigned[j] = 1;
3618                                 break;
3619                         }
3620                 }
3621         }
3622         spec->multiout.num_dacs = cfg->line_outs;
3623         return 0;
3624 }
3625
3626 /* add playback controls from the parsed DAC table */
3627 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3628                                              const struct auto_pin_cfg *cfg)
3629 {
3630         char name[32];
3631         static const char *chname[4] = {
3632                 "Front", "Surround", NULL /*CLFE*/, "Side"
3633         };
3634         hda_nid_t nid;
3635         int i, err;
3636
3637         for (i = 0; i < cfg->line_outs; i++) {
3638                 if (!spec->multiout.dac_nids[i])
3639                         continue;
3640                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3641                 if (i == 2) {
3642                         /* Center/LFE */
3643                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3644                                           "Center Playback Volume",
3645                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3646                                                               HDA_OUTPUT));
3647                         if (err < 0)
3648                                 return err;
3649                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3650                                           "LFE Playback Volume",
3651                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3652                                                               HDA_OUTPUT));
3653                         if (err < 0)
3654                                 return err;
3655                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3656                                           "Center Playback Switch",
3657                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
3658                                                               HDA_INPUT));
3659                         if (err < 0)
3660                                 return err;
3661                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3662                                           "LFE Playback Switch",
3663                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
3664                                                               HDA_INPUT));
3665                         if (err < 0)
3666                                 return err;
3667                 } else {
3668                         sprintf(name, "%s Playback Volume", chname[i]);
3669                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3670                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3671                                                               HDA_OUTPUT));
3672                         if (err < 0)
3673                                 return err;
3674                         sprintf(name, "%s Playback Switch", chname[i]);
3675                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3676                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
3677                                                               HDA_INPUT));
3678                         if (err < 0)
3679                                 return err;
3680                 }
3681         }
3682         return 0;
3683 }
3684
3685 /* add playback controls for speaker and HP outputs */
3686 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
3687                                         const char *pfx)
3688 {
3689         hda_nid_t nid;
3690         int err;
3691         char name[32];
3692
3693         if (!pin)
3694                 return 0;
3695
3696         if (alc880_is_fixed_pin(pin)) {
3697                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
3698                 /* specify the DAC as the extra output */
3699                 if (!spec->multiout.hp_nid)
3700                         spec->multiout.hp_nid = nid;
3701                 else
3702                         spec->multiout.extra_out_nid[0] = nid;
3703                 /* control HP volume/switch on the output mixer amp */
3704                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
3705                 sprintf(name, "%s Playback Volume", pfx);
3706                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3707                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3708                 if (err < 0)
3709                         return err;
3710                 sprintf(name, "%s Playback Switch", pfx);
3711                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3712                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
3713                 if (err < 0)
3714                         return err;
3715         } else if (alc880_is_multi_pin(pin)) {
3716                 /* set manual connection */
3717                 /* we have only a switch on HP-out PIN */
3718                 sprintf(name, "%s Playback Switch", pfx);
3719                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3720                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3721                 if (err < 0)
3722                         return err;
3723         }
3724         return 0;
3725 }
3726
3727 /* create input playback/capture controls for the given pin */
3728 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
3729                             const char *ctlname,
3730                             int idx, hda_nid_t mix_nid)
3731 {
3732         char name[32];
3733         int err;
3734
3735         sprintf(name, "%s Playback Volume", ctlname);
3736         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3737                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3738         if (err < 0)
3739                 return err;
3740         sprintf(name, "%s Playback Switch", ctlname);
3741         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3742                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3743         if (err < 0)
3744                 return err;
3745         return 0;
3746 }
3747
3748 /* create playback/capture controls for input pins */
3749 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3750                                                 const struct auto_pin_cfg *cfg)
3751 {
3752         struct hda_input_mux *imux = &spec->private_imux;
3753         int i, err, idx;
3754
3755         for (i = 0; i < AUTO_PIN_LAST; i++) {
3756                 if (alc880_is_input_pin(cfg->input_pins[i])) {
3757                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
3758                         err = new_analog_input(spec, cfg->input_pins[i],
3759                                                auto_pin_cfg_labels[i],
3760                                                idx, 0x0b);
3761                         if (err < 0)
3762                                 return err;
3763                         imux->items[imux->num_items].label =
3764                                 auto_pin_cfg_labels[i];
3765                         imux->items[imux->num_items].index =
3766                                 alc880_input_pin_idx(cfg->input_pins[i]);
3767                         imux->num_items++;
3768                 }
3769         }
3770         return 0;
3771 }
3772
3773 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
3774                                unsigned int pin_type)
3775 {
3776         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3777                             pin_type);
3778         /* unmute pin */
3779         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3780                             AMP_OUT_UNMUTE);
3781 }
3782
3783 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3784                                               hda_nid_t nid, int pin_type,
3785                                               int dac_idx)
3786 {
3787         alc_set_pin_output(codec, nid, pin_type);
3788         /* need the manual connection? */
3789         if (alc880_is_multi_pin(nid)) {
3790                 struct alc_spec *spec = codec->spec;
3791                 int idx = alc880_multi_pin_idx(nid);
3792                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
3793                                     AC_VERB_SET_CONNECT_SEL,
3794                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
3795         }
3796 }
3797
3798 static int get_pin_type(int line_out_type)
3799 {
3800         if (line_out_type == AUTO_PIN_HP_OUT)
3801                 return PIN_HP;
3802         else
3803                 return PIN_OUT;
3804 }
3805
3806 static void alc880_auto_init_multi_out(struct hda_codec *codec)
3807 {
3808         struct alc_spec *spec = codec->spec;
3809         int i;
3810
3811         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
3812         for (i = 0; i < spec->autocfg.line_outs; i++) {
3813                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3814                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3815                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
3816         }
3817 }
3818
3819 static void alc880_auto_init_extra_out(struct hda_codec *codec)
3820 {
3821         struct alc_spec *spec = codec->spec;
3822         hda_nid_t pin;
3823
3824         pin = spec->autocfg.speaker_pins[0];
3825         if (pin) /* connect to front */
3826                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
3827         pin = spec->autocfg.hp_pins[0];
3828         if (pin) /* connect to front */
3829                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3830 }
3831
3832 static void alc880_auto_init_analog_input(struct hda_codec *codec)
3833 {
3834         struct alc_spec *spec = codec->spec;
3835         int i;
3836
3837         for (i = 0; i < AUTO_PIN_LAST; i++) {
3838                 hda_nid_t nid = spec->autocfg.input_pins[i];
3839                 if (alc880_is_input_pin(nid)) {
3840                         snd_hda_codec_write(codec, nid, 0,
3841                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
3842                                             i <= AUTO_PIN_FRONT_MIC ?
3843                                             PIN_VREF80 : PIN_IN);
3844                         if (nid != ALC880_PIN_CD_NID)
3845                                 snd_hda_codec_write(codec, nid, 0,
3846                                                     AC_VERB_SET_AMP_GAIN_MUTE,
3847                                                     AMP_OUT_MUTE);
3848                 }
3849         }
3850 }
3851
3852 /* parse the BIOS configuration and set up the alc_spec */
3853 /* return 1 if successful, 0 if the proper config is not found,
3854  * or a negative error code
3855  */
3856 static int alc880_parse_auto_config(struct hda_codec *codec)
3857 {
3858         struct alc_spec *spec = codec->spec;
3859         int err;
3860         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3861
3862         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3863                                            alc880_ignore);
3864         if (err < 0)
3865                 return err;
3866         if (!spec->autocfg.line_outs)
3867                 return 0; /* can't find valid BIOS pin config */
3868
3869         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
3870         if (err < 0)
3871                 return err;
3872         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
3873         if (err < 0)
3874                 return err;
3875         err = alc880_auto_create_extra_out(spec,
3876                                            spec->autocfg.speaker_pins[0],
3877                                            "Speaker");
3878         if (err < 0)
3879                 return err;
3880         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
3881                                            "Headphone");
3882         if (err < 0)
3883                 return err;
3884         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
3885         if (err < 0)
3886                 return err;
3887
3888         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3889
3890         if (spec->autocfg.dig_out_pin)
3891                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
3892         if (spec->autocfg.dig_in_pin)
3893                 spec->dig_in_nid = ALC880_DIGIN_NID;
3894
3895         if (spec->kctl_alloc)
3896                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3897
3898         spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
3899
3900         spec->num_mux_defs = 1;
3901         spec->input_mux = &spec->private_imux;
3902
3903         store_pin_configs(codec);
3904         return 1;
3905 }
3906
3907 /* additional initialization for auto-configuration model */
3908 static void alc880_auto_init(struct hda_codec *codec)
3909 {
3910         struct alc_spec *spec = codec->spec;
3911         alc880_auto_init_multi_out(codec);
3912         alc880_auto_init_extra_out(codec);
3913         alc880_auto_init_analog_input(codec);
3914         if (spec->unsol_event)
3915                 alc_inithook(codec);
3916 }
3917
3918 /*
3919  * OK, here we have finally the patch for ALC880
3920  */
3921
3922 static int patch_alc880(struct hda_codec *codec)
3923 {
3924         struct alc_spec *spec;
3925         int board_config;
3926         int err;
3927
3928         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3929         if (spec == NULL)
3930                 return -ENOMEM;
3931
3932         codec->spec = spec;
3933
3934         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
3935                                                   alc880_models,
3936                                                   alc880_cfg_tbl);
3937         if (board_config < 0) {
3938                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
3939                        "trying auto-probe from BIOS...\n");
3940                 board_config = ALC880_AUTO;
3941         }
3942
3943         if (board_config == ALC880_AUTO) {
3944                 /* automatic parse from the BIOS config */
3945                 err = alc880_parse_auto_config(codec);
3946                 if (err < 0) {
3947                         alc_free(codec);
3948                         return err;
3949                 } else if (!err) {
3950                         printk(KERN_INFO
3951                                "hda_codec: Cannot set up configuration "
3952                                "from BIOS.  Using 3-stack mode...\n");
3953                         board_config = ALC880_3ST;
3954                 }
3955         }
3956
3957         if (board_config != ALC880_AUTO)
3958                 setup_preset(spec, &alc880_presets[board_config]);
3959
3960         spec->stream_name_analog = "ALC880 Analog";
3961         spec->stream_analog_playback = &alc880_pcm_analog_playback;
3962         spec->stream_analog_capture = &alc880_pcm_analog_capture;
3963         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
3964
3965         spec->stream_name_digital = "ALC880 Digital";
3966         spec->stream_digital_playback = &alc880_pcm_digital_playback;
3967         spec->stream_digital_capture = &alc880_pcm_digital_capture;
3968
3969         if (!spec->adc_nids && spec->input_mux) {
3970                 /* check whether NID 0x07 is valid */
3971                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
3972                 /* get type */
3973                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3974                 if (wcap != AC_WID_AUD_IN) {
3975                         spec->adc_nids = alc880_adc_nids_alt;
3976                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
3977                         spec->mixers[spec->num_mixers] =
3978                                 alc880_capture_alt_mixer;
3979                         spec->num_mixers++;
3980                 } else {
3981                         spec->adc_nids = alc880_adc_nids;
3982                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
3983                         spec->mixers[spec->num_mixers] = alc880_capture_mixer;
3984                         spec->num_mixers++;
3985                 }
3986         }
3987
3988         spec->vmaster_nid = 0x0c;
3989
3990         codec->patch_ops = alc_patch_ops;
3991         if (board_config == ALC880_AUTO)
3992                 spec->init_hook = alc880_auto_init;
3993 #ifdef CONFIG_SND_HDA_POWER_SAVE
3994         if (!spec->loopback.amplist)
3995                 spec->loopback.amplist = alc880_loopbacks;
3996 #endif
3997
3998         return 0;
3999 }
4000
4001
4002 /*
4003  * ALC260 support
4004  */
4005
4006 static hda_nid_t alc260_dac_nids[1] = {
4007         /* front */
4008         0x02,
4009 };
4010
4011 static hda_nid_t alc260_adc_nids[1] = {
4012         /* ADC0 */
4013         0x04,
4014 };
4015
4016 static hda_nid_t alc260_adc_nids_alt[1] = {
4017         /* ADC1 */
4018         0x05,
4019 };
4020
4021 static hda_nid_t alc260_hp_adc_nids[2] = {
4022         /* ADC1, 0 */
4023         0x05, 0x04
4024 };
4025
4026 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4027  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4028  */
4029 static hda_nid_t alc260_dual_adc_nids[2] = {
4030         /* ADC0, ADC1 */
4031         0x04, 0x05
4032 };
4033
4034 #define ALC260_DIGOUT_NID       0x03
4035 #define ALC260_DIGIN_NID        0x06
4036
4037 static struct hda_input_mux alc260_capture_source = {
4038         .num_items = 4,
4039         .items = {
4040                 { "Mic", 0x0 },
4041                 { "Front Mic", 0x1 },
4042                 { "Line", 0x2 },
4043                 { "CD", 0x4 },
4044         },
4045 };
4046
4047 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4048  * headphone jack and the internal CD lines since these are the only pins at
4049  * which audio can appear.  For flexibility, also allow the option of
4050  * recording the mixer output on the second ADC (ADC0 doesn't have a
4051  * connection to the mixer output).
4052  */
4053 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4054         {
4055                 .num_items = 3,
4056                 .items = {
4057                         { "Mic/Line", 0x0 },
4058                         { "CD", 0x4 },
4059                         { "Headphone", 0x2 },
4060                 },
4061         },
4062         {
4063                 .num_items = 4,
4064                 .items = {
4065                         { "Mic/Line", 0x0 },
4066                         { "CD", 0x4 },
4067                         { "Headphone", 0x2 },
4068                         { "Mixer", 0x5 },
4069                 },
4070         },
4071
4072 };
4073
4074 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4075  * the Fujitsu S702x, but jacks are marked differently.
4076  */
4077 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4078         {
4079                 .num_items = 4,
4080                 .items = {
4081                         { "Mic", 0x0 },
4082                         { "Line", 0x2 },
4083                         { "CD", 0x4 },
4084                         { "Headphone", 0x5 },
4085                 },
4086         },
4087         {
4088                 .num_items = 5,
4089                 .items = {
4090                         { "Mic", 0x0 },
4091                         { "Line", 0x2 },
4092                         { "CD", 0x4 },
4093                         { "Headphone", 0x6 },
4094                         { "Mixer", 0x5 },
4095                 },
4096         },
4097 };
4098 /*
4099  * This is just place-holder, so there's something for alc_build_pcms to look
4100  * at when it calculates the maximum number of channels. ALC260 has no mixer
4101  * element which allows changing the channel mode, so the verb list is
4102  * never used.
4103  */
4104 static struct hda_channel_mode alc260_modes[1] = {
4105         { 2, NULL },
4106 };
4107
4108
4109 /* Mixer combinations
4110  *
4111  * basic: base_output + input + pc_beep + capture
4112  * HP: base_output + input + capture_alt
4113  * HP_3013: hp_3013 + input + capture
4114  * fujitsu: fujitsu + capture
4115  * acer: acer + capture
4116  */
4117
4118 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
4119         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4120         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4121         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4122         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4123         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4124         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4125         { } /* end */
4126 };
4127
4128 static struct snd_kcontrol_new alc260_input_mixer[] = {
4129         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4130         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4131         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4132         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4133         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4134         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4135         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4136         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4137         { } /* end */
4138 };
4139
4140 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
4141         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
4142         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
4143         { } /* end */
4144 };
4145
4146 /* update HP, line and mono out pins according to the master switch */
4147 static void alc260_hp_master_update(struct hda_codec *codec,
4148                                     hda_nid_t hp, hda_nid_t line,
4149                                     hda_nid_t mono)
4150 {
4151         struct alc_spec *spec = codec->spec;
4152         unsigned int val = spec->master_sw ? PIN_HP : 0;
4153         /* change HP and line-out pins */
4154         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4155                             val);
4156         snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4157                             val);
4158         /* mono (speaker) depending on the HP jack sense */
4159         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4160         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4161                             val);
4162 }
4163
4164 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4165                                    struct snd_ctl_elem_value *ucontrol)
4166 {
4167         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4168         struct alc_spec *spec = codec->spec;
4169         *ucontrol->value.integer.value = spec->master_sw;
4170         return 0;
4171 }
4172
4173 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4174                                    struct snd_ctl_elem_value *ucontrol)
4175 {
4176         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4177         struct alc_spec *spec = codec->spec;
4178         int val = !!*ucontrol->value.integer.value;
4179         hda_nid_t hp, line, mono;
4180
4181         if (val == spec->master_sw)
4182                 return 0;
4183         spec->master_sw = val;
4184         hp = (kcontrol->private_value >> 16) & 0xff;
4185         line = (kcontrol->private_value >> 8) & 0xff;
4186         mono = kcontrol->private_value & 0xff;
4187         alc260_hp_master_update(codec, hp, line, mono);
4188         return 1;
4189 }
4190
4191 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4192         {
4193                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4194                 .name = "Master Playback Switch",
4195                 .info = snd_ctl_boolean_mono_info,
4196                 .get = alc260_hp_master_sw_get,
4197                 .put = alc260_hp_master_sw_put,
4198                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4199         },
4200         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4201         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4202         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4203         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4204         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4205                               HDA_OUTPUT),
4206         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4207         { } /* end */
4208 };
4209
4210 static struct hda_verb alc260_hp_unsol_verbs[] = {
4211         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4212         {},
4213 };
4214
4215 static void alc260_hp_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, 0x10, 0,
4221                                      AC_VERB_GET_PIN_SENSE, 0);
4222         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4223         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4224 }
4225
4226 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4227 {
4228         if ((res >> 26) == ALC880_HP_EVENT)
4229                 alc260_hp_automute(codec);
4230 }
4231
4232 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4233         {
4234                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4235                 .name = "Master Playback Switch",
4236                 .info = snd_ctl_boolean_mono_info,
4237                 .get = alc260_hp_master_sw_get,
4238                 .put = alc260_hp_master_sw_put,
4239                 .private_value = (0x10 << 16) | (0x15 << 8) | 0x11
4240         },
4241         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4242         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4243         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4244         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4245         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4246         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4247         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4248         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4249         { } /* end */
4250 };
4251
4252 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
4253         .ops = &snd_hda_bind_vol,
4254         .values = {
4255                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
4256                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
4257                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
4258                 0
4259         },
4260 };
4261
4262 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
4263         .ops = &snd_hda_bind_sw,
4264         .values = {
4265                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
4266                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
4267                 0
4268         },
4269 };
4270
4271 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
4272         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
4273         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
4274         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
4275         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4276         { } /* end */
4277 };
4278
4279 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4280         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4281         {},
4282 };
4283
4284 static void alc260_hp_3013_automute(struct hda_codec *codec)
4285 {
4286         struct alc_spec *spec = codec->spec;
4287         unsigned int present;
4288
4289         present = snd_hda_codec_read(codec, 0x15, 0,
4290                                      AC_VERB_GET_PIN_SENSE, 0);
4291         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4292         alc260_hp_master_update(codec, 0x10, 0x15, 0x11);
4293 }
4294
4295 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4296                                        unsigned int res)
4297 {
4298         if ((res >> 26) == ALC880_HP_EVENT)
4299                 alc260_hp_3013_automute(codec);
4300 }
4301
4302 static void alc260_hp_3012_automute(struct hda_codec *codec)
4303 {
4304         unsigned int present, bits;
4305
4306         present = snd_hda_codec_read(codec, 0x10, 0,
4307                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
4308
4309         bits = present ? 0 : PIN_OUT;
4310         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4311                             bits);
4312         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4313                             bits);
4314         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4315                             bits);
4316 }
4317
4318 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
4319                                        unsigned int res)
4320 {
4321         if ((res >> 26) == ALC880_HP_EVENT)
4322                 alc260_hp_3012_automute(codec);
4323 }
4324
4325 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
4326  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4327  */
4328 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4329         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4330         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4331         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4332         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4333         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4334         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4335         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4336         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4337         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4338         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4339         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4340         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4341         { } /* end */
4342 };
4343
4344 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4345  * versions of the ALC260 don't act on requests to enable mic bias from NID
4346  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4347  * datasheet doesn't mention this restriction.  At this stage it's not clear
4348  * whether this behaviour is intentional or is a hardware bug in chip
4349  * revisions available in early 2006.  Therefore for now allow the
4350  * "Headphone Jack Mode" control to span all choices, but if it turns out
4351  * that the lack of mic bias for this NID is intentional we could change the
4352  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4353  *
4354  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4355  * don't appear to make the mic bias available from the "line" jack, even
4356  * though the NID used for this jack (0x14) can supply it.  The theory is
4357  * that perhaps Acer have included blocking capacitors between the ALC260
4358  * and the output jack.  If this turns out to be the case for all such
4359  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4360  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4361  *
4362  * The C20x Tablet series have a mono internal speaker which is controlled
4363  * via the chip's Mono sum widget and pin complex, so include the necessary
4364  * controls for such models.  On models without a "mono speaker" the control
4365  * won't do anything.
4366  */
4367 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4368         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4369         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4370         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4371         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4372                               HDA_OUTPUT),
4373         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4374                            HDA_INPUT),
4375         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4376         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4377         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4378         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4379         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4380         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4381         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4382         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4383         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4384         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4385         { } /* end */
4386 };
4387
4388 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4389  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4390  */
4391 static struct snd_kcontrol_new alc260_will_mixer[] = {
4392         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4393         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4394         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4395         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4396         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4397         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4398         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4399         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4400         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4401         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4402         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4403         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4404         { } /* end */
4405 };
4406
4407 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4408  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4409  */
4410 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4411         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4412         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4413         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4414         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4415         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4416         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4417         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4418         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4419         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4420         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4421         { } /* end */
4422 };
4423
4424 /* capture mixer elements */
4425 static struct snd_kcontrol_new alc260_capture_mixer[] = {
4426         HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
4427         HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
4428         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
4429         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),
4430         {
4431                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4432                 /* The multiple "Capture Source" controls confuse alsamixer
4433                  * So call somewhat different..
4434                  */
4435                 /* .name = "Capture Source", */
4436                 .name = "Input Source",
4437                 .count = 2,
4438                 .info = alc_mux_enum_info,
4439                 .get = alc_mux_enum_get,
4440                 .put = alc_mux_enum_put,
4441         },
4442         { } /* end */
4443 };
4444
4445 static struct snd_kcontrol_new alc260_capture_alt_mixer[] = {
4446         HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
4447         HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
4448         {
4449                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4450                 /* The multiple "Capture Source" controls confuse alsamixer
4451                  * So call somewhat different..
4452                  */
4453                 /* .name = "Capture Source", */
4454                 .name = "Input Source",
4455                 .count = 1,
4456                 .info = alc_mux_enum_info,
4457                 .get = alc_mux_enum_get,
4458                 .put = alc_mux_enum_put,
4459         },
4460         { } /* end */
4461 };
4462
4463 /*
4464  * initialization verbs
4465  */
4466 static struct hda_verb alc260_init_verbs[] = {
4467         /* Line In pin widget for input */
4468         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4469         /* CD pin widget for input */
4470         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4471         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4472         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4473         /* Mic2 (front panel) pin widget for input and vref at 80% */
4474         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4475         /* LINE-2 is used for line-out in rear */
4476         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4477         /* select line-out */
4478         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4479         /* LINE-OUT pin */
4480         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4481         /* enable HP */
4482         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4483         /* enable Mono */
4484         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4485         /* mute capture amp left and right */
4486         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4487         /* set connection select to line in (default select for this ADC) */
4488         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4489         /* mute capture amp left and right */
4490         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4491         /* set connection select to line in (default select for this ADC) */
4492         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4493         /* set vol=0 Line-Out mixer amp left and right */
4494         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4495         /* unmute pin widget amp left and right (no gain on this amp) */
4496         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4497         /* set vol=0 HP mixer amp left and right */
4498         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4499         /* unmute pin widget amp left and right (no gain on this amp) */
4500         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4501         /* set vol=0 Mono mixer amp left and right */
4502         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4503         /* unmute pin widget amp left and right (no gain on this amp) */
4504         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4505         /* unmute LINE-2 out pin */
4506         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4507         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4508          * Line In 2 = 0x03
4509          */
4510         /* mute analog inputs */
4511         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4512         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4513         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4514         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4515         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4516         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4517         /* mute Front out path */
4518         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4519         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4520         /* mute Headphone out path */
4521         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4522         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4523         /* mute Mono out path */
4524         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4525         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4526         { }
4527 };
4528
4529 #if 0 /* should be identical with alc260_init_verbs? */
4530 static struct hda_verb alc260_hp_init_verbs[] = {
4531         /* Headphone and output */
4532         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4533         /* mono output */
4534         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4535         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4536         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4537         /* Mic2 (front panel) pin widget for input and vref at 80% */
4538         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4539         /* Line In pin widget for input */
4540         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4541         /* Line-2 pin widget for output */
4542         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4543         /* CD pin widget for input */
4544         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4545         /* unmute amp left and right */
4546         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4547         /* set connection select to line in (default select for this ADC) */
4548         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4549         /* unmute Line-Out mixer amp left and right (volume = 0) */
4550         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4551         /* mute pin widget amp left and right (no gain on this amp) */
4552         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4553         /* unmute HP mixer amp left and right (volume = 0) */
4554         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4555         /* mute pin widget amp left and right (no gain on this amp) */
4556         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4557         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4558          * Line In 2 = 0x03
4559          */
4560         /* mute analog inputs */
4561         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4562         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4563         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4564         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4565         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4566         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4567         /* Unmute Front out path */
4568         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4569         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4570         /* Unmute Headphone out path */
4571         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4572         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4573         /* Unmute Mono out path */
4574         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4575         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4576         { }
4577 };
4578 #endif
4579
4580 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4581         /* Line out and output */
4582         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4583         /* mono output */
4584         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4585         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4586         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4587         /* Mic2 (front panel) pin widget for input and vref at 80% */
4588         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4589         /* Line In pin widget for input */
4590         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4591         /* Headphone pin widget for output */
4592         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4593         /* CD pin widget for input */
4594         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4595         /* unmute amp left and right */
4596         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4597         /* set connection select to line in (default select for this ADC) */
4598         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4599         /* unmute Line-Out mixer amp left and right (volume = 0) */
4600         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4601         /* mute pin widget amp left and right (no gain on this amp) */
4602         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4603         /* unmute HP mixer amp left and right (volume = 0) */
4604         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4605         /* mute pin widget amp left and right (no gain on this amp) */
4606         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4607         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4608          * Line In 2 = 0x03
4609          */
4610         /* mute analog inputs */
4611         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4612         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4613         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4614         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4615         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4616         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4617         /* Unmute Front out path */
4618         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4619         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4620         /* Unmute Headphone out path */
4621         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4622         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4623         /* Unmute Mono out path */
4624         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4625         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4626         { }
4627 };
4628
4629 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4630  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4631  * audio = 0x16, internal speaker = 0x10.
4632  */
4633 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4634         /* Disable all GPIOs */
4635         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4636         /* Internal speaker is connected to headphone pin */
4637         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4638         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4639         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4640         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4641         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4642         /* Ensure all other unused pins are disabled and muted. */
4643         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4644         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4645         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4646         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4647         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4648         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4649         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4650         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4651
4652         /* Disable digital (SPDIF) pins */
4653         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4654         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4655
4656         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
4657          * when acting as an output.
4658          */
4659         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4660
4661         /* Start with output sum widgets muted and their output gains at min */
4662         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4663         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4664         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4665         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4666         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4667         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4668         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4669         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4670         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4671
4672         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
4673         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4674         /* Unmute Line1 pin widget output buffer since it starts as an output.
4675          * If the pin mode is changed by the user the pin mode control will
4676          * take care of enabling the pin's input/output buffers as needed.
4677          * Therefore there's no need to enable the input buffer at this
4678          * stage.
4679          */
4680         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4681         /* Unmute input buffer of pin widget used for Line-in (no equiv
4682          * mixer ctrl)
4683          */
4684         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4685
4686         /* Mute capture amp left and right */
4687         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4688         /* Set ADC connection select to match default mixer setting - line
4689          * in (on mic1 pin)
4690          */
4691         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4692
4693         /* Do the same for the second ADC: mute capture input amp and
4694          * set ADC connection to line in (on mic1 pin)
4695          */
4696         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4697         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4698
4699         /* Mute all inputs to mixer widget (even unconnected ones) */
4700         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4701         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4702         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4703         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4704         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4705         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4706         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4707         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4708
4709         { }
4710 };
4711
4712 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
4713  * similar laptops (adapted from Fujitsu init verbs).
4714  */
4715 static struct hda_verb alc260_acer_init_verbs[] = {
4716         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
4717          * the headphone jack.  Turn this on and rely on the standard mute
4718          * methods whenever the user wants to turn these outputs off.
4719          */
4720         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4721         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4722         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
4723         /* Internal speaker/Headphone jack is connected to Line-out pin */
4724         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4725         /* Internal microphone/Mic jack is connected to Mic1 pin */
4726         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
4727         /* Line In jack is connected to Line1 pin */
4728         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4729         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
4730         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4731         /* Ensure all other unused pins are disabled and muted. */
4732         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4733         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4734         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4735         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4736         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4737         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4738         /* Disable digital (SPDIF) pins */
4739         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4740         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4741
4742         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
4743          * bus when acting as outputs.
4744          */
4745         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4746         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4747
4748         /* Start with output sum widgets muted and their output gains at min */
4749         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4750         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4751         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4752         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4753         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4754         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4755         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4756         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4757         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4758
4759         /* Unmute Line-out pin widget amp left and right
4760          * (no equiv mixer ctrl)
4761          */
4762         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4763         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
4764         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4765         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
4766          * inputs. If the pin mode is changed by the user the pin mode control
4767          * will take care of enabling the pin's input/output buffers as needed.
4768          * Therefore there's no need to enable the input buffer at this
4769          * stage.
4770          */
4771         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4772         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4773
4774         /* Mute capture amp left and right */
4775         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4776         /* Set ADC connection select to match default mixer setting - mic
4777          * (on mic1 pin)
4778          */
4779         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4780
4781         /* Do similar with the second ADC: mute capture input amp and
4782          * set ADC connection to mic to match ALSA's default state.
4783          */
4784         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4785         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4786
4787         /* Mute all inputs to mixer widget (even unconnected ones) */
4788         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4789         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4790         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4791         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4792         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4793         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4794         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4795         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4796
4797         { }
4798 };
4799
4800 static struct hda_verb alc260_will_verbs[] = {
4801         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4802         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
4803         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
4804         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4805         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4806         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
4807         {}
4808 };
4809
4810 static struct hda_verb alc260_replacer_672v_verbs[] = {
4811         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4812         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4813         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
4814
4815         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4816         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4817         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4818
4819         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4820         {}
4821 };
4822
4823 /* toggle speaker-output according to the hp-jack state */
4824 static void alc260_replacer_672v_automute(struct hda_codec *codec)
4825 {
4826         unsigned int present;
4827
4828         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
4829         present = snd_hda_codec_read(codec, 0x0f, 0,
4830                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
4831         if (present) {
4832                 snd_hda_codec_write_cache(codec, 0x01, 0,
4833                                           AC_VERB_SET_GPIO_DATA, 1);
4834                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4835                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4836                                           PIN_HP);
4837         } else {
4838                 snd_hda_codec_write_cache(codec, 0x01, 0,
4839                                           AC_VERB_SET_GPIO_DATA, 0);
4840                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4841                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4842                                           PIN_OUT);
4843         }
4844 }
4845
4846 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
4847                                        unsigned int res)
4848 {
4849         if ((res >> 26) == ALC880_HP_EVENT)
4850                 alc260_replacer_672v_automute(codec);
4851 }
4852
4853 static struct hda_verb alc260_hp_dc7600_verbs[] = {
4854         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
4855         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
4856         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4857         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4858         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4859         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4860         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4861         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4862         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4863         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4864         {}
4865 };
4866
4867 /* Test configuration for debugging, modelled after the ALC880 test
4868  * configuration.
4869  */
4870 #ifdef CONFIG_SND_DEBUG
4871 static hda_nid_t alc260_test_dac_nids[1] = {
4872         0x02,
4873 };
4874 static hda_nid_t alc260_test_adc_nids[2] = {
4875         0x04, 0x05,
4876 };
4877 /* For testing the ALC260, each input MUX needs its own definition since
4878  * the signal assignments are different.  This assumes that the first ADC
4879  * is NID 0x04.
4880  */
4881 static struct hda_input_mux alc260_test_capture_sources[2] = {
4882         {
4883                 .num_items = 7,
4884                 .items = {
4885                         { "MIC1 pin", 0x0 },
4886                         { "MIC2 pin", 0x1 },
4887                         { "LINE1 pin", 0x2 },
4888                         { "LINE2 pin", 0x3 },
4889                         { "CD pin", 0x4 },
4890                         { "LINE-OUT pin", 0x5 },
4891                         { "HP-OUT pin", 0x6 },
4892                 },
4893         },
4894         {
4895                 .num_items = 8,
4896                 .items = {
4897                         { "MIC1 pin", 0x0 },
4898                         { "MIC2 pin", 0x1 },
4899                         { "LINE1 pin", 0x2 },
4900                         { "LINE2 pin", 0x3 },
4901                         { "CD pin", 0x4 },
4902                         { "Mixer", 0x5 },
4903                         { "LINE-OUT pin", 0x6 },
4904                         { "HP-OUT pin", 0x7 },
4905                 },
4906         },
4907 };
4908 static struct snd_kcontrol_new alc260_test_mixer[] = {
4909         /* Output driver widgets */
4910         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4911         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4912         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4913         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
4914         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4915         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
4916
4917         /* Modes for retasking pin widgets
4918          * Note: the ALC260 doesn't seem to act on requests to enable mic
4919          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
4920          * mention this restriction.  At this stage it's not clear whether
4921          * this behaviour is intentional or is a hardware bug in chip
4922          * revisions available at least up until early 2006.  Therefore for
4923          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
4924          * choices, but if it turns out that the lack of mic bias for these
4925          * NIDs is intentional we could change their modes from
4926          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4927          */
4928         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
4929         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
4930         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
4931         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
4932         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
4933         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
4934
4935         /* Loopback mixer controls */
4936         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
4937         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
4938         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
4939         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
4940         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
4941         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
4942         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
4943         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
4944         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4945         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4946         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4947         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4948         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
4949         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
4950         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
4951         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
4952
4953         /* Controls for GPIO pins, assuming they are configured as outputs */
4954         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
4955         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
4956         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
4957         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
4958
4959         /* Switches to allow the digital IO pins to be enabled.  The datasheet
4960          * is ambigious as to which NID is which; testing on laptops which
4961          * make this output available should provide clarification.
4962          */
4963         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
4964         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
4965
4966         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
4967          * this output to turn on an external amplifier.
4968          */
4969         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
4970         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
4971
4972         { } /* end */
4973 };
4974 static struct hda_verb alc260_test_init_verbs[] = {
4975         /* Enable all GPIOs as outputs with an initial value of 0 */
4976         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
4977         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4978         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
4979
4980         /* Enable retasking pins as output, initially without power amp */
4981         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4982         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4983         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4984         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4985         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4986         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4987
4988         /* Disable digital (SPDIF) pins initially, but users can enable
4989          * them via a mixer switch.  In the case of SPDIF-out, this initverb
4990          * payload also sets the generation to 0, output to be in "consumer"
4991          * PCM format, copyright asserted, no pre-emphasis and no validity
4992          * control.
4993          */
4994         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4995         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4996
4997         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
4998          * OUT1 sum bus when acting as an output.
4999          */
5000         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5001         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5002         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5003         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5004
5005         /* Start with output sum widgets muted and their output gains at min */
5006         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5007         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5008         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5009         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5010         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5011         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5012         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5013         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5014         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5015
5016         /* Unmute retasking pin widget output buffers since the default
5017          * state appears to be output.  As the pin mode is changed by the
5018          * user the pin mode control will take care of enabling the pin's
5019          * input/output buffers as needed.
5020          */
5021         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5022         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5023         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5024         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5025         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5026         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5027         /* Also unmute the mono-out pin widget */
5028         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5029
5030         /* Mute capture amp left and right */
5031         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5032         /* Set ADC connection select to match default mixer setting (mic1
5033          * pin)
5034          */
5035         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5036
5037         /* Do the same for the second ADC: mute capture input amp and
5038          * set ADC connection to mic1 pin
5039          */
5040         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5041         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5042
5043         /* Mute all inputs to mixer widget (even unconnected ones) */
5044         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5045         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5046         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5047         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5048         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5049         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5050         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5051         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5052
5053         { }
5054 };
5055 #endif
5056
5057 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5058 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5059
5060 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5061 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5062
5063 /*
5064  * for BIOS auto-configuration
5065  */
5066
5067 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5068                                         const char *pfx, int *vol_bits)
5069 {
5070         hda_nid_t nid_vol;
5071         unsigned long vol_val, sw_val;
5072         char name[32];
5073         int err;
5074
5075         if (nid >= 0x0f && nid < 0x11) {
5076                 nid_vol = nid - 0x7;
5077                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5078                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5079         } else if (nid == 0x11) {
5080                 nid_vol = nid - 0x7;
5081                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
5082                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
5083         } else if (nid >= 0x12 && nid <= 0x15) {
5084                 nid_vol = 0x08;
5085                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5086                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5087         } else
5088                 return 0; /* N/A */
5089
5090         if (!(*vol_bits & (1 << nid_vol))) {
5091                 /* first control for the volume widget */
5092                 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
5093                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
5094                 if (err < 0)
5095                         return err;
5096                 *vol_bits |= (1 << nid_vol);
5097         }
5098         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
5099         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
5100         if (err < 0)
5101                 return err;
5102         return 1;
5103 }
5104
5105 /* add playback controls from the parsed DAC table */
5106 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5107                                              const struct auto_pin_cfg *cfg)
5108 {
5109         hda_nid_t nid;
5110         int err;
5111         int vols = 0;
5112
5113         spec->multiout.num_dacs = 1;
5114         spec->multiout.dac_nids = spec->private_dac_nids;
5115         spec->multiout.dac_nids[0] = 0x02;
5116
5117         nid = cfg->line_out_pins[0];
5118         if (nid) {
5119                 err = alc260_add_playback_controls(spec, nid, "Front", &vols);
5120                 if (err < 0)
5121                         return err;
5122         }
5123
5124         nid = cfg->speaker_pins[0];
5125         if (nid) {
5126                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
5127                 if (err < 0)
5128                         return err;
5129         }
5130
5131         nid = cfg->hp_pins[0];
5132         if (nid) {
5133                 err = alc260_add_playback_controls(spec, nid, "Headphone",
5134                                                    &vols);
5135                 if (err < 0)
5136                         return err;
5137         }
5138         return 0;
5139 }
5140
5141 /* create playback/capture controls for input pins */
5142 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
5143                                                 const struct auto_pin_cfg *cfg)
5144 {
5145         struct hda_input_mux *imux = &spec->private_imux;
5146         int i, err, idx;
5147
5148         for (i = 0; i < AUTO_PIN_LAST; i++) {
5149                 if (cfg->input_pins[i] >= 0x12) {
5150                         idx = cfg->input_pins[i] - 0x12;
5151                         err = new_analog_input(spec, cfg->input_pins[i],
5152                                                auto_pin_cfg_labels[i], idx,
5153                                                0x07);
5154                         if (err < 0)
5155                                 return err;
5156                         imux->items[imux->num_items].label =
5157                                 auto_pin_cfg_labels[i];
5158                         imux->items[imux->num_items].index = idx;
5159                         imux->num_items++;
5160                 }
5161                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
5162                         idx = cfg->input_pins[i] - 0x09;
5163                         err = new_analog_input(spec, cfg->input_pins[i],
5164                                                auto_pin_cfg_labels[i], idx,
5165                                                0x07);
5166                         if (err < 0)
5167                                 return err;
5168                         imux->items[imux->num_items].label =
5169                                 auto_pin_cfg_labels[i];
5170                         imux->items[imux->num_items].index = idx;
5171                         imux->num_items++;
5172                 }
5173         }
5174         return 0;
5175 }
5176
5177 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
5178                                               hda_nid_t nid, int pin_type,
5179                                               int sel_idx)
5180 {
5181         alc_set_pin_output(codec, nid, pin_type);
5182         /* need the manual connection? */
5183         if (nid >= 0x12) {
5184                 int idx = nid - 0x12;
5185                 snd_hda_codec_write(codec, idx + 0x0b, 0,
5186                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
5187         }
5188 }
5189
5190 static void alc260_auto_init_multi_out(struct hda_codec *codec)
5191 {
5192         struct alc_spec *spec = codec->spec;
5193         hda_nid_t nid;
5194
5195         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
5196         nid = spec->autocfg.line_out_pins[0];
5197         if (nid) {
5198                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5199                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5200         }
5201
5202         nid = spec->autocfg.speaker_pins[0];
5203         if (nid)
5204                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5205
5206         nid = spec->autocfg.hp_pins[0];
5207         if (nid)
5208                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5209 }
5210
5211 #define ALC260_PIN_CD_NID               0x16
5212 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5213 {
5214         struct alc_spec *spec = codec->spec;
5215         int i;
5216
5217         for (i = 0; i < AUTO_PIN_LAST; i++) {
5218                 hda_nid_t nid = spec->autocfg.input_pins[i];
5219                 if (nid >= 0x12) {
5220                         snd_hda_codec_write(codec, nid, 0,
5221                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5222                                             i <= AUTO_PIN_FRONT_MIC ?
5223                                             PIN_VREF80 : PIN_IN);
5224                         if (nid != ALC260_PIN_CD_NID)
5225                                 snd_hda_codec_write(codec, nid, 0,
5226                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5227                                                     AMP_OUT_MUTE);
5228                 }
5229         }
5230 }
5231
5232 /*
5233  * generic initialization of ADC, input mixers and output mixers
5234  */
5235 static struct hda_verb alc260_volume_init_verbs[] = {
5236         /*
5237          * Unmute ADC0-1 and set the default input to mic-in
5238          */
5239         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5240         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5241         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5242         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5243
5244         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5245          * mixer widget
5246          * Note: PASD motherboards uses the Line In 2 as the input for
5247          * front panel mic (mic 2)
5248          */
5249         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5250         /* mute analog inputs */
5251         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5252         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5253         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5254         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5255         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5256
5257         /*
5258          * Set up output mixers (0x08 - 0x0a)
5259          */
5260         /* set vol=0 to output mixers */
5261         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5262         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5263         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5264         /* set up input amps for analog loopback */
5265         /* Amp Indices: DAC = 0, mixer = 1 */
5266         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5267         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5268         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5269         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5270         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5271         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5272
5273         { }
5274 };
5275
5276 static int alc260_parse_auto_config(struct hda_codec *codec)
5277 {
5278         struct alc_spec *spec = codec->spec;
5279         unsigned int wcap;
5280         int err;
5281         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5282
5283         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5284                                            alc260_ignore);
5285         if (err < 0)
5286                 return err;
5287         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5288         if (err < 0)
5289                 return err;
5290         if (!spec->kctl_alloc)
5291                 return 0; /* can't find valid BIOS pin config */
5292         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5293         if (err < 0)
5294                 return err;
5295
5296         spec->multiout.max_channels = 2;
5297
5298         if (spec->autocfg.dig_out_pin)
5299                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5300         if (spec->kctl_alloc)
5301                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
5302
5303         spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs;
5304
5305         spec->num_mux_defs = 1;
5306         spec->input_mux = &spec->private_imux;
5307
5308         /* check whether NID 0x04 is valid */
5309         wcap = get_wcaps(codec, 0x04);
5310         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
5311         if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
5312                 spec->adc_nids = alc260_adc_nids_alt;
5313                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
5314                 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
5315         } else {
5316                 spec->adc_nids = alc260_adc_nids;
5317                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
5318                 spec->mixers[spec->num_mixers] = alc260_capture_mixer;
5319         }
5320         spec->num_mixers++;
5321
5322         store_pin_configs(codec);
5323         return 1;
5324 }
5325
5326 /* additional initialization for auto-configuration model */
5327 static void alc260_auto_init(struct hda_codec *codec)
5328 {
5329         struct alc_spec *spec = codec->spec;
5330         alc260_auto_init_multi_out(codec);
5331         alc260_auto_init_analog_input(codec);
5332         if (spec->unsol_event)
5333                 alc_inithook(codec);
5334 }
5335
5336 #ifdef CONFIG_SND_HDA_POWER_SAVE
5337 static struct hda_amp_list alc260_loopbacks[] = {
5338         { 0x07, HDA_INPUT, 0 },
5339         { 0x07, HDA_INPUT, 1 },
5340         { 0x07, HDA_INPUT, 2 },
5341         { 0x07, HDA_INPUT, 3 },
5342         { 0x07, HDA_INPUT, 4 },
5343         { } /* end */
5344 };
5345 #endif
5346
5347 /*
5348  * ALC260 configurations
5349  */
5350 static const char *alc260_models[ALC260_MODEL_LAST] = {
5351         [ALC260_BASIC]          = "basic",
5352         [ALC260_HP]             = "hp",
5353         [ALC260_HP_3013]        = "hp-3013",
5354         [ALC260_HP_DC7600]      = "hp-dc7600",
5355         [ALC260_FUJITSU_S702X]  = "fujitsu",
5356         [ALC260_ACER]           = "acer",
5357         [ALC260_WILL]           = "will",
5358         [ALC260_REPLACER_672V]  = "replacer",
5359 #ifdef CONFIG_SND_DEBUG
5360         [ALC260_TEST]           = "test",
5361 #endif
5362         [ALC260_AUTO]           = "auto",
5363 };
5364
5365 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5366         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5367         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5368         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5369         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5370         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5371         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
5372         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
5373         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5374         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5375         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5376         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5377         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5378         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5379         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5380         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5381         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5382         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5383         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5384         {}
5385 };
5386
5387 static struct alc_config_preset alc260_presets[] = {
5388         [ALC260_BASIC] = {
5389                 .mixers = { alc260_base_output_mixer,
5390                             alc260_input_mixer,
5391                             alc260_pc_beep_mixer,
5392                             alc260_capture_mixer },
5393                 .init_verbs = { alc260_init_verbs },
5394                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5395                 .dac_nids = alc260_dac_nids,
5396                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5397                 .adc_nids = alc260_adc_nids,
5398                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5399                 .channel_mode = alc260_modes,
5400                 .input_mux = &alc260_capture_source,
5401         },
5402         [ALC260_HP] = {
5403                 .mixers = { alc260_hp_output_mixer,
5404                             alc260_input_mixer,
5405                             alc260_capture_alt_mixer },
5406                 .init_verbs = { alc260_init_verbs,
5407                                 alc260_hp_unsol_verbs },
5408                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5409                 .dac_nids = alc260_dac_nids,
5410                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5411                 .adc_nids = alc260_hp_adc_nids,
5412                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5413                 .channel_mode = alc260_modes,
5414                 .input_mux = &alc260_capture_source,
5415                 .unsol_event = alc260_hp_unsol_event,
5416                 .init_hook = alc260_hp_automute,
5417         },
5418         [ALC260_HP_DC7600] = {
5419                 .mixers = { alc260_hp_dc7600_mixer,
5420                             alc260_input_mixer,
5421                             alc260_capture_alt_mixer },
5422                 .init_verbs = { alc260_init_verbs,
5423                                 alc260_hp_dc7600_verbs },
5424                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5425                 .dac_nids = alc260_dac_nids,
5426                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5427                 .adc_nids = alc260_hp_adc_nids,
5428                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5429                 .channel_mode = alc260_modes,
5430                 .input_mux = &alc260_capture_source,
5431                 .unsol_event = alc260_hp_3012_unsol_event,
5432                 .init_hook = alc260_hp_3012_automute,
5433         },
5434         [ALC260_HP_3013] = {
5435                 .mixers = { alc260_hp_3013_mixer,
5436                             alc260_input_mixer,
5437                             alc260_capture_alt_mixer },
5438                 .init_verbs = { alc260_hp_3013_init_verbs,
5439                                 alc260_hp_3013_unsol_verbs },
5440                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5441                 .dac_nids = alc260_dac_nids,
5442                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5443                 .adc_nids = alc260_hp_adc_nids,
5444                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5445                 .channel_mode = alc260_modes,
5446                 .input_mux = &alc260_capture_source,
5447                 .unsol_event = alc260_hp_3013_unsol_event,
5448                 .init_hook = alc260_hp_3013_automute,
5449         },
5450         [ALC260_FUJITSU_S702X] = {
5451                 .mixers = { alc260_fujitsu_mixer,
5452                             alc260_capture_mixer },
5453                 .init_verbs = { alc260_fujitsu_init_verbs },
5454                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5455                 .dac_nids = alc260_dac_nids,
5456                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5457                 .adc_nids = alc260_dual_adc_nids,
5458                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5459                 .channel_mode = alc260_modes,
5460                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5461                 .input_mux = alc260_fujitsu_capture_sources,
5462         },
5463         [ALC260_ACER] = {
5464                 .mixers = { alc260_acer_mixer,
5465                             alc260_capture_mixer },
5466                 .init_verbs = { alc260_acer_init_verbs },
5467                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5468                 .dac_nids = alc260_dac_nids,
5469                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5470                 .adc_nids = alc260_dual_adc_nids,
5471                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5472                 .channel_mode = alc260_modes,
5473                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5474                 .input_mux = alc260_acer_capture_sources,
5475         },
5476         [ALC260_WILL] = {
5477                 .mixers = { alc260_will_mixer,
5478                             alc260_capture_mixer },
5479                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5480                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5481                 .dac_nids = alc260_dac_nids,
5482                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5483                 .adc_nids = alc260_adc_nids,
5484                 .dig_out_nid = ALC260_DIGOUT_NID,
5485                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5486                 .channel_mode = alc260_modes,
5487                 .input_mux = &alc260_capture_source,
5488         },
5489         [ALC260_REPLACER_672V] = {
5490                 .mixers = { alc260_replacer_672v_mixer,
5491                             alc260_capture_mixer },
5492                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5493                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5494                 .dac_nids = alc260_dac_nids,
5495                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5496                 .adc_nids = alc260_adc_nids,
5497                 .dig_out_nid = ALC260_DIGOUT_NID,
5498                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5499                 .channel_mode = alc260_modes,
5500                 .input_mux = &alc260_capture_source,
5501                 .unsol_event = alc260_replacer_672v_unsol_event,
5502                 .init_hook = alc260_replacer_672v_automute,
5503         },
5504 #ifdef CONFIG_SND_DEBUG
5505         [ALC260_TEST] = {
5506                 .mixers = { alc260_test_mixer,
5507                             alc260_capture_mixer },
5508                 .init_verbs = { alc260_test_init_verbs },
5509                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5510                 .dac_nids = alc260_test_dac_nids,
5511                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5512                 .adc_nids = alc260_test_adc_nids,
5513                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5514                 .channel_mode = alc260_modes,
5515                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5516                 .input_mux = alc260_test_capture_sources,
5517         },
5518 #endif
5519 };
5520
5521 static int patch_alc260(struct hda_codec *codec)
5522 {
5523         struct alc_spec *spec;
5524         int err, board_config;
5525
5526         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5527         if (spec == NULL)
5528                 return -ENOMEM;
5529
5530         codec->spec = spec;
5531
5532         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
5533                                                   alc260_models,
5534                                                   alc260_cfg_tbl);
5535         if (board_config < 0) {
5536                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
5537                            "trying auto-probe from BIOS...\n");
5538                 board_config = ALC260_AUTO;
5539         }
5540
5541         if (board_config == ALC260_AUTO) {
5542                 /* automatic parse from the BIOS config */
5543                 err = alc260_parse_auto_config(codec);
5544                 if (err < 0) {
5545                         alc_free(codec);
5546                         return err;
5547                 } else if (!err) {
5548                         printk(KERN_INFO
5549                                "hda_codec: Cannot set up configuration "
5550                                "from BIOS.  Using base mode...\n");
5551                         board_config = ALC260_BASIC;
5552                 }
5553         }
5554
5555         if (board_config != ALC260_AUTO)
5556                 setup_preset(spec, &alc260_presets[board_config]);
5557
5558         spec->stream_name_analog = "ALC260 Analog";
5559         spec->stream_analog_playback = &alc260_pcm_analog_playback;
5560         spec->stream_analog_capture = &alc260_pcm_analog_capture;
5561
5562         spec->stream_name_digital = "ALC260 Digital";
5563         spec->stream_digital_playback = &alc260_pcm_digital_playback;
5564         spec->stream_digital_capture = &alc260_pcm_digital_capture;
5565
5566         spec->vmaster_nid = 0x08;
5567
5568         codec->patch_ops = alc_patch_ops;
5569         if (board_config == ALC260_AUTO)
5570                 spec->init_hook = alc260_auto_init;
5571 #ifdef CONFIG_SND_HDA_POWER_SAVE
5572         if (!spec->loopback.amplist)
5573                 spec->loopback.amplist = alc260_loopbacks;
5574 #endif
5575
5576         return 0;
5577 }
5578
5579
5580 /*
5581  * ALC882 support
5582  *
5583  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5584  * configuration.  Each pin widget can choose any input DACs and a mixer.
5585  * Each ADC is connected from a mixer of all inputs.  This makes possible
5586  * 6-channel independent captures.
5587  *
5588  * In addition, an independent DAC for the multi-playback (not used in this
5589  * driver yet).
5590  */
5591 #define ALC882_DIGOUT_NID       0x06
5592 #define ALC882_DIGIN_NID        0x0a
5593
5594 static struct hda_channel_mode alc882_ch_modes[1] = {
5595         { 8, NULL }
5596 };
5597
5598 static hda_nid_t alc882_dac_nids[4] = {
5599         /* front, rear, clfe, rear_surr */
5600         0x02, 0x03, 0x04, 0x05
5601 };
5602
5603 /* identical with ALC880 */
5604 #define alc882_adc_nids         alc880_adc_nids
5605 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5606
5607 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5608 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5609
5610 /* input MUX */
5611 /* FIXME: should be a matrix-type input source selection */
5612
5613 static struct hda_input_mux alc882_capture_source = {
5614         .num_items = 4,
5615         .items = {
5616                 { "Mic", 0x0 },
5617                 { "Front Mic", 0x1 },
5618                 { "Line", 0x2 },
5619                 { "CD", 0x4 },
5620         },
5621 };
5622 #define alc882_mux_enum_info alc_mux_enum_info
5623 #define alc882_mux_enum_get alc_mux_enum_get
5624
5625 static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol,
5626                                struct snd_ctl_elem_value *ucontrol)
5627 {
5628         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5629         struct alc_spec *spec = codec->spec;
5630         const struct hda_input_mux *imux = spec->input_mux;
5631         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
5632         hda_nid_t nid = spec->capsrc_nids ?
5633                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
5634         unsigned int *cur_val = &spec->cur_mux[adc_idx];
5635         unsigned int i, idx;
5636
5637         idx = ucontrol->value.enumerated.item[0];
5638         if (idx >= imux->num_items)
5639                 idx = imux->num_items - 1;
5640         if (*cur_val == idx)
5641                 return 0;
5642         for (i = 0; i < imux->num_items; i++) {
5643                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
5644                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
5645                                          imux->items[i].index,
5646                                          HDA_AMP_MUTE, v);
5647         }
5648         *cur_val = idx;
5649         return 1;
5650 }
5651
5652 /*
5653  * 2ch mode
5654  */
5655 static struct hda_verb alc882_3ST_ch2_init[] = {
5656         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5657         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5658         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5659         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5660         { } /* end */
5661 };
5662
5663 /*
5664  * 6ch mode
5665  */
5666 static struct hda_verb alc882_3ST_ch6_init[] = {
5667         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5668         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5669         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5670         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5671         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5672         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5673         { } /* end */
5674 };
5675
5676 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5677         { 2, alc882_3ST_ch2_init },
5678         { 6, alc882_3ST_ch6_init },
5679 };
5680
5681 /*
5682  * 6ch mode
5683  */
5684 static struct hda_verb alc882_sixstack_ch6_init[] = {
5685         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5686         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5687         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5688         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5689         { } /* end */
5690 };
5691
5692 /*
5693  * 8ch mode
5694  */
5695 static struct hda_verb alc882_sixstack_ch8_init[] = {
5696         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5697         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5698         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5699         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5700         { } /* end */
5701 };
5702
5703 static struct hda_channel_mode alc882_sixstack_modes[2] = {
5704         { 6, alc882_sixstack_ch6_init },
5705         { 8, alc882_sixstack_ch8_init },
5706 };
5707
5708 /*
5709  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
5710  */
5711
5712 /*
5713  * 2ch mode
5714  */
5715 static struct hda_verb alc885_mbp_ch2_init[] = {
5716         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5717         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5718         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5719         { } /* end */
5720 };
5721
5722 /*
5723  * 6ch mode
5724  */
5725 static struct hda_verb alc885_mbp_ch6_init[] = {
5726         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5727         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5728         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5729         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5730         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5731         { } /* end */
5732 };
5733
5734 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
5735         { 2, alc885_mbp_ch2_init },
5736         { 6, alc885_mbp_ch6_init },
5737 };
5738
5739
5740 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
5741  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
5742  */
5743 static struct snd_kcontrol_new alc882_base_mixer[] = {
5744         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5745         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5746         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5747         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5748         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5749         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5750         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5751         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5752         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
5753         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
5754         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5755         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5756         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5757         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5758         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5759         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5760         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5761         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5762         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5763         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5764         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5765         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5766         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5767         { } /* end */
5768 };
5769
5770 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
5771         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5772         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
5773         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
5774         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
5775         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5776         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5777         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
5778         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
5779         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
5780         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
5781         { } /* end */
5782 };
5783 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
5784         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5785         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5786         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5787         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5788         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5789         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5790         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5791         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5792         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5793         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5794         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5795         { } /* end */
5796 };
5797
5798 static struct snd_kcontrol_new alc882_targa_mixer[] = {
5799         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5800         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5801         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5802         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5803         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5804         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5805         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5806         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5807         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5808         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5809         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5810         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5811         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5812         { } /* end */
5813 };
5814
5815 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
5816  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
5817  */
5818 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
5819         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5820         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5821         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5822         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
5823         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5824         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5825         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5826         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5827         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
5828         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
5829         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5830         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5831         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5832         { } /* end */
5833 };
5834
5835 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
5836         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5837         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5838         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5839         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5840         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5841         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5842         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5843         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5844         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5845         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5846         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5847         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5848         { } /* end */
5849 };
5850
5851 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
5852         {
5853                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5854                 .name = "Channel Mode",
5855                 .info = alc_ch_mode_info,
5856                 .get = alc_ch_mode_get,
5857                 .put = alc_ch_mode_put,
5858         },
5859         { } /* end */
5860 };
5861
5862 static struct hda_verb alc882_init_verbs[] = {
5863         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5864         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5865         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5866         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5867         /* Rear mixer */
5868         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5869         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5870         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5871         /* CLFE mixer */
5872         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5873         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5874         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5875         /* Side mixer */
5876         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5877         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5878         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5879
5880         /* Front Pin: output 0 (0x0c) */
5881         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5882         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5883         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5884         /* Rear Pin: output 1 (0x0d) */
5885         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5886         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5887         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5888         /* CLFE Pin: output 2 (0x0e) */
5889         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5890         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5891         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
5892         /* Side Pin: output 3 (0x0f) */
5893         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5894         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5895         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
5896         /* Mic (rear) pin: input vref at 80% */
5897         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5898         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5899         /* Front Mic pin: input vref at 80% */
5900         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5901         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5902         /* Line In pin: input */
5903         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5904         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5905         /* Line-2 In: Headphone output (output 0 - 0x0c) */
5906         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5907         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5908         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
5909         /* CD pin widget for input */
5910         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
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 static struct hda_verb alc882_eapd_verbs[] = {
5943         /* change to EAPD mode */
5944         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5945         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
5946         { }
5947 };
5948
5949 /* Mac Pro test */
5950 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
5951         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5952         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5953         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
5954         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
5955         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
5956         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
5957         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
5958         { } /* end */
5959 };
5960
5961 static struct hda_verb alc882_macpro_init_verbs[] = {
5962         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5963         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5964         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5965         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5966         /* Front Pin: output 0 (0x0c) */
5967         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5968         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5969         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5970         /* Front Mic pin: input vref at 80% */
5971         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5972         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5973         /* Speaker:  output */
5974         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5975         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5976         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
5977         /* Headphone output (output 0 - 0x0c) */
5978         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5979         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5980         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5981
5982         /* FIXME: use matrix-type input source selection */
5983         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5984         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5985         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5986         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5987         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5988         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5989         /* Input mixer2 */
5990         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5991         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5992         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5993         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5994         /* Input mixer3 */
5995         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5996         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5997         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5998         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5999         /* ADC1: mute amp left and right */
6000         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6001         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6002         /* ADC2: mute amp left and right */
6003         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6004         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6005         /* ADC3: mute amp left and right */
6006         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6007         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6008
6009         { }
6010 };
6011
6012 /* Macbook Pro rev3 */
6013 static struct hda_verb alc885_mbp3_init_verbs[] = {
6014         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6015         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6016         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6017         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6018         /* Rear mixer */
6019         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6020         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6021         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6022         /* Front Pin: output 0 (0x0c) */
6023         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6024         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6025         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6026         /* HP Pin: output 0 (0x0d) */
6027         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
6028         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6029         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6030         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6031         /* Mic (rear) pin: input vref at 80% */
6032         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6033         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6034         /* Front Mic pin: input vref at 80% */
6035         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6036         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6037         /* Line In pin: use output 1 when in LineOut mode */
6038         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6039         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6040         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
6041
6042         /* FIXME: use matrix-type input source selection */
6043         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6044         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6045         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6046         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6047         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6048         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6049         /* Input mixer2 */
6050         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6051         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6052         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6053         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6054         /* Input mixer3 */
6055         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6056         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6057         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6058         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6059         /* ADC1: mute amp left and right */
6060         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6061         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6062         /* ADC2: mute amp left and right */
6063         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6064         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6065         /* ADC3: mute amp left and right */
6066         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6067         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6068
6069         { }
6070 };
6071
6072 /* iMac 24 mixer. */
6073 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
6074         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6075         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
6076         { } /* end */
6077 };
6078
6079 /* iMac 24 init verbs. */
6080 static struct hda_verb alc885_imac24_init_verbs[] = {
6081         /* Internal speakers: output 0 (0x0c) */
6082         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6083         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6084         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6085         /* Internal speakers: output 0 (0x0c) */
6086         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6087         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6088         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
6089         /* Headphone: output 0 (0x0c) */
6090         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6091         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6092         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6093         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6094         /* Front Mic: input vref at 80% */
6095         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6096         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6097         { }
6098 };
6099
6100 /* Toggle speaker-output according to the hp-jack state */
6101 static void alc885_imac24_automute(struct hda_codec *codec)
6102 {
6103         unsigned int present;
6104
6105         present = snd_hda_codec_read(codec, 0x14, 0,
6106                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6107         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
6108                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6109         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
6110                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6111 }
6112
6113 /* Processes unsolicited events. */
6114 static void alc885_imac24_unsol_event(struct hda_codec *codec,
6115                                       unsigned int res)
6116 {
6117         /* Headphone insertion or removal. */
6118         if ((res >> 26) == ALC880_HP_EVENT)
6119                 alc885_imac24_automute(codec);
6120 }
6121
6122 static void alc885_mbp3_automute(struct hda_codec *codec)
6123 {
6124         unsigned int present;
6125
6126         present = snd_hda_codec_read(codec, 0x15, 0,
6127                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6128         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
6129                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6130         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6131                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
6132
6133 }
6134 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
6135                                     unsigned int res)
6136 {
6137         /* Headphone insertion or removal. */
6138         if ((res >> 26) == ALC880_HP_EVENT)
6139                 alc885_mbp3_automute(codec);
6140 }
6141
6142
6143 static struct hda_verb alc882_targa_verbs[] = {
6144         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6145         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6146
6147         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6148         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6149
6150         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6151         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6152         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6153
6154         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6155         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6156         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6157         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6158         { } /* end */
6159 };
6160
6161 /* toggle speaker-output according to the hp-jack state */
6162 static void alc882_targa_automute(struct hda_codec *codec)
6163 {
6164         unsigned int present;
6165
6166         present = snd_hda_codec_read(codec, 0x14, 0,
6167                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6168         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
6169                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6170         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6171                                   present ? 1 : 3);
6172 }
6173
6174 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
6175 {
6176         /* Looks like the unsol event is incompatible with the standard
6177          * definition.  4bit tag is placed at 26 bit!
6178          */
6179         if (((res >> 26) == ALC880_HP_EVENT)) {
6180                 alc882_targa_automute(codec);
6181         }
6182 }
6183
6184 static struct hda_verb alc882_asus_a7j_verbs[] = {
6185         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6186         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6187
6188         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6189         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6190         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6191
6192         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6193         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6194         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6195
6196         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6197         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6198         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6199         { } /* end */
6200 };
6201
6202 static struct hda_verb alc882_asus_a7m_verbs[] = {
6203         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6204         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6205
6206         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6207         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6208         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6209
6210         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6211         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6212         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6213
6214         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6215         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6216         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6217         { } /* end */
6218 };
6219
6220 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6221 {
6222         unsigned int gpiostate, gpiomask, gpiodir;
6223
6224         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6225                                        AC_VERB_GET_GPIO_DATA, 0);
6226
6227         if (!muted)
6228                 gpiostate |= (1 << pin);
6229         else
6230                 gpiostate &= ~(1 << pin);
6231
6232         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
6233                                       AC_VERB_GET_GPIO_MASK, 0);
6234         gpiomask |= (1 << pin);
6235
6236         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
6237                                      AC_VERB_GET_GPIO_DIRECTION, 0);
6238         gpiodir |= (1 << pin);
6239
6240
6241         snd_hda_codec_write(codec, codec->afg, 0,
6242                             AC_VERB_SET_GPIO_MASK, gpiomask);
6243         snd_hda_codec_write(codec, codec->afg, 0,
6244                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
6245
6246         msleep(1);
6247
6248         snd_hda_codec_write(codec, codec->afg, 0,
6249                             AC_VERB_SET_GPIO_DATA, gpiostate);
6250 }
6251
6252 /* set up GPIO at initialization */
6253 static void alc885_macpro_init_hook(struct hda_codec *codec)
6254 {
6255         alc882_gpio_mute(codec, 0, 0);
6256         alc882_gpio_mute(codec, 1, 0);
6257 }
6258
6259 /* set up GPIO and update auto-muting at initialization */
6260 static void alc885_imac24_init_hook(struct hda_codec *codec)
6261 {
6262         alc885_macpro_init_hook(codec);
6263         alc885_imac24_automute(codec);
6264 }
6265
6266 /*
6267  * generic initialization of ADC, input mixers and output mixers
6268  */
6269 static struct hda_verb alc882_auto_init_verbs[] = {
6270         /*
6271          * Unmute ADC0-2 and set the default input to mic-in
6272          */
6273         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6274         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6275         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6276         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6277         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6278         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6279
6280         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6281          * mixer widget
6282          * Note: PASD motherboards uses the Line In 2 as the input for
6283          * front panel mic (mic 2)
6284          */
6285         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6286         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6287         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6288         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6289         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6290         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6291
6292         /*
6293          * Set up output mixers (0x0c - 0x0f)
6294          */
6295         /* set vol=0 to output mixers */
6296         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6297         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6298         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6299         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6300         /* set up input amps for analog loopback */
6301         /* Amp Indices: DAC = 0, mixer = 1 */
6302         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6303         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6304         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6305         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6306         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6307         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6308         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6309         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6310         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6311         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6312
6313         /* FIXME: use matrix-type input source selection */
6314         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6315         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6316         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6317         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6318         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6319         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6320         /* Input mixer2 */
6321         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6322         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6323         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6324         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6325         /* Input mixer3 */
6326         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6327         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6328         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6329         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6330
6331         { }
6332 };
6333
6334 /* capture mixer elements */
6335 static struct snd_kcontrol_new alc882_capture_alt_mixer[] = {
6336         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6337         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6338         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6339         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6340         {
6341                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6342                 /* The multiple "Capture Source" controls confuse alsamixer
6343                  * So call somewhat different..
6344                  */
6345                 /* .name = "Capture Source", */
6346                 .name = "Input Source",
6347                 .count = 2,
6348                 .info = alc882_mux_enum_info,
6349                 .get = alc882_mux_enum_get,
6350                 .put = alc882_mux_enum_put,
6351         },
6352         { } /* end */
6353 };
6354
6355 static struct snd_kcontrol_new alc882_capture_mixer[] = {
6356         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
6357         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
6358         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
6359         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
6360         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
6361         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
6362         {
6363                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6364                 /* The multiple "Capture Source" controls confuse alsamixer
6365                  * So call somewhat different..
6366                  */
6367                 /* .name = "Capture Source", */
6368                 .name = "Input Source",
6369                 .count = 3,
6370                 .info = alc882_mux_enum_info,
6371                 .get = alc882_mux_enum_get,
6372                 .put = alc882_mux_enum_put,
6373         },
6374         { } /* end */
6375 };
6376
6377 #ifdef CONFIG_SND_HDA_POWER_SAVE
6378 #define alc882_loopbacks        alc880_loopbacks
6379 #endif
6380
6381 /* pcm configuration: identiacal with ALC880 */
6382 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6383 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6384 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6385 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6386
6387 /*
6388  * configuration and preset
6389  */
6390 static const char *alc882_models[ALC882_MODEL_LAST] = {
6391         [ALC882_3ST_DIG]        = "3stack-dig",
6392         [ALC882_6ST_DIG]        = "6stack-dig",
6393         [ALC882_ARIMA]          = "arima",
6394         [ALC882_W2JC]           = "w2jc",
6395         [ALC882_TARGA]          = "targa",
6396         [ALC882_ASUS_A7J]       = "asus-a7j",
6397         [ALC882_ASUS_A7M]       = "asus-a7m",
6398         [ALC885_MACPRO]         = "macpro",
6399         [ALC885_MBP3]           = "mbp3",
6400         [ALC885_IMAC24]         = "imac24",
6401         [ALC882_AUTO]           = "auto",
6402 };
6403
6404 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6405         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6406         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6407         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6408         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6409         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6410         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6411         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6412         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6413         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6414         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6415         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6416         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6417         {}
6418 };
6419
6420 static struct alc_config_preset alc882_presets[] = {
6421         [ALC882_3ST_DIG] = {
6422                 .mixers = { alc882_base_mixer },
6423                 .init_verbs = { alc882_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                 .need_dac_fix = 1,
6431                 .input_mux = &alc882_capture_source,
6432         },
6433         [ALC882_6ST_DIG] = {
6434                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6435                 .init_verbs = { alc882_init_verbs },
6436                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6437                 .dac_nids = alc882_dac_nids,
6438                 .dig_out_nid = ALC882_DIGOUT_NID,
6439                 .dig_in_nid = ALC882_DIGIN_NID,
6440                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6441                 .channel_mode = alc882_sixstack_modes,
6442                 .input_mux = &alc882_capture_source,
6443         },
6444         [ALC882_ARIMA] = {
6445                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6446                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6447                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6448                 .dac_nids = alc882_dac_nids,
6449                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6450                 .channel_mode = alc882_sixstack_modes,
6451                 .input_mux = &alc882_capture_source,
6452         },
6453         [ALC882_W2JC] = {
6454                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6455                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6456                                 alc880_gpio1_init_verbs },
6457                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6458                 .dac_nids = alc882_dac_nids,
6459                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6460                 .channel_mode = alc880_threestack_modes,
6461                 .need_dac_fix = 1,
6462                 .input_mux = &alc882_capture_source,
6463                 .dig_out_nid = ALC882_DIGOUT_NID,
6464         },
6465         [ALC885_MBP3] = {
6466                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6467                 .init_verbs = { alc885_mbp3_init_verbs,
6468                                 alc880_gpio1_init_verbs },
6469                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6470                 .dac_nids = alc882_dac_nids,
6471                 .channel_mode = alc885_mbp_6ch_modes,
6472                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
6473                 .input_mux = &alc882_capture_source,
6474                 .dig_out_nid = ALC882_DIGOUT_NID,
6475                 .dig_in_nid = ALC882_DIGIN_NID,
6476                 .unsol_event = alc885_mbp3_unsol_event,
6477                 .init_hook = alc885_mbp3_automute,
6478         },
6479         [ALC885_MACPRO] = {
6480                 .mixers = { alc882_macpro_mixer },
6481                 .init_verbs = { alc882_macpro_init_verbs },
6482                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6483                 .dac_nids = alc882_dac_nids,
6484                 .dig_out_nid = ALC882_DIGOUT_NID,
6485                 .dig_in_nid = ALC882_DIGIN_NID,
6486                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6487                 .channel_mode = alc882_ch_modes,
6488                 .input_mux = &alc882_capture_source,
6489                 .init_hook = alc885_macpro_init_hook,
6490         },
6491         [ALC885_IMAC24] = {
6492                 .mixers = { alc885_imac24_mixer },
6493                 .init_verbs = { alc885_imac24_init_verbs },
6494                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6495                 .dac_nids = alc882_dac_nids,
6496                 .dig_out_nid = ALC882_DIGOUT_NID,
6497                 .dig_in_nid = ALC882_DIGIN_NID,
6498                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6499                 .channel_mode = alc882_ch_modes,
6500                 .input_mux = &alc882_capture_source,
6501                 .unsol_event = alc885_imac24_unsol_event,
6502                 .init_hook = alc885_imac24_init_hook,
6503         },
6504         [ALC882_TARGA] = {
6505                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer,
6506                             alc882_capture_mixer },
6507                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6508                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6509                 .dac_nids = alc882_dac_nids,
6510                 .dig_out_nid = ALC882_DIGOUT_NID,
6511                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6512                 .adc_nids = alc882_adc_nids,
6513                 .capsrc_nids = alc882_capsrc_nids,
6514                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6515                 .channel_mode = alc882_3ST_6ch_modes,
6516                 .need_dac_fix = 1,
6517                 .input_mux = &alc882_capture_source,
6518                 .unsol_event = alc882_targa_unsol_event,
6519                 .init_hook = alc882_targa_automute,
6520         },
6521         [ALC882_ASUS_A7J] = {
6522                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer,
6523                             alc882_capture_mixer },
6524                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6525                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6526                 .dac_nids = alc882_dac_nids,
6527                 .dig_out_nid = ALC882_DIGOUT_NID,
6528                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6529                 .adc_nids = alc882_adc_nids,
6530                 .capsrc_nids = alc882_capsrc_nids,
6531                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6532                 .channel_mode = alc882_3ST_6ch_modes,
6533                 .need_dac_fix = 1,
6534                 .input_mux = &alc882_capture_source,
6535         },
6536         [ALC882_ASUS_A7M] = {
6537                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6538                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6539                                 alc880_gpio1_init_verbs,
6540                                 alc882_asus_a7m_verbs },
6541                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6542                 .dac_nids = alc882_dac_nids,
6543                 .dig_out_nid = ALC882_DIGOUT_NID,
6544                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6545                 .channel_mode = alc880_threestack_modes,
6546                 .need_dac_fix = 1,
6547                 .input_mux = &alc882_capture_source,
6548         },
6549 };
6550
6551
6552 /*
6553  * Pin config fixes
6554  */
6555 enum {
6556         PINFIX_ABIT_AW9D_MAX
6557 };
6558
6559 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6560         { 0x15, 0x01080104 }, /* side */
6561         { 0x16, 0x01011012 }, /* rear */
6562         { 0x17, 0x01016011 }, /* clfe */
6563         { }
6564 };
6565
6566 static const struct alc_pincfg *alc882_pin_fixes[] = {
6567         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6568 };
6569
6570 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6571         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6572         {}
6573 };
6574
6575 /*
6576  * BIOS auto configuration
6577  */
6578 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6579                                               hda_nid_t nid, int pin_type,
6580                                               int dac_idx)
6581 {
6582         /* set as output */
6583         struct alc_spec *spec = codec->spec;
6584         int idx;
6585
6586         alc_set_pin_output(codec, nid, pin_type);
6587         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6588                 idx = 4;
6589         else
6590                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6591         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6592
6593 }
6594
6595 static void alc882_auto_init_multi_out(struct hda_codec *codec)
6596 {
6597         struct alc_spec *spec = codec->spec;
6598         int i;
6599
6600         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6601         for (i = 0; i <= HDA_SIDE; i++) {
6602                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6603                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6604                 if (nid)
6605                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6606                                                           i);
6607         }
6608 }
6609
6610 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6611 {
6612         struct alc_spec *spec = codec->spec;
6613         hda_nid_t pin;
6614
6615         pin = spec->autocfg.hp_pins[0];
6616         if (pin) /* connect to front */
6617                 /* use dac 0 */
6618                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6619         pin = spec->autocfg.speaker_pins[0];
6620         if (pin)
6621                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6622 }
6623
6624 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6625 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6626
6627 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6628 {
6629         struct alc_spec *spec = codec->spec;
6630         int i;
6631
6632         for (i = 0; i < AUTO_PIN_LAST; i++) {
6633                 hda_nid_t nid = spec->autocfg.input_pins[i];
6634                 unsigned int vref;
6635                 if (!nid)
6636                         continue;
6637                 vref = PIN_IN;
6638                 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6639                         unsigned int pincap;
6640                         pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
6641                         if ((pincap >> AC_PINCAP_VREF_SHIFT) &
6642                             AC_PINCAP_VREF_80)
6643                                 vref = PIN_VREF80;
6644                 }
6645                 snd_hda_codec_write(codec, nid, 0,
6646                                     AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6647                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6648                         snd_hda_codec_write(codec, nid, 0,
6649                                             AC_VERB_SET_AMP_GAIN_MUTE,
6650                                             AMP_OUT_MUTE);
6651         }
6652 }
6653
6654 static void alc882_auto_init_input_src(struct hda_codec *codec)
6655 {
6656         struct alc_spec *spec = codec->spec;
6657         const struct hda_input_mux *imux = spec->input_mux;
6658         int c;
6659
6660         for (c = 0; c < spec->num_adc_nids; c++) {
6661                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
6662                 hda_nid_t nid = spec->capsrc_nids[c];
6663                 int conns, mute, idx, item;
6664
6665                 conns = snd_hda_get_connections(codec, nid, conn_list,
6666                                                 ARRAY_SIZE(conn_list));
6667                 if (conns < 0)
6668                         continue;
6669                 for (idx = 0; idx < conns; idx++) {
6670                         /* if the current connection is the selected one,
6671                          * unmute it as default - otherwise mute it
6672                          */
6673                         mute = AMP_IN_MUTE(idx);
6674                         for (item = 0; item < imux->num_items; item++) {
6675                                 if (imux->items[item].index == idx) {
6676                                         if (spec->cur_mux[c] == item)
6677                                                 mute = AMP_IN_UNMUTE(idx);
6678                                         break;
6679                                 }
6680                         }
6681                         snd_hda_codec_write(codec, nid, 0,
6682                                             AC_VERB_SET_AMP_GAIN_MUTE, mute);
6683                 }
6684         }
6685 }
6686
6687 /* add mic boosts if needed */
6688 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6689 {
6690         struct alc_spec *spec = codec->spec;
6691         int err;
6692         hda_nid_t nid;
6693
6694         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6695         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6696                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6697                                   "Mic Boost",
6698                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6699                 if (err < 0)
6700                         return err;
6701         }
6702         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6703         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6704                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6705                                   "Front Mic Boost",
6706                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6707                 if (err < 0)
6708                         return err;
6709         }
6710         return 0;
6711 }
6712
6713 /* almost identical with ALC880 parser... */
6714 static int alc882_parse_auto_config(struct hda_codec *codec)
6715 {
6716         struct alc_spec *spec = codec->spec;
6717         int err = alc880_parse_auto_config(codec);
6718
6719         if (err < 0)
6720                 return err;
6721         else if (!err)
6722                 return 0; /* no config found */
6723
6724         err = alc_auto_add_mic_boost(codec);
6725         if (err < 0)
6726                 return err;
6727
6728         /* hack - override the init verbs */
6729         spec->init_verbs[0] = alc882_auto_init_verbs;
6730
6731         return 1; /* config found */
6732 }
6733
6734 /* additional initialization for auto-configuration model */
6735 static void alc882_auto_init(struct hda_codec *codec)
6736 {
6737         struct alc_spec *spec = codec->spec;
6738         alc882_auto_init_multi_out(codec);
6739         alc882_auto_init_hp_out(codec);
6740         alc882_auto_init_analog_input(codec);
6741         alc882_auto_init_input_src(codec);
6742         if (spec->unsol_event)
6743                 alc_inithook(codec);
6744 }
6745
6746 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
6747
6748 static int patch_alc882(struct hda_codec *codec)
6749 {
6750         struct alc_spec *spec;
6751         int err, board_config;
6752
6753         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6754         if (spec == NULL)
6755                 return -ENOMEM;
6756
6757         codec->spec = spec;
6758
6759         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
6760                                                   alc882_models,
6761                                                   alc882_cfg_tbl);
6762
6763         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
6764                 /* Pick up systems that don't supply PCI SSID */
6765                 switch (codec->subsystem_id) {
6766                 case 0x106b0c00: /* Mac Pro */
6767                         board_config = ALC885_MACPRO;
6768                         break;
6769                 case 0x106b1000: /* iMac 24 */
6770                 case 0x106b2800: /* AppleTV */
6771                         board_config = ALC885_IMAC24;
6772                         break;
6773                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
6774                 case 0x106b00a4: /* MacbookPro4,1 */
6775                 case 0x106b2c00: /* Macbook Pro rev3 */
6776                 case 0x106b3600: /* Macbook 3.1 */
6777                         board_config = ALC885_MBP3;
6778                         break;
6779                 default:
6780                         /* ALC889A is handled better as ALC888-compatible */
6781                         if (codec->revision_id == 0x100101 ||
6782                             codec->revision_id == 0x100103) {
6783                                 alc_free(codec);
6784                                 return patch_alc883(codec);
6785                         }
6786                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
6787                                          "trying auto-probe from BIOS...\n");
6788                         board_config = ALC882_AUTO;
6789                 }
6790         }
6791
6792         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
6793
6794         if (board_config == ALC882_AUTO) {
6795                 /* automatic parse from the BIOS config */
6796                 err = alc882_parse_auto_config(codec);
6797                 if (err < 0) {
6798                         alc_free(codec);
6799                         return err;
6800                 } else if (!err) {
6801                         printk(KERN_INFO
6802                                "hda_codec: Cannot set up configuration "
6803                                "from BIOS.  Using base mode...\n");
6804                         board_config = ALC882_3ST_DIG;
6805                 }
6806         }
6807
6808         if (board_config != ALC882_AUTO)
6809                 setup_preset(spec, &alc882_presets[board_config]);
6810
6811         if (codec->vendor_id == 0x10ec0885) {
6812                 spec->stream_name_analog = "ALC885 Analog";
6813                 spec->stream_name_digital = "ALC885 Digital";
6814         } else {
6815                 spec->stream_name_analog = "ALC882 Analog";
6816                 spec->stream_name_digital = "ALC882 Digital";
6817         }
6818
6819         spec->stream_analog_playback = &alc882_pcm_analog_playback;
6820         spec->stream_analog_capture = &alc882_pcm_analog_capture;
6821         /* FIXME: setup DAC5 */
6822         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
6823         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
6824
6825         spec->stream_digital_playback = &alc882_pcm_digital_playback;
6826         spec->stream_digital_capture = &alc882_pcm_digital_capture;
6827
6828         if (!spec->adc_nids && spec->input_mux) {
6829                 /* check whether NID 0x07 is valid */
6830                 unsigned int wcap = get_wcaps(codec, 0x07);
6831                 /* get type */
6832                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
6833                 if (wcap != AC_WID_AUD_IN) {
6834                         spec->adc_nids = alc882_adc_nids_alt;
6835                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
6836                         spec->capsrc_nids = alc882_capsrc_nids_alt;
6837                         spec->mixers[spec->num_mixers] =
6838                                 alc882_capture_alt_mixer;
6839                         spec->num_mixers++;
6840                 } else {
6841                         spec->adc_nids = alc882_adc_nids;
6842                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
6843                         spec->capsrc_nids = alc882_capsrc_nids;
6844                         spec->mixers[spec->num_mixers] = alc882_capture_mixer;
6845                         spec->num_mixers++;
6846                 }
6847         }
6848
6849         spec->vmaster_nid = 0x0c;
6850
6851         codec->patch_ops = alc_patch_ops;
6852         if (board_config == ALC882_AUTO)
6853                 spec->init_hook = alc882_auto_init;
6854 #ifdef CONFIG_SND_HDA_POWER_SAVE
6855         if (!spec->loopback.amplist)
6856                 spec->loopback.amplist = alc882_loopbacks;
6857 #endif
6858
6859         return 0;
6860 }
6861
6862 /*
6863  * ALC883 support
6864  *
6865  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
6866  * configuration.  Each pin widget can choose any input DACs and a mixer.
6867  * Each ADC is connected from a mixer of all inputs.  This makes possible
6868  * 6-channel independent captures.
6869  *
6870  * In addition, an independent DAC for the multi-playback (not used in this
6871  * driver yet).
6872  */
6873 #define ALC883_DIGOUT_NID       0x06
6874 #define ALC883_DIGIN_NID        0x0a
6875
6876 static hda_nid_t alc883_dac_nids[4] = {
6877         /* front, rear, clfe, rear_surr */
6878         0x02, 0x03, 0x04, 0x05
6879 };
6880
6881 static hda_nid_t alc883_adc_nids[2] = {
6882         /* ADC1-2 */
6883         0x08, 0x09,
6884 };
6885
6886 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
6887
6888 /* input MUX */
6889 /* FIXME: should be a matrix-type input source selection */
6890
6891 static struct hda_input_mux alc883_capture_source = {
6892         .num_items = 4,
6893         .items = {
6894                 { "Mic", 0x0 },
6895                 { "Front Mic", 0x1 },
6896                 { "Line", 0x2 },
6897                 { "CD", 0x4 },
6898         },
6899 };
6900
6901 static struct hda_input_mux alc883_3stack_6ch_intel = {
6902         .num_items = 4,
6903         .items = {
6904                 { "Mic", 0x1 },
6905                 { "Front Mic", 0x0 },
6906                 { "Line", 0x2 },
6907                 { "CD", 0x4 },
6908         },
6909 };
6910
6911 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6912         .num_items = 2,
6913         .items = {
6914                 { "Mic", 0x1 },
6915                 { "Line", 0x2 },
6916         },
6917 };
6918
6919 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6920         .num_items = 4,
6921         .items = {
6922                 { "Mic", 0x0 },
6923                 { "iMic", 0x1 },
6924                 { "Line", 0x2 },
6925                 { "CD", 0x4 },
6926         },
6927 };
6928
6929 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6930         .num_items = 2,
6931         .items = {
6932                 { "Mic", 0x0 },
6933                 { "Int Mic", 0x1 },
6934         },
6935 };
6936
6937 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
6938         .num_items = 3,
6939         .items = {
6940                 { "Mic", 0x0 },
6941                 { "Front Mic", 0x1 },
6942                 { "Line", 0x4 },
6943         },
6944 };
6945
6946 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
6947         .num_items = 2,
6948         .items = {
6949                 { "Mic", 0x0 },
6950                 { "Line", 0x2 },
6951         },
6952 };
6953
6954 #define alc883_mux_enum_info alc_mux_enum_info
6955 #define alc883_mux_enum_get alc_mux_enum_get
6956 /* ALC883 has the ALC882-type input selection */
6957 #define alc883_mux_enum_put alc882_mux_enum_put
6958
6959 /*
6960  * 2ch mode
6961  */
6962 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6963         { 2, NULL }
6964 };
6965
6966 /*
6967  * 2ch mode
6968  */
6969 static struct hda_verb alc883_3ST_ch2_init[] = {
6970         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6971         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6972         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6973         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6974         { } /* end */
6975 };
6976
6977 /*
6978  * 4ch mode
6979  */
6980 static struct hda_verb alc883_3ST_ch4_init[] = {
6981         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6982         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6983         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6984         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6985         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6986         { } /* end */
6987 };
6988
6989 /*
6990  * 6ch mode
6991  */
6992 static struct hda_verb alc883_3ST_ch6_init[] = {
6993         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6994         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6995         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6996         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6997         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6998         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6999         { } /* end */
7000 };
7001
7002 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
7003         { 2, alc883_3ST_ch2_init },
7004         { 4, alc883_3ST_ch4_init },
7005         { 6, alc883_3ST_ch6_init },
7006 };
7007
7008 /*
7009  * 2ch mode
7010  */
7011 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
7012         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7013         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7014         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7015         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7016         { } /* end */
7017 };
7018
7019 /*
7020  * 4ch mode
7021  */
7022 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
7023         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7024         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7025         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7026         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7027         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7028         { } /* end */
7029 };
7030
7031 /*
7032  * 6ch mode
7033  */
7034 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
7035         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7036         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7037         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
7038         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7039         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7040         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7041         { } /* end */
7042 };
7043
7044 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
7045         { 2, alc883_3ST_ch2_intel_init },
7046         { 4, alc883_3ST_ch4_intel_init },
7047         { 6, alc883_3ST_ch6_intel_init },
7048 };
7049
7050 /*
7051  * 6ch mode
7052  */
7053 static struct hda_verb alc883_sixstack_ch6_init[] = {
7054         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7055         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7056         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7057         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7058         { } /* end */
7059 };
7060
7061 /*
7062  * 8ch mode
7063  */
7064 static struct hda_verb alc883_sixstack_ch8_init[] = {
7065         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7066         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7067         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7068         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7069         { } /* end */
7070 };
7071
7072 static struct hda_channel_mode alc883_sixstack_modes[2] = {
7073         { 6, alc883_sixstack_ch6_init },
7074         { 8, alc883_sixstack_ch8_init },
7075 };
7076
7077 static struct hda_verb alc883_medion_eapd_verbs[] = {
7078         /* eanable EAPD on medion laptop */
7079         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7080         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7081         { }
7082 };
7083
7084 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
7085  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
7086  */
7087
7088 static struct snd_kcontrol_new alc883_base_mixer[] = {
7089         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7090         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7091         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7092         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7093         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7094         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7095         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7096         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7097         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7098         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7099         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7100         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7101         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7102         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7103         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7104         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7105         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7106         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7107         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7108         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7109         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7110         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7111         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7112         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7113         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7114         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7115         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7116         {
7117                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7118                 /* .name = "Capture Source", */
7119                 .name = "Input Source",
7120                 .count = 2,
7121                 .info = alc883_mux_enum_info,
7122                 .get = alc883_mux_enum_get,
7123                 .put = alc883_mux_enum_put,
7124         },
7125         { } /* end */
7126 };
7127
7128 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7129         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7130         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7131         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7132         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7133         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7134         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7135         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7136         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7137         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7138         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7139         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7140         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7141         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7142         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7143         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7144         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7145         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7146         {
7147                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7148                 /* .name = "Capture Source", */
7149                 .name = "Input Source",
7150                 .count = 2,
7151                 .info = alc883_mux_enum_info,
7152                 .get = alc883_mux_enum_get,
7153                 .put = alc883_mux_enum_put,
7154         },
7155         { } /* end */
7156 };
7157
7158 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7159         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7160         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7161         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7162         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7163         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7164         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7165         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7166         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7167         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7168         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7169         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7170         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7171         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7172         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7173         {
7174                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7175                 /* .name = "Capture Source", */
7176                 .name = "Input Source",
7177                 .count = 2,
7178                 .info = alc883_mux_enum_info,
7179                 .get = alc883_mux_enum_get,
7180                 .put = alc883_mux_enum_put,
7181         },
7182         { } /* end */
7183 };
7184
7185 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7186         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7187         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7188         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7189         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7190         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7191         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7192         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7193         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7194         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7195         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7196         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7197         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7198         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7199         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7200         {
7201                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7202                 /* .name = "Capture Source", */
7203                 .name = "Input Source",
7204                 .count = 2,
7205                 .info = alc883_mux_enum_info,
7206                 .get = alc883_mux_enum_get,
7207                 .put = alc883_mux_enum_put,
7208         },
7209         { } /* end */
7210 };
7211
7212 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7213         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7214         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7215         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7216         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7217         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7218         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7219         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7220         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7221         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7222         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7223         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7224         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7225         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7226         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7227         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7228         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7229         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7230         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7231         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7232         {
7233                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7234                 /* .name = "Capture Source", */
7235                 .name = "Input Source",
7236                 .count = 2,
7237                 .info = alc883_mux_enum_info,
7238                 .get = alc883_mux_enum_get,
7239                 .put = alc883_mux_enum_put,
7240         },
7241         { } /* end */
7242 };
7243
7244 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7245         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7246         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7247         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7248         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7249         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7250         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7251         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7252         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7253         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7254         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7255         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7256         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7257         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7258         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7259         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7260         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7261         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7262         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7263         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7264         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7265         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7266         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7267         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7268         {
7269                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7270                 /* .name = "Capture Source", */
7271                 .name = "Input Source",
7272                 .count = 1,
7273                 .info = alc883_mux_enum_info,
7274                 .get = alc883_mux_enum_get,
7275                 .put = alc883_mux_enum_put,
7276         },
7277         { } /* end */
7278 };
7279
7280 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7281         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7282         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7283         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7284         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7285         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7286                               HDA_OUTPUT),
7287         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7288         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7289         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7290         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7291         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7292         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7293         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7294         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7295         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7296         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7297         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7298         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7299         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7300         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7301         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7302         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, 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_fivestack_mixer[] = {
7320         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7321         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7322         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7323         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7324         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7325         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7326         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7327         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7328         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7329         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7330         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7331         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7332         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7333         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7334         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7335         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7336         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7337         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7338         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7339         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7340         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7341         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7342         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7343
7344         {
7345                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7346                 /* .name = "Capture Source", */
7347                 .name = "Input Source",
7348                 .count = 1,
7349                 .info = alc883_mux_enum_info,
7350                 .get = alc883_mux_enum_get,
7351                 .put = alc883_mux_enum_put,
7352         },
7353         { } /* end */
7354 };
7355
7356 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
7357         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7358         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7359         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7360         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7361         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7362         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7363         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7364         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7365         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7366         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7367         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7368         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7369         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7370         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7371         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7372         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7373         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7374         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7375         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7376         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7377         {
7378                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7379                 /* .name = "Capture Source", */
7380                 .name = "Input Source",
7381                 .count = 2,
7382                 .info = alc883_mux_enum_info,
7383                 .get = alc883_mux_enum_get,
7384                 .put = alc883_mux_enum_put,
7385         },
7386         { } /* end */
7387 };
7388
7389 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
7390         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7391         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7392         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7393         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7394         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7395         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7396         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7397         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7398         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7399         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7400         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7401         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7402         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7403         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7404         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7405         {
7406                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7407                 /* .name = "Capture Source", */
7408                 .name = "Input Source",
7409                 .count = 2,
7410                 .info = alc883_mux_enum_info,
7411                 .get = alc883_mux_enum_get,
7412                 .put = alc883_mux_enum_put,
7413         },
7414         { } /* end */
7415 };
7416
7417 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7418         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7419         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7420         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7421         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7422         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7423         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7424         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7425         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7426         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7427         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7428         {
7429                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7430                 /* .name = "Capture Source", */
7431                 .name = "Input Source",
7432                 .count = 1,
7433                 .info = alc883_mux_enum_info,
7434                 .get = alc883_mux_enum_get,
7435                 .put = alc883_mux_enum_put,
7436         },
7437         { } /* end */
7438 };
7439
7440 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7441         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7442         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7443         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7444         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7445         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7446         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7447         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7448         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7449         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7450         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7451         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7452         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7453         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7454         {
7455                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7456                 /* .name = "Capture Source", */
7457                 .name = "Input Source",
7458                 .count = 2,
7459                 .info = alc883_mux_enum_info,
7460                 .get = alc883_mux_enum_get,
7461                 .put = alc883_mux_enum_put,
7462         },
7463         { } /* end */
7464 };
7465
7466 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7467         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7468         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7469         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7470         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7471         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7472         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7473         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7474         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7475         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7476         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7477         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7478         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7479         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7480         {
7481                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7482                 /* .name = "Capture Source", */
7483                 .name = "Input Source",
7484                 .count = 2,
7485                 .info = alc883_mux_enum_info,
7486                 .get = alc883_mux_enum_get,
7487                 .put = alc883_mux_enum_put,
7488         },
7489         { } /* end */
7490 };
7491
7492 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7493         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7494         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7495         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7496         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7497         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7498         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7499         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7500         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7501         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7502         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7503         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7504         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7505         {
7506                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7507                 /* .name = "Capture Source", */
7508                 .name = "Input Source",
7509                 .count = 2,
7510                 .info = alc883_mux_enum_info,
7511                 .get = alc883_mux_enum_get,
7512                 .put = alc883_mux_enum_put,
7513         },
7514         { } /* end */
7515 };
7516
7517 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
7518         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7519         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7520         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
7521         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
7522         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
7523                                                 0x0d, 1, 0x0, HDA_OUTPUT),
7524         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
7525         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
7526         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
7527         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7528         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7529         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7530         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
7531         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7532         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7533         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7534         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7535         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7536         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7537         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7538         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7539         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7540         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7541         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7542         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7543         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7544         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7545         {
7546                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7547                 /* .name = "Capture Source", */
7548                 .name = "Input Source",
7549                 .count = 2,
7550                 .info = alc883_mux_enum_info,
7551                 .get = alc883_mux_enum_get,
7552                 .put = alc883_mux_enum_put,
7553         },
7554         { } /* end */
7555 };
7556
7557 static struct hda_bind_ctls alc883_bind_cap_vol = {
7558         .ops = &snd_hda_bind_vol,
7559         .values = {
7560                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7561                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7562                 0
7563         },
7564 };
7565
7566 static struct hda_bind_ctls alc883_bind_cap_switch = {
7567         .ops = &snd_hda_bind_sw,
7568         .values = {
7569                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7570                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7571                 0
7572         },
7573 };
7574
7575 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
7576         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7577         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7578         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7579         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7580         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7581         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7582         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7583         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7584         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
7585         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
7586         {
7587                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7588                 /* .name = "Capture Source", */
7589                 .name = "Input Source",
7590                 .count = 1,
7591                 .info = alc883_mux_enum_info,
7592                 .get = alc883_mux_enum_get,
7593                 .put = alc883_mux_enum_put,
7594         },
7595         { } /* end */
7596 };
7597
7598 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7599         {
7600                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7601                 .name = "Channel Mode",
7602                 .info = alc_ch_mode_info,
7603                 .get = alc_ch_mode_get,
7604                 .put = alc_ch_mode_put,
7605         },
7606         { } /* end */
7607 };
7608
7609 static struct hda_verb alc883_init_verbs[] = {
7610         /* ADC1: mute amp left and right */
7611         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7612         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7613         /* ADC2: mute amp left and right */
7614         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7615         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7616         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7617         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7618         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7619         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7620         /* Rear mixer */
7621         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7622         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7623         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7624         /* CLFE mixer */
7625         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7626         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7627         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7628         /* Side mixer */
7629         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7630         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7631         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7632
7633         /* mute analog input loopbacks */
7634         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7635         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7636         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7637         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7638         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7639
7640         /* Front Pin: output 0 (0x0c) */
7641         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7642         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7643         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7644         /* Rear Pin: output 1 (0x0d) */
7645         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7646         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7647         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7648         /* CLFE Pin: output 2 (0x0e) */
7649         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7650         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7651         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7652         /* Side Pin: output 3 (0x0f) */
7653         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7654         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7655         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7656         /* Mic (rear) pin: input vref at 80% */
7657         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7658         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7659         /* Front Mic pin: input vref at 80% */
7660         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7661         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7662         /* Line In pin: input */
7663         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7664         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7665         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7666         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7667         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7668         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7669         /* CD pin widget for input */
7670         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7671
7672         /* FIXME: use matrix-type input source selection */
7673         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7674         /* Input mixer2 */
7675         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7676         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7677         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7678         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7679         /* Input mixer3 */
7680         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7681         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7682         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7683         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7684         { }
7685 };
7686
7687 /* toggle speaker-output according to the hp-jack state */
7688 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7689 {
7690         unsigned int present;
7691
7692         present = snd_hda_codec_read(codec, 0x15, 0,
7693                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7694         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7695                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7696         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7697                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7698 }
7699
7700 /* auto-toggle front mic */
7701 /*
7702 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7703 {
7704         unsigned int present;
7705         unsigned char bits;
7706
7707         present = snd_hda_codec_read(codec, 0x18, 0,
7708                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7709         bits = present ? HDA_AMP_MUTE : 0;
7710         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7711 }
7712 */
7713
7714 static void alc883_mitac_automute(struct hda_codec *codec)
7715 {
7716         alc883_mitac_hp_automute(codec);
7717         /* alc883_mitac_mic_automute(codec); */
7718 }
7719
7720 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7721                                            unsigned int res)
7722 {
7723         switch (res >> 26) {
7724         case ALC880_HP_EVENT:
7725                 alc883_mitac_hp_automute(codec);
7726                 break;
7727         case ALC880_MIC_EVENT:
7728                 /* alc883_mitac_mic_automute(codec); */
7729                 break;
7730         }
7731 }
7732
7733 static struct hda_verb alc883_mitac_verbs[] = {
7734         /* HP */
7735         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7736         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7737         /* Subwoofer */
7738         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7739         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7740
7741         /* enable unsolicited event */
7742         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7743         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7744
7745         { } /* end */
7746 };
7747
7748 static struct hda_verb alc883_clevo_m720_verbs[] = {
7749         /* HP */
7750         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7751         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7752         /* Int speaker */
7753         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7754         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7755
7756         /* enable unsolicited event */
7757         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7758         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7759
7760         { } /* end */
7761 };
7762
7763 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7764         /* HP */
7765         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7766         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7767         /* Subwoofer */
7768         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7769         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7770
7771         /* enable unsolicited event */
7772         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7773
7774         { } /* end */
7775 };
7776
7777 static struct hda_verb alc883_tagra_verbs[] = {
7778         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7779         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7780
7781         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7782         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7783
7784         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7785         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7786         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7787
7788         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7789         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7790         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7791         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7792
7793         { } /* end */
7794 };
7795
7796 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7797         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7798         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7799         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7800         { } /* end */
7801 };
7802
7803 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7804         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7805         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7806         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7807         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7808         { } /* end */
7809 };
7810
7811 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7812         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7813         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7814         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7815         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7816         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7817         { } /* end */
7818 };
7819
7820 static struct hda_verb alc883_haier_w66_verbs[] = {
7821         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7822         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7823
7824         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7825
7826         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7827         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7828         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7829         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7830         { } /* end */
7831 };
7832
7833 static struct hda_verb alc888_lenovo_sky_verbs[] = {
7834         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7835         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7836         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7837         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7838         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7839         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7840         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7841         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7842         { } /* end */
7843 };
7844
7845 static struct hda_verb alc888_3st_hp_verbs[] = {
7846         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7847         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7848         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7849         { }
7850 };
7851
7852 static struct hda_verb alc888_6st_dell_verbs[] = {
7853         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7854         { }
7855 };
7856
7857 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7858         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7859         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7860         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7861         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7862         { }
7863 };
7864
7865 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7866         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7867         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7868         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7869         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7870         { }
7871 };
7872
7873 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7874         { 2, alc888_3st_hp_2ch_init },
7875         { 6, alc888_3st_hp_6ch_init },
7876 };
7877
7878 /* toggle front-jack and RCA according to the hp-jack state */
7879 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7880 {
7881         unsigned int present;
7882
7883         present = snd_hda_codec_read(codec, 0x1b, 0,
7884                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7885         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7886                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7887         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7888                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7889 }
7890
7891 /* toggle RCA according to the front-jack state */
7892 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7893 {
7894         unsigned int present;
7895
7896         present = snd_hda_codec_read(codec, 0x14, 0,
7897                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7898         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7899                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7900 }
7901
7902 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7903                                              unsigned int res)
7904 {
7905         if ((res >> 26) == ALC880_HP_EVENT)
7906                 alc888_lenovo_ms7195_front_automute(codec);
7907         if ((res >> 26) == ALC880_FRONT_EVENT)
7908                 alc888_lenovo_ms7195_rca_automute(codec);
7909 }
7910
7911 static struct hda_verb alc883_medion_md2_verbs[] = {
7912         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7913         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7914
7915         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7916
7917         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7918         { } /* end */
7919 };
7920
7921 /* toggle speaker-output according to the hp-jack state */
7922 static void alc883_medion_md2_automute(struct hda_codec *codec)
7923 {
7924         unsigned int present;
7925
7926         present = snd_hda_codec_read(codec, 0x14, 0,
7927                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7928         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7929                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7930 }
7931
7932 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
7933                                           unsigned int res)
7934 {
7935         if ((res >> 26) == ALC880_HP_EVENT)
7936                 alc883_medion_md2_automute(codec);
7937 }
7938
7939 /* toggle speaker-output according to the hp-jack state */
7940 static void alc883_tagra_automute(struct hda_codec *codec)
7941 {
7942         unsigned int present;
7943         unsigned char bits;
7944
7945         present = snd_hda_codec_read(codec, 0x14, 0,
7946                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7947         bits = present ? HDA_AMP_MUTE : 0;
7948         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
7949                                  HDA_AMP_MUTE, bits);
7950         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7951                                   present ? 1 : 3);
7952 }
7953
7954 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
7955 {
7956         if ((res >> 26) == ALC880_HP_EVENT)
7957                 alc883_tagra_automute(codec);
7958 }
7959
7960 /* toggle speaker-output according to the hp-jack state */
7961 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
7962 {
7963         unsigned int present;
7964         unsigned char bits;
7965
7966         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
7967                 & AC_PINSENSE_PRESENCE;
7968         bits = present ? HDA_AMP_MUTE : 0;
7969         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7970                                  HDA_AMP_MUTE, bits);
7971 }
7972
7973 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
7974 {
7975         unsigned int present;
7976
7977         present = snd_hda_codec_read(codec, 0x18, 0,
7978                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7979         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
7980                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7981 }
7982
7983 static void alc883_clevo_m720_automute(struct hda_codec *codec)
7984 {
7985         alc883_clevo_m720_hp_automute(codec);
7986         alc883_clevo_m720_mic_automute(codec);
7987 }
7988
7989 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
7990                                            unsigned int res)
7991 {
7992         switch (res >> 26) {
7993         case ALC880_HP_EVENT:
7994                 alc883_clevo_m720_hp_automute(codec);
7995                 break;
7996         case ALC880_MIC_EVENT:
7997                 alc883_clevo_m720_mic_automute(codec);
7998                 break;
7999         }
8000 }
8001
8002 /* toggle speaker-output according to the hp-jack state */
8003 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
8004 {
8005         unsigned int present;
8006         unsigned char bits;
8007
8008         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8009                 & AC_PINSENSE_PRESENCE;
8010         bits = present ? HDA_AMP_MUTE : 0;
8011         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8012                                  HDA_AMP_MUTE, bits);
8013 }
8014
8015 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
8016                                                   unsigned int res)
8017 {
8018         if ((res >> 26) == ALC880_HP_EVENT)
8019                 alc883_2ch_fujitsu_pi2515_automute(codec);
8020 }
8021
8022 static void alc883_haier_w66_automute(struct hda_codec *codec)
8023 {
8024         unsigned int present;
8025         unsigned char bits;
8026
8027         present = snd_hda_codec_read(codec, 0x1b, 0,
8028                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8029         bits = present ? 0x80 : 0;
8030         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8031                                  0x80, bits);
8032 }
8033
8034 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
8035                                          unsigned int res)
8036 {
8037         if ((res >> 26) == ALC880_HP_EVENT)
8038                 alc883_haier_w66_automute(codec);
8039 }
8040
8041 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8042 {
8043         unsigned int present;
8044         unsigned char bits;
8045
8046         present = snd_hda_codec_read(codec, 0x14, 0,
8047                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8048         bits = present ? HDA_AMP_MUTE : 0;
8049         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8050                                  HDA_AMP_MUTE, bits);
8051 }
8052
8053 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8054 {
8055         unsigned int present;
8056         unsigned char bits;
8057
8058         present = snd_hda_codec_read(codec, 0x1b, 0,
8059                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8060         bits = present ? HDA_AMP_MUTE : 0;
8061         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8062                                  HDA_AMP_MUTE, bits);
8063         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8064                                  HDA_AMP_MUTE, bits);
8065 }
8066
8067 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8068                                            unsigned int res)
8069 {
8070         if ((res >> 26) == ALC880_HP_EVENT)
8071                 alc883_lenovo_101e_all_automute(codec);
8072         if ((res >> 26) == ALC880_FRONT_EVENT)
8073                 alc883_lenovo_101e_ispeaker_automute(codec);
8074 }
8075
8076 /* toggle speaker-output according to the hp-jack state */
8077 static void alc883_acer_aspire_automute(struct hda_codec *codec)
8078 {
8079         unsigned int present;
8080
8081         present = snd_hda_codec_read(codec, 0x14, 0,
8082                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8083         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8084                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8085         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8086                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8087 }
8088
8089 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
8090                                            unsigned int res)
8091 {
8092         if ((res >> 26) == ALC880_HP_EVENT)
8093                 alc883_acer_aspire_automute(codec);
8094 }
8095
8096 static struct hda_verb alc883_acer_eapd_verbs[] = {
8097         /* HP Pin: output 0 (0x0c) */
8098         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8099         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8100         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8101         /* Front Pin: output 0 (0x0c) */
8102         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8103         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8104         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8105         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
8106         /* eanable EAPD on medion laptop */
8107         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8108         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8109         /* enable unsolicited event */
8110         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8111         { }
8112 };
8113
8114 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
8115 {
8116         unsigned int present;
8117
8118         present = snd_hda_codec_read(codec, 0x1b, 0,
8119                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8120         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8121                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8122         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8123                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8124         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8125                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8126         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8127                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8128 }
8129
8130 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
8131                                              unsigned int res)
8132 {
8133         switch (res >> 26) {
8134         case ALC880_HP_EVENT:
8135                 printk("hp_event\n");
8136                 alc888_6st_dell_front_automute(codec);
8137                 break;
8138         }
8139 }
8140
8141 static void alc888_lenovo_sky_front_automute(struct hda_codec *codec)
8142 {
8143         unsigned int mute;
8144         unsigned int present;
8145
8146         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8147         present = snd_hda_codec_read(codec, 0x1b, 0,
8148                                      AC_VERB_GET_PIN_SENSE, 0);
8149         present = (present & 0x80000000) != 0;
8150         if (present) {
8151                 /* mute internal speaker */
8152                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8153                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8154                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8155                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8156                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8157                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8158                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8159                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8160                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8161                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8162         } else {
8163                 /* unmute internal speaker if necessary */
8164                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8165                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8166                                          HDA_AMP_MUTE, mute);
8167                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8168                                          HDA_AMP_MUTE, mute);
8169                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8170                                          HDA_AMP_MUTE, mute);
8171                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8172                                          HDA_AMP_MUTE, mute);
8173                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8174                                          HDA_AMP_MUTE, mute);
8175         }
8176 }
8177
8178 static void alc883_lenovo_sky_unsol_event(struct hda_codec *codec,
8179                                              unsigned int res)
8180 {
8181         if ((res >> 26) == ALC880_HP_EVENT)
8182                 alc888_lenovo_sky_front_automute(codec);
8183 }
8184
8185 /*
8186  * generic initialization of ADC, input mixers and output mixers
8187  */
8188 static struct hda_verb alc883_auto_init_verbs[] = {
8189         /*
8190          * Unmute ADC0-2 and set the default input to mic-in
8191          */
8192         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8193         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8194         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8195         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8196
8197         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8198          * mixer widget
8199          * Note: PASD motherboards uses the Line In 2 as the input for
8200          * front panel mic (mic 2)
8201          */
8202         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8203         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8204         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8205         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8206         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8207         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8208
8209         /*
8210          * Set up output mixers (0x0c - 0x0f)
8211          */
8212         /* set vol=0 to output mixers */
8213         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8214         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8215         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8216         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8217         /* set up input amps for analog loopback */
8218         /* Amp Indices: DAC = 0, mixer = 1 */
8219         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8220         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8221         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8222         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8223         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8224         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8225         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8226         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8227         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8228         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8229
8230         /* FIXME: use matrix-type input source selection */
8231         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8232         /* Input mixer1 */
8233         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8234         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8235         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8236         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8237         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8238         /* Input mixer2 */
8239         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8240         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8241         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8242         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8243         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8244
8245         { }
8246 };
8247
8248 /* capture mixer elements */
8249 static struct snd_kcontrol_new alc883_capture_mixer[] = {
8250         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
8251         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
8252         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
8253         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
8254         {
8255                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8256                 /* The multiple "Capture Source" controls confuse alsamixer
8257                  * So call somewhat different..
8258                  */
8259                 /* .name = "Capture Source", */
8260                 .name = "Input Source",
8261                 .count = 2,
8262                 .info = alc882_mux_enum_info,
8263                 .get = alc882_mux_enum_get,
8264                 .put = alc882_mux_enum_put,
8265         },
8266         { } /* end */
8267 };
8268
8269 static struct hda_verb alc888_asus_m90v_verbs[] = {
8270         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8271         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8272         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8273         /* enable unsolicited event */
8274         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8275         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8276         { } /* end */
8277 };
8278
8279 static void alc883_nb_mic_automute(struct hda_codec *codec)
8280 {
8281         unsigned int present;
8282
8283         present = snd_hda_codec_read(codec, 0x18, 0,
8284                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8285         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8286                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
8287         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8288                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
8289 }
8290
8291 static void alc883_M90V_speaker_automute(struct hda_codec *codec)
8292 {
8293         unsigned int present;
8294         unsigned char bits;
8295
8296         present = snd_hda_codec_read(codec, 0x1b, 0,
8297                                      AC_VERB_GET_PIN_SENSE, 0)
8298                 & AC_PINSENSE_PRESENCE;
8299         bits = present ? 0 : PIN_OUT;
8300         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8301                             bits);
8302         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8303                             bits);
8304         snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8305                             bits);
8306 }
8307
8308 static void alc883_mode2_unsol_event(struct hda_codec *codec,
8309                                            unsigned int res)
8310 {
8311         switch (res >> 26) {
8312         case ALC880_HP_EVENT:
8313                 alc883_M90V_speaker_automute(codec);
8314                 break;
8315         case ALC880_MIC_EVENT:
8316                 alc883_nb_mic_automute(codec);
8317                 break;
8318         }
8319 }
8320
8321 static void alc883_mode2_inithook(struct hda_codec *codec)
8322 {
8323         alc883_M90V_speaker_automute(codec);
8324         alc883_nb_mic_automute(codec);
8325 }
8326
8327 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8328         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8329         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8330         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8331         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8332         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8333         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8334         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8335         /* enable unsolicited event */
8336         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8337         { } /* end */
8338 };
8339
8340 static void alc883_eee1601_speaker_automute(struct hda_codec *codec)
8341 {
8342         unsigned int present;
8343         unsigned char bits;
8344
8345         present = snd_hda_codec_read(codec, 0x14, 0,
8346                                      AC_VERB_GET_PIN_SENSE, 0)
8347                 & AC_PINSENSE_PRESENCE;
8348         bits = present ? 0 : PIN_OUT;
8349         snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8350                             bits);
8351 }
8352
8353 static void alc883_eee1601_unsol_event(struct hda_codec *codec,
8354                                            unsigned int res)
8355 {
8356         switch (res >> 26) {
8357         case ALC880_HP_EVENT:
8358                 alc883_eee1601_speaker_automute(codec);
8359                 break;
8360         }
8361 }
8362
8363 static void alc883_eee1601_inithook(struct hda_codec *codec)
8364 {
8365         alc883_eee1601_speaker_automute(codec);
8366 }
8367
8368 #ifdef CONFIG_SND_HDA_POWER_SAVE
8369 #define alc883_loopbacks        alc880_loopbacks
8370 #endif
8371
8372 /* pcm configuration: identiacal with ALC880 */
8373 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
8374 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
8375 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
8376 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
8377 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
8378
8379 /*
8380  * configuration and preset
8381  */
8382 static const char *alc883_models[ALC883_MODEL_LAST] = {
8383         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
8384         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8385         [ALC883_3ST_6ch]        = "3stack-6ch",
8386         [ALC883_6ST_DIG]        = "6stack-dig",
8387         [ALC883_TARGA_DIG]      = "targa-dig",
8388         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8389         [ALC883_ACER]           = "acer",
8390         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8391         [ALC883_MEDION]         = "medion",
8392         [ALC883_MEDION_MD2]     = "medion-md2",
8393         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8394         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8395         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8396         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8397         [ALC888_LENOVO_SKY] = "lenovo-sky",
8398         [ALC883_HAIER_W66]      = "haier-w66",
8399         [ALC888_3ST_HP]         = "3stack-hp",
8400         [ALC888_6ST_DELL]       = "6stack-dell",
8401         [ALC883_MITAC]          = "mitac",
8402         [ALC883_CLEVO_M720]     = "clevo-m720",
8403         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8404         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8405         [ALC883_AUTO]           = "auto",
8406 };
8407
8408 static struct snd_pci_quirk alc883_cfg_tbl[] = {
8409         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
8410         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8411         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8412         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8413         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8414         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
8415         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8416         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8417         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8418         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8419         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8420         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8421         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8422         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8423         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8424         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
8425         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8426         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8427         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
8428         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8429         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
8430         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8431         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8432         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8433         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8434         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8435         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8436         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8437         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8438         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8439         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8440         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8441         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8442         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8443         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8444         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8445         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8446         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8447         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8448         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8449         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8450         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8451         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8452         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8453         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8454         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8455         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
8456         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8457         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8458         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
8459         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8460         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8461         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8462         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8463         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
8464         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8465         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8466         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8467         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8468         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8469         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8470         {}
8471 };
8472
8473 static struct alc_config_preset alc883_presets[] = {
8474         [ALC883_3ST_2ch_DIG] = {
8475                 .mixers = { alc883_3ST_2ch_mixer },
8476                 .init_verbs = { alc883_init_verbs },
8477                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8478                 .dac_nids = alc883_dac_nids,
8479                 .dig_out_nid = ALC883_DIGOUT_NID,
8480                 .dig_in_nid = ALC883_DIGIN_NID,
8481                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8482                 .channel_mode = alc883_3ST_2ch_modes,
8483                 .input_mux = &alc883_capture_source,
8484         },
8485         [ALC883_3ST_6ch_DIG] = {
8486                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8487                 .init_verbs = { alc883_init_verbs },
8488                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8489                 .dac_nids = alc883_dac_nids,
8490                 .dig_out_nid = ALC883_DIGOUT_NID,
8491                 .dig_in_nid = ALC883_DIGIN_NID,
8492                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8493                 .channel_mode = alc883_3ST_6ch_modes,
8494                 .need_dac_fix = 1,
8495                 .input_mux = &alc883_capture_source,
8496         },
8497         [ALC883_3ST_6ch] = {
8498                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8499                 .init_verbs = { alc883_init_verbs },
8500                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8501                 .dac_nids = alc883_dac_nids,
8502                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8503                 .channel_mode = alc883_3ST_6ch_modes,
8504                 .need_dac_fix = 1,
8505                 .input_mux = &alc883_capture_source,
8506         },
8507         [ALC883_3ST_6ch_INTEL] = {
8508                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
8509                 .init_verbs = { alc883_init_verbs },
8510                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8511                 .dac_nids = alc883_dac_nids,
8512                 .dig_out_nid = ALC883_DIGOUT_NID,
8513                 .dig_in_nid = ALC883_DIGIN_NID,
8514                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
8515                 .channel_mode = alc883_3ST_6ch_intel_modes,
8516                 .need_dac_fix = 1,
8517                 .input_mux = &alc883_3stack_6ch_intel,
8518         },
8519         [ALC883_6ST_DIG] = {
8520                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8521                 .init_verbs = { alc883_init_verbs },
8522                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8523                 .dac_nids = alc883_dac_nids,
8524                 .dig_out_nid = ALC883_DIGOUT_NID,
8525                 .dig_in_nid = ALC883_DIGIN_NID,
8526                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8527                 .channel_mode = alc883_sixstack_modes,
8528                 .input_mux = &alc883_capture_source,
8529         },
8530         [ALC883_TARGA_DIG] = {
8531                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
8532                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8533                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8534                 .dac_nids = alc883_dac_nids,
8535                 .dig_out_nid = ALC883_DIGOUT_NID,
8536                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8537                 .channel_mode = alc883_3ST_6ch_modes,
8538                 .need_dac_fix = 1,
8539                 .input_mux = &alc883_capture_source,
8540                 .unsol_event = alc883_tagra_unsol_event,
8541                 .init_hook = alc883_tagra_automute,
8542         },
8543         [ALC883_TARGA_2ch_DIG] = {
8544                 .mixers = { alc883_tagra_2ch_mixer},
8545                 .init_verbs = { alc883_init_verbs, alc883_tagra_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_tagra_unsol_event,
8553                 .init_hook = alc883_tagra_automute,
8554         },
8555         [ALC883_ACER] = {
8556                 .mixers = { alc883_base_mixer },
8557                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
8558                  * and the headphone jack.  Turn this on and rely on the
8559                  * standard mute methods whenever the user wants to turn
8560                  * these outputs off.
8561                  */
8562                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
8563                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8564                 .dac_nids = alc883_dac_nids,
8565                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8566                 .channel_mode = alc883_3ST_2ch_modes,
8567                 .input_mux = &alc883_capture_source,
8568         },
8569         [ALC883_ACER_ASPIRE] = {
8570                 .mixers = { alc883_acer_aspire_mixer },
8571                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
8572                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8573                 .dac_nids = alc883_dac_nids,
8574                 .dig_out_nid = ALC883_DIGOUT_NID,
8575                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8576                 .channel_mode = alc883_3ST_2ch_modes,
8577                 .input_mux = &alc883_capture_source,
8578                 .unsol_event = alc883_acer_aspire_unsol_event,
8579                 .init_hook = alc883_acer_aspire_automute,
8580         },
8581         [ALC883_MEDION] = {
8582                 .mixers = { alc883_fivestack_mixer,
8583                             alc883_chmode_mixer },
8584                 .init_verbs = { alc883_init_verbs,
8585                                 alc883_medion_eapd_verbs },
8586                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8587                 .dac_nids = alc883_dac_nids,
8588                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8589                 .channel_mode = alc883_sixstack_modes,
8590                 .input_mux = &alc883_capture_source,
8591         },
8592         [ALC883_MEDION_MD2] = {
8593                 .mixers = { alc883_medion_md2_mixer},
8594                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
8595                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8596                 .dac_nids = alc883_dac_nids,
8597                 .dig_out_nid = ALC883_DIGOUT_NID,
8598                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8599                 .channel_mode = alc883_3ST_2ch_modes,
8600                 .input_mux = &alc883_capture_source,
8601                 .unsol_event = alc883_medion_md2_unsol_event,
8602                 .init_hook = alc883_medion_md2_automute,
8603         },
8604         [ALC883_LAPTOP_EAPD] = {
8605                 .mixers = { alc883_base_mixer },
8606                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
8607                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8608                 .dac_nids = alc883_dac_nids,
8609                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8610                 .channel_mode = alc883_3ST_2ch_modes,
8611                 .input_mux = &alc883_capture_source,
8612         },
8613         [ALC883_CLEVO_M720] = {
8614                 .mixers = { alc883_clevo_m720_mixer },
8615                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
8616                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8617                 .dac_nids = alc883_dac_nids,
8618                 .dig_out_nid = ALC883_DIGOUT_NID,
8619                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8620                 .channel_mode = alc883_3ST_2ch_modes,
8621                 .input_mux = &alc883_capture_source,
8622                 .unsol_event = alc883_clevo_m720_unsol_event,
8623                 .init_hook = alc883_clevo_m720_automute,
8624         },
8625         [ALC883_LENOVO_101E_2ch] = {
8626                 .mixers = { alc883_lenovo_101e_2ch_mixer},
8627                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
8628                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8629                 .dac_nids = alc883_dac_nids,
8630                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8631                 .channel_mode = alc883_3ST_2ch_modes,
8632                 .input_mux = &alc883_lenovo_101e_capture_source,
8633                 .unsol_event = alc883_lenovo_101e_unsol_event,
8634                 .init_hook = alc883_lenovo_101e_all_automute,
8635         },
8636         [ALC883_LENOVO_NB0763] = {
8637                 .mixers = { alc883_lenovo_nb0763_mixer },
8638                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
8639                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8640                 .dac_nids = alc883_dac_nids,
8641                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8642                 .channel_mode = alc883_3ST_2ch_modes,
8643                 .need_dac_fix = 1,
8644                 .input_mux = &alc883_lenovo_nb0763_capture_source,
8645                 .unsol_event = alc883_medion_md2_unsol_event,
8646                 .init_hook = alc883_medion_md2_automute,
8647         },
8648         [ALC888_LENOVO_MS7195_DIG] = {
8649                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8650                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
8651                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8652                 .dac_nids = alc883_dac_nids,
8653                 .dig_out_nid = ALC883_DIGOUT_NID,
8654                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8655                 .channel_mode = alc883_3ST_6ch_modes,
8656                 .need_dac_fix = 1,
8657                 .input_mux = &alc883_capture_source,
8658                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
8659                 .init_hook = alc888_lenovo_ms7195_front_automute,
8660         },
8661         [ALC883_HAIER_W66] = {
8662                 .mixers = { alc883_tagra_2ch_mixer},
8663                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
8664                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8665                 .dac_nids = alc883_dac_nids,
8666                 .dig_out_nid = ALC883_DIGOUT_NID,
8667                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8668                 .channel_mode = alc883_3ST_2ch_modes,
8669                 .input_mux = &alc883_capture_source,
8670                 .unsol_event = alc883_haier_w66_unsol_event,
8671                 .init_hook = alc883_haier_w66_automute,
8672         },
8673         [ALC888_3ST_HP] = {
8674                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8675                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
8676                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8677                 .dac_nids = alc883_dac_nids,
8678                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
8679                 .channel_mode = alc888_3st_hp_modes,
8680                 .need_dac_fix = 1,
8681                 .input_mux = &alc883_capture_source,
8682         },
8683         [ALC888_6ST_DELL] = {
8684                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8685                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
8686                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8687                 .dac_nids = alc883_dac_nids,
8688                 .dig_out_nid = ALC883_DIGOUT_NID,
8689                 .dig_in_nid = ALC883_DIGIN_NID,
8690                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8691                 .channel_mode = alc883_sixstack_modes,
8692                 .input_mux = &alc883_capture_source,
8693                 .unsol_event = alc888_6st_dell_unsol_event,
8694                 .init_hook = alc888_6st_dell_front_automute,
8695         },
8696         [ALC883_MITAC] = {
8697                 .mixers = { alc883_mitac_mixer },
8698                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
8699                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8700                 .dac_nids = alc883_dac_nids,
8701                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8702                 .channel_mode = alc883_3ST_2ch_modes,
8703                 .input_mux = &alc883_capture_source,
8704                 .unsol_event = alc883_mitac_unsol_event,
8705                 .init_hook = alc883_mitac_automute,
8706         },
8707         [ALC883_FUJITSU_PI2515] = {
8708                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
8709                 .init_verbs = { alc883_init_verbs,
8710                                 alc883_2ch_fujitsu_pi2515_verbs},
8711                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8712                 .dac_nids = alc883_dac_nids,
8713                 .dig_out_nid = ALC883_DIGOUT_NID,
8714                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8715                 .channel_mode = alc883_3ST_2ch_modes,
8716                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8717                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8718                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8719         },
8720         [ALC888_LENOVO_SKY] = {
8721                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
8722                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
8723                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8724                 .dac_nids = alc883_dac_nids,
8725                 .dig_out_nid = ALC883_DIGOUT_NID,
8726                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
8727                 .adc_nids = alc883_adc_nids,
8728                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8729                 .channel_mode = alc883_sixstack_modes,
8730                 .need_dac_fix = 1,
8731                 .input_mux = &alc883_lenovo_sky_capture_source,
8732                 .unsol_event = alc883_lenovo_sky_unsol_event,
8733                 .init_hook = alc888_lenovo_sky_front_automute,
8734         },
8735         [ALC888_ASUS_M90V] = {
8736                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8737                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
8738                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8739                 .dac_nids = alc883_dac_nids,
8740                 .dig_out_nid = ALC883_DIGOUT_NID,
8741                 .dig_in_nid = ALC883_DIGIN_NID,
8742                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8743                 .channel_mode = alc883_3ST_6ch_modes,
8744                 .need_dac_fix = 1,
8745                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8746                 .unsol_event = alc883_mode2_unsol_event,
8747                 .init_hook = alc883_mode2_inithook,
8748         },
8749         [ALC888_ASUS_EEE1601] = {
8750                 .mixers = { alc883_asus_eee1601_mixer },
8751                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
8752                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8753                 .dac_nids = alc883_dac_nids,
8754                 .dig_out_nid = ALC883_DIGOUT_NID,
8755                 .dig_in_nid = ALC883_DIGIN_NID,
8756                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8757                 .channel_mode = alc883_3ST_2ch_modes,
8758                 .need_dac_fix = 1,
8759                 .input_mux = &alc883_asus_eee1601_capture_source,
8760                 .unsol_event = alc883_eee1601_unsol_event,
8761                 .init_hook = alc883_eee1601_inithook,
8762         },
8763 };
8764
8765
8766 /*
8767  * BIOS auto configuration
8768  */
8769 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
8770                                               hda_nid_t nid, int pin_type,
8771                                               int dac_idx)
8772 {
8773         /* set as output */
8774         struct alc_spec *spec = codec->spec;
8775         int idx;
8776
8777         alc_set_pin_output(codec, nid, pin_type);
8778         if (spec->multiout.dac_nids[dac_idx] == 0x25)
8779                 idx = 4;
8780         else
8781                 idx = spec->multiout.dac_nids[dac_idx] - 2;
8782         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
8783
8784 }
8785
8786 static void alc883_auto_init_multi_out(struct hda_codec *codec)
8787 {
8788         struct alc_spec *spec = codec->spec;
8789         int i;
8790
8791         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
8792         for (i = 0; i <= HDA_SIDE; i++) {
8793                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
8794                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
8795                 if (nid)
8796                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
8797                                                           i);
8798         }
8799 }
8800
8801 static void alc883_auto_init_hp_out(struct hda_codec *codec)
8802 {
8803         struct alc_spec *spec = codec->spec;
8804         hda_nid_t pin;
8805
8806         pin = spec->autocfg.hp_pins[0];
8807         if (pin) /* connect to front */
8808                 /* use dac 0 */
8809                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8810         pin = spec->autocfg.speaker_pins[0];
8811         if (pin)
8812                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
8813 }
8814
8815 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
8816 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
8817
8818 static void alc883_auto_init_analog_input(struct hda_codec *codec)
8819 {
8820         struct alc_spec *spec = codec->spec;
8821         int i;
8822
8823         for (i = 0; i < AUTO_PIN_LAST; i++) {
8824                 hda_nid_t nid = spec->autocfg.input_pins[i];
8825                 if (alc883_is_input_pin(nid)) {
8826                         snd_hda_codec_write(codec, nid, 0,
8827                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
8828                                             (i <= AUTO_PIN_FRONT_MIC ?
8829                                              PIN_VREF80 : PIN_IN));
8830                         if (nid != ALC883_PIN_CD_NID)
8831                                 snd_hda_codec_write(codec, nid, 0,
8832                                                     AC_VERB_SET_AMP_GAIN_MUTE,
8833                                                     AMP_OUT_MUTE);
8834                 }
8835         }
8836 }
8837
8838 #define alc883_auto_init_input_src      alc882_auto_init_input_src
8839
8840 /* almost identical with ALC880 parser... */
8841 static int alc883_parse_auto_config(struct hda_codec *codec)
8842 {
8843         struct alc_spec *spec = codec->spec;
8844         int err = alc880_parse_auto_config(codec);
8845
8846         if (err < 0)
8847                 return err;
8848         else if (!err)
8849                 return 0; /* no config found */
8850
8851         err = alc_auto_add_mic_boost(codec);
8852         if (err < 0)
8853                 return err;
8854
8855         /* hack - override the init verbs */
8856         spec->init_verbs[0] = alc883_auto_init_verbs;
8857         spec->mixers[spec->num_mixers] = alc883_capture_mixer;
8858         spec->num_mixers++;
8859
8860         return 1; /* config found */
8861 }
8862
8863 /* additional initialization for auto-configuration model */
8864 static void alc883_auto_init(struct hda_codec *codec)
8865 {
8866         struct alc_spec *spec = codec->spec;
8867         alc883_auto_init_multi_out(codec);
8868         alc883_auto_init_hp_out(codec);
8869         alc883_auto_init_analog_input(codec);
8870         alc883_auto_init_input_src(codec);
8871         if (spec->unsol_event)
8872                 alc_inithook(codec);
8873 }
8874
8875 static int patch_alc883(struct hda_codec *codec)
8876 {
8877         struct alc_spec *spec;
8878         int err, board_config;
8879
8880         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8881         if (spec == NULL)
8882                 return -ENOMEM;
8883
8884         codec->spec = spec;
8885
8886         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
8887
8888         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
8889                                                   alc883_models,
8890                                                   alc883_cfg_tbl);
8891         if (board_config < 0) {
8892                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
8893                        "trying auto-probe from BIOS...\n");
8894                 board_config = ALC883_AUTO;
8895         }
8896
8897         if (board_config == ALC883_AUTO) {
8898                 /* automatic parse from the BIOS config */
8899                 err = alc883_parse_auto_config(codec);
8900                 if (err < 0) {
8901                         alc_free(codec);
8902                         return err;
8903                 } else if (!err) {
8904                         printk(KERN_INFO
8905                                "hda_codec: Cannot set up configuration "
8906                                "from BIOS.  Using base mode...\n");
8907                         board_config = ALC883_3ST_2ch_DIG;
8908                 }
8909         }
8910
8911         if (board_config != ALC883_AUTO)
8912                 setup_preset(spec, &alc883_presets[board_config]);
8913
8914         switch (codec->vendor_id) {
8915         case 0x10ec0888:
8916                 if (codec->revision_id == 0x100101) {
8917                         spec->stream_name_analog = "ALC1200 Analog";
8918                         spec->stream_name_digital = "ALC1200 Digital";
8919                 } else {
8920                         spec->stream_name_analog = "ALC888 Analog";
8921                         spec->stream_name_digital = "ALC888 Digital";
8922                 }
8923                 break;
8924         case 0x10ec0889:
8925                 spec->stream_name_analog = "ALC889 Analog";
8926                 spec->stream_name_digital = "ALC889 Digital";
8927                 break;
8928         default:
8929                 spec->stream_name_analog = "ALC883 Analog";
8930                 spec->stream_name_digital = "ALC883 Digital";
8931                 break;
8932         }
8933
8934         spec->stream_analog_playback = &alc883_pcm_analog_playback;
8935         spec->stream_analog_capture = &alc883_pcm_analog_capture;
8936         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
8937
8938         spec->stream_digital_playback = &alc883_pcm_digital_playback;
8939         spec->stream_digital_capture = &alc883_pcm_digital_capture;
8940
8941         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
8942         spec->adc_nids = alc883_adc_nids;
8943         spec->capsrc_nids = alc883_capsrc_nids;
8944
8945         spec->vmaster_nid = 0x0c;
8946
8947         codec->patch_ops = alc_patch_ops;
8948         if (board_config == ALC883_AUTO)
8949                 spec->init_hook = alc883_auto_init;
8950
8951 #ifdef CONFIG_SND_HDA_POWER_SAVE
8952         if (!spec->loopback.amplist)
8953                 spec->loopback.amplist = alc883_loopbacks;
8954 #endif
8955
8956         return 0;
8957 }
8958
8959 /*
8960  * ALC262 support
8961  */
8962
8963 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
8964 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
8965
8966 #define alc262_dac_nids         alc260_dac_nids
8967 #define alc262_adc_nids         alc882_adc_nids
8968 #define alc262_adc_nids_alt     alc882_adc_nids_alt
8969 #define alc262_capsrc_nids      alc882_capsrc_nids
8970 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
8971
8972 #define alc262_modes            alc260_modes
8973 #define alc262_capture_source   alc882_capture_source
8974
8975 static hda_nid_t alc262_dmic_adc_nids[1] = {
8976         /* ADC0 */
8977         0x09
8978 };
8979
8980 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
8981
8982 static struct snd_kcontrol_new alc262_base_mixer[] = {
8983         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8984         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8985         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8986         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8987         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8988         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8989         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8990         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8991         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8992         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8993         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8994         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8995         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8996            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8997         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
8998         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8999         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9000         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
9001         { } /* end */
9002 };
9003
9004 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
9005         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9006         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9007         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9008         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9009         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9010         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9011         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9012         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9013         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9014         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9015         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9016         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9017         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9018            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
9019         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
9020         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9021         { } /* end */
9022 };
9023
9024 /* update HP, line and mono-out pins according to the master switch */
9025 static void alc262_hp_master_update(struct hda_codec *codec)
9026 {
9027         struct alc_spec *spec = codec->spec;
9028         int val = spec->master_sw;
9029
9030         /* HP & line-out */
9031         snd_hda_codec_write_cache(codec, 0x1b, 0,
9032                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9033                                   val ? PIN_HP : 0);
9034         snd_hda_codec_write_cache(codec, 0x15, 0,
9035                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9036                                   val ? PIN_HP : 0);
9037         /* mono (speaker) depending on the HP jack sense */
9038         val = val && !spec->jack_present;
9039         snd_hda_codec_write_cache(codec, 0x16, 0,
9040                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9041                                   val ? PIN_OUT : 0);
9042 }
9043
9044 static void alc262_hp_bpc_automute(struct hda_codec *codec)
9045 {
9046         struct alc_spec *spec = codec->spec;
9047         unsigned int presence;
9048         presence = snd_hda_codec_read(codec, 0x1b, 0,
9049                                       AC_VERB_GET_PIN_SENSE, 0);
9050         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9051         alc262_hp_master_update(codec);
9052 }
9053
9054 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
9055 {
9056         if ((res >> 26) != ALC880_HP_EVENT)
9057                 return;
9058         alc262_hp_bpc_automute(codec);
9059 }
9060
9061 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
9062 {
9063         struct alc_spec *spec = codec->spec;
9064         unsigned int presence;
9065         presence = snd_hda_codec_read(codec, 0x15, 0,
9066                                       AC_VERB_GET_PIN_SENSE, 0);
9067         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9068         alc262_hp_master_update(codec);
9069 }
9070
9071 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
9072                                            unsigned int res)
9073 {
9074         if ((res >> 26) != ALC880_HP_EVENT)
9075                 return;
9076         alc262_hp_wildwest_automute(codec);
9077 }
9078
9079 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
9080                                    struct snd_ctl_elem_value *ucontrol)
9081 {
9082         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9083         struct alc_spec *spec = codec->spec;
9084         *ucontrol->value.integer.value = spec->master_sw;
9085         return 0;
9086 }
9087
9088 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
9089                                    struct snd_ctl_elem_value *ucontrol)
9090 {
9091         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9092         struct alc_spec *spec = codec->spec;
9093         int val = !!*ucontrol->value.integer.value;
9094
9095         if (val == spec->master_sw)
9096                 return 0;
9097         spec->master_sw = val;
9098         alc262_hp_master_update(codec);
9099         return 1;
9100 }
9101
9102 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
9103         {
9104                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9105                 .name = "Master Playback Switch",
9106                 .info = snd_ctl_boolean_mono_info,
9107                 .get = alc262_hp_master_sw_get,
9108                 .put = alc262_hp_master_sw_put,
9109         },
9110         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9111         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9112         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9113         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9114                               HDA_OUTPUT),
9115         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9116                             HDA_OUTPUT),
9117         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9118         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9119         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9120         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9121         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9122         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9123         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9124         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9125         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9126         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9127         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9128         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9129         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
9130         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
9131         { } /* end */
9132 };
9133
9134 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
9135         {
9136                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9137                 .name = "Master Playback Switch",
9138                 .info = snd_ctl_boolean_mono_info,
9139                 .get = alc262_hp_master_sw_get,
9140                 .put = alc262_hp_master_sw_put,
9141         },
9142         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9143         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9144         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9145         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9146         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9147                               HDA_OUTPUT),
9148         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9149                             HDA_OUTPUT),
9150         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
9151         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
9152         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
9153         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9154         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9155         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9156         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9157         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9158         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9159         { } /* end */
9160 };
9161
9162 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
9163         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9164         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9165         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
9166         { } /* end */
9167 };
9168
9169 /* mute/unmute internal speaker according to the hp jack and mute state */
9170 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
9171 {
9172         struct alc_spec *spec = codec->spec;
9173
9174         if (force || !spec->sense_updated) {
9175                 unsigned int present;
9176                 present = snd_hda_codec_read(codec, 0x15, 0,
9177                                              AC_VERB_GET_PIN_SENSE, 0);
9178                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9179                 spec->sense_updated = 1;
9180         }
9181         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
9182                                  spec->jack_present ? HDA_AMP_MUTE : 0);
9183 }
9184
9185 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
9186                                         unsigned int res)
9187 {
9188         if ((res >> 26) != ALC880_HP_EVENT)
9189                 return;
9190         alc262_hp_t5735_automute(codec, 1);
9191 }
9192
9193 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
9194 {
9195         alc262_hp_t5735_automute(codec, 1);
9196 }
9197
9198 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
9199         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9200         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9201         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9202         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9203         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9204         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9205         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9206         { } /* end */
9207 };
9208
9209 static struct hda_verb alc262_hp_t5735_verbs[] = {
9210         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9211         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9212
9213         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9214         { }
9215 };
9216
9217 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
9218         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9219         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9220         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
9221         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
9222         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9223         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9224         { } /* end */
9225 };
9226
9227 static struct hda_verb alc262_hp_rp5700_verbs[] = {
9228         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9229         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9230         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9231         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9232         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9233         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9234         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9235         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9236         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9237         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9238         {}
9239 };
9240
9241 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
9242         .num_items = 1,
9243         .items = {
9244                 { "Line", 0x1 },
9245         },
9246 };
9247
9248 /* bind hp and internal speaker mute (with plug check) */
9249 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
9250                                      struct snd_ctl_elem_value *ucontrol)
9251 {
9252         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9253         long *valp = ucontrol->value.integer.value;
9254         int change;
9255
9256         /* change hp mute */
9257         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
9258                                           HDA_AMP_MUTE,
9259                                           valp[0] ? 0 : HDA_AMP_MUTE);
9260         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
9261                                            HDA_AMP_MUTE,
9262                                            valp[1] ? 0 : HDA_AMP_MUTE);
9263         if (change) {
9264                 /* change speaker according to HP jack state */
9265                 struct alc_spec *spec = codec->spec;
9266                 unsigned int mute;
9267                 if (spec->jack_present)
9268                         mute = HDA_AMP_MUTE;
9269                 else
9270                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
9271                                                       HDA_OUTPUT, 0);
9272                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9273                                          HDA_AMP_MUTE, mute);
9274         }
9275         return change;
9276 }
9277
9278 static struct snd_kcontrol_new alc262_sony_mixer[] = {
9279         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9280         {
9281                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9282                 .name = "Master Playback Switch",
9283                 .info = snd_hda_mixer_amp_switch_info,
9284                 .get = snd_hda_mixer_amp_switch_get,
9285                 .put = alc262_sony_master_sw_put,
9286                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9287         },
9288         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9289         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9290         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9291         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9292         { } /* end */
9293 };
9294
9295 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
9296         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9297         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9298         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9299         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9300         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9301         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9302         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9303         { } /* end */
9304 };
9305
9306 #define alc262_capture_mixer            alc882_capture_mixer
9307 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
9308
9309 /*
9310  * generic initialization of ADC, input mixers and output mixers
9311  */
9312 static struct hda_verb alc262_init_verbs[] = {
9313         /*
9314          * Unmute ADC0-2 and set the default input to mic-in
9315          */
9316         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9317         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9318         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9319         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9320         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9321         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9322
9323         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9324          * mixer widget
9325          * Note: PASD motherboards uses the Line In 2 as the input for
9326          * front panel mic (mic 2)
9327          */
9328         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9329         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9330         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9331         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9332         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9333         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9334
9335         /*
9336          * Set up output mixers (0x0c - 0x0e)
9337          */
9338         /* set vol=0 to output mixers */
9339         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9340         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9341         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9342         /* set up input amps for analog loopback */
9343         /* Amp Indices: DAC = 0, mixer = 1 */
9344         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9345         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9346         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9347         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9348         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9349         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9350
9351         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9352         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9353         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9354         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9355         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9356         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9357
9358         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9359         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9360         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9361         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9362         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9363
9364         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9365         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9366
9367         /* FIXME: use matrix-type input source selection */
9368         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9369         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9370         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9371         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9372         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9373         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9374         /* Input mixer2 */
9375         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9376         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9377         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9378         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9379         /* Input mixer3 */
9380         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9381         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9382         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9383         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9384
9385         { }
9386 };
9387
9388 static struct hda_verb alc262_eapd_verbs[] = {
9389         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9390         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9391         { }
9392 };
9393
9394 static struct hda_verb alc262_hippo_unsol_verbs[] = {
9395         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9396         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9397         {}
9398 };
9399
9400 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
9401         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9402         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9403         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9404
9405         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9406         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9407         {}
9408 };
9409
9410 static struct hda_verb alc262_sony_unsol_verbs[] = {
9411         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9412         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9413         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
9414
9415         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9416         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9417         {}
9418 };
9419
9420 static struct hda_input_mux alc262_dmic_capture_source = {
9421         .num_items = 2,
9422         .items = {
9423                 { "Int DMic", 0x9 },
9424                 { "Mic", 0x0 },
9425         },
9426 };
9427
9428 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
9429         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9430         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9431         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9432         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9433         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9434         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
9435         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
9436         {
9437                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9438                 /* The multiple "Capture Source" controls confuse alsamixer
9439                  * So call somewhat different..
9440                  */
9441                 /* .name = "Capture Source", */
9442                 .name = "Input Source",
9443                 .count = 1,
9444                 .info = alc_mux_enum_info,
9445                 .get = alc_mux_enum_get,
9446                 .put = alc_mux_enum_put,
9447         },
9448         { } /* end */
9449 };
9450
9451 static struct hda_verb alc262_toshiba_s06_verbs[] = {
9452         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9453         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9454         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9455         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9456         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
9457         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9458         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
9459         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9460         {}
9461 };
9462
9463 static void alc262_dmic_automute(struct hda_codec *codec)
9464 {
9465         unsigned int present;
9466
9467         present = snd_hda_codec_read(codec, 0x18, 0,
9468                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9469         snd_hda_codec_write(codec, 0x22, 0,
9470                                 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x09);
9471 }
9472
9473 /* toggle speaker-output according to the hp-jack state */
9474 static void alc262_toshiba_s06_speaker_automute(struct hda_codec *codec)
9475 {
9476         unsigned int present;
9477         unsigned char bits;
9478
9479         present = snd_hda_codec_read(codec, 0x15, 0,
9480                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9481         bits = present ? 0 : PIN_OUT;
9482         snd_hda_codec_write(codec, 0x14, 0,
9483                                         AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
9484 }
9485
9486
9487
9488 /* unsolicited event for HP jack sensing */
9489 static void alc262_toshiba_s06_unsol_event(struct hda_codec *codec,
9490                                        unsigned int res)
9491 {
9492         if ((res >> 26) == ALC880_HP_EVENT)
9493                 alc262_toshiba_s06_speaker_automute(codec);
9494         if ((res >> 26) == ALC880_MIC_EVENT)
9495                 alc262_dmic_automute(codec);
9496
9497 }
9498
9499 static void alc262_toshiba_s06_init_hook(struct hda_codec *codec)
9500 {
9501         alc262_toshiba_s06_speaker_automute(codec);
9502         alc262_dmic_automute(codec);
9503 }
9504
9505 /* mute/unmute internal speaker according to the hp jack and mute state */
9506 static void alc262_hippo_automute(struct hda_codec *codec)
9507 {
9508         struct alc_spec *spec = codec->spec;
9509         unsigned int mute;
9510         unsigned int present;
9511
9512         /* need to execute and sync at first */
9513         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9514         present = snd_hda_codec_read(codec, 0x15, 0,
9515                                      AC_VERB_GET_PIN_SENSE, 0);
9516         spec->jack_present = (present & 0x80000000) != 0;
9517         if (spec->jack_present) {
9518                 /* mute internal speaker */
9519                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9520                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9521         } else {
9522                 /* unmute internal speaker if necessary */
9523                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
9524                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9525                                          HDA_AMP_MUTE, mute);
9526         }
9527 }
9528
9529 /* unsolicited event for HP jack sensing */
9530 static void alc262_hippo_unsol_event(struct hda_codec *codec,
9531                                        unsigned int res)
9532 {
9533         if ((res >> 26) != ALC880_HP_EVENT)
9534                 return;
9535         alc262_hippo_automute(codec);
9536 }
9537
9538 static void alc262_hippo1_automute(struct hda_codec *codec)
9539 {
9540         unsigned int mute;
9541         unsigned int present;
9542
9543         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9544         present = snd_hda_codec_read(codec, 0x1b, 0,
9545                                      AC_VERB_GET_PIN_SENSE, 0);
9546         present = (present & 0x80000000) != 0;
9547         if (present) {
9548                 /* mute internal speaker */
9549                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9550                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9551         } else {
9552                 /* unmute internal speaker if necessary */
9553                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9554                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9555                                          HDA_AMP_MUTE, mute);
9556         }
9557 }
9558
9559 /* unsolicited event for HP jack sensing */
9560 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
9561                                        unsigned int res)
9562 {
9563         if ((res >> 26) != ALC880_HP_EVENT)
9564                 return;
9565         alc262_hippo1_automute(codec);
9566 }
9567
9568 /*
9569  * nec model
9570  *  0x15 = headphone
9571  *  0x16 = internal speaker
9572  *  0x18 = external mic
9573  */
9574
9575 static struct snd_kcontrol_new alc262_nec_mixer[] = {
9576         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9577         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
9578
9579         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9580         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9581         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9582
9583         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9584         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9585         { } /* end */
9586 };
9587
9588 static struct hda_verb alc262_nec_verbs[] = {
9589         /* Unmute Speaker */
9590         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9591
9592         /* Headphone */
9593         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9594         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9595
9596         /* External mic to headphone */
9597         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9598         /* External mic to speaker */
9599         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9600         {}
9601 };
9602
9603 /*
9604  * fujitsu model
9605  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
9606  *  0x1b = port replicator headphone out
9607  */
9608
9609 #define ALC_HP_EVENT    0x37
9610
9611 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
9612         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9613         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9614         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9615         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9616         {}
9617 };
9618
9619 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
9620         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9621         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9622         {}
9623 };
9624
9625 static struct hda_input_mux alc262_fujitsu_capture_source = {
9626         .num_items = 3,
9627         .items = {
9628                 { "Mic", 0x0 },
9629                 { "Int Mic", 0x1 },
9630                 { "CD", 0x4 },
9631         },
9632 };
9633
9634 static struct hda_input_mux alc262_HP_capture_source = {
9635         .num_items = 5,
9636         .items = {
9637                 { "Mic", 0x0 },
9638                 { "Front Mic", 0x1 },
9639                 { "Line", 0x2 },
9640                 { "CD", 0x4 },
9641                 { "AUX IN", 0x6 },
9642         },
9643 };
9644
9645 static struct hda_input_mux alc262_HP_D7000_capture_source = {
9646         .num_items = 4,
9647         .items = {
9648                 { "Mic", 0x0 },
9649                 { "Front Mic", 0x2 },
9650                 { "Line", 0x1 },
9651                 { "CD", 0x4 },
9652         },
9653 };
9654
9655 /* mute/unmute internal speaker according to the hp jacks and mute state */
9656 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
9657 {
9658         struct alc_spec *spec = codec->spec;
9659         unsigned int mute;
9660
9661         if (force || !spec->sense_updated) {
9662                 unsigned int present;
9663                 /* need to execute and sync at first */
9664                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
9665                 /* check laptop HP jack */
9666                 present = snd_hda_codec_read(codec, 0x14, 0,
9667                                              AC_VERB_GET_PIN_SENSE, 0);
9668                 /* need to execute and sync at first */
9669                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9670                 /* check docking HP jack */
9671                 present |= snd_hda_codec_read(codec, 0x1b, 0,
9672                                               AC_VERB_GET_PIN_SENSE, 0);
9673                 if (present & AC_PINSENSE_PRESENCE)
9674                         spec->jack_present = 1;
9675                 else
9676                         spec->jack_present = 0;
9677                 spec->sense_updated = 1;
9678         }
9679         /* unmute internal speaker only if both HPs are unplugged and
9680          * master switch is on
9681          */
9682         if (spec->jack_present)
9683                 mute = HDA_AMP_MUTE;
9684         else
9685                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9686         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9687                                  HDA_AMP_MUTE, mute);
9688 }
9689
9690 /* unsolicited event for HP jack sensing */
9691 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
9692                                        unsigned int res)
9693 {
9694         if ((res >> 26) != ALC_HP_EVENT)
9695                 return;
9696         alc262_fujitsu_automute(codec, 1);
9697 }
9698
9699 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
9700 {
9701         alc262_fujitsu_automute(codec, 1);
9702 }
9703
9704 /* bind volumes of both NID 0x0c and 0x0d */
9705 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
9706         .ops = &snd_hda_bind_vol,
9707         .values = {
9708                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
9709                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
9710                 0
9711         },
9712 };
9713
9714 /* mute/unmute internal speaker according to the hp jack and mute state */
9715 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
9716 {
9717         struct alc_spec *spec = codec->spec;
9718         unsigned int mute;
9719
9720         if (force || !spec->sense_updated) {
9721                 unsigned int present_int_hp;
9722                 /* need to execute and sync at first */
9723                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9724                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
9725                                         AC_VERB_GET_PIN_SENSE, 0);
9726                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
9727                 spec->sense_updated = 1;
9728         }
9729         if (spec->jack_present) {
9730                 /* mute internal speaker */
9731                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9732                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9733                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9734                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9735         } else {
9736                 /* unmute internal speaker if necessary */
9737                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9738                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9739                                          HDA_AMP_MUTE, mute);
9740                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9741                                          HDA_AMP_MUTE, mute);
9742         }
9743 }
9744
9745 /* unsolicited event for HP jack sensing */
9746 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
9747                                        unsigned int res)
9748 {
9749         if ((res >> 26) != ALC_HP_EVENT)
9750                 return;
9751         alc262_lenovo_3000_automute(codec, 1);
9752 }
9753
9754 /* bind hp and internal speaker mute (with plug check) */
9755 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
9756                                          struct snd_ctl_elem_value *ucontrol)
9757 {
9758         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9759         long *valp = ucontrol->value.integer.value;
9760         int change;
9761
9762         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9763                                                  HDA_AMP_MUTE,
9764                                                  valp ? 0 : HDA_AMP_MUTE);
9765         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9766                                                  HDA_AMP_MUTE,
9767                                                  valp ? 0 : HDA_AMP_MUTE);
9768
9769         if (change)
9770                 alc262_fujitsu_automute(codec, 0);
9771         return change;
9772 }
9773
9774 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
9775         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9776         {
9777                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9778                 .name = "Master Playback Switch",
9779                 .info = snd_hda_mixer_amp_switch_info,
9780                 .get = snd_hda_mixer_amp_switch_get,
9781                 .put = alc262_fujitsu_master_sw_put,
9782                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9783         },
9784         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9785         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9786         HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
9787         HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
9788         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9789         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9790         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9791         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9792         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9793         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9794         { } /* end */
9795 };
9796
9797 /* bind hp and internal speaker mute (with plug check) */
9798 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
9799                                          struct snd_ctl_elem_value *ucontrol)
9800 {
9801         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9802         long *valp = ucontrol->value.integer.value;
9803         int change;
9804
9805         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9806                                                  HDA_AMP_MUTE,
9807                                                  valp ? 0 : HDA_AMP_MUTE);
9808
9809         if (change)
9810                 alc262_lenovo_3000_automute(codec, 0);
9811         return change;
9812 }
9813
9814 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
9815         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9816         {
9817                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9818                 .name = "Master Playback Switch",
9819                 .info = snd_hda_mixer_amp_switch_info,
9820                 .get = snd_hda_mixer_amp_switch_get,
9821                 .put = alc262_lenovo_3000_master_sw_put,
9822                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
9823         },
9824         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9825         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9826         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9827         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9828         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9829         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9830         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9831         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9832         { } /* end */
9833 };
9834
9835 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
9836         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9837         {
9838                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9839                 .name = "Master Playback Switch",
9840                 .info = snd_hda_mixer_amp_switch_info,
9841                 .get = snd_hda_mixer_amp_switch_get,
9842                 .put = alc262_sony_master_sw_put,
9843                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9844         },
9845         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9846         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9847         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9848         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9849         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9850         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9851         { } /* end */
9852 };
9853
9854 /* additional init verbs for Benq laptops */
9855 static struct hda_verb alc262_EAPD_verbs[] = {
9856         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9857         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
9858         {}
9859 };
9860
9861 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
9862         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9863         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9864
9865         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9866         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
9867         {}
9868 };
9869
9870 /* Samsung Q1 Ultra Vista model setup */
9871 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
9872         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9873         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
9874         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9875         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9876         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
9877         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
9878         { } /* end */
9879 };
9880
9881 static struct hda_verb alc262_ultra_verbs[] = {
9882         /* output mixer */
9883         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9884         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9885         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9886         /* speaker */
9887         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9888         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9889         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9890         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9891         /* HP */
9892         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9893         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9894         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9895         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9896         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9897         /* internal mic */
9898         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9899         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9900         /* ADC, choose mic */
9901         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9902         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9903         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9904         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9905         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9906         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9907         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9908         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9909         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
9910         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
9911         {}
9912 };
9913
9914 /* mute/unmute internal speaker according to the hp jack and mute state */
9915 static void alc262_ultra_automute(struct hda_codec *codec)
9916 {
9917         struct alc_spec *spec = codec->spec;
9918         unsigned int mute;
9919
9920         mute = 0;
9921         /* auto-mute only when HP is used as HP */
9922         if (!spec->cur_mux[0]) {
9923                 unsigned int present;
9924                 /* need to execute and sync at first */
9925                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9926                 present = snd_hda_codec_read(codec, 0x15, 0,
9927                                              AC_VERB_GET_PIN_SENSE, 0);
9928                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9929                 if (spec->jack_present)
9930                         mute = HDA_AMP_MUTE;
9931         }
9932         /* mute/unmute internal speaker */
9933         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9934                                  HDA_AMP_MUTE, mute);
9935         /* mute/unmute HP */
9936         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9937                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
9938 }
9939
9940 /* unsolicited event for HP jack sensing */
9941 static void alc262_ultra_unsol_event(struct hda_codec *codec,
9942                                        unsigned int res)
9943 {
9944         if ((res >> 26) != ALC880_HP_EVENT)
9945                 return;
9946         alc262_ultra_automute(codec);
9947 }
9948
9949 static struct hda_input_mux alc262_ultra_capture_source = {
9950         .num_items = 2,
9951         .items = {
9952                 { "Mic", 0x1 },
9953                 { "Headphone", 0x7 },
9954         },
9955 };
9956
9957 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
9958                                      struct snd_ctl_elem_value *ucontrol)
9959 {
9960         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9961         struct alc_spec *spec = codec->spec;
9962         int ret;
9963
9964         ret = alc882_mux_enum_put(kcontrol, ucontrol);
9965         if (!ret)
9966                 return 0;
9967         /* reprogram the HP pin as mic or HP according to the input source */
9968         snd_hda_codec_write_cache(codec, 0x15, 0,
9969                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9970                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
9971         alc262_ultra_automute(codec); /* mute/unmute HP */
9972         return ret;
9973 }
9974
9975 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
9976         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
9977         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
9978         {
9979                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9980                 .name = "Capture Source",
9981                 .info = alc882_mux_enum_info,
9982                 .get = alc882_mux_enum_get,
9983                 .put = alc262_ultra_mux_enum_put,
9984         },
9985         { } /* end */
9986 };
9987
9988 /* add playback controls from the parsed DAC table */
9989 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
9990                                              const struct auto_pin_cfg *cfg)
9991 {
9992         hda_nid_t nid;
9993         int err;
9994
9995         spec->multiout.num_dacs = 1;    /* only use one dac */
9996         spec->multiout.dac_nids = spec->private_dac_nids;
9997         spec->multiout.dac_nids[0] = 2;
9998
9999         nid = cfg->line_out_pins[0];
10000         if (nid) {
10001                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10002                                   "Front Playback Volume",
10003                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
10004                 if (err < 0)
10005                         return err;
10006                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10007                                   "Front Playback Switch",
10008                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
10009                 if (err < 0)
10010                         return err;
10011         }
10012
10013         nid = cfg->speaker_pins[0];
10014         if (nid) {
10015                 if (nid == 0x16) {
10016                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10017                                           "Speaker Playback Volume",
10018                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10019                                                               HDA_OUTPUT));
10020                         if (err < 0)
10021                                 return err;
10022                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10023                                           "Speaker Playback Switch",
10024                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10025                                                               HDA_OUTPUT));
10026                         if (err < 0)
10027                                 return err;
10028                 } else {
10029                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10030                                           "Speaker Playback Switch",
10031                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10032                                                               HDA_OUTPUT));
10033                         if (err < 0)
10034                                 return err;
10035                 }
10036         }
10037         nid = cfg->hp_pins[0];
10038         if (nid) {
10039                 /* spec->multiout.hp_nid = 2; */
10040                 if (nid == 0x16) {
10041                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10042                                           "Headphone Playback Volume",
10043                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10044                                                               HDA_OUTPUT));
10045                         if (err < 0)
10046                                 return err;
10047                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10048                                           "Headphone Playback Switch",
10049                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10050                                                               HDA_OUTPUT));
10051                         if (err < 0)
10052                                 return err;
10053                 } else {
10054                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10055                                           "Headphone Playback Switch",
10056                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10057                                                               HDA_OUTPUT));
10058                         if (err < 0)
10059                                 return err;
10060                 }
10061         }
10062         return 0;
10063 }
10064
10065 /* identical with ALC880 */
10066 #define alc262_auto_create_analog_input_ctls \
10067         alc880_auto_create_analog_input_ctls
10068
10069 /*
10070  * generic initialization of ADC, input mixers and output mixers
10071  */
10072 static struct hda_verb alc262_volume_init_verbs[] = {
10073         /*
10074          * Unmute ADC0-2 and set the default input to mic-in
10075          */
10076         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10077         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10078         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10079         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10080         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10081         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10082
10083         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10084          * mixer widget
10085          * Note: PASD motherboards uses the Line In 2 as the input for
10086          * front panel mic (mic 2)
10087          */
10088         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10089         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10090         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10091         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10092         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10093         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10094
10095         /*
10096          * Set up output mixers (0x0c - 0x0f)
10097          */
10098         /* set vol=0 to output mixers */
10099         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10100         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10101         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10102
10103         /* set up input amps for analog loopback */
10104         /* Amp Indices: DAC = 0, mixer = 1 */
10105         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10106         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10107         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10108         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10109         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10110         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10111
10112         /* FIXME: use matrix-type input source selection */
10113         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10114         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10115         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10116         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10117         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10118         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10119         /* Input mixer2 */
10120         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10121         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10122         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10123         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10124         /* Input mixer3 */
10125         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10126         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10127         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10128         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10129
10130         { }
10131 };
10132
10133 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
10134         /*
10135          * Unmute ADC0-2 and set the default input to mic-in
10136          */
10137         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10138         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10139         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10140         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10141         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10142         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10143
10144         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10145          * mixer widget
10146          * Note: PASD motherboards uses the Line In 2 as the input for
10147          * front panel mic (mic 2)
10148          */
10149         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10150         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10151         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10152         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10153         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10154         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10155         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10156         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10157
10158         /*
10159          * Set up output mixers (0x0c - 0x0e)
10160          */
10161         /* set vol=0 to output mixers */
10162         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10163         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10164         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10165
10166         /* set up input amps for analog loopback */
10167         /* Amp Indices: DAC = 0, mixer = 1 */
10168         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10169         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10170         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10171         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10172         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10173         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10174
10175         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10176         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10177         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10178
10179         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10180         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10181
10182         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10183         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10184
10185         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10186         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10187         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10188         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10189         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10190
10191         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10192         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10193         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10194         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10195         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10196         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10197
10198
10199         /* FIXME: use matrix-type input source selection */
10200         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10201         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10202         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10203         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10204         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10205         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10206         /* Input mixer2 */
10207         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10208         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10209         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10210         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10211         /* Input mixer3 */
10212         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10213         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10214         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10215         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10216
10217         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10218
10219         { }
10220 };
10221
10222 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
10223         /*
10224          * Unmute ADC0-2 and set the default input to mic-in
10225          */
10226         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10227         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10228         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10229         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10230         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10231         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10232
10233         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10234          * mixer widget
10235          * Note: PASD motherboards uses the Line In 2 as the input for front
10236          * panel mic (mic 2)
10237          */
10238         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10239         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10240         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10241         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10242         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10243         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10244         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10245         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10246         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10247         /*
10248          * Set up output mixers (0x0c - 0x0e)
10249          */
10250         /* set vol=0 to output mixers */
10251         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10252         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10253         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10254
10255         /* set up input amps for analog loopback */
10256         /* Amp Indices: DAC = 0, mixer = 1 */
10257         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10258         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10259         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10260         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10261         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10262         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10263
10264
10265         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
10266         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
10267         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
10268         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
10269         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10270         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
10271         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
10272
10273         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10274         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10275
10276         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10277         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10278
10279         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
10280         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10281         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10282         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10283         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10284         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10285
10286         /* FIXME: use matrix-type input source selection */
10287         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10288         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10289         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
10290         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
10291         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
10292         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
10293         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
10294         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
10295         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
10296         /* Input mixer2 */
10297         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10298         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10299         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10300         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10301         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10302         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10303         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10304         /* Input mixer3 */
10305         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10306         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10307         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10308         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10309         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10310         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10311         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10312
10313         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10314
10315         { }
10316 };
10317
10318 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
10319
10320         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
10321         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10322         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
10323
10324         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
10325         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10326         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10327         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10328
10329         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
10330         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10331         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10332         {}
10333 };
10334
10335
10336 #ifdef CONFIG_SND_HDA_POWER_SAVE
10337 #define alc262_loopbacks        alc880_loopbacks
10338 #endif
10339
10340 /* pcm configuration: identiacal with ALC880 */
10341 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
10342 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
10343 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
10344 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
10345
10346 /*
10347  * BIOS auto configuration
10348  */
10349 static int alc262_parse_auto_config(struct hda_codec *codec)
10350 {
10351         struct alc_spec *spec = codec->spec;
10352         int err;
10353         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
10354
10355         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10356                                            alc262_ignore);
10357         if (err < 0)
10358                 return err;
10359         if (!spec->autocfg.line_outs)
10360                 return 0; /* can't find valid BIOS pin config */
10361         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
10362         if (err < 0)
10363                 return err;
10364         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
10365         if (err < 0)
10366                 return err;
10367
10368         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10369
10370         if (spec->autocfg.dig_out_pin)
10371                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
10372         if (spec->autocfg.dig_in_pin)
10373                 spec->dig_in_nid = ALC262_DIGIN_NID;
10374
10375         if (spec->kctl_alloc)
10376                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10377
10378         spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs;
10379         spec->num_mux_defs = 1;
10380         spec->input_mux = &spec->private_imux;
10381
10382         err = alc_auto_add_mic_boost(codec);
10383         if (err < 0)
10384                 return err;
10385
10386         store_pin_configs(codec);
10387         return 1;
10388 }
10389
10390 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
10391 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
10392 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
10393 #define alc262_auto_init_input_src      alc882_auto_init_input_src
10394
10395
10396 /* init callback for auto-configuration model -- overriding the default init */
10397 static void alc262_auto_init(struct hda_codec *codec)
10398 {
10399         struct alc_spec *spec = codec->spec;
10400         alc262_auto_init_multi_out(codec);
10401         alc262_auto_init_hp_out(codec);
10402         alc262_auto_init_analog_input(codec);
10403         alc262_auto_init_input_src(codec);
10404         if (spec->unsol_event)
10405                 alc_inithook(codec);
10406 }
10407
10408 /*
10409  * configuration and preset
10410  */
10411 static const char *alc262_models[ALC262_MODEL_LAST] = {
10412         [ALC262_BASIC]          = "basic",
10413         [ALC262_HIPPO]          = "hippo",
10414         [ALC262_HIPPO_1]        = "hippo_1",
10415         [ALC262_FUJITSU]        = "fujitsu",
10416         [ALC262_HP_BPC]         = "hp-bpc",
10417         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
10418         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
10419         [ALC262_HP_RP5700]      = "hp-rp5700",
10420         [ALC262_BENQ_ED8]       = "benq",
10421         [ALC262_BENQ_T31]       = "benq-t31",
10422         [ALC262_SONY_ASSAMD]    = "sony-assamd",
10423         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
10424         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
10425         [ALC262_ULTRA]          = "ultra",
10426         [ALC262_LENOVO_3000]    = "lenovo-3000",
10427         [ALC262_NEC]            = "nec",
10428         [ALC262_AUTO]           = "auto",
10429 };
10430
10431 static struct snd_pci_quirk alc262_cfg_tbl[] = {
10432         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
10433         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
10434         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
10435         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
10436         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
10437         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
10438         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
10439         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
10440         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
10441         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
10442         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
10443         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
10444         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
10445         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
10446         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
10447         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
10448         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
10449         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
10450         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
10451         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
10452         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
10453         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
10454                       ALC262_HP_TC_T5735),
10455         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
10456         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10457         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
10458         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10459         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10460         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
10461         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
10462                       ALC262_TOSHIBA_RX1),
10463         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
10464         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
10465         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
10466         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
10467         SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
10468         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
10469         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
10470         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
10471         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
10472         {}
10473 };
10474
10475 static struct alc_config_preset alc262_presets[] = {
10476         [ALC262_BASIC] = {
10477                 .mixers = { alc262_base_mixer },
10478                 .init_verbs = { alc262_init_verbs },
10479                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10480                 .dac_nids = alc262_dac_nids,
10481                 .hp_nid = 0x03,
10482                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10483                 .channel_mode = alc262_modes,
10484                 .input_mux = &alc262_capture_source,
10485         },
10486         [ALC262_HIPPO] = {
10487                 .mixers = { alc262_base_mixer },
10488                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
10489                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10490                 .dac_nids = alc262_dac_nids,
10491                 .hp_nid = 0x03,
10492                 .dig_out_nid = ALC262_DIGOUT_NID,
10493                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10494                 .channel_mode = alc262_modes,
10495                 .input_mux = &alc262_capture_source,
10496                 .unsol_event = alc262_hippo_unsol_event,
10497                 .init_hook = alc262_hippo_automute,
10498         },
10499         [ALC262_HIPPO_1] = {
10500                 .mixers = { alc262_hippo1_mixer },
10501                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
10502                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10503                 .dac_nids = alc262_dac_nids,
10504                 .hp_nid = 0x02,
10505                 .dig_out_nid = ALC262_DIGOUT_NID,
10506                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10507                 .channel_mode = alc262_modes,
10508                 .input_mux = &alc262_capture_source,
10509                 .unsol_event = alc262_hippo1_unsol_event,
10510                 .init_hook = alc262_hippo1_automute,
10511         },
10512         [ALC262_FUJITSU] = {
10513                 .mixers = { alc262_fujitsu_mixer },
10514                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10515                                 alc262_fujitsu_unsol_verbs },
10516                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10517                 .dac_nids = alc262_dac_nids,
10518                 .hp_nid = 0x03,
10519                 .dig_out_nid = ALC262_DIGOUT_NID,
10520                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10521                 .channel_mode = alc262_modes,
10522                 .input_mux = &alc262_fujitsu_capture_source,
10523                 .unsol_event = alc262_fujitsu_unsol_event,
10524                 .init_hook = alc262_fujitsu_init_hook,
10525         },
10526         [ALC262_HP_BPC] = {
10527                 .mixers = { alc262_HP_BPC_mixer },
10528                 .init_verbs = { alc262_HP_BPC_init_verbs },
10529                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10530                 .dac_nids = alc262_dac_nids,
10531                 .hp_nid = 0x03,
10532                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10533                 .channel_mode = alc262_modes,
10534                 .input_mux = &alc262_HP_capture_source,
10535                 .unsol_event = alc262_hp_bpc_unsol_event,
10536                 .init_hook = alc262_hp_bpc_automute,
10537         },
10538         [ALC262_HP_BPC_D7000_WF] = {
10539                 .mixers = { alc262_HP_BPC_WildWest_mixer },
10540                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10541                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10542                 .dac_nids = alc262_dac_nids,
10543                 .hp_nid = 0x03,
10544                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10545                 .channel_mode = alc262_modes,
10546                 .input_mux = &alc262_HP_D7000_capture_source,
10547                 .unsol_event = alc262_hp_wildwest_unsol_event,
10548                 .init_hook = alc262_hp_wildwest_automute,
10549         },
10550         [ALC262_HP_BPC_D7000_WL] = {
10551                 .mixers = { alc262_HP_BPC_WildWest_mixer,
10552                             alc262_HP_BPC_WildWest_option_mixer },
10553                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10554                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10555                 .dac_nids = alc262_dac_nids,
10556                 .hp_nid = 0x03,
10557                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10558                 .channel_mode = alc262_modes,
10559                 .input_mux = &alc262_HP_D7000_capture_source,
10560                 .unsol_event = alc262_hp_wildwest_unsol_event,
10561                 .init_hook = alc262_hp_wildwest_automute,
10562         },
10563         [ALC262_HP_TC_T5735] = {
10564                 .mixers = { alc262_hp_t5735_mixer },
10565                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
10566                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10567                 .dac_nids = alc262_dac_nids,
10568                 .hp_nid = 0x03,
10569                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10570                 .channel_mode = alc262_modes,
10571                 .input_mux = &alc262_capture_source,
10572                 .unsol_event = alc262_hp_t5735_unsol_event,
10573                 .init_hook = alc262_hp_t5735_init_hook,
10574         },
10575         [ALC262_HP_RP5700] = {
10576                 .mixers = { alc262_hp_rp5700_mixer },
10577                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
10578                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10579                 .dac_nids = alc262_dac_nids,
10580                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10581                 .channel_mode = alc262_modes,
10582                 .input_mux = &alc262_hp_rp5700_capture_source,
10583         },
10584         [ALC262_BENQ_ED8] = {
10585                 .mixers = { alc262_base_mixer },
10586                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
10587                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10588                 .dac_nids = alc262_dac_nids,
10589                 .hp_nid = 0x03,
10590                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10591                 .channel_mode = alc262_modes,
10592                 .input_mux = &alc262_capture_source,
10593         },
10594         [ALC262_SONY_ASSAMD] = {
10595                 .mixers = { alc262_sony_mixer },
10596                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
10597                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10598                 .dac_nids = alc262_dac_nids,
10599                 .hp_nid = 0x02,
10600                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10601                 .channel_mode = alc262_modes,
10602                 .input_mux = &alc262_capture_source,
10603                 .unsol_event = alc262_hippo_unsol_event,
10604                 .init_hook = alc262_hippo_automute,
10605         },
10606         [ALC262_BENQ_T31] = {
10607                 .mixers = { alc262_benq_t31_mixer },
10608                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
10609                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10610                 .dac_nids = alc262_dac_nids,
10611                 .hp_nid = 0x03,
10612                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10613                 .channel_mode = alc262_modes,
10614                 .input_mux = &alc262_capture_source,
10615                 .unsol_event = alc262_hippo_unsol_event,
10616                 .init_hook = alc262_hippo_automute,
10617         },
10618         [ALC262_ULTRA] = {
10619                 .mixers = { alc262_ultra_mixer, alc262_ultra_capture_mixer },
10620                 .init_verbs = { alc262_ultra_verbs },
10621                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10622                 .dac_nids = alc262_dac_nids,
10623                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10624                 .channel_mode = alc262_modes,
10625                 .input_mux = &alc262_ultra_capture_source,
10626                 .adc_nids = alc262_adc_nids, /* ADC0 */
10627                 .capsrc_nids = alc262_capsrc_nids,
10628                 .num_adc_nids = 1, /* single ADC */
10629                 .unsol_event = alc262_ultra_unsol_event,
10630                 .init_hook = alc262_ultra_automute,
10631         },
10632         [ALC262_LENOVO_3000] = {
10633                 .mixers = { alc262_lenovo_3000_mixer },
10634                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10635                                 alc262_lenovo_3000_unsol_verbs },
10636                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10637                 .dac_nids = alc262_dac_nids,
10638                 .hp_nid = 0x03,
10639                 .dig_out_nid = ALC262_DIGOUT_NID,
10640                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10641                 .channel_mode = alc262_modes,
10642                 .input_mux = &alc262_fujitsu_capture_source,
10643                 .unsol_event = alc262_lenovo_3000_unsol_event,
10644         },
10645         [ALC262_NEC] = {
10646                 .mixers = { alc262_nec_mixer },
10647                 .init_verbs = { alc262_nec_verbs },
10648                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10649                 .dac_nids = alc262_dac_nids,
10650                 .hp_nid = 0x03,
10651                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10652                 .channel_mode = alc262_modes,
10653                 .input_mux = &alc262_capture_source,
10654         },
10655         [ALC262_TOSHIBA_S06] = {
10656                 .mixers = { alc262_toshiba_s06_mixer },
10657                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
10658                                                         alc262_eapd_verbs },
10659                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10660                 .capsrc_nids = alc262_dmic_capsrc_nids,
10661                 .dac_nids = alc262_dac_nids,
10662                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
10663                 .dig_out_nid = ALC262_DIGOUT_NID,
10664                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10665                 .channel_mode = alc262_modes,
10666                 .input_mux = &alc262_dmic_capture_source,
10667                 .unsol_event = alc262_toshiba_s06_unsol_event,
10668                 .init_hook = alc262_toshiba_s06_init_hook,
10669         },
10670         [ALC262_TOSHIBA_RX1] = {
10671                 .mixers = { alc262_toshiba_rx1_mixer },
10672                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
10673                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10674                 .dac_nids = alc262_dac_nids,
10675                 .hp_nid = 0x03,
10676                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10677                 .channel_mode = alc262_modes,
10678                 .input_mux = &alc262_capture_source,
10679                 .unsol_event = alc262_hippo_unsol_event,
10680                 .init_hook = alc262_hippo_automute,
10681         },
10682 };
10683
10684 static int patch_alc262(struct hda_codec *codec)
10685 {
10686         struct alc_spec *spec;
10687         int board_config;
10688         int err;
10689
10690         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10691         if (spec == NULL)
10692                 return -ENOMEM;
10693
10694         codec->spec = spec;
10695 #if 0
10696         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
10697          * under-run
10698          */
10699         {
10700         int tmp;
10701         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10702         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
10703         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10704         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
10705         }
10706 #endif
10707
10708         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
10709
10710         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
10711                                                   alc262_models,
10712                                                   alc262_cfg_tbl);
10713
10714         if (board_config < 0) {
10715                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
10716                        "trying auto-probe from BIOS...\n");
10717                 board_config = ALC262_AUTO;
10718         }
10719
10720         if (board_config == ALC262_AUTO) {
10721                 /* automatic parse from the BIOS config */
10722                 err = alc262_parse_auto_config(codec);
10723                 if (err < 0) {
10724                         alc_free(codec);
10725                         return err;
10726                 } else if (!err) {
10727                         printk(KERN_INFO
10728                                "hda_codec: Cannot set up configuration "
10729                                "from BIOS.  Using base mode...\n");
10730                         board_config = ALC262_BASIC;
10731                 }
10732         }
10733
10734         if (board_config != ALC262_AUTO)
10735                 setup_preset(spec, &alc262_presets[board_config]);
10736
10737         spec->stream_name_analog = "ALC262 Analog";
10738         spec->stream_analog_playback = &alc262_pcm_analog_playback;
10739         spec->stream_analog_capture = &alc262_pcm_analog_capture;
10740
10741         spec->stream_name_digital = "ALC262 Digital";
10742         spec->stream_digital_playback = &alc262_pcm_digital_playback;
10743         spec->stream_digital_capture = &alc262_pcm_digital_capture;
10744
10745         if (!spec->adc_nids && spec->input_mux) {
10746                 /* check whether NID 0x07 is valid */
10747                 unsigned int wcap = get_wcaps(codec, 0x07);
10748
10749                 /* get type */
10750                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10751                 if (wcap != AC_WID_AUD_IN) {
10752                         spec->adc_nids = alc262_adc_nids_alt;
10753                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
10754                         spec->capsrc_nids = alc262_capsrc_nids_alt;
10755                         spec->mixers[spec->num_mixers] =
10756                                 alc262_capture_alt_mixer;
10757                         spec->num_mixers++;
10758                 } else {
10759                         spec->adc_nids = alc262_adc_nids;
10760                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
10761                         spec->capsrc_nids = alc262_capsrc_nids;
10762                         spec->mixers[spec->num_mixers] = alc262_capture_mixer;
10763                         spec->num_mixers++;
10764                 }
10765         }
10766
10767         spec->vmaster_nid = 0x0c;
10768
10769         codec->patch_ops = alc_patch_ops;
10770         if (board_config == ALC262_AUTO)
10771                 spec->init_hook = alc262_auto_init;
10772 #ifdef CONFIG_SND_HDA_POWER_SAVE
10773         if (!spec->loopback.amplist)
10774                 spec->loopback.amplist = alc262_loopbacks;
10775 #endif
10776
10777         return 0;
10778 }
10779
10780 /*
10781  *  ALC268 channel source setting (2 channel)
10782  */
10783 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
10784 #define alc268_modes            alc260_modes
10785
10786 static hda_nid_t alc268_dac_nids[2] = {
10787         /* front, hp */
10788         0x02, 0x03
10789 };
10790
10791 static hda_nid_t alc268_adc_nids[2] = {
10792         /* ADC0-1 */
10793         0x08, 0x07
10794 };
10795
10796 static hda_nid_t alc268_adc_nids_alt[1] = {
10797         /* ADC0 */
10798         0x08
10799 };
10800
10801 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
10802
10803 static struct snd_kcontrol_new alc268_base_mixer[] = {
10804         /* output mixer control */
10805         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10806         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10807         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10808         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10809         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10810         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10811         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10812         { }
10813 };
10814
10815 /* bind Beep switches of both NID 0x0f and 0x10 */
10816 static struct hda_bind_ctls alc268_bind_beep_sw = {
10817         .ops = &snd_hda_bind_sw,
10818         .values = {
10819                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
10820                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
10821                 0
10822         },
10823 };
10824
10825 static struct snd_kcontrol_new alc268_beep_mixer[] = {
10826         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
10827         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
10828         { }
10829 };
10830
10831 static struct hda_verb alc268_eapd_verbs[] = {
10832         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10833         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10834         { }
10835 };
10836
10837 /* Toshiba specific */
10838 #define alc268_toshiba_automute alc262_hippo_automute
10839
10840 static struct hda_verb alc268_toshiba_verbs[] = {
10841         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10842         { } /* end */
10843 };
10844
10845 static struct hda_input_mux alc268_acer_lc_capture_source = {
10846         .num_items = 2,
10847         .items = {
10848                 { "i-Mic", 0x6 },
10849                 { "E-Mic", 0x0 },
10850         },
10851 };
10852
10853 /* Acer specific */
10854 /* bind volumes of both NID 0x02 and 0x03 */
10855 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
10856         .ops = &snd_hda_bind_vol,
10857         .values = {
10858                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
10859                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
10860                 0
10861         },
10862 };
10863
10864 /* mute/unmute internal speaker according to the hp jack and mute state */
10865 static void alc268_acer_automute(struct hda_codec *codec, int force)
10866 {
10867         struct alc_spec *spec = codec->spec;
10868         unsigned int mute;
10869
10870         if (force || !spec->sense_updated) {
10871                 unsigned int present;
10872                 present = snd_hda_codec_read(codec, 0x14, 0,
10873                                          AC_VERB_GET_PIN_SENSE, 0);
10874                 spec->jack_present = (present & 0x80000000) != 0;
10875                 spec->sense_updated = 1;
10876         }
10877         if (spec->jack_present)
10878                 mute = HDA_AMP_MUTE; /* mute internal speaker */
10879         else /* unmute internal speaker if necessary */
10880                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10881         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10882                                  HDA_AMP_MUTE, mute);
10883 }
10884
10885
10886 /* bind hp and internal speaker mute (with plug check) */
10887 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
10888                                      struct snd_ctl_elem_value *ucontrol)
10889 {
10890         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10891         long *valp = ucontrol->value.integer.value;
10892         int change;
10893
10894         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
10895                                           HDA_AMP_MUTE,
10896                                           valp[0] ? 0 : HDA_AMP_MUTE);
10897         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
10898                                            HDA_AMP_MUTE,
10899                                            valp[1] ? 0 : HDA_AMP_MUTE);
10900         if (change)
10901                 alc268_acer_automute(codec, 0);
10902         return change;
10903 }
10904
10905 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
10906         /* output mixer control */
10907         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
10908         {
10909                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10910                 .name = "Master Playback Switch",
10911                 .info = snd_hda_mixer_amp_switch_info,
10912                 .get = snd_hda_mixer_amp_switch_get,
10913                 .put = alc268_acer_master_sw_put,
10914                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10915         },
10916         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
10917         { }
10918 };
10919
10920 static struct snd_kcontrol_new alc268_acer_mixer[] = {
10921         /* output mixer control */
10922         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
10923         {
10924                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10925                 .name = "Master Playback Switch",
10926                 .info = snd_hda_mixer_amp_switch_info,
10927                 .get = snd_hda_mixer_amp_switch_get,
10928                 .put = alc268_acer_master_sw_put,
10929                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10930         },
10931         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10932         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
10933         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10934         { }
10935 };
10936
10937 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
10938         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10939         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10940         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10941         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
10942         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
10943         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
10944         { }
10945 };
10946
10947 static struct hda_verb alc268_acer_verbs[] = {
10948         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
10949         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10950         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10951         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10952         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10953         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10954         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10955         { }
10956 };
10957
10958 /* unsolicited event for HP jack sensing */
10959 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
10960                                        unsigned int res)
10961 {
10962         if ((res >> 26) != ALC880_HP_EVENT)
10963                 return;
10964         alc268_toshiba_automute(codec);
10965 }
10966
10967 static void alc268_acer_unsol_event(struct hda_codec *codec,
10968                                        unsigned int res)
10969 {
10970         if ((res >> 26) != ALC880_HP_EVENT)
10971                 return;
10972         alc268_acer_automute(codec, 1);
10973 }
10974
10975 static void alc268_acer_init_hook(struct hda_codec *codec)
10976 {
10977         alc268_acer_automute(codec, 1);
10978 }
10979
10980 /* toggle speaker-output according to the hp-jack state */
10981 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
10982 {
10983         unsigned int present;
10984         unsigned char bits;
10985
10986         present = snd_hda_codec_read(codec, 0x15, 0,
10987                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10988         bits = present ? AMP_IN_MUTE(0) : 0;
10989         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
10990                                 AMP_IN_MUTE(0), bits);
10991         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
10992                                 AMP_IN_MUTE(0), bits);
10993 }
10994
10995
10996 static void alc268_acer_mic_automute(struct hda_codec *codec)
10997 {
10998         unsigned int present;
10999
11000         present = snd_hda_codec_read(codec, 0x18, 0,
11001                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11002         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
11003                             present ? 0x0 : 0x6);
11004 }
11005
11006 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
11007                                     unsigned int res)
11008 {
11009         if ((res >> 26) == ALC880_HP_EVENT)
11010                 alc268_aspire_one_speaker_automute(codec);
11011         if ((res >> 26) == ALC880_MIC_EVENT)
11012                 alc268_acer_mic_automute(codec);
11013 }
11014
11015 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
11016 {
11017         alc268_aspire_one_speaker_automute(codec);
11018         alc268_acer_mic_automute(codec);
11019 }
11020
11021 static struct snd_kcontrol_new alc268_dell_mixer[] = {
11022         /* output mixer control */
11023         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11024         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11025         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11026         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11027         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11028         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11029         { }
11030 };
11031
11032 static struct hda_verb alc268_dell_verbs[] = {
11033         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11034         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11035         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11036         { }
11037 };
11038
11039 /* mute/unmute internal speaker according to the hp jack and mute state */
11040 static void alc268_dell_automute(struct hda_codec *codec)
11041 {
11042         unsigned int present;
11043         unsigned int mute;
11044
11045         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
11046         if (present & 0x80000000)
11047                 mute = HDA_AMP_MUTE;
11048         else
11049                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
11050         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
11051                                  HDA_AMP_MUTE, mute);
11052 }
11053
11054 static void alc268_dell_unsol_event(struct hda_codec *codec,
11055                                     unsigned int res)
11056 {
11057         if ((res >> 26) != ALC880_HP_EVENT)
11058                 return;
11059         alc268_dell_automute(codec);
11060 }
11061
11062 #define alc268_dell_init_hook   alc268_dell_automute
11063
11064 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
11065         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11066         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11067         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11068         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11069         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11070         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
11071         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
11072         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
11073         { }
11074 };
11075
11076 static struct hda_verb alc267_quanta_il1_verbs[] = {
11077         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11078         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
11079         { }
11080 };
11081
11082 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
11083 {
11084         unsigned int present;
11085
11086         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
11087                 & AC_PINSENSE_PRESENCE;
11088         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
11089                             present ? 0 : PIN_OUT);
11090 }
11091
11092 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
11093 {
11094         unsigned int present;
11095
11096         present = snd_hda_codec_read(codec, 0x18, 0,
11097                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11098         snd_hda_codec_write(codec, 0x23, 0,
11099                             AC_VERB_SET_CONNECT_SEL,
11100                             present ? 0x00 : 0x01);
11101 }
11102
11103 static void alc267_quanta_il1_automute(struct hda_codec *codec)
11104 {
11105         alc267_quanta_il1_hp_automute(codec);
11106         alc267_quanta_il1_mic_automute(codec);
11107 }
11108
11109 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
11110                                            unsigned int res)
11111 {
11112         switch (res >> 26) {
11113         case ALC880_HP_EVENT:
11114                 alc267_quanta_il1_hp_automute(codec);
11115                 break;
11116         case ALC880_MIC_EVENT:
11117                 alc267_quanta_il1_mic_automute(codec);
11118                 break;
11119         }
11120 }
11121
11122 /*
11123  * generic initialization of ADC, input mixers and output mixers
11124  */
11125 static struct hda_verb alc268_base_init_verbs[] = {
11126         /* Unmute DAC0-1 and set vol = 0 */
11127         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11128         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11129         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11130         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11131         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11132         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11133
11134         /*
11135          * Set up output mixers (0x0c - 0x0e)
11136          */
11137         /* set vol=0 to output mixers */
11138         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11139         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11140         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11141         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
11142
11143         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11144         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11145
11146         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11147         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
11148         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11149         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11150         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11151         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11152         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11153         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11154
11155         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11156         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11157         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11158         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11159         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11160         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11161         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11162
11163         /* set PCBEEP vol = 0, mute connections */
11164         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11165         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11166         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11167
11168         /* Unmute Selector 23h,24h and set the default input to mic-in */
11169
11170         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
11171         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11172         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
11173         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11174
11175         { }
11176 };
11177
11178 /*
11179  * generic initialization of ADC, input mixers and output mixers
11180  */
11181 static struct hda_verb alc268_volume_init_verbs[] = {
11182         /* set output DAC */
11183         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11184         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11185         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11186         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11187
11188         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11189         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11190         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11191         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11192         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11193
11194         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11195         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11196         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11197         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11198         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11199
11200         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11201         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11202         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11203         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11204
11205         /* set PCBEEP vol = 0, mute connections */
11206         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11207         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11208         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11209
11210         { }
11211 };
11212
11213 #define alc268_mux_enum_info alc_mux_enum_info
11214 #define alc268_mux_enum_get alc_mux_enum_get
11215 #define alc268_mux_enum_put alc_mux_enum_put
11216
11217 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
11218         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11219         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11220         {
11221                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11222                 /* The multiple "Capture Source" controls confuse alsamixer
11223                  * So call somewhat different..
11224                  */
11225                 /* .name = "Capture Source", */
11226                 .name = "Input Source",
11227                 .count = 1,
11228                 .info = alc268_mux_enum_info,
11229                 .get = alc268_mux_enum_get,
11230                 .put = alc268_mux_enum_put,
11231         },
11232         { } /* end */
11233 };
11234
11235 static struct snd_kcontrol_new alc268_capture_mixer[] = {
11236         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11237         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11238         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
11239         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
11240         {
11241                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11242                 /* The multiple "Capture Source" controls confuse alsamixer
11243                  * So call somewhat different..
11244                  */
11245                 /* .name = "Capture Source", */
11246                 .name = "Input Source",
11247                 .count = 2,
11248                 .info = alc268_mux_enum_info,
11249                 .get = alc268_mux_enum_get,
11250                 .put = alc268_mux_enum_put,
11251         },
11252         { } /* end */
11253 };
11254
11255 static struct hda_input_mux alc268_capture_source = {
11256         .num_items = 4,
11257         .items = {
11258                 { "Mic", 0x0 },
11259                 { "Front Mic", 0x1 },
11260                 { "Line", 0x2 },
11261                 { "CD", 0x3 },
11262         },
11263 };
11264
11265 static struct hda_input_mux alc268_acer_capture_source = {
11266         .num_items = 3,
11267         .items = {
11268                 { "Mic", 0x0 },
11269                 { "Internal Mic", 0x6 },
11270                 { "Line", 0x2 },
11271         },
11272 };
11273
11274 #ifdef CONFIG_SND_DEBUG
11275 static struct snd_kcontrol_new alc268_test_mixer[] = {
11276         /* Volume widgets */
11277         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11278         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11279         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
11280         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
11281         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
11282         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
11283         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
11284         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
11285         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
11286         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
11287         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
11288         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
11289         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
11290         /* The below appears problematic on some hardwares */
11291         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
11292         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11293         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
11294         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
11295         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
11296
11297         /* Modes for retasking pin widgets */
11298         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
11299         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
11300         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
11301         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
11302
11303         /* Controls for GPIO pins, assuming they are configured as outputs */
11304         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
11305         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
11306         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
11307         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
11308
11309         /* Switches to allow the digital SPDIF output pin to be enabled.
11310          * The ALC268 does not have an SPDIF input.
11311          */
11312         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
11313
11314         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
11315          * this output to turn on an external amplifier.
11316          */
11317         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
11318         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
11319
11320         { } /* end */
11321 };
11322 #endif
11323
11324 /* create input playback/capture controls for the given pin */
11325 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
11326                                     const char *ctlname, int idx)
11327 {
11328         char name[32];
11329         int err;
11330
11331         sprintf(name, "%s Playback Volume", ctlname);
11332         if (nid == 0x14) {
11333                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11334                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
11335                                                       HDA_OUTPUT));
11336                 if (err < 0)
11337                         return err;
11338         } else if (nid == 0x15) {
11339                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11340                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
11341                                                       HDA_OUTPUT));
11342                 if (err < 0)
11343                         return err;
11344         } else
11345                 return -1;
11346         sprintf(name, "%s Playback Switch", ctlname);
11347         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11348                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
11349         if (err < 0)
11350                 return err;
11351         return 0;
11352 }
11353
11354 /* add playback controls from the parsed DAC table */
11355 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
11356                                              const struct auto_pin_cfg *cfg)
11357 {
11358         hda_nid_t nid;
11359         int err;
11360
11361         spec->multiout.num_dacs = 2;    /* only use one dac */
11362         spec->multiout.dac_nids = spec->private_dac_nids;
11363         spec->multiout.dac_nids[0] = 2;
11364         spec->multiout.dac_nids[1] = 3;
11365
11366         nid = cfg->line_out_pins[0];
11367         if (nid)
11368                 alc268_new_analog_output(spec, nid, "Front", 0);
11369
11370         nid = cfg->speaker_pins[0];
11371         if (nid == 0x1d) {
11372                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
11373                                   "Speaker Playback Volume",
11374                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
11375                 if (err < 0)
11376                         return err;
11377         }
11378         nid = cfg->hp_pins[0];
11379         if (nid)
11380                 alc268_new_analog_output(spec, nid, "Headphone", 0);
11381
11382         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
11383         if (nid == 0x16) {
11384                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11385                                   "Mono Playback Switch",
11386                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
11387                 if (err < 0)
11388                         return err;
11389         }
11390         return 0;
11391 }
11392
11393 /* create playback/capture controls for input pins */
11394 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
11395                                                 const struct auto_pin_cfg *cfg)
11396 {
11397         struct hda_input_mux *imux = &spec->private_imux;
11398         int i, idx1;
11399
11400         for (i = 0; i < AUTO_PIN_LAST; i++) {
11401                 switch(cfg->input_pins[i]) {
11402                 case 0x18:
11403                         idx1 = 0;       /* Mic 1 */
11404                         break;
11405                 case 0x19:
11406                         idx1 = 1;       /* Mic 2 */
11407                         break;
11408                 case 0x1a:
11409                         idx1 = 2;       /* Line In */
11410                         break;
11411                 case 0x1c:
11412                         idx1 = 3;       /* CD */
11413                         break;
11414                 case 0x12:
11415                 case 0x13:
11416                         idx1 = 6;       /* digital mics */
11417                         break;
11418                 default:
11419                         continue;
11420                 }
11421                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
11422                 imux->items[imux->num_items].index = idx1;
11423                 imux->num_items++;
11424         }
11425         return 0;
11426 }
11427
11428 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
11429 {
11430         struct alc_spec *spec = codec->spec;
11431         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
11432         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
11433         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
11434         unsigned int    dac_vol1, dac_vol2;
11435
11436         if (speaker_nid) {
11437                 snd_hda_codec_write(codec, speaker_nid, 0,
11438                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
11439                 snd_hda_codec_write(codec, 0x0f, 0,
11440                                     AC_VERB_SET_AMP_GAIN_MUTE,
11441                                     AMP_IN_UNMUTE(1));
11442                 snd_hda_codec_write(codec, 0x10, 0,
11443                                     AC_VERB_SET_AMP_GAIN_MUTE,
11444                                     AMP_IN_UNMUTE(1));
11445         } else {
11446                 snd_hda_codec_write(codec, 0x0f, 0,
11447                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11448                 snd_hda_codec_write(codec, 0x10, 0,
11449                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11450         }
11451
11452         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
11453         if (line_nid == 0x14)
11454                 dac_vol2 = AMP_OUT_ZERO;
11455         else if (line_nid == 0x15)
11456                 dac_vol1 = AMP_OUT_ZERO;
11457         if (hp_nid == 0x14)
11458                 dac_vol2 = AMP_OUT_ZERO;
11459         else if (hp_nid == 0x15)
11460                 dac_vol1 = AMP_OUT_ZERO;
11461         if (line_nid != 0x16 || hp_nid != 0x16 ||
11462             spec->autocfg.line_out_pins[1] != 0x16 ||
11463             spec->autocfg.line_out_pins[2] != 0x16)
11464                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
11465
11466         snd_hda_codec_write(codec, 0x02, 0,
11467                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
11468         snd_hda_codec_write(codec, 0x03, 0,
11469                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
11470 }
11471
11472 /* pcm configuration: identiacal with ALC880 */
11473 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
11474 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
11475 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
11476 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
11477
11478 /*
11479  * BIOS auto configuration
11480  */
11481 static int alc268_parse_auto_config(struct hda_codec *codec)
11482 {
11483         struct alc_spec *spec = codec->spec;
11484         int err;
11485         static hda_nid_t alc268_ignore[] = { 0 };
11486
11487         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11488                                            alc268_ignore);
11489         if (err < 0)
11490                 return err;
11491         if (!spec->autocfg.line_outs)
11492                 return 0; /* can't find valid BIOS pin config */
11493
11494         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
11495         if (err < 0)
11496                 return err;
11497         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
11498         if (err < 0)
11499                 return err;
11500
11501         spec->multiout.max_channels = 2;
11502
11503         /* digital only support output */
11504         if (spec->autocfg.dig_out_pin)
11505                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
11506
11507         if (spec->kctl_alloc)
11508                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
11509
11510         if (spec->autocfg.speaker_pins[0] != 0x1d)
11511                 spec->mixers[spec->num_mixers++] = alc268_beep_mixer;
11512
11513         spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs;
11514         spec->num_mux_defs = 1;
11515         spec->input_mux = &spec->private_imux;
11516
11517         err = alc_auto_add_mic_boost(codec);
11518         if (err < 0)
11519                 return err;
11520
11521         store_pin_configs(codec);
11522         return 1;
11523 }
11524
11525 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
11526 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
11527 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
11528
11529 /* init callback for auto-configuration model -- overriding the default init */
11530 static void alc268_auto_init(struct hda_codec *codec)
11531 {
11532         struct alc_spec *spec = codec->spec;
11533         alc268_auto_init_multi_out(codec);
11534         alc268_auto_init_hp_out(codec);
11535         alc268_auto_init_mono_speaker_out(codec);
11536         alc268_auto_init_analog_input(codec);
11537         if (spec->unsol_event)
11538                 alc_inithook(codec);
11539 }
11540
11541 /*
11542  * configuration and preset
11543  */
11544 static const char *alc268_models[ALC268_MODEL_LAST] = {
11545         [ALC267_QUANTA_IL1]     = "quanta-il1",
11546         [ALC268_3ST]            = "3stack",
11547         [ALC268_TOSHIBA]        = "toshiba",
11548         [ALC268_ACER]           = "acer",
11549         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
11550         [ALC268_DELL]           = "dell",
11551         [ALC268_ZEPTO]          = "zepto",
11552 #ifdef CONFIG_SND_DEBUG
11553         [ALC268_TEST]           = "test",
11554 #endif
11555         [ALC268_AUTO]           = "auto",
11556 };
11557
11558 static struct snd_pci_quirk alc268_cfg_tbl[] = {
11559         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
11560         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
11561         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
11562         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
11563         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
11564         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
11565                                                 ALC268_ACER_ASPIRE_ONE),
11566         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
11567         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
11568         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
11569         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
11570         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
11571         SND_PCI_QUIRK(0x1179, 0xff64, "TOSHIBA L305", ALC268_TOSHIBA),
11572         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
11573         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
11574         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
11575         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
11576         {}
11577 };
11578
11579 static struct alc_config_preset alc268_presets[] = {
11580         [ALC267_QUANTA_IL1] = {
11581                 .mixers = { alc267_quanta_il1_mixer },
11582                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11583                                 alc267_quanta_il1_verbs },
11584                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11585                 .dac_nids = alc268_dac_nids,
11586                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11587                 .adc_nids = alc268_adc_nids_alt,
11588                 .hp_nid = 0x03,
11589                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11590                 .channel_mode = alc268_modes,
11591                 .input_mux = &alc268_capture_source,
11592                 .unsol_event = alc267_quanta_il1_unsol_event,
11593                 .init_hook = alc267_quanta_il1_automute,
11594         },
11595         [ALC268_3ST] = {
11596                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11597                             alc268_beep_mixer },
11598                 .init_verbs = { alc268_base_init_verbs },
11599                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11600                 .dac_nids = alc268_dac_nids,
11601                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11602                 .adc_nids = alc268_adc_nids_alt,
11603                 .capsrc_nids = alc268_capsrc_nids,
11604                 .hp_nid = 0x03,
11605                 .dig_out_nid = ALC268_DIGOUT_NID,
11606                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11607                 .channel_mode = alc268_modes,
11608                 .input_mux = &alc268_capture_source,
11609         },
11610         [ALC268_TOSHIBA] = {
11611                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11612                             alc268_beep_mixer },
11613                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11614                                 alc268_toshiba_verbs },
11615                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11616                 .dac_nids = alc268_dac_nids,
11617                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11618                 .adc_nids = alc268_adc_nids_alt,
11619                 .capsrc_nids = alc268_capsrc_nids,
11620                 .hp_nid = 0x03,
11621                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11622                 .channel_mode = alc268_modes,
11623                 .input_mux = &alc268_capture_source,
11624                 .unsol_event = alc268_toshiba_unsol_event,
11625                 .init_hook = alc268_toshiba_automute,
11626         },
11627         [ALC268_ACER] = {
11628                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
11629                             alc268_beep_mixer },
11630                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11631                                 alc268_acer_verbs },
11632                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11633                 .dac_nids = alc268_dac_nids,
11634                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11635                 .adc_nids = alc268_adc_nids_alt,
11636                 .capsrc_nids = alc268_capsrc_nids,
11637                 .hp_nid = 0x02,
11638                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11639                 .channel_mode = alc268_modes,
11640                 .input_mux = &alc268_acer_capture_source,
11641                 .unsol_event = alc268_acer_unsol_event,
11642                 .init_hook = alc268_acer_init_hook,
11643         },
11644         [ALC268_ACER_ASPIRE_ONE] = {
11645                 .mixers = { alc268_acer_aspire_one_mixer,
11646                                 alc268_capture_alt_mixer },
11647                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11648                                 alc268_acer_aspire_one_verbs },
11649                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11650                 .dac_nids = alc268_dac_nids,
11651                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11652                 .adc_nids = alc268_adc_nids_alt,
11653                 .capsrc_nids = alc268_capsrc_nids,
11654                 .hp_nid = 0x03,
11655                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11656                 .channel_mode = alc268_modes,
11657                 .input_mux = &alc268_acer_lc_capture_source,
11658                 .unsol_event = alc268_acer_lc_unsol_event,
11659                 .init_hook = alc268_acer_lc_init_hook,
11660         },
11661         [ALC268_DELL] = {
11662                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
11663                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11664                                 alc268_dell_verbs },
11665                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11666                 .dac_nids = alc268_dac_nids,
11667                 .hp_nid = 0x02,
11668                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11669                 .channel_mode = alc268_modes,
11670                 .unsol_event = alc268_dell_unsol_event,
11671                 .init_hook = alc268_dell_init_hook,
11672                 .input_mux = &alc268_capture_source,
11673         },
11674         [ALC268_ZEPTO] = {
11675                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11676                             alc268_beep_mixer },
11677                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11678                                 alc268_toshiba_verbs },
11679                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11680                 .dac_nids = alc268_dac_nids,
11681                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11682                 .adc_nids = alc268_adc_nids_alt,
11683                 .capsrc_nids = alc268_capsrc_nids,
11684                 .hp_nid = 0x03,
11685                 .dig_out_nid = ALC268_DIGOUT_NID,
11686                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11687                 .channel_mode = alc268_modes,
11688                 .input_mux = &alc268_capture_source,
11689                 .unsol_event = alc268_toshiba_unsol_event,
11690                 .init_hook = alc268_toshiba_automute
11691         },
11692 #ifdef CONFIG_SND_DEBUG
11693         [ALC268_TEST] = {
11694                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
11695                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11696                                 alc268_volume_init_verbs },
11697                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11698                 .dac_nids = alc268_dac_nids,
11699                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11700                 .adc_nids = alc268_adc_nids_alt,
11701                 .capsrc_nids = alc268_capsrc_nids,
11702                 .hp_nid = 0x03,
11703                 .dig_out_nid = ALC268_DIGOUT_NID,
11704                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11705                 .channel_mode = alc268_modes,
11706                 .input_mux = &alc268_capture_source,
11707         },
11708 #endif
11709 };
11710
11711 static int patch_alc268(struct hda_codec *codec)
11712 {
11713         struct alc_spec *spec;
11714         int board_config;
11715         int err;
11716
11717         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
11718         if (spec == NULL)
11719                 return -ENOMEM;
11720
11721         codec->spec = spec;
11722
11723         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
11724                                                   alc268_models,
11725                                                   alc268_cfg_tbl);
11726
11727         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
11728                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
11729                        "trying auto-probe from BIOS...\n");
11730                 board_config = ALC268_AUTO;
11731         }
11732
11733         if (board_config == ALC268_AUTO) {
11734                 /* automatic parse from the BIOS config */
11735                 err = alc268_parse_auto_config(codec);
11736                 if (err < 0) {
11737                         alc_free(codec);
11738                         return err;
11739                 } else if (!err) {
11740                         printk(KERN_INFO
11741                                "hda_codec: Cannot set up configuration "
11742                                "from BIOS.  Using base mode...\n");
11743                         board_config = ALC268_3ST;
11744                 }
11745         }
11746
11747         if (board_config != ALC268_AUTO)
11748                 setup_preset(spec, &alc268_presets[board_config]);
11749
11750         if (codec->vendor_id == 0x10ec0267) {
11751                 spec->stream_name_analog = "ALC267 Analog";
11752                 spec->stream_name_digital = "ALC267 Digital";
11753         } else {
11754                 spec->stream_name_analog = "ALC268 Analog";
11755                 spec->stream_name_digital = "ALC268 Digital";
11756         }
11757
11758         spec->stream_analog_playback = &alc268_pcm_analog_playback;
11759         spec->stream_analog_capture = &alc268_pcm_analog_capture;
11760         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
11761
11762         spec->stream_digital_playback = &alc268_pcm_digital_playback;
11763
11764         if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
11765                 /* override the amp caps for beep generator */
11766                 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
11767                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
11768                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
11769                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
11770                                           (0 << AC_AMPCAP_MUTE_SHIFT));
11771
11772         if (!spec->adc_nids && spec->input_mux) {
11773                 /* check whether NID 0x07 is valid */
11774                 unsigned int wcap = get_wcaps(codec, 0x07);
11775                 int i;
11776
11777                 /* get type */
11778                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
11779                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
11780                         spec->adc_nids = alc268_adc_nids_alt;
11781                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
11782                         spec->mixers[spec->num_mixers] =
11783                                         alc268_capture_alt_mixer;
11784                         spec->num_mixers++;
11785                 } else {
11786                         spec->adc_nids = alc268_adc_nids;
11787                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
11788                         spec->mixers[spec->num_mixers] =
11789                                 alc268_capture_mixer;
11790                         spec->num_mixers++;
11791                 }
11792                 spec->capsrc_nids = alc268_capsrc_nids;
11793                 /* set default input source */
11794                 for (i = 0; i < spec->num_adc_nids; i++)
11795                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
11796                                 0, AC_VERB_SET_CONNECT_SEL,
11797                                 spec->input_mux->items[0].index);
11798         }
11799
11800         spec->vmaster_nid = 0x02;
11801
11802         codec->patch_ops = alc_patch_ops;
11803         if (board_config == ALC268_AUTO)
11804                 spec->init_hook = alc268_auto_init;
11805
11806         return 0;
11807 }
11808
11809 /*
11810  *  ALC269 channel source setting (2 channel)
11811  */
11812 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
11813
11814 #define alc269_dac_nids         alc260_dac_nids
11815
11816 static hda_nid_t alc269_adc_nids[1] = {
11817         /* ADC1 */
11818         0x08,
11819 };
11820
11821 static hda_nid_t alc269_capsrc_nids[1] = {
11822         0x23,
11823 };
11824
11825 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
11826  *       not a mux!
11827  */
11828
11829 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
11830         .num_items = 2,
11831         .items = {
11832                 { "i-Mic", 0x5 },
11833                 { "e-Mic", 0x0 },
11834         },
11835 };
11836
11837 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
11838         .num_items = 2,
11839         .items = {
11840                 { "i-Mic", 0x1 },
11841                 { "e-Mic", 0x0 },
11842         },
11843 };
11844
11845 #define alc269_modes            alc260_modes
11846 #define alc269_capture_source   alc880_lg_lw_capture_source
11847
11848 static struct snd_kcontrol_new alc269_base_mixer[] = {
11849         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11850         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11851         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11852         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11853         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11854         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11855         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
11856         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
11857         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11858         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11859         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11860         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11861         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11862         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
11863         { } /* end */
11864 };
11865
11866 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
11867         /* output mixer control */
11868         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11869         {
11870                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11871                 .name = "Master Playback Switch",
11872                 .info = snd_hda_mixer_amp_switch_info,
11873                 .get = snd_hda_mixer_amp_switch_get,
11874                 .put = alc268_acer_master_sw_put,
11875                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11876         },
11877         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11878         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11879         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11880         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11881         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11882         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11883         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
11884         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
11885         { }
11886 };
11887
11888 /* bind volumes of both NID 0x0c and 0x0d */
11889 static struct hda_bind_ctls alc269_epc_bind_vol = {
11890         .ops = &snd_hda_bind_vol,
11891         .values = {
11892                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
11893                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
11894                 0
11895         },
11896 };
11897
11898 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
11899         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11900         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
11901         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11902         { } /* end */
11903 };
11904
11905 /* capture mixer elements */
11906 static struct snd_kcontrol_new alc269_capture_mixer[] = {
11907         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11908         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11909         {
11910                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11911                 /* The multiple "Capture Source" controls confuse alsamixer
11912                  * So call somewhat different..
11913                  */
11914                 /* .name = "Capture Source", */
11915                 .name = "Input Source",
11916                 .count = 1,
11917                 .info = alc_mux_enum_info,
11918                 .get = alc_mux_enum_get,
11919                 .put = alc_mux_enum_put,
11920         },
11921         { } /* end */
11922 };
11923
11924 /* capture mixer elements */
11925 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
11926         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11927         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11928         { } /* end */
11929 };
11930
11931 /* beep control */
11932 static struct snd_kcontrol_new alc269_beep_mixer[] = {
11933         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
11934         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
11935         { } /* end */
11936 };
11937
11938 static struct hda_verb alc269_quanta_fl1_verbs[] = {
11939         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11940         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11941         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11942         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11943         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11944         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11945         { }
11946 };
11947
11948 /* toggle speaker-output according to the hp-jack state */
11949 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
11950 {
11951         unsigned int present;
11952         unsigned char bits;
11953
11954         present = snd_hda_codec_read(codec, 0x15, 0,
11955                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11956         bits = present ? AMP_IN_MUTE(0) : 0;
11957         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
11958                         AMP_IN_MUTE(0), bits);
11959         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
11960                         AMP_IN_MUTE(0), bits);
11961
11962         snd_hda_codec_write(codec, 0x20, 0,
11963                         AC_VERB_SET_COEF_INDEX, 0x0c);
11964         snd_hda_codec_write(codec, 0x20, 0,
11965                         AC_VERB_SET_PROC_COEF, 0x680);
11966
11967         snd_hda_codec_write(codec, 0x20, 0,
11968                         AC_VERB_SET_COEF_INDEX, 0x0c);
11969         snd_hda_codec_write(codec, 0x20, 0,
11970                         AC_VERB_SET_PROC_COEF, 0x480);
11971 }
11972
11973 static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
11974 {
11975         unsigned int present;
11976
11977         present = snd_hda_codec_read(codec, 0x18, 0,
11978                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11979         snd_hda_codec_write(codec, 0x23, 0,
11980                             AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
11981 }
11982
11983 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
11984                                     unsigned int res)
11985 {
11986         if ((res >> 26) == ALC880_HP_EVENT)
11987                 alc269_quanta_fl1_speaker_automute(codec);
11988         if ((res >> 26) == ALC880_MIC_EVENT)
11989                 alc269_quanta_fl1_mic_automute(codec);
11990 }
11991
11992 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
11993 {
11994         alc269_quanta_fl1_speaker_automute(codec);
11995         alc269_quanta_fl1_mic_automute(codec);
11996 }
11997
11998 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
11999         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12000         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
12001         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12002         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
12003         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12004         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12005         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12006         {}
12007 };
12008
12009 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
12010         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12011         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
12012         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12013         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
12014         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12015         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12016         {}
12017 };
12018
12019 /* toggle speaker-output according to the hp-jack state */
12020 static void alc269_speaker_automute(struct hda_codec *codec)
12021 {
12022         unsigned int present;
12023         unsigned char bits;
12024
12025         present = snd_hda_codec_read(codec, 0x15, 0,
12026                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12027         bits = present ? AMP_IN_MUTE(0) : 0;
12028         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12029                                 AMP_IN_MUTE(0), bits);
12030         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12031                                 AMP_IN_MUTE(0), bits);
12032 }
12033
12034 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
12035 {
12036         unsigned int present;
12037
12038         present = snd_hda_codec_read(codec, 0x18, 0,
12039                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12040         snd_hda_codec_write(codec, 0x23, 0,
12041                                 AC_VERB_SET_CONNECT_SEL,  (present ? 0 : 5));
12042 }
12043
12044 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
12045 {
12046         unsigned int present;
12047
12048         present = snd_hda_codec_read(codec, 0x18, 0,
12049                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12050         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12051                                 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
12052         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12053                                 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
12054 }
12055
12056 /* unsolicited event for HP jack sensing */
12057 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
12058                                      unsigned int res)
12059 {
12060         if ((res >> 26) == ALC880_HP_EVENT)
12061                 alc269_speaker_automute(codec);
12062
12063         if ((res >> 26) == ALC880_MIC_EVENT)
12064                 alc269_eeepc_dmic_automute(codec);
12065 }
12066
12067 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
12068 {
12069         alc269_speaker_automute(codec);
12070         alc269_eeepc_dmic_automute(codec);
12071 }
12072
12073 /* unsolicited event for HP jack sensing */
12074 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
12075                                      unsigned int res)
12076 {
12077         if ((res >> 26) == ALC880_HP_EVENT)
12078                 alc269_speaker_automute(codec);
12079
12080         if ((res >> 26) == ALC880_MIC_EVENT)
12081                 alc269_eeepc_amic_automute(codec);
12082 }
12083
12084 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
12085 {
12086         alc269_speaker_automute(codec);
12087         alc269_eeepc_amic_automute(codec);
12088 }
12089
12090 /*
12091  * generic initialization of ADC, input mixers and output mixers
12092  */
12093 static struct hda_verb alc269_init_verbs[] = {
12094         /*
12095          * Unmute ADC0 and set the default input to mic-in
12096          */
12097         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12098
12099         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
12100          * analog-loopback mixer widget
12101          * Note: PASD motherboards uses the Line In 2 as the input for
12102          * front panel mic (mic 2)
12103          */
12104         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12105         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12106         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12107         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12108         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12109         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12110
12111         /*
12112          * Set up output mixers (0x0c - 0x0e)
12113          */
12114         /* set vol=0 to output mixers */
12115         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12116         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12117
12118         /* set up input amps for analog loopback */
12119         /* Amp Indices: DAC = 0, mixer = 1 */
12120         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12121         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12122         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12123         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12124         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12125         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12126
12127         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12128         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12129         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12130         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12131         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12132         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12133         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12134
12135         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12136         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12137         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12138         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12139         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12140         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12141         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12142
12143         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12144         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12145
12146         /* FIXME: use matrix-type input source selection */
12147         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
12148         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
12149         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12150         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12151         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12152         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12153
12154         /* set EAPD */
12155         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
12156         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
12157         { }
12158 };
12159
12160 /* add playback controls from the parsed DAC table */
12161 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
12162                                              const struct auto_pin_cfg *cfg)
12163 {
12164         hda_nid_t nid;
12165         int err;
12166
12167         spec->multiout.num_dacs = 1;    /* only use one dac */
12168         spec->multiout.dac_nids = spec->private_dac_nids;
12169         spec->multiout.dac_nids[0] = 2;
12170
12171         nid = cfg->line_out_pins[0];
12172         if (nid) {
12173                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
12174                                   "Front Playback Volume",
12175                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
12176                 if (err < 0)
12177                         return err;
12178                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12179                                   "Front Playback Switch",
12180                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12181                 if (err < 0)
12182                         return err;
12183         }
12184
12185         nid = cfg->speaker_pins[0];
12186         if (nid) {
12187                 if (!cfg->line_out_pins[0]) {
12188                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12189                                           "Speaker Playback Volume",
12190                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12191                                                               HDA_OUTPUT));
12192                         if (err < 0)
12193                                 return err;
12194                 }
12195                 if (nid == 0x16) {
12196                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12197                                           "Speaker Playback Switch",
12198                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12199                                                               HDA_OUTPUT));
12200                         if (err < 0)
12201                                 return err;
12202                 } else {
12203                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12204                                           "Speaker Playback Switch",
12205                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12206                                                               HDA_OUTPUT));
12207                         if (err < 0)
12208                                 return err;
12209                 }
12210         }
12211         nid = cfg->hp_pins[0];
12212         if (nid) {
12213                 /* spec->multiout.hp_nid = 2; */
12214                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
12215                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12216                                           "Headphone Playback Volume",
12217                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12218                                                               HDA_OUTPUT));
12219                         if (err < 0)
12220                                 return err;
12221                 }
12222                 if (nid == 0x16) {
12223                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12224                                           "Headphone Playback Switch",
12225                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12226                                                               HDA_OUTPUT));
12227                         if (err < 0)
12228                                 return err;
12229                 } else {
12230                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12231                                           "Headphone Playback Switch",
12232                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12233                                                               HDA_OUTPUT));
12234                         if (err < 0)
12235                                 return err;
12236                 }
12237         }
12238         return 0;
12239 }
12240
12241 #define alc269_auto_create_analog_input_ctls \
12242         alc880_auto_create_analog_input_ctls
12243
12244 #ifdef CONFIG_SND_HDA_POWER_SAVE
12245 #define alc269_loopbacks        alc880_loopbacks
12246 #endif
12247
12248 /* pcm configuration: identiacal with ALC880 */
12249 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
12250 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
12251 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
12252 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
12253
12254 /*
12255  * BIOS auto configuration
12256  */
12257 static int alc269_parse_auto_config(struct hda_codec *codec)
12258 {
12259         struct alc_spec *spec = codec->spec;
12260         int i, err;
12261         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
12262
12263         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12264                                            alc269_ignore);
12265         if (err < 0)
12266                 return err;
12267
12268         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
12269         if (err < 0)
12270                 return err;
12271         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
12272         if (err < 0)
12273                 return err;
12274
12275         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12276
12277         if (spec->autocfg.dig_out_pin)
12278                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
12279
12280         if (spec->kctl_alloc)
12281                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
12282
12283         /* create a beep mixer control if the pin 0x1d isn't assigned */
12284         for (i = 0; i < ARRAY_SIZE(spec->autocfg.input_pins); i++)
12285                 if (spec->autocfg.input_pins[i] == 0x1d)
12286                         break;
12287         if (i >= ARRAY_SIZE(spec->autocfg.input_pins))
12288                 spec->mixers[spec->num_mixers++] = alc269_beep_mixer;
12289
12290         spec->init_verbs[spec->num_init_verbs++] = alc269_init_verbs;
12291         spec->num_mux_defs = 1;
12292         spec->input_mux = &spec->private_imux;
12293         /* set default input source */
12294         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
12295                                   0, AC_VERB_SET_CONNECT_SEL,
12296                                   spec->input_mux->items[0].index);
12297
12298         err = alc_auto_add_mic_boost(codec);
12299         if (err < 0)
12300                 return err;
12301
12302         spec->mixers[spec->num_mixers] = alc269_capture_mixer;
12303         spec->num_mixers++;
12304
12305         store_pin_configs(codec);
12306         return 1;
12307 }
12308
12309 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
12310 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
12311 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
12312
12313
12314 /* init callback for auto-configuration model -- overriding the default init */
12315 static void alc269_auto_init(struct hda_codec *codec)
12316 {
12317         struct alc_spec *spec = codec->spec;
12318         alc269_auto_init_multi_out(codec);
12319         alc269_auto_init_hp_out(codec);
12320         alc269_auto_init_analog_input(codec);
12321         if (spec->unsol_event)
12322                 alc_inithook(codec);
12323 }
12324
12325 /*
12326  * configuration and preset
12327  */
12328 static const char *alc269_models[ALC269_MODEL_LAST] = {
12329         [ALC269_BASIC]                  = "basic",
12330         [ALC269_QUANTA_FL1]             = "quanta",
12331         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
12332         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901"
12333 };
12334
12335 static struct snd_pci_quirk alc269_cfg_tbl[] = {
12336         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
12337         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
12338                       ALC269_ASUS_EEEPC_P703),
12339         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
12340                       ALC269_ASUS_EEEPC_P901),
12341         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
12342                       ALC269_ASUS_EEEPC_P901),
12343         {}
12344 };
12345
12346 static struct alc_config_preset alc269_presets[] = {
12347         [ALC269_BASIC] = {
12348                 .mixers = { alc269_base_mixer, alc269_capture_mixer },
12349                 .init_verbs = { alc269_init_verbs },
12350                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12351                 .dac_nids = alc269_dac_nids,
12352                 .hp_nid = 0x03,
12353                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12354                 .channel_mode = alc269_modes,
12355                 .input_mux = &alc269_capture_source,
12356         },
12357         [ALC269_QUANTA_FL1] = {
12358                 .mixers = { alc269_quanta_fl1_mixer },
12359                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
12360                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12361                 .dac_nids = alc269_dac_nids,
12362                 .hp_nid = 0x03,
12363                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12364                 .channel_mode = alc269_modes,
12365                 .input_mux = &alc269_capture_source,
12366                 .unsol_event = alc269_quanta_fl1_unsol_event,
12367                 .init_hook = alc269_quanta_fl1_init_hook,
12368         },
12369         [ALC269_ASUS_EEEPC_P703] = {
12370                 .mixers = { alc269_eeepc_mixer, alc269_epc_capture_mixer },
12371                 .init_verbs = { alc269_init_verbs,
12372                                 alc269_eeepc_amic_init_verbs },
12373                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12374                 .dac_nids = alc269_dac_nids,
12375                 .hp_nid = 0x03,
12376                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12377                 .channel_mode = alc269_modes,
12378                 .input_mux = &alc269_eeepc_amic_capture_source,
12379                 .unsol_event = alc269_eeepc_amic_unsol_event,
12380                 .init_hook = alc269_eeepc_amic_inithook,
12381         },
12382         [ALC269_ASUS_EEEPC_P901] = {
12383                 .mixers = { alc269_eeepc_mixer, alc269_epc_capture_mixer},
12384                 .init_verbs = { alc269_init_verbs,
12385                                 alc269_eeepc_dmic_init_verbs },
12386                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12387                 .dac_nids = alc269_dac_nids,
12388                 .hp_nid = 0x03,
12389                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12390                 .channel_mode = alc269_modes,
12391                 .input_mux = &alc269_eeepc_dmic_capture_source,
12392                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12393                 .init_hook = alc269_eeepc_dmic_inithook,
12394         },
12395 };
12396
12397 static int patch_alc269(struct hda_codec *codec)
12398 {
12399         struct alc_spec *spec;
12400         int board_config;
12401         int err;
12402
12403         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12404         if (spec == NULL)
12405                 return -ENOMEM;
12406
12407         codec->spec = spec;
12408
12409         alc_fix_pll_init(codec, 0x20, 0x04, 15);
12410
12411         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
12412                                                   alc269_models,
12413                                                   alc269_cfg_tbl);
12414
12415         if (board_config < 0) {
12416                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
12417                        "trying auto-probe from BIOS...\n");
12418                 board_config = ALC269_AUTO;
12419         }
12420
12421         if (board_config == ALC269_AUTO) {
12422                 /* automatic parse from the BIOS config */
12423                 err = alc269_parse_auto_config(codec);
12424                 if (err < 0) {
12425                         alc_free(codec);
12426                         return err;
12427                 } else if (!err) {
12428                         printk(KERN_INFO
12429                                "hda_codec: Cannot set up configuration "
12430                                "from BIOS.  Using base mode...\n");
12431                         board_config = ALC269_BASIC;
12432                 }
12433         }
12434
12435         if (board_config != ALC269_AUTO)
12436                 setup_preset(spec, &alc269_presets[board_config]);
12437
12438         spec->stream_name_analog = "ALC269 Analog";
12439         spec->stream_analog_playback = &alc269_pcm_analog_playback;
12440         spec->stream_analog_capture = &alc269_pcm_analog_capture;
12441
12442         spec->stream_name_digital = "ALC269 Digital";
12443         spec->stream_digital_playback = &alc269_pcm_digital_playback;
12444         spec->stream_digital_capture = &alc269_pcm_digital_capture;
12445
12446         spec->adc_nids = alc269_adc_nids;
12447         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
12448         spec->capsrc_nids = alc269_capsrc_nids;
12449
12450         codec->patch_ops = alc_patch_ops;
12451         if (board_config == ALC269_AUTO)
12452                 spec->init_hook = alc269_auto_init;
12453 #ifdef CONFIG_SND_HDA_POWER_SAVE
12454         if (!spec->loopback.amplist)
12455                 spec->loopback.amplist = alc269_loopbacks;
12456 #endif
12457
12458         return 0;
12459 }
12460
12461 /*
12462  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
12463  */
12464
12465 /*
12466  * set the path ways for 2 channel output
12467  * need to set the codec line out and mic 1 pin widgets to inputs
12468  */
12469 static struct hda_verb alc861_threestack_ch2_init[] = {
12470         /* set pin widget 1Ah (line in) for input */
12471         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12472         /* set pin widget 18h (mic1/2) for input, for mic also enable
12473          * the vref
12474          */
12475         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12476
12477         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12478 #if 0
12479         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12480         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12481 #endif
12482         { } /* end */
12483 };
12484 /*
12485  * 6ch mode
12486  * need to set the codec line out and mic 1 pin widgets to outputs
12487  */
12488 static struct hda_verb alc861_threestack_ch6_init[] = {
12489         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12490         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12491         /* set pin widget 18h (mic1) for output (CLFE)*/
12492         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12493
12494         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12495         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12496
12497         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12498 #if 0
12499         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12500         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12501 #endif
12502         { } /* end */
12503 };
12504
12505 static struct hda_channel_mode alc861_threestack_modes[2] = {
12506         { 2, alc861_threestack_ch2_init },
12507         { 6, alc861_threestack_ch6_init },
12508 };
12509 /* Set mic1 as input and unmute the mixer */
12510 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
12511         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12512         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12513         { } /* end */
12514 };
12515 /* Set mic1 as output and mute mixer */
12516 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
12517         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12518         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12519         { } /* end */
12520 };
12521
12522 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
12523         { 2, alc861_uniwill_m31_ch2_init },
12524         { 4, alc861_uniwill_m31_ch4_init },
12525 };
12526
12527 /* Set mic1 and line-in as input and unmute the mixer */
12528 static struct hda_verb alc861_asus_ch2_init[] = {
12529         /* set pin widget 1Ah (line in) for input */
12530         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12531         /* set pin widget 18h (mic1/2) for input, for mic also enable
12532          * the vref
12533          */
12534         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12535
12536         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12537 #if 0
12538         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12539         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12540 #endif
12541         { } /* end */
12542 };
12543 /* Set mic1 nad line-in as output and mute mixer */
12544 static struct hda_verb alc861_asus_ch6_init[] = {
12545         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12546         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12547         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12548         /* set pin widget 18h (mic1) for output (CLFE)*/
12549         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12550         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12551         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12552         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12553
12554         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12555 #if 0
12556         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12557         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12558 #endif
12559         { } /* end */
12560 };
12561
12562 static struct hda_channel_mode alc861_asus_modes[2] = {
12563         { 2, alc861_asus_ch2_init },
12564         { 6, alc861_asus_ch6_init },
12565 };
12566
12567 /* patch-ALC861 */
12568
12569 static struct snd_kcontrol_new alc861_base_mixer[] = {
12570         /* output mixer control */
12571         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12572         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12573         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12574         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12575         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12576
12577         /*Input mixer control */
12578         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12579            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12580         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12581         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12582         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12583         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12584         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12585         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12586         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12587         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12588
12589         /* Capture mixer control */
12590         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12591         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12592         {
12593                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12594                 .name = "Capture Source",
12595                 .count = 1,
12596                 .info = alc_mux_enum_info,
12597                 .get = alc_mux_enum_get,
12598                 .put = alc_mux_enum_put,
12599         },
12600         { } /* end */
12601 };
12602
12603 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
12604         /* output mixer control */
12605         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12606         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12607         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12608         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12609         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12610
12611         /* Input mixer control */
12612         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12613            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12614         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12615         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12616         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12617         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12618         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12619         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12620         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12621         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12622
12623         /* Capture mixer control */
12624         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12625         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12626         {
12627                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12628                 .name = "Capture Source",
12629                 .count = 1,
12630                 .info = alc_mux_enum_info,
12631                 .get = alc_mux_enum_get,
12632                 .put = alc_mux_enum_put,
12633         },
12634         {
12635                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12636                 .name = "Channel Mode",
12637                 .info = alc_ch_mode_info,
12638                 .get = alc_ch_mode_get,
12639                 .put = alc_ch_mode_put,
12640                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
12641         },
12642         { } /* end */
12643 };
12644
12645 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
12646         /* output mixer control */
12647         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12648         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12649         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12650
12651         /*Capture mixer control */
12652         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12653         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12654         {
12655                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12656                 .name = "Capture Source",
12657                 .count = 1,
12658                 .info = alc_mux_enum_info,
12659                 .get = alc_mux_enum_get,
12660                 .put = alc_mux_enum_put,
12661         },
12662
12663         { } /* end */
12664 };
12665
12666 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
12667         /* output mixer control */
12668         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12669         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12670         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12671         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12672         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12673
12674         /* Input mixer control */
12675         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12676            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12677         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12678         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12679         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12680         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12681         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12682         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12683         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12684         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12685
12686         /* Capture mixer control */
12687         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12688         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12689         {
12690                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12691                 .name = "Capture Source",
12692                 .count = 1,
12693                 .info = alc_mux_enum_info,
12694                 .get = alc_mux_enum_get,
12695                 .put = alc_mux_enum_put,
12696         },
12697         {
12698                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12699                 .name = "Channel Mode",
12700                 .info = alc_ch_mode_info,
12701                 .get = alc_ch_mode_get,
12702                 .put = alc_ch_mode_put,
12703                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
12704         },
12705         { } /* end */
12706 };
12707
12708 static struct snd_kcontrol_new alc861_asus_mixer[] = {
12709         /* output mixer control */
12710         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12711         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12712         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12713         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12714         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12715
12716         /* Input mixer control */
12717         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12718         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12719         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12720         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12721         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12722         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12723         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12724         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12725         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12726         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
12727
12728         /* Capture mixer control */
12729         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12730         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12731         {
12732                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12733                 .name = "Capture Source",
12734                 .count = 1,
12735                 .info = alc_mux_enum_info,
12736                 .get = alc_mux_enum_get,
12737                 .put = alc_mux_enum_put,
12738         },
12739         {
12740                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12741                 .name = "Channel Mode",
12742                 .info = alc_ch_mode_info,
12743                 .get = alc_ch_mode_get,
12744                 .put = alc_ch_mode_put,
12745                 .private_value = ARRAY_SIZE(alc861_asus_modes),
12746         },
12747         { }
12748 };
12749
12750 /* additional mixer */
12751 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
12752         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12753         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12754         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
12755         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
12756         { }
12757 };
12758
12759 /*
12760  * generic initialization of ADC, input mixers and output mixers
12761  */
12762 static struct hda_verb alc861_base_init_verbs[] = {
12763         /*
12764          * Unmute ADC0 and set the default input to mic-in
12765          */
12766         /* port-A for surround (rear panel) */
12767         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12768         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
12769         /* port-B for mic-in (rear panel) with vref */
12770         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12771         /* port-C for line-in (rear panel) */
12772         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12773         /* port-D for Front */
12774         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12775         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12776         /* port-E for HP out (front panel) */
12777         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
12778         /* route front PCM to HP */
12779         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12780         /* port-F for mic-in (front panel) with vref */
12781         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12782         /* port-G for CLFE (rear panel) */
12783         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12784         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12785         /* port-H for side (rear panel) */
12786         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12787         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
12788         /* CD-in */
12789         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12790         /* route front mic to ADC1*/
12791         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12792         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12793
12794         /* Unmute DAC0~3 & spdif out*/
12795         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12796         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12797         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12798         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12799         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12800
12801         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12802         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12803         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12804         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12805         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12806
12807         /* Unmute Stereo Mixer 15 */
12808         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12809         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12810         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12811         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12812
12813         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12814         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12815         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12816         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12817         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12818         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12819         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12820         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12821         /* hp used DAC 3 (Front) */
12822         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12823         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12824
12825         { }
12826 };
12827
12828 static struct hda_verb alc861_threestack_init_verbs[] = {
12829         /*
12830          * Unmute ADC0 and set the default input to mic-in
12831          */
12832         /* port-A for surround (rear panel) */
12833         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12834         /* port-B for mic-in (rear panel) with vref */
12835         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12836         /* port-C for line-in (rear panel) */
12837         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12838         /* port-D for Front */
12839         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12840         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12841         /* port-E for HP out (front panel) */
12842         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
12843         /* route front PCM to HP */
12844         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12845         /* port-F for mic-in (front panel) with vref */
12846         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12847         /* port-G for CLFE (rear panel) */
12848         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12849         /* port-H for side (rear panel) */
12850         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12851         /* CD-in */
12852         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12853         /* route front mic to ADC1*/
12854         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12855         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12856         /* Unmute DAC0~3 & spdif out*/
12857         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12858         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12859         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12860         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12861         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12862
12863         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12864         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12865         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12866         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12867         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12868
12869         /* Unmute Stereo Mixer 15 */
12870         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12871         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12872         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12873         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12874
12875         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12876         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12877         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12878         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12879         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12880         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12881         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12882         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12883         /* hp used DAC 3 (Front) */
12884         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12885         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12886         { }
12887 };
12888
12889 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
12890         /*
12891          * Unmute ADC0 and set the default input to mic-in
12892          */
12893         /* port-A for surround (rear panel) */
12894         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12895         /* port-B for mic-in (rear panel) with vref */
12896         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12897         /* port-C for line-in (rear panel) */
12898         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12899         /* port-D for Front */
12900         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12901         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12902         /* port-E for HP out (front panel) */
12903         /* this has to be set to VREF80 */
12904         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12905         /* route front PCM to HP */
12906         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12907         /* port-F for mic-in (front panel) with vref */
12908         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12909         /* port-G for CLFE (rear panel) */
12910         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12911         /* port-H for side (rear panel) */
12912         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12913         /* CD-in */
12914         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12915         /* route front mic to ADC1*/
12916         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12917         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12918         /* Unmute DAC0~3 & spdif out*/
12919         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12920         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12921         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12922         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12923         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12924
12925         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12926         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12927         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12928         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12929         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12930
12931         /* Unmute Stereo Mixer 15 */
12932         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12933         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12934         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12935         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12936
12937         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12938         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12939         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12940         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12941         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12942         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12943         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12944         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12945         /* hp used DAC 3 (Front) */
12946         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12947         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12948         { }
12949 };
12950
12951 static struct hda_verb alc861_asus_init_verbs[] = {
12952         /*
12953          * Unmute ADC0 and set the default input to mic-in
12954          */
12955         /* port-A for surround (rear panel)
12956          * according to codec#0 this is the HP jack
12957          */
12958         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
12959         /* route front PCM to HP */
12960         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
12961         /* port-B for mic-in (rear panel) with vref */
12962         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12963         /* port-C for line-in (rear panel) */
12964         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12965         /* port-D for Front */
12966         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12967         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12968         /* port-E for HP out (front panel) */
12969         /* this has to be set to VREF80 */
12970         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12971         /* route front PCM to HP */
12972         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12973         /* port-F for mic-in (front panel) with vref */
12974         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12975         /* port-G for CLFE (rear panel) */
12976         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12977         /* port-H for side (rear panel) */
12978         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12979         /* CD-in */
12980         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12981         /* route front mic to ADC1*/
12982         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12983         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12984         /* Unmute DAC0~3 & spdif out*/
12985         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12986         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12987         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12988         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12989         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12990         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12991         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12992         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12993         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12994         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12995
12996         /* Unmute Stereo Mixer 15 */
12997         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12998         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12999         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13000         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13001
13002         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13003         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13004         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13005         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13006         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13007         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13008         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13009         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13010         /* hp used DAC 3 (Front) */
13011         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13012         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13013         { }
13014 };
13015
13016 /* additional init verbs for ASUS laptops */
13017 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
13018         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
13019         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
13020         { }
13021 };
13022
13023 /*
13024  * generic initialization of ADC, input mixers and output mixers
13025  */
13026 static struct hda_verb alc861_auto_init_verbs[] = {
13027         /*
13028          * Unmute ADC0 and set the default input to mic-in
13029          */
13030         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
13031         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13032
13033         /* Unmute DAC0~3 & spdif out*/
13034         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13035         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13036         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13037         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13038         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13039
13040         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13041         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13042         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13043         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13044         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13045
13046         /* Unmute Stereo Mixer 15 */
13047         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13048         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13049         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13050         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
13051
13052         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13053         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13054         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13055         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13056         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13057         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13058         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13059         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13060
13061         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13062         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13063         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13064         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13065         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13066         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13067         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13068         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13069
13070         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
13071
13072         { }
13073 };
13074
13075 static struct hda_verb alc861_toshiba_init_verbs[] = {
13076         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13077
13078         { }
13079 };
13080
13081 /* toggle speaker-output according to the hp-jack state */
13082 static void alc861_toshiba_automute(struct hda_codec *codec)
13083 {
13084         unsigned int present;
13085
13086         present = snd_hda_codec_read(codec, 0x0f, 0,
13087                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13088         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
13089                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
13090         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
13091                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
13092 }
13093
13094 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
13095                                        unsigned int res)
13096 {
13097         if ((res >> 26) == ALC880_HP_EVENT)
13098                 alc861_toshiba_automute(codec);
13099 }
13100
13101 /* pcm configuration: identiacal with ALC880 */
13102 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
13103 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
13104 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
13105 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
13106
13107
13108 #define ALC861_DIGOUT_NID       0x07
13109
13110 static struct hda_channel_mode alc861_8ch_modes[1] = {
13111         { 8, NULL }
13112 };
13113
13114 static hda_nid_t alc861_dac_nids[4] = {
13115         /* front, surround, clfe, side */
13116         0x03, 0x06, 0x05, 0x04
13117 };
13118
13119 static hda_nid_t alc660_dac_nids[3] = {
13120         /* front, clfe, surround */
13121         0x03, 0x05, 0x06
13122 };
13123
13124 static hda_nid_t alc861_adc_nids[1] = {
13125         /* ADC0-2 */
13126         0x08,
13127 };
13128
13129 static struct hda_input_mux alc861_capture_source = {
13130         .num_items = 5,
13131         .items = {
13132                 { "Mic", 0x0 },
13133                 { "Front Mic", 0x3 },
13134                 { "Line", 0x1 },
13135                 { "CD", 0x4 },
13136                 { "Mixer", 0x5 },
13137         },
13138 };
13139
13140 /* fill in the dac_nids table from the parsed pin configuration */
13141 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
13142                                      const struct auto_pin_cfg *cfg)
13143 {
13144         int i;
13145         hda_nid_t nid;
13146
13147         spec->multiout.dac_nids = spec->private_dac_nids;
13148         for (i = 0; i < cfg->line_outs; i++) {
13149                 nid = cfg->line_out_pins[i];
13150                 if (nid) {
13151                         if (i >= ARRAY_SIZE(alc861_dac_nids))
13152                                 continue;
13153                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
13154                 }
13155         }
13156         spec->multiout.num_dacs = cfg->line_outs;
13157         return 0;
13158 }
13159
13160 /* add playback controls from the parsed DAC table */
13161 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
13162                                              const struct auto_pin_cfg *cfg)
13163 {
13164         char name[32];
13165         static const char *chname[4] = {
13166                 "Front", "Surround", NULL /*CLFE*/, "Side"
13167         };
13168         hda_nid_t nid;
13169         int i, idx, err;
13170
13171         for (i = 0; i < cfg->line_outs; i++) {
13172                 nid = spec->multiout.dac_nids[i];
13173                 if (!nid)
13174                         continue;
13175                 if (nid == 0x05) {
13176                         /* Center/LFE */
13177                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13178                                           "Center Playback Switch",
13179                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
13180                                                               HDA_OUTPUT));
13181                         if (err < 0)
13182                                 return err;
13183                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13184                                           "LFE Playback Switch",
13185                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13186                                                               HDA_OUTPUT));
13187                         if (err < 0)
13188                                 return err;
13189                 } else {
13190                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
13191                              idx++)
13192                                 if (nid == alc861_dac_nids[idx])
13193                                         break;
13194                         sprintf(name, "%s Playback Switch", chname[idx]);
13195                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13196                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13197                                                               HDA_OUTPUT));
13198                         if (err < 0)
13199                                 return err;
13200                 }
13201         }
13202         return 0;
13203 }
13204
13205 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
13206 {
13207         int err;
13208         hda_nid_t nid;
13209
13210         if (!pin)
13211                 return 0;
13212
13213         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
13214                 nid = 0x03;
13215                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13216                                   "Headphone Playback Switch",
13217                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13218                 if (err < 0)
13219                         return err;
13220                 spec->multiout.hp_nid = nid;
13221         }
13222         return 0;
13223 }
13224
13225 /* create playback/capture controls for input pins */
13226 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
13227                                                 const struct auto_pin_cfg *cfg)
13228 {
13229         struct hda_input_mux *imux = &spec->private_imux;
13230         int i, err, idx, idx1;
13231
13232         for (i = 0; i < AUTO_PIN_LAST; i++) {
13233                 switch (cfg->input_pins[i]) {
13234                 case 0x0c:
13235                         idx1 = 1;
13236                         idx = 2;        /* Line In */
13237                         break;
13238                 case 0x0f:
13239                         idx1 = 2;
13240                         idx = 2;        /* Line In */
13241                         break;
13242                 case 0x0d:
13243                         idx1 = 0;
13244                         idx = 1;        /* Mic In */
13245                         break;
13246                 case 0x10:
13247                         idx1 = 3;
13248                         idx = 1;        /* Mic In */
13249                         break;
13250                 case 0x11:
13251                         idx1 = 4;
13252                         idx = 0;        /* CD */
13253                         break;
13254                 default:
13255                         continue;
13256                 }
13257
13258                 err = new_analog_input(spec, cfg->input_pins[i],
13259                                        auto_pin_cfg_labels[i], idx, 0x15);
13260                 if (err < 0)
13261                         return err;
13262
13263                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
13264                 imux->items[imux->num_items].index = idx1;
13265                 imux->num_items++;
13266         }
13267         return 0;
13268 }
13269
13270 static struct snd_kcontrol_new alc861_capture_mixer[] = {
13271         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
13272         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
13273
13274         {
13275                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13276                 /* The multiple "Capture Source" controls confuse alsamixer
13277                  * So call somewhat different..
13278                  */
13279                 /* .name = "Capture Source", */
13280                 .name = "Input Source",
13281                 .count = 1,
13282                 .info = alc_mux_enum_info,
13283                 .get = alc_mux_enum_get,
13284                 .put = alc_mux_enum_put,
13285         },
13286         { } /* end */
13287 };
13288
13289 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
13290                                               hda_nid_t nid,
13291                                               int pin_type, int dac_idx)
13292 {
13293         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
13294                             pin_type);
13295         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13296                             AMP_OUT_UNMUTE);
13297 }
13298
13299 static void alc861_auto_init_multi_out(struct hda_codec *codec)
13300 {
13301         struct alc_spec *spec = codec->spec;
13302         int i;
13303
13304         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
13305         for (i = 0; i < spec->autocfg.line_outs; i++) {
13306                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13307                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13308                 if (nid)
13309                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
13310                                                           spec->multiout.dac_nids[i]);
13311         }
13312 }
13313
13314 static void alc861_auto_init_hp_out(struct hda_codec *codec)
13315 {
13316         struct alc_spec *spec = codec->spec;
13317         hda_nid_t pin;
13318
13319         pin = spec->autocfg.hp_pins[0];
13320         if (pin) /* connect to front */
13321                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
13322                                                   spec->multiout.dac_nids[0]);
13323         pin = spec->autocfg.speaker_pins[0];
13324         if (pin)
13325                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13326 }
13327
13328 static void alc861_auto_init_analog_input(struct hda_codec *codec)
13329 {
13330         struct alc_spec *spec = codec->spec;
13331         int i;
13332
13333         for (i = 0; i < AUTO_PIN_LAST; i++) {
13334                 hda_nid_t nid = spec->autocfg.input_pins[i];
13335                 if (nid >= 0x0c && nid <= 0x11) {
13336                         snd_hda_codec_write(codec, nid, 0,
13337                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
13338                                             i <= AUTO_PIN_FRONT_MIC ?
13339                                             PIN_VREF80 : PIN_IN);
13340                 }
13341         }
13342 }
13343
13344 /* parse the BIOS configuration and set up the alc_spec */
13345 /* return 1 if successful, 0 if the proper config is not found,
13346  * or a negative error code
13347  */
13348 static int alc861_parse_auto_config(struct hda_codec *codec)
13349 {
13350         struct alc_spec *spec = codec->spec;
13351         int err;
13352         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
13353
13354         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13355                                            alc861_ignore);
13356         if (err < 0)
13357                 return err;
13358         if (!spec->autocfg.line_outs)
13359                 return 0; /* can't find valid BIOS pin config */
13360
13361         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
13362         if (err < 0)
13363                 return err;
13364         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
13365         if (err < 0)
13366                 return err;
13367         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
13368         if (err < 0)
13369                 return err;
13370         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
13371         if (err < 0)
13372                 return err;
13373
13374         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13375
13376         if (spec->autocfg.dig_out_pin)
13377                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
13378
13379         if (spec->kctl_alloc)
13380                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
13381
13382         spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs;
13383
13384         spec->num_mux_defs = 1;
13385         spec->input_mux = &spec->private_imux;
13386
13387         spec->adc_nids = alc861_adc_nids;
13388         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
13389         spec->mixers[spec->num_mixers] = alc861_capture_mixer;
13390         spec->num_mixers++;
13391
13392         store_pin_configs(codec);
13393         return 1;
13394 }
13395
13396 /* additional initialization for auto-configuration model */
13397 static void alc861_auto_init(struct hda_codec *codec)
13398 {
13399         struct alc_spec *spec = codec->spec;
13400         alc861_auto_init_multi_out(codec);
13401         alc861_auto_init_hp_out(codec);
13402         alc861_auto_init_analog_input(codec);
13403         if (spec->unsol_event)
13404                 alc_inithook(codec);
13405 }
13406
13407 #ifdef CONFIG_SND_HDA_POWER_SAVE
13408 static struct hda_amp_list alc861_loopbacks[] = {
13409         { 0x15, HDA_INPUT, 0 },
13410         { 0x15, HDA_INPUT, 1 },
13411         { 0x15, HDA_INPUT, 2 },
13412         { 0x15, HDA_INPUT, 3 },
13413         { } /* end */
13414 };
13415 #endif
13416
13417
13418 /*
13419  * configuration and preset
13420  */
13421 static const char *alc861_models[ALC861_MODEL_LAST] = {
13422         [ALC861_3ST]            = "3stack",
13423         [ALC660_3ST]            = "3stack-660",
13424         [ALC861_3ST_DIG]        = "3stack-dig",
13425         [ALC861_6ST_DIG]        = "6stack-dig",
13426         [ALC861_UNIWILL_M31]    = "uniwill-m31",
13427         [ALC861_TOSHIBA]        = "toshiba",
13428         [ALC861_ASUS]           = "asus",
13429         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
13430         [ALC861_AUTO]           = "auto",
13431 };
13432
13433 static struct snd_pci_quirk alc861_cfg_tbl[] = {
13434         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
13435         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13436         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13437         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
13438         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
13439         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
13440         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
13441         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
13442          *        Any other models that need this preset?
13443          */
13444         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
13445         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
13446         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
13447         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
13448         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
13449         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
13450         /* FIXME: the below seems conflict */
13451         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
13452         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
13453         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
13454         {}
13455 };
13456
13457 static struct alc_config_preset alc861_presets[] = {
13458         [ALC861_3ST] = {
13459                 .mixers = { alc861_3ST_mixer },
13460                 .init_verbs = { alc861_threestack_init_verbs },
13461                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13462                 .dac_nids = alc861_dac_nids,
13463                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13464                 .channel_mode = alc861_threestack_modes,
13465                 .need_dac_fix = 1,
13466                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13467                 .adc_nids = alc861_adc_nids,
13468                 .input_mux = &alc861_capture_source,
13469         },
13470         [ALC861_3ST_DIG] = {
13471                 .mixers = { alc861_base_mixer },
13472                 .init_verbs = { alc861_threestack_init_verbs },
13473                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13474                 .dac_nids = alc861_dac_nids,
13475                 .dig_out_nid = ALC861_DIGOUT_NID,
13476                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13477                 .channel_mode = alc861_threestack_modes,
13478                 .need_dac_fix = 1,
13479                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13480                 .adc_nids = alc861_adc_nids,
13481                 .input_mux = &alc861_capture_source,
13482         },
13483         [ALC861_6ST_DIG] = {
13484                 .mixers = { alc861_base_mixer },
13485                 .init_verbs = { alc861_base_init_verbs },
13486                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13487                 .dac_nids = alc861_dac_nids,
13488                 .dig_out_nid = ALC861_DIGOUT_NID,
13489                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
13490                 .channel_mode = alc861_8ch_modes,
13491                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13492                 .adc_nids = alc861_adc_nids,
13493                 .input_mux = &alc861_capture_source,
13494         },
13495         [ALC660_3ST] = {
13496                 .mixers = { alc861_3ST_mixer },
13497                 .init_verbs = { alc861_threestack_init_verbs },
13498                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
13499                 .dac_nids = alc660_dac_nids,
13500                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13501                 .channel_mode = alc861_threestack_modes,
13502                 .need_dac_fix = 1,
13503                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13504                 .adc_nids = alc861_adc_nids,
13505                 .input_mux = &alc861_capture_source,
13506         },
13507         [ALC861_UNIWILL_M31] = {
13508                 .mixers = { alc861_uniwill_m31_mixer },
13509                 .init_verbs = { alc861_uniwill_m31_init_verbs },
13510                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13511                 .dac_nids = alc861_dac_nids,
13512                 .dig_out_nid = ALC861_DIGOUT_NID,
13513                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
13514                 .channel_mode = alc861_uniwill_m31_modes,
13515                 .need_dac_fix = 1,
13516                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13517                 .adc_nids = alc861_adc_nids,
13518                 .input_mux = &alc861_capture_source,
13519         },
13520         [ALC861_TOSHIBA] = {
13521                 .mixers = { alc861_toshiba_mixer },
13522                 .init_verbs = { alc861_base_init_verbs,
13523                                 alc861_toshiba_init_verbs },
13524                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13525                 .dac_nids = alc861_dac_nids,
13526                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13527                 .channel_mode = alc883_3ST_2ch_modes,
13528                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13529                 .adc_nids = alc861_adc_nids,
13530                 .input_mux = &alc861_capture_source,
13531                 .unsol_event = alc861_toshiba_unsol_event,
13532                 .init_hook = alc861_toshiba_automute,
13533         },
13534         [ALC861_ASUS] = {
13535                 .mixers = { alc861_asus_mixer },
13536                 .init_verbs = { alc861_asus_init_verbs },
13537                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13538                 .dac_nids = alc861_dac_nids,
13539                 .dig_out_nid = ALC861_DIGOUT_NID,
13540                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
13541                 .channel_mode = alc861_asus_modes,
13542                 .need_dac_fix = 1,
13543                 .hp_nid = 0x06,
13544                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13545                 .adc_nids = alc861_adc_nids,
13546                 .input_mux = &alc861_capture_source,
13547         },
13548         [ALC861_ASUS_LAPTOP] = {
13549                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
13550                 .init_verbs = { alc861_asus_init_verbs,
13551                                 alc861_asus_laptop_init_verbs },
13552                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13553                 .dac_nids = alc861_dac_nids,
13554                 .dig_out_nid = ALC861_DIGOUT_NID,
13555                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13556                 .channel_mode = alc883_3ST_2ch_modes,
13557                 .need_dac_fix = 1,
13558                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13559                 .adc_nids = alc861_adc_nids,
13560                 .input_mux = &alc861_capture_source,
13561         },
13562 };
13563
13564
13565 static int patch_alc861(struct hda_codec *codec)
13566 {
13567         struct alc_spec *spec;
13568         int board_config;
13569         int err;
13570
13571         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13572         if (spec == NULL)
13573                 return -ENOMEM;
13574
13575         codec->spec = spec;
13576
13577         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
13578                                                   alc861_models,
13579                                                   alc861_cfg_tbl);
13580
13581         if (board_config < 0) {
13582                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
13583                        "trying auto-probe from BIOS...\n");
13584                 board_config = ALC861_AUTO;
13585         }
13586
13587         if (board_config == ALC861_AUTO) {
13588                 /* automatic parse from the BIOS config */
13589                 err = alc861_parse_auto_config(codec);
13590                 if (err < 0) {
13591                         alc_free(codec);
13592                         return err;
13593                 } else if (!err) {
13594                         printk(KERN_INFO
13595                                "hda_codec: Cannot set up configuration "
13596                                "from BIOS.  Using base mode...\n");
13597                    board_config = ALC861_3ST_DIG;
13598                 }
13599         }
13600
13601         if (board_config != ALC861_AUTO)
13602                 setup_preset(spec, &alc861_presets[board_config]);
13603
13604         spec->stream_name_analog = "ALC861 Analog";
13605         spec->stream_analog_playback = &alc861_pcm_analog_playback;
13606         spec->stream_analog_capture = &alc861_pcm_analog_capture;
13607
13608         spec->stream_name_digital = "ALC861 Digital";
13609         spec->stream_digital_playback = &alc861_pcm_digital_playback;
13610         spec->stream_digital_capture = &alc861_pcm_digital_capture;
13611
13612         spec->vmaster_nid = 0x03;
13613
13614         codec->patch_ops = alc_patch_ops;
13615         if (board_config == ALC861_AUTO)
13616                 spec->init_hook = alc861_auto_init;
13617 #ifdef CONFIG_SND_HDA_POWER_SAVE
13618         if (!spec->loopback.amplist)
13619                 spec->loopback.amplist = alc861_loopbacks;
13620 #endif
13621
13622         return 0;
13623 }
13624
13625 /*
13626  * ALC861-VD support
13627  *
13628  * Based on ALC882
13629  *
13630  * In addition, an independent DAC
13631  */
13632 #define ALC861VD_DIGOUT_NID     0x06
13633
13634 static hda_nid_t alc861vd_dac_nids[4] = {
13635         /* front, surr, clfe, side surr */
13636         0x02, 0x03, 0x04, 0x05
13637 };
13638
13639 /* dac_nids for ALC660vd are in a different order - according to
13640  * Realtek's driver.
13641  * This should probably tesult in a different mixer for 6stack models
13642  * of ALC660vd codecs, but for now there is only 3stack mixer
13643  * - and it is the same as in 861vd.
13644  * adc_nids in ALC660vd are (is) the same as in 861vd
13645  */
13646 static hda_nid_t alc660vd_dac_nids[3] = {
13647         /* front, rear, clfe, rear_surr */
13648         0x02, 0x04, 0x03
13649 };
13650
13651 static hda_nid_t alc861vd_adc_nids[1] = {
13652         /* ADC0 */
13653         0x09,
13654 };
13655
13656 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
13657
13658 /* input MUX */
13659 /* FIXME: should be a matrix-type input source selection */
13660 static struct hda_input_mux alc861vd_capture_source = {
13661         .num_items = 4,
13662         .items = {
13663                 { "Mic", 0x0 },
13664                 { "Front Mic", 0x1 },
13665                 { "Line", 0x2 },
13666                 { "CD", 0x4 },
13667         },
13668 };
13669
13670 static struct hda_input_mux alc861vd_dallas_capture_source = {
13671         .num_items = 2,
13672         .items = {
13673                 { "Ext Mic", 0x0 },
13674                 { "Int Mic", 0x1 },
13675         },
13676 };
13677
13678 static struct hda_input_mux alc861vd_hp_capture_source = {
13679         .num_items = 2,
13680         .items = {
13681                 { "Front Mic", 0x0 },
13682                 { "ATAPI Mic", 0x1 },
13683         },
13684 };
13685
13686 #define alc861vd_mux_enum_info alc_mux_enum_info
13687 #define alc861vd_mux_enum_get alc_mux_enum_get
13688 /* ALC861VD has the ALC882-type input selection (but has only one ADC) */
13689 #define alc861vd_mux_enum_put alc882_mux_enum_put
13690
13691 /*
13692  * 2ch mode
13693  */
13694 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
13695         { 2, NULL }
13696 };
13697
13698 /*
13699  * 6ch mode
13700  */
13701 static struct hda_verb alc861vd_6stack_ch6_init[] = {
13702         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13703         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13704         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13705         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13706         { } /* end */
13707 };
13708
13709 /*
13710  * 8ch mode
13711  */
13712 static struct hda_verb alc861vd_6stack_ch8_init[] = {
13713         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13714         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13715         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13716         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13717         { } /* end */
13718 };
13719
13720 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
13721         { 6, alc861vd_6stack_ch6_init },
13722         { 8, alc861vd_6stack_ch8_init },
13723 };
13724
13725 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
13726         {
13727                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13728                 .name = "Channel Mode",
13729                 .info = alc_ch_mode_info,
13730                 .get = alc_ch_mode_get,
13731                 .put = alc_ch_mode_put,
13732         },
13733         { } /* end */
13734 };
13735
13736 static struct snd_kcontrol_new alc861vd_capture_mixer[] = {
13737         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
13738         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
13739
13740         {
13741                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13742                 /* The multiple "Capture Source" controls confuse alsamixer
13743                  * So call somewhat different..
13744                  */
13745                 /* .name = "Capture Source", */
13746                 .name = "Input Source",
13747                 .count = 1,
13748                 .info = alc861vd_mux_enum_info,
13749                 .get = alc861vd_mux_enum_get,
13750                 .put = alc861vd_mux_enum_put,
13751         },
13752         { } /* end */
13753 };
13754
13755 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
13756  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
13757  */
13758 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
13759         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13760         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13761
13762         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13763         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
13764
13765         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
13766                                 HDA_OUTPUT),
13767         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
13768                                 HDA_OUTPUT),
13769         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
13770         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
13771
13772         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
13773         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
13774
13775         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13776
13777         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13778         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13779         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13780
13781         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13782         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13783         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13784
13785         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13786         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13787
13788         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13789         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13790
13791         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13792         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13793
13794         { } /* end */
13795 };
13796
13797 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
13798         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13799         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13800
13801         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13802
13803         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13804         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13805         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13806
13807         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13808         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13809         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13810
13811         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13812         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13813
13814         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13815         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13816
13817         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13818         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13819
13820         { } /* end */
13821 };
13822
13823 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
13824         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13825         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
13826         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13827
13828         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13829
13830         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13831         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13832         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13833
13834         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13835         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13836         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13837
13838         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13839         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13840
13841         { } /* end */
13842 };
13843
13844 /* Pin assignment: Speaker=0x14, HP = 0x15,
13845  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
13846  */
13847 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
13848         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13849         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
13850         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13851         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
13852         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
13853         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13854         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13855         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
13856         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13857         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13858         HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
13859         HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
13860         { } /* end */
13861 };
13862
13863 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
13864  *                 Front Mic=0x18, ATAPI Mic = 0x19,
13865  */
13866 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
13867         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13868         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13869         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13870         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
13871         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13872         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13873         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13874         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13875
13876         { } /* end */
13877 };
13878
13879 /*
13880  * generic initialization of ADC, input mixers and output mixers
13881  */
13882 static struct hda_verb alc861vd_volume_init_verbs[] = {
13883         /*
13884          * Unmute ADC0 and set the default input to mic-in
13885          */
13886         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
13887         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13888
13889         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
13890          * the analog-loopback mixer widget
13891          */
13892         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
13893         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13894         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13895         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13896         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13897         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13898
13899         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
13900         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13901         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13902         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13903         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
13904
13905         /*
13906          * Set up output mixers (0x02 - 0x05)
13907          */
13908         /* set vol=0 to output mixers */
13909         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13910         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13911         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13912         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13913
13914         /* set up input amps for analog loopback */
13915         /* Amp Indices: DAC = 0, mixer = 1 */
13916         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13917         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13918         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13919         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13920         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13921         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13922         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13923         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13924
13925         { }
13926 };
13927
13928 /*
13929  * 3-stack pin configuration:
13930  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
13931  */
13932 static struct hda_verb alc861vd_3stack_init_verbs[] = {
13933         /*
13934          * Set pin mode and muting
13935          */
13936         /* set front pin widgets 0x14 for output */
13937         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13938         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13939         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13940
13941         /* Mic (rear) pin: input vref at 80% */
13942         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13943         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13944         /* Front Mic pin: input vref at 80% */
13945         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13946         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13947         /* Line In pin: input */
13948         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13949         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13950         /* Line-2 In: Headphone output (output 0 - 0x0c) */
13951         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13952         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13953         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13954         /* CD pin widget for input */
13955         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13956
13957         { }
13958 };
13959
13960 /*
13961  * 6-stack pin configuration:
13962  */
13963 static struct hda_verb alc861vd_6stack_init_verbs[] = {
13964         /*
13965          * Set pin mode and muting
13966          */
13967         /* set front pin widgets 0x14 for output */
13968         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13969         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13970         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13971
13972         /* Rear Pin: output 1 (0x0d) */
13973         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13974         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13975         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13976         /* CLFE Pin: output 2 (0x0e) */
13977         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13978         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13979         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
13980         /* Side Pin: output 3 (0x0f) */
13981         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13982         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13983         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
13984
13985         /* Mic (rear) pin: input vref at 80% */
13986         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13987         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13988         /* Front Mic pin: input vref at 80% */
13989         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13990         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13991         /* Line In pin: input */
13992         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13993         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13994         /* Line-2 In: Headphone output (output 0 - 0x0c) */
13995         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13996         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13997         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13998         /* CD pin widget for input */
13999         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14000
14001         { }
14002 };
14003
14004 static struct hda_verb alc861vd_eapd_verbs[] = {
14005         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14006         { }
14007 };
14008
14009 static struct hda_verb alc660vd_eapd_verbs[] = {
14010         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14011         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
14012         { }
14013 };
14014
14015 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
14016         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14017         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14018         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
14019         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14020         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14021         {}
14022 };
14023
14024 /* toggle speaker-output according to the hp-jack state */
14025 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
14026 {
14027         unsigned int present;
14028         unsigned char bits;
14029
14030         present = snd_hda_codec_read(codec, 0x1b, 0,
14031                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14032         bits = present ? HDA_AMP_MUTE : 0;
14033         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14034                                  HDA_AMP_MUTE, bits);
14035 }
14036
14037 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
14038 {
14039         unsigned int present;
14040         unsigned char bits;
14041
14042         present = snd_hda_codec_read(codec, 0x18, 0,
14043                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14044         bits = present ? HDA_AMP_MUTE : 0;
14045         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
14046                                  HDA_AMP_MUTE, bits);
14047 }
14048
14049 static void alc861vd_lenovo_automute(struct hda_codec *codec)
14050 {
14051         alc861vd_lenovo_hp_automute(codec);
14052         alc861vd_lenovo_mic_automute(codec);
14053 }
14054
14055 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
14056                                         unsigned int res)
14057 {
14058         switch (res >> 26) {
14059         case ALC880_HP_EVENT:
14060                 alc861vd_lenovo_hp_automute(codec);
14061                 break;
14062         case ALC880_MIC_EVENT:
14063                 alc861vd_lenovo_mic_automute(codec);
14064                 break;
14065         }
14066 }
14067
14068 static struct hda_verb alc861vd_dallas_verbs[] = {
14069         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14070         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14071         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14072         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14073
14074         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14075         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14076         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14077         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14078         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14079         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14080         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14081         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14082
14083         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14084         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14085         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14086         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14087         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14088         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14089         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14090         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14091
14092         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14093         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14094         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14095         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14096         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14097         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14098         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14099         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14100
14101         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14102         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14103         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14104         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14105
14106         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14107         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14108         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14109
14110         { } /* end */
14111 };
14112
14113 /* toggle speaker-output according to the hp-jack state */
14114 static void alc861vd_dallas_automute(struct hda_codec *codec)
14115 {
14116         unsigned int present;
14117
14118         present = snd_hda_codec_read(codec, 0x15, 0,
14119                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14120         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14121                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14122 }
14123
14124 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
14125 {
14126         if ((res >> 26) == ALC880_HP_EVENT)
14127                 alc861vd_dallas_automute(codec);
14128 }
14129
14130 #ifdef CONFIG_SND_HDA_POWER_SAVE
14131 #define alc861vd_loopbacks      alc880_loopbacks
14132 #endif
14133
14134 /* pcm configuration: identiacal with ALC880 */
14135 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
14136 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
14137 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
14138 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
14139
14140 /*
14141  * configuration and preset
14142  */
14143 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
14144         [ALC660VD_3ST]          = "3stack-660",
14145         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
14146         [ALC861VD_3ST]          = "3stack",
14147         [ALC861VD_3ST_DIG]      = "3stack-digout",
14148         [ALC861VD_6ST_DIG]      = "6stack-digout",
14149         [ALC861VD_LENOVO]       = "lenovo",
14150         [ALC861VD_DALLAS]       = "dallas",
14151         [ALC861VD_HP]           = "hp",
14152         [ALC861VD_AUTO]         = "auto",
14153 };
14154
14155 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
14156         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
14157         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
14158         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
14159         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
14160         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC861VD_LENOVO),
14161         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
14162         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
14163         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
14164         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
14165         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
14166         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
14167         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
14168         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
14169         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
14170         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
14171         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 N200", ALC861VD_LENOVO),
14172         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
14173         {}
14174 };
14175
14176 static struct alc_config_preset alc861vd_presets[] = {
14177         [ALC660VD_3ST] = {
14178                 .mixers = { alc861vd_3st_mixer },
14179                 .init_verbs = { alc861vd_volume_init_verbs,
14180                                  alc861vd_3stack_init_verbs },
14181                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14182                 .dac_nids = alc660vd_dac_nids,
14183                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14184                 .channel_mode = alc861vd_3stack_2ch_modes,
14185                 .input_mux = &alc861vd_capture_source,
14186         },
14187         [ALC660VD_3ST_DIG] = {
14188                 .mixers = { alc861vd_3st_mixer },
14189                 .init_verbs = { alc861vd_volume_init_verbs,
14190                                  alc861vd_3stack_init_verbs },
14191                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14192                 .dac_nids = alc660vd_dac_nids,
14193                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14194                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14195                 .channel_mode = alc861vd_3stack_2ch_modes,
14196                 .input_mux = &alc861vd_capture_source,
14197         },
14198         [ALC861VD_3ST] = {
14199                 .mixers = { alc861vd_3st_mixer },
14200                 .init_verbs = { alc861vd_volume_init_verbs,
14201                                  alc861vd_3stack_init_verbs },
14202                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14203                 .dac_nids = alc861vd_dac_nids,
14204                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14205                 .channel_mode = alc861vd_3stack_2ch_modes,
14206                 .input_mux = &alc861vd_capture_source,
14207         },
14208         [ALC861VD_3ST_DIG] = {
14209                 .mixers = { alc861vd_3st_mixer },
14210                 .init_verbs = { alc861vd_volume_init_verbs,
14211                                  alc861vd_3stack_init_verbs },
14212                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14213                 .dac_nids = alc861vd_dac_nids,
14214                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14215                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14216                 .channel_mode = alc861vd_3stack_2ch_modes,
14217                 .input_mux = &alc861vd_capture_source,
14218         },
14219         [ALC861VD_6ST_DIG] = {
14220                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
14221                 .init_verbs = { alc861vd_volume_init_verbs,
14222                                 alc861vd_6stack_init_verbs },
14223                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14224                 .dac_nids = alc861vd_dac_nids,
14225                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14226                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
14227                 .channel_mode = alc861vd_6stack_modes,
14228                 .input_mux = &alc861vd_capture_source,
14229         },
14230         [ALC861VD_LENOVO] = {
14231                 .mixers = { alc861vd_lenovo_mixer },
14232                 .init_verbs = { alc861vd_volume_init_verbs,
14233                                 alc861vd_3stack_init_verbs,
14234                                 alc861vd_eapd_verbs,
14235                                 alc861vd_lenovo_unsol_verbs },
14236                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14237                 .dac_nids = alc660vd_dac_nids,
14238                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14239                 .channel_mode = alc861vd_3stack_2ch_modes,
14240                 .input_mux = &alc861vd_capture_source,
14241                 .unsol_event = alc861vd_lenovo_unsol_event,
14242                 .init_hook = alc861vd_lenovo_automute,
14243         },
14244         [ALC861VD_DALLAS] = {
14245                 .mixers = { alc861vd_dallas_mixer },
14246                 .init_verbs = { alc861vd_dallas_verbs },
14247                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14248                 .dac_nids = alc861vd_dac_nids,
14249                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14250                 .channel_mode = alc861vd_3stack_2ch_modes,
14251                 .input_mux = &alc861vd_dallas_capture_source,
14252                 .unsol_event = alc861vd_dallas_unsol_event,
14253                 .init_hook = alc861vd_dallas_automute,
14254         },
14255         [ALC861VD_HP] = {
14256                 .mixers = { alc861vd_hp_mixer },
14257                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
14258                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14259                 .dac_nids = alc861vd_dac_nids,
14260                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14261                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14262                 .channel_mode = alc861vd_3stack_2ch_modes,
14263                 .input_mux = &alc861vd_hp_capture_source,
14264                 .unsol_event = alc861vd_dallas_unsol_event,
14265                 .init_hook = alc861vd_dallas_automute,
14266         },
14267 };
14268
14269 /*
14270  * BIOS auto configuration
14271  */
14272 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
14273                                 hda_nid_t nid, int pin_type, int dac_idx)
14274 {
14275         alc_set_pin_output(codec, nid, pin_type);
14276 }
14277
14278 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
14279 {
14280         struct alc_spec *spec = codec->spec;
14281         int i;
14282
14283         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
14284         for (i = 0; i <= HDA_SIDE; i++) {
14285                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14286                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14287                 if (nid)
14288                         alc861vd_auto_set_output_and_unmute(codec, nid,
14289                                                             pin_type, i);
14290         }
14291 }
14292
14293
14294 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
14295 {
14296         struct alc_spec *spec = codec->spec;
14297         hda_nid_t pin;
14298
14299         pin = spec->autocfg.hp_pins[0];
14300         if (pin) /* connect to front and  use dac 0 */
14301                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
14302         pin = spec->autocfg.speaker_pins[0];
14303         if (pin)
14304                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14305 }
14306
14307 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
14308 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
14309
14310 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
14311 {
14312         struct alc_spec *spec = codec->spec;
14313         int i;
14314
14315         for (i = 0; i < AUTO_PIN_LAST; i++) {
14316                 hda_nid_t nid = spec->autocfg.input_pins[i];
14317                 if (alc861vd_is_input_pin(nid)) {
14318                         snd_hda_codec_write(codec, nid, 0,
14319                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
14320                                         i <= AUTO_PIN_FRONT_MIC ?
14321                                                         PIN_VREF80 : PIN_IN);
14322                         if (nid != ALC861VD_PIN_CD_NID)
14323                                 snd_hda_codec_write(codec, nid, 0,
14324                                                 AC_VERB_SET_AMP_GAIN_MUTE,
14325                                                 AMP_OUT_MUTE);
14326                 }
14327         }
14328 }
14329
14330 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
14331
14332 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
14333 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
14334
14335 /* add playback controls from the parsed DAC table */
14336 /* Based on ALC880 version. But ALC861VD has separate,
14337  * different NIDs for mute/unmute switch and volume control */
14338 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
14339                                              const struct auto_pin_cfg *cfg)
14340 {
14341         char name[32];
14342         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
14343         hda_nid_t nid_v, nid_s;
14344         int i, err;
14345
14346         for (i = 0; i < cfg->line_outs; i++) {
14347                 if (!spec->multiout.dac_nids[i])
14348                         continue;
14349                 nid_v = alc861vd_idx_to_mixer_vol(
14350                                 alc880_dac_to_idx(
14351                                         spec->multiout.dac_nids[i]));
14352                 nid_s = alc861vd_idx_to_mixer_switch(
14353                                 alc880_dac_to_idx(
14354                                         spec->multiout.dac_nids[i]));
14355
14356                 if (i == 2) {
14357                         /* Center/LFE */
14358                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14359                                           "Center Playback Volume",
14360                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
14361                                                               HDA_OUTPUT));
14362                         if (err < 0)
14363                                 return err;
14364                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14365                                           "LFE Playback Volume",
14366                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
14367                                                               HDA_OUTPUT));
14368                         if (err < 0)
14369                                 return err;
14370                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14371                                           "Center Playback Switch",
14372                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
14373                                                               HDA_INPUT));
14374                         if (err < 0)
14375                                 return err;
14376                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14377                                           "LFE Playback Switch",
14378                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
14379                                                               HDA_INPUT));
14380                         if (err < 0)
14381                                 return err;
14382                 } else {
14383                         sprintf(name, "%s Playback Volume", chname[i]);
14384                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14385                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
14386                                                               HDA_OUTPUT));
14387                         if (err < 0)
14388                                 return err;
14389                         sprintf(name, "%s Playback Switch", chname[i]);
14390                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14391                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
14392                                                               HDA_INPUT));
14393                         if (err < 0)
14394                                 return err;
14395                 }
14396         }
14397         return 0;
14398 }
14399
14400 /* add playback controls for speaker and HP outputs */
14401 /* Based on ALC880 version. But ALC861VD has separate,
14402  * different NIDs for mute/unmute switch and volume control */
14403 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
14404                                         hda_nid_t pin, const char *pfx)
14405 {
14406         hda_nid_t nid_v, nid_s;
14407         int err;
14408         char name[32];
14409
14410         if (!pin)
14411                 return 0;
14412
14413         if (alc880_is_fixed_pin(pin)) {
14414                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14415                 /* specify the DAC as the extra output */
14416                 if (!spec->multiout.hp_nid)
14417                         spec->multiout.hp_nid = nid_v;
14418                 else
14419                         spec->multiout.extra_out_nid[0] = nid_v;
14420                 /* control HP volume/switch on the output mixer amp */
14421                 nid_v = alc861vd_idx_to_mixer_vol(
14422                                 alc880_fixed_pin_idx(pin));
14423                 nid_s = alc861vd_idx_to_mixer_switch(
14424                                 alc880_fixed_pin_idx(pin));
14425
14426                 sprintf(name, "%s Playback Volume", pfx);
14427                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14428                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
14429                 if (err < 0)
14430                         return err;
14431                 sprintf(name, "%s Playback Switch", pfx);
14432                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14433                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
14434                 if (err < 0)
14435                         return err;
14436         } else if (alc880_is_multi_pin(pin)) {
14437                 /* set manual connection */
14438                 /* we have only a switch on HP-out PIN */
14439                 sprintf(name, "%s Playback Switch", pfx);
14440                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14441                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
14442                 if (err < 0)
14443                         return err;
14444         }
14445         return 0;
14446 }
14447
14448 /* parse the BIOS configuration and set up the alc_spec
14449  * return 1 if successful, 0 if the proper config is not found,
14450  * or a negative error code
14451  * Based on ALC880 version - had to change it to override
14452  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
14453 static int alc861vd_parse_auto_config(struct hda_codec *codec)
14454 {
14455         struct alc_spec *spec = codec->spec;
14456         int err;
14457         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
14458
14459         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14460                                            alc861vd_ignore);
14461         if (err < 0)
14462                 return err;
14463         if (!spec->autocfg.line_outs)
14464                 return 0; /* can't find valid BIOS pin config */
14465
14466         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
14467         if (err < 0)
14468                 return err;
14469         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
14470         if (err < 0)
14471                 return err;
14472         err = alc861vd_auto_create_extra_out(spec,
14473                                              spec->autocfg.speaker_pins[0],
14474                                              "Speaker");
14475         if (err < 0)
14476                 return err;
14477         err = alc861vd_auto_create_extra_out(spec,
14478                                              spec->autocfg.hp_pins[0],
14479                                              "Headphone");
14480         if (err < 0)
14481                 return err;
14482         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
14483         if (err < 0)
14484                 return err;
14485
14486         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14487
14488         if (spec->autocfg.dig_out_pin)
14489                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
14490
14491         if (spec->kctl_alloc)
14492                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
14493
14494         spec->init_verbs[spec->num_init_verbs++]
14495                 = alc861vd_volume_init_verbs;
14496
14497         spec->num_mux_defs = 1;
14498         spec->input_mux = &spec->private_imux;
14499
14500         err = alc_auto_add_mic_boost(codec);
14501         if (err < 0)
14502                 return err;
14503
14504         store_pin_configs(codec);
14505         return 1;
14506 }
14507
14508 /* additional initialization for auto-configuration model */
14509 static void alc861vd_auto_init(struct hda_codec *codec)
14510 {
14511         struct alc_spec *spec = codec->spec;
14512         alc861vd_auto_init_multi_out(codec);
14513         alc861vd_auto_init_hp_out(codec);
14514         alc861vd_auto_init_analog_input(codec);
14515         alc861vd_auto_init_input_src(codec);
14516         if (spec->unsol_event)
14517                 alc_inithook(codec);
14518 }
14519
14520 static int patch_alc861vd(struct hda_codec *codec)
14521 {
14522         struct alc_spec *spec;
14523         int err, board_config;
14524
14525         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14526         if (spec == NULL)
14527                 return -ENOMEM;
14528
14529         codec->spec = spec;
14530
14531         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
14532                                                   alc861vd_models,
14533                                                   alc861vd_cfg_tbl);
14534
14535         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
14536                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
14537                         "ALC861VD, trying auto-probe from BIOS...\n");
14538                 board_config = ALC861VD_AUTO;
14539         }
14540
14541         if (board_config == ALC861VD_AUTO) {
14542                 /* automatic parse from the BIOS config */
14543                 err = alc861vd_parse_auto_config(codec);
14544                 if (err < 0) {
14545                         alc_free(codec);
14546                         return err;
14547                 } else if (!err) {
14548                         printk(KERN_INFO
14549                                "hda_codec: Cannot set up configuration "
14550                                "from BIOS.  Using base mode...\n");
14551                         board_config = ALC861VD_3ST;
14552                 }
14553         }
14554
14555         if (board_config != ALC861VD_AUTO)
14556                 setup_preset(spec, &alc861vd_presets[board_config]);
14557
14558         if (codec->vendor_id == 0x10ec0660) {
14559                 spec->stream_name_analog = "ALC660-VD Analog";
14560                 spec->stream_name_digital = "ALC660-VD Digital";
14561                 /* always turn on EAPD */
14562                 spec->init_verbs[spec->num_init_verbs++] = alc660vd_eapd_verbs;
14563         } else {
14564                 spec->stream_name_analog = "ALC861VD Analog";
14565                 spec->stream_name_digital = "ALC861VD Digital";
14566         }
14567
14568         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
14569         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
14570
14571         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
14572         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
14573
14574         spec->adc_nids = alc861vd_adc_nids;
14575         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
14576         spec->capsrc_nids = alc861vd_capsrc_nids;
14577
14578         spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
14579         spec->num_mixers++;
14580
14581         spec->vmaster_nid = 0x02;
14582
14583         codec->patch_ops = alc_patch_ops;
14584
14585         if (board_config == ALC861VD_AUTO)
14586                 spec->init_hook = alc861vd_auto_init;
14587 #ifdef CONFIG_SND_HDA_POWER_SAVE
14588         if (!spec->loopback.amplist)
14589                 spec->loopback.amplist = alc861vd_loopbacks;
14590 #endif
14591
14592         return 0;
14593 }
14594
14595 /*
14596  * ALC662 support
14597  *
14598  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
14599  * configuration.  Each pin widget can choose any input DACs and a mixer.
14600  * Each ADC is connected from a mixer of all inputs.  This makes possible
14601  * 6-channel independent captures.
14602  *
14603  * In addition, an independent DAC for the multi-playback (not used in this
14604  * driver yet).
14605  */
14606 #define ALC662_DIGOUT_NID       0x06
14607 #define ALC662_DIGIN_NID        0x0a
14608
14609 static hda_nid_t alc662_dac_nids[4] = {
14610         /* front, rear, clfe, rear_surr */
14611         0x02, 0x03, 0x04
14612 };
14613
14614 static hda_nid_t alc662_adc_nids[1] = {
14615         /* ADC1-2 */
14616         0x09,
14617 };
14618
14619 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
14620
14621 /* input MUX */
14622 /* FIXME: should be a matrix-type input source selection */
14623 static struct hda_input_mux alc662_capture_source = {
14624         .num_items = 4,
14625         .items = {
14626                 { "Mic", 0x0 },
14627                 { "Front Mic", 0x1 },
14628                 { "Line", 0x2 },
14629                 { "CD", 0x4 },
14630         },
14631 };
14632
14633 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
14634         .num_items = 2,
14635         .items = {
14636                 { "Mic", 0x1 },
14637                 { "Line", 0x2 },
14638         },
14639 };
14640
14641 static struct hda_input_mux alc662_eeepc_capture_source = {
14642         .num_items = 2,
14643         .items = {
14644                 { "i-Mic", 0x1 },
14645                 { "e-Mic", 0x0 },
14646         },
14647 };
14648
14649 static struct hda_input_mux alc663_capture_source = {
14650         .num_items = 3,
14651         .items = {
14652                 { "Mic", 0x0 },
14653                 { "Front Mic", 0x1 },
14654                 { "Line", 0x2 },
14655         },
14656 };
14657
14658 static struct hda_input_mux alc663_m51va_capture_source = {
14659         .num_items = 2,
14660         .items = {
14661                 { "Ext-Mic", 0x0 },
14662                 { "D-Mic", 0x9 },
14663         },
14664 };
14665
14666 #define alc662_mux_enum_info alc_mux_enum_info
14667 #define alc662_mux_enum_get alc_mux_enum_get
14668 #define alc662_mux_enum_put alc882_mux_enum_put
14669
14670 /*
14671  * 2ch mode
14672  */
14673 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
14674         { 2, NULL }
14675 };
14676
14677 /*
14678  * 2ch mode
14679  */
14680 static struct hda_verb alc662_3ST_ch2_init[] = {
14681         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
14682         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14683         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
14684         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14685         { } /* end */
14686 };
14687
14688 /*
14689  * 6ch mode
14690  */
14691 static struct hda_verb alc662_3ST_ch6_init[] = {
14692         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14693         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14694         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
14695         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14696         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14697         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
14698         { } /* end */
14699 };
14700
14701 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
14702         { 2, alc662_3ST_ch2_init },
14703         { 6, alc662_3ST_ch6_init },
14704 };
14705
14706 /*
14707  * 2ch mode
14708  */
14709 static struct hda_verb alc662_sixstack_ch6_init[] = {
14710         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14711         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14712         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14713         { } /* end */
14714 };
14715
14716 /*
14717  * 6ch mode
14718  */
14719 static struct hda_verb alc662_sixstack_ch8_init[] = {
14720         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14721         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14722         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14723         { } /* end */
14724 };
14725
14726 static struct hda_channel_mode alc662_5stack_modes[2] = {
14727         { 2, alc662_sixstack_ch6_init },
14728         { 6, alc662_sixstack_ch8_init },
14729 };
14730
14731 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14732  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14733  */
14734
14735 static struct snd_kcontrol_new alc662_base_mixer[] = {
14736         /* output mixer control */
14737         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
14738         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14739         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
14740         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
14741         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14742         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14743         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
14744         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
14745         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14746
14747         /*Input mixer control */
14748         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
14749         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
14750         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
14751         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
14752         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
14753         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
14754         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
14755         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
14756         { } /* end */
14757 };
14758
14759 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
14760         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14761         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14762         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14763         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14764         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14765         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14766         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14767         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14768         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14769         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14770         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14771         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14772         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14773         { } /* end */
14774 };
14775
14776 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
14777         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14778         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14779         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14780         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
14781         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14782         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14783         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
14784         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
14785         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14786         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14787         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14788         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14789         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14790         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14791         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14792         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14793         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14794         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14795         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14796         { } /* end */
14797 };
14798
14799 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
14800         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14801         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
14802         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14803         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
14804         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14805         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14806         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14807         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14808         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14809         { } /* end */
14810 };
14811
14812 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
14813         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14814
14815         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14816         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14817
14818         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
14819         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14820         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14821
14822         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
14823         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14824         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14825         { } /* end */
14826 };
14827
14828 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
14829         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14830         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14831         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14832         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
14833         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14834         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14835         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
14836         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
14837         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14838         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
14839         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14840         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14841         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14842         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14843         { } /* end */
14844 };
14845
14846 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
14847         .ops = &snd_hda_bind_vol,
14848         .values = {
14849                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
14850                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
14851                 0
14852         },
14853 };
14854
14855 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
14856         .ops = &snd_hda_bind_sw,
14857         .values = {
14858                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14859                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
14860                 0
14861         },
14862 };
14863
14864 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
14865         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14866         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
14867         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14868         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14869         { } /* end */
14870 };
14871
14872 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
14873         .ops = &snd_hda_bind_sw,
14874         .values = {
14875                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14876                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
14877                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
14878                 0
14879         },
14880 };
14881
14882 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
14883         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14884         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
14885         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14886         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14887         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14888         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14889
14890         { } /* end */
14891 };
14892
14893 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
14894         .ops = &snd_hda_bind_sw,
14895         .values = {
14896                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14897                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
14898                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
14899                 0
14900         },
14901 };
14902
14903 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
14904         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14905         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
14906         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14907         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14908         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14909         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14910         { } /* end */
14911 };
14912
14913 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
14914         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14915         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14916         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14917         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14918         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14919         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14920         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14921         { } /* end */
14922 };
14923
14924 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
14925         .ops = &snd_hda_bind_vol,
14926         .values = {
14927                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
14928                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
14929                 0
14930         },
14931 };
14932
14933 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
14934         .ops = &snd_hda_bind_sw,
14935         .values = {
14936                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
14937                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
14938                 0
14939         },
14940 };
14941
14942 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
14943         HDA_BIND_VOL("Master Playback Volume",
14944                                 &alc663_asus_two_bind_master_vol),
14945         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
14946         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14947         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
14948         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14949         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14950         { } /* end */
14951 };
14952
14953 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
14954         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
14955         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
14956         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14957         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
14958         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14959         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14960         { } /* end */
14961 };
14962
14963 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
14964         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14965         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14966         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14967         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
14968         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
14969
14970         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14971         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14972         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14973         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14974         { } /* end */
14975 };
14976
14977 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
14978         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14979         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14980         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
14981
14982         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14983         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14984         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14985         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14986         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14987         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14988         { } /* end */
14989 };
14990
14991 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
14992         {
14993                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14994                 .name = "Channel Mode",
14995                 .info = alc_ch_mode_info,
14996                 .get = alc_ch_mode_get,
14997                 .put = alc_ch_mode_put,
14998         },
14999         { } /* end */
15000 };
15001
15002 static struct hda_verb alc662_init_verbs[] = {
15003         /* ADC: mute amp left and right */
15004         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15005         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15006         /* Front mixer: unmute input/output amp left and right (volume = 0) */
15007
15008         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15009         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15010         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15011         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15012         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15013
15014         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15015         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15016         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15017         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15018         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15019         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15020
15021         /* Front Pin: output 0 (0x0c) */
15022         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15023         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15024
15025         /* Rear Pin: output 1 (0x0d) */
15026         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15027         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15028
15029         /* CLFE Pin: output 2 (0x0e) */
15030         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15031         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15032
15033         /* Mic (rear) pin: input vref at 80% */
15034         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15035         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15036         /* Front Mic pin: input vref at 80% */
15037         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15038         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15039         /* Line In pin: input */
15040         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15041         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15042         /* Line-2 In: Headphone output (output 0 - 0x0c) */
15043         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15044         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15045         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
15046         /* CD pin widget for input */
15047         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15048
15049         /* FIXME: use matrix-type input source selection */
15050         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15051         /* Input mixer */
15052         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15053         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15054         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15055         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15056
15057         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15058         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15059         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15060         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15061
15062         /* always trun on EAPD */
15063         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15064         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
15065
15066         { }
15067 };
15068
15069 static struct hda_verb alc662_sue_init_verbs[] = {
15070         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15071         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15072         {}
15073 };
15074
15075 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
15076         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15077         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15078         {}
15079 };
15080
15081 /* Set Unsolicited Event*/
15082 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
15083         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15084         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15085         {}
15086 };
15087
15088 /*
15089  * generic initialization of ADC, input mixers and output mixers
15090  */
15091 static struct hda_verb alc662_auto_init_verbs[] = {
15092         /*
15093          * Unmute ADC and set the default input to mic-in
15094          */
15095         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15096         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15097
15098         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
15099          * mixer widget
15100          * Note: PASD motherboards uses the Line In 2 as the input for front
15101          * panel mic (mic 2)
15102          */
15103         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
15104         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15105         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15106         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15107         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15108         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15109
15110         /*
15111          * Set up output mixers (0x0c - 0x0f)
15112          */
15113         /* set vol=0 to output mixers */
15114         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15115         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15116         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15117
15118         /* set up input amps for analog loopback */
15119         /* Amp Indices: DAC = 0, mixer = 1 */
15120         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15121         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15122         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15123         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15124         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15125         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15126
15127
15128         /* FIXME: use matrix-type input source selection */
15129         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15130         /* Input mixer */
15131         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15132         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15133         { }
15134 };
15135
15136 /* additional verbs for ALC663 */
15137 static struct hda_verb alc663_auto_init_verbs[] = {
15138         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15139         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15140         { }
15141 };
15142
15143 static struct hda_verb alc663_m51va_init_verbs[] = {
15144         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15145         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15146         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15147         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15148         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15149         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15150         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
15151         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15152         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15153         {}
15154 };
15155
15156 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
15157         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15158         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15159         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15160         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15161         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15162         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15163         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15164         {}
15165 };
15166
15167 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
15168         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15169         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15170         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15171         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15172         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15173         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15174         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15175         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15176         {}
15177 };
15178
15179 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
15180         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15181         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15182         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15183         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15184         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15185         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15186         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15187         {}
15188 };
15189
15190 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
15191         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15192         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15193         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15194         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15195         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15196         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15197         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15198         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15199         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15200         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15201         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15202         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15203         {}
15204 };
15205
15206 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
15207         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15208         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15209         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15210         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15211         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15212         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15213         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15214         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15215         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15216         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15217         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15218         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15219         {}
15220 };
15221
15222 static struct hda_verb alc663_g71v_init_verbs[] = {
15223         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15224         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
15225         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
15226
15227         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15228         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15229         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15230
15231         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15232         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
15233         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15234         {}
15235 };
15236
15237 static struct hda_verb alc663_g50v_init_verbs[] = {
15238         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15239         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15240         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15241
15242         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15243         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15244         {}
15245 };
15246
15247 static struct hda_verb alc662_ecs_init_verbs[] = {
15248         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
15249         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15250         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15251         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15252         {}
15253 };
15254
15255 /* capture mixer elements */
15256 static struct snd_kcontrol_new alc662_capture_mixer[] = {
15257         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
15258         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
15259         {
15260                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15261                 /* The multiple "Capture Source" controls confuse alsamixer
15262                  * So call somewhat different..
15263                  */
15264                 /* .name = "Capture Source", */
15265                 .name = "Input Source",
15266                 .count = 1,
15267                 .info = alc662_mux_enum_info,
15268                 .get = alc662_mux_enum_get,
15269                 .put = alc662_mux_enum_put,
15270         },
15271         { } /* end */
15272 };
15273
15274 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
15275         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
15276         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
15277         { } /* end */
15278 };
15279
15280 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
15281 {
15282         unsigned int present;
15283         unsigned char bits;
15284
15285         present = snd_hda_codec_read(codec, 0x14, 0,
15286                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15287         bits = present ? HDA_AMP_MUTE : 0;
15288         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15289                                  HDA_AMP_MUTE, bits);
15290 }
15291
15292 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
15293 {
15294         unsigned int present;
15295         unsigned char bits;
15296
15297         present = snd_hda_codec_read(codec, 0x1b, 0,
15298                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15299         bits = present ? HDA_AMP_MUTE : 0;
15300         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15301                                  HDA_AMP_MUTE, bits);
15302         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15303                                  HDA_AMP_MUTE, bits);
15304 }
15305
15306 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
15307                                            unsigned int res)
15308 {
15309         if ((res >> 26) == ALC880_HP_EVENT)
15310                 alc662_lenovo_101e_all_automute(codec);
15311         if ((res >> 26) == ALC880_FRONT_EVENT)
15312                 alc662_lenovo_101e_ispeaker_automute(codec);
15313 }
15314
15315 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
15316 {
15317         unsigned int present;
15318
15319         present = snd_hda_codec_read(codec, 0x18, 0,
15320                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15321         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15322                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15323         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15324                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15325         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15326                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15327         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15328                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15329 }
15330
15331 /* unsolicited event for HP jack sensing */
15332 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
15333                                      unsigned int res)
15334 {
15335         if ((res >> 26) == ALC880_HP_EVENT)
15336                 alc262_hippo1_automute( codec );
15337
15338         if ((res >> 26) == ALC880_MIC_EVENT)
15339                 alc662_eeepc_mic_automute(codec);
15340 }
15341
15342 static void alc662_eeepc_inithook(struct hda_codec *codec)
15343 {
15344         alc262_hippo1_automute( codec );
15345         alc662_eeepc_mic_automute(codec);
15346 }
15347
15348 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
15349 {
15350         unsigned int mute;
15351         unsigned int present;
15352
15353         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
15354         present = snd_hda_codec_read(codec, 0x14, 0,
15355                                      AC_VERB_GET_PIN_SENSE, 0);
15356         present = (present & 0x80000000) != 0;
15357         if (present) {
15358                 /* mute internal speaker */
15359                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15360                                         HDA_AMP_MUTE, HDA_AMP_MUTE);
15361         } else {
15362                 /* unmute internal speaker if necessary */
15363                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
15364                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15365                                         HDA_AMP_MUTE, mute);
15366         }
15367 }
15368
15369 /* unsolicited event for HP jack sensing */
15370 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
15371                                           unsigned int res)
15372 {
15373         if ((res >> 26) == ALC880_HP_EVENT)
15374                 alc662_eeepc_ep20_automute(codec);
15375 }
15376
15377 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
15378 {
15379         alc662_eeepc_ep20_automute(codec);
15380 }
15381
15382 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
15383 {
15384         unsigned int present;
15385         unsigned char bits;
15386
15387         present = snd_hda_codec_read(codec, 0x21, 0,
15388                         AC_VERB_GET_PIN_SENSE, 0)
15389                         & AC_PINSENSE_PRESENCE;
15390         bits = present ? HDA_AMP_MUTE : 0;
15391         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15392                                 AMP_IN_MUTE(0), bits);
15393         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15394                                 AMP_IN_MUTE(0), bits);
15395 }
15396
15397 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
15398 {
15399         unsigned int present;
15400         unsigned char bits;
15401
15402         present = snd_hda_codec_read(codec, 0x21, 0,
15403                         AC_VERB_GET_PIN_SENSE, 0)
15404                         & AC_PINSENSE_PRESENCE;
15405         bits = present ? HDA_AMP_MUTE : 0;
15406         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15407                                 AMP_IN_MUTE(0), bits);
15408         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15409                                 AMP_IN_MUTE(0), bits);
15410         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15411                                 AMP_IN_MUTE(0), bits);
15412         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15413                                 AMP_IN_MUTE(0), bits);
15414 }
15415
15416 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
15417 {
15418         unsigned int present;
15419         unsigned char bits;
15420
15421         present = snd_hda_codec_read(codec, 0x15, 0,
15422                         AC_VERB_GET_PIN_SENSE, 0)
15423                         & AC_PINSENSE_PRESENCE;
15424         bits = present ? HDA_AMP_MUTE : 0;
15425         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15426                                 AMP_IN_MUTE(0), bits);
15427         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15428                                 AMP_IN_MUTE(0), bits);
15429         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15430                                 AMP_IN_MUTE(0), bits);
15431         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15432                                 AMP_IN_MUTE(0), bits);
15433 }
15434
15435 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
15436 {
15437         unsigned int present;
15438         unsigned char bits;
15439
15440         present = snd_hda_codec_read(codec, 0x1b, 0,
15441                         AC_VERB_GET_PIN_SENSE, 0)
15442                         & AC_PINSENSE_PRESENCE;
15443         bits = present ? 0 : PIN_OUT;
15444         snd_hda_codec_write(codec, 0x14, 0,
15445                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
15446 }
15447
15448 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
15449 {
15450         unsigned int present1, present2;
15451
15452         present1 = snd_hda_codec_read(codec, 0x21, 0,
15453                         AC_VERB_GET_PIN_SENSE, 0)
15454                         & AC_PINSENSE_PRESENCE;
15455         present2 = snd_hda_codec_read(codec, 0x15, 0,
15456                         AC_VERB_GET_PIN_SENSE, 0)
15457                         & AC_PINSENSE_PRESENCE;
15458
15459         if (present1 || present2) {
15460                 snd_hda_codec_write_cache(codec, 0x14, 0,
15461                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
15462         } else {
15463                 snd_hda_codec_write_cache(codec, 0x14, 0,
15464                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
15465         }
15466 }
15467
15468 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
15469 {
15470         unsigned int present1, present2;
15471
15472         present1 = snd_hda_codec_read(codec, 0x1b, 0,
15473                                 AC_VERB_GET_PIN_SENSE, 0)
15474                                 & AC_PINSENSE_PRESENCE;
15475         present2 = snd_hda_codec_read(codec, 0x15, 0,
15476                                 AC_VERB_GET_PIN_SENSE, 0)
15477                                 & AC_PINSENSE_PRESENCE;
15478
15479         if (present1 || present2) {
15480                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15481                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15482                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15483                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15484         } else {
15485                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15486                                 AMP_IN_MUTE(0), 0);
15487                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15488                                 AMP_IN_MUTE(0), 0);
15489         }
15490 }
15491
15492 static void alc663_m51va_mic_automute(struct hda_codec *codec)
15493 {
15494         unsigned int present;
15495
15496         present = snd_hda_codec_read(codec, 0x18, 0,
15497                         AC_VERB_GET_PIN_SENSE, 0)
15498                         & AC_PINSENSE_PRESENCE;
15499         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15500                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15501         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15502                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15503         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15504                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15505         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15506                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15507 }
15508
15509 static void alc663_m51va_unsol_event(struct hda_codec *codec,
15510                                            unsigned int res)
15511 {
15512         switch (res >> 26) {
15513         case ALC880_HP_EVENT:
15514                 alc663_m51va_speaker_automute(codec);
15515                 break;
15516         case ALC880_MIC_EVENT:
15517                 alc663_m51va_mic_automute(codec);
15518                 break;
15519         }
15520 }
15521
15522 static void alc663_m51va_inithook(struct hda_codec *codec)
15523 {
15524         alc663_m51va_speaker_automute(codec);
15525         alc663_m51va_mic_automute(codec);
15526 }
15527
15528 /* ***************** Mode1 ******************************/
15529 static void alc663_mode1_unsol_event(struct hda_codec *codec,
15530                                            unsigned int res)
15531 {
15532         switch (res >> 26) {
15533         case ALC880_HP_EVENT:
15534                 alc663_m51va_speaker_automute(codec);
15535                 break;
15536         case ALC880_MIC_EVENT:
15537                 alc662_eeepc_mic_automute(codec);
15538                 break;
15539         }
15540 }
15541
15542 static void alc663_mode1_inithook(struct hda_codec *codec)
15543 {
15544         alc663_m51va_speaker_automute(codec);
15545         alc662_eeepc_mic_automute(codec);
15546 }
15547 /* ***************** Mode2 ******************************/
15548 static void alc662_mode2_unsol_event(struct hda_codec *codec,
15549                                            unsigned int res)
15550 {
15551         switch (res >> 26) {
15552         case ALC880_HP_EVENT:
15553                 alc662_f5z_speaker_automute(codec);
15554                 break;
15555         case ALC880_MIC_EVENT:
15556                 alc662_eeepc_mic_automute(codec);
15557                 break;
15558         }
15559 }
15560
15561 static void alc662_mode2_inithook(struct hda_codec *codec)
15562 {
15563         alc662_f5z_speaker_automute(codec);
15564         alc662_eeepc_mic_automute(codec);
15565 }
15566 /* ***************** Mode3 ******************************/
15567 static void alc663_mode3_unsol_event(struct hda_codec *codec,
15568                                            unsigned int res)
15569 {
15570         switch (res >> 26) {
15571         case ALC880_HP_EVENT:
15572                 alc663_two_hp_m1_speaker_automute(codec);
15573                 break;
15574         case ALC880_MIC_EVENT:
15575                 alc662_eeepc_mic_automute(codec);
15576                 break;
15577         }
15578 }
15579
15580 static void alc663_mode3_inithook(struct hda_codec *codec)
15581 {
15582         alc663_two_hp_m1_speaker_automute(codec);
15583         alc662_eeepc_mic_automute(codec);
15584 }
15585 /* ***************** Mode4 ******************************/
15586 static void alc663_mode4_unsol_event(struct hda_codec *codec,
15587                                            unsigned int res)
15588 {
15589         switch (res >> 26) {
15590         case ALC880_HP_EVENT:
15591                 alc663_21jd_two_speaker_automute(codec);
15592                 break;
15593         case ALC880_MIC_EVENT:
15594                 alc662_eeepc_mic_automute(codec);
15595                 break;
15596         }
15597 }
15598
15599 static void alc663_mode4_inithook(struct hda_codec *codec)
15600 {
15601         alc663_21jd_two_speaker_automute(codec);
15602         alc662_eeepc_mic_automute(codec);
15603 }
15604 /* ***************** Mode5 ******************************/
15605 static void alc663_mode5_unsol_event(struct hda_codec *codec,
15606                                            unsigned int res)
15607 {
15608         switch (res >> 26) {
15609         case ALC880_HP_EVENT:
15610                 alc663_15jd_two_speaker_automute(codec);
15611                 break;
15612         case ALC880_MIC_EVENT:
15613                 alc662_eeepc_mic_automute(codec);
15614                 break;
15615         }
15616 }
15617
15618 static void alc663_mode5_inithook(struct hda_codec *codec)
15619 {
15620         alc663_15jd_two_speaker_automute(codec);
15621         alc662_eeepc_mic_automute(codec);
15622 }
15623 /* ***************** Mode6 ******************************/
15624 static void alc663_mode6_unsol_event(struct hda_codec *codec,
15625                                            unsigned int res)
15626 {
15627         switch (res >> 26) {
15628         case ALC880_HP_EVENT:
15629                 alc663_two_hp_m2_speaker_automute(codec);
15630                 break;
15631         case ALC880_MIC_EVENT:
15632                 alc662_eeepc_mic_automute(codec);
15633                 break;
15634         }
15635 }
15636
15637 static void alc663_mode6_inithook(struct hda_codec *codec)
15638 {
15639         alc663_two_hp_m2_speaker_automute(codec);
15640         alc662_eeepc_mic_automute(codec);
15641 }
15642
15643 static void alc663_g71v_hp_automute(struct hda_codec *codec)
15644 {
15645         unsigned int present;
15646         unsigned char bits;
15647
15648         present = snd_hda_codec_read(codec, 0x21, 0,
15649                                      AC_VERB_GET_PIN_SENSE, 0)
15650                 & AC_PINSENSE_PRESENCE;
15651         bits = present ? HDA_AMP_MUTE : 0;
15652         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15653                                  HDA_AMP_MUTE, bits);
15654         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15655                                  HDA_AMP_MUTE, bits);
15656 }
15657
15658 static void alc663_g71v_front_automute(struct hda_codec *codec)
15659 {
15660         unsigned int present;
15661         unsigned char bits;
15662
15663         present = snd_hda_codec_read(codec, 0x15, 0,
15664                                      AC_VERB_GET_PIN_SENSE, 0)
15665                 & AC_PINSENSE_PRESENCE;
15666         bits = present ? HDA_AMP_MUTE : 0;
15667         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15668                                  HDA_AMP_MUTE, bits);
15669 }
15670
15671 static void alc663_g71v_unsol_event(struct hda_codec *codec,
15672                                            unsigned int res)
15673 {
15674         switch (res >> 26) {
15675         case ALC880_HP_EVENT:
15676                 alc663_g71v_hp_automute(codec);
15677                 break;
15678         case ALC880_FRONT_EVENT:
15679                 alc663_g71v_front_automute(codec);
15680                 break;
15681         case ALC880_MIC_EVENT:
15682                 alc662_eeepc_mic_automute(codec);
15683                 break;
15684         }
15685 }
15686
15687 static void alc663_g71v_inithook(struct hda_codec *codec)
15688 {
15689         alc663_g71v_front_automute(codec);
15690         alc663_g71v_hp_automute(codec);
15691         alc662_eeepc_mic_automute(codec);
15692 }
15693
15694 static void alc663_g50v_unsol_event(struct hda_codec *codec,
15695                                            unsigned int res)
15696 {
15697         switch (res >> 26) {
15698         case ALC880_HP_EVENT:
15699                 alc663_m51va_speaker_automute(codec);
15700                 break;
15701         case ALC880_MIC_EVENT:
15702                 alc662_eeepc_mic_automute(codec);
15703                 break;
15704         }
15705 }
15706
15707 static void alc663_g50v_inithook(struct hda_codec *codec)
15708 {
15709         alc663_m51va_speaker_automute(codec);
15710         alc662_eeepc_mic_automute(codec);
15711 }
15712
15713 /* bind hp and internal speaker mute (with plug check) */
15714 static int alc662_ecs_master_sw_put(struct snd_kcontrol *kcontrol,
15715                                      struct snd_ctl_elem_value *ucontrol)
15716 {
15717         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
15718         long *valp = ucontrol->value.integer.value;
15719         int change;
15720
15721         change = snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
15722                                           HDA_AMP_MUTE,
15723                                           valp[0] ? 0 : HDA_AMP_MUTE);
15724         change |= snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
15725                                            HDA_AMP_MUTE,
15726                                            valp[1] ? 0 : HDA_AMP_MUTE);
15727         if (change)
15728                 alc262_hippo1_automute(codec);
15729         return change;
15730 }
15731
15732 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
15733         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15734         {
15735                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15736                 .name = "Master Playback Switch",
15737                 .info = snd_hda_mixer_amp_switch_info,
15738                 .get = snd_hda_mixer_amp_switch_get,
15739                 .put = alc662_ecs_master_sw_put,
15740                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15741         },
15742
15743         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
15744         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
15745         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
15746
15747         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15748         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15749         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15750         { } /* end */
15751 };
15752
15753 #ifdef CONFIG_SND_HDA_POWER_SAVE
15754 #define alc662_loopbacks        alc880_loopbacks
15755 #endif
15756
15757
15758 /* pcm configuration: identiacal with ALC880 */
15759 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
15760 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
15761 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
15762 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
15763
15764 /*
15765  * configuration and preset
15766  */
15767 static const char *alc662_models[ALC662_MODEL_LAST] = {
15768         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
15769         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
15770         [ALC662_3ST_6ch]        = "3stack-6ch",
15771         [ALC662_5ST_DIG]        = "6stack-dig",
15772         [ALC662_LENOVO_101E]    = "lenovo-101e",
15773         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
15774         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
15775         [ALC662_ECS] = "ecs",
15776         [ALC663_ASUS_M51VA] = "m51va",
15777         [ALC663_ASUS_G71V] = "g71v",
15778         [ALC663_ASUS_H13] = "h13",
15779         [ALC663_ASUS_G50V] = "g50v",
15780         [ALC663_ASUS_MODE1] = "asus-mode1",
15781         [ALC662_ASUS_MODE2] = "asus-mode2",
15782         [ALC663_ASUS_MODE3] = "asus-mode3",
15783         [ALC663_ASUS_MODE4] = "asus-mode4",
15784         [ALC663_ASUS_MODE5] = "asus-mode5",
15785         [ALC663_ASUS_MODE6] = "asus-mode6",
15786         [ALC662_AUTO]           = "auto",
15787 };
15788
15789 static struct snd_pci_quirk alc662_cfg_tbl[] = {
15790         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
15791         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
15792         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
15793         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
15794         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
15795         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
15796         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),
15797         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
15798         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
15799         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
15800         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),
15801         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
15802         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
15803         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
15804         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
15805         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
15806         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
15807         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
15808         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
15809         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
15810         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
15811         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
15812         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
15813         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
15814         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
15815         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
15816         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
15817         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
15818         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
15819         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
15820         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
15821         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
15822         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
15823         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
15824         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
15825         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
15826         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
15827         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
15828                       ALC662_3ST_6ch_DIG),
15829         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
15830         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
15831         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
15832         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
15833                       ALC662_3ST_6ch_DIG),
15834         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
15835         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
15836                                         ALC662_3ST_6ch_DIG),
15837         SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13),
15838         SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13),
15839         SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13),
15840         {}
15841 };
15842
15843 static struct alc_config_preset alc662_presets[] = {
15844         [ALC662_3ST_2ch_DIG] = {
15845                 .mixers = { alc662_3ST_2ch_mixer, alc662_capture_mixer },
15846                 .init_verbs = { alc662_init_verbs },
15847                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15848                 .dac_nids = alc662_dac_nids,
15849                 .dig_out_nid = ALC662_DIGOUT_NID,
15850                 .dig_in_nid = ALC662_DIGIN_NID,
15851                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15852                 .channel_mode = alc662_3ST_2ch_modes,
15853                 .input_mux = &alc662_capture_source,
15854         },
15855         [ALC662_3ST_6ch_DIG] = {
15856                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
15857                             alc662_capture_mixer },
15858                 .init_verbs = { alc662_init_verbs },
15859                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15860                 .dac_nids = alc662_dac_nids,
15861                 .dig_out_nid = ALC662_DIGOUT_NID,
15862                 .dig_in_nid = ALC662_DIGIN_NID,
15863                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
15864                 .channel_mode = alc662_3ST_6ch_modes,
15865                 .need_dac_fix = 1,
15866                 .input_mux = &alc662_capture_source,
15867         },
15868         [ALC662_3ST_6ch] = {
15869                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
15870                             alc662_capture_mixer },
15871                 .init_verbs = { alc662_init_verbs },
15872                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15873                 .dac_nids = alc662_dac_nids,
15874                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
15875                 .channel_mode = alc662_3ST_6ch_modes,
15876                 .need_dac_fix = 1,
15877                 .input_mux = &alc662_capture_source,
15878         },
15879         [ALC662_5ST_DIG] = {
15880                 .mixers = { alc662_base_mixer, alc662_chmode_mixer,
15881                             alc662_capture_mixer },
15882                 .init_verbs = { alc662_init_verbs },
15883                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15884                 .dac_nids = alc662_dac_nids,
15885                 .dig_out_nid = ALC662_DIGOUT_NID,
15886                 .dig_in_nid = ALC662_DIGIN_NID,
15887                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
15888                 .channel_mode = alc662_5stack_modes,
15889                 .input_mux = &alc662_capture_source,
15890         },
15891         [ALC662_LENOVO_101E] = {
15892                 .mixers = { alc662_lenovo_101e_mixer, alc662_capture_mixer },
15893                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
15894                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15895                 .dac_nids = alc662_dac_nids,
15896                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15897                 .channel_mode = alc662_3ST_2ch_modes,
15898                 .input_mux = &alc662_lenovo_101e_capture_source,
15899                 .unsol_event = alc662_lenovo_101e_unsol_event,
15900                 .init_hook = alc662_lenovo_101e_all_automute,
15901         },
15902         [ALC662_ASUS_EEEPC_P701] = {
15903                 .mixers = { alc662_eeepc_p701_mixer, alc662_capture_mixer },
15904                 .init_verbs = { alc662_init_verbs,
15905                                 alc662_eeepc_sue_init_verbs },
15906                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15907                 .dac_nids = alc662_dac_nids,
15908                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15909                 .channel_mode = alc662_3ST_2ch_modes,
15910                 .input_mux = &alc662_eeepc_capture_source,
15911                 .unsol_event = alc662_eeepc_unsol_event,
15912                 .init_hook = alc662_eeepc_inithook,
15913         },
15914         [ALC662_ASUS_EEEPC_EP20] = {
15915                 .mixers = { alc662_eeepc_ep20_mixer, alc662_capture_mixer,
15916                             alc662_chmode_mixer },
15917                 .init_verbs = { alc662_init_verbs,
15918                                 alc662_eeepc_ep20_sue_init_verbs },
15919                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15920                 .dac_nids = alc662_dac_nids,
15921                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
15922                 .channel_mode = alc662_3ST_6ch_modes,
15923                 .input_mux = &alc662_lenovo_101e_capture_source,
15924                 .unsol_event = alc662_eeepc_ep20_unsol_event,
15925                 .init_hook = alc662_eeepc_ep20_inithook,
15926         },
15927         [ALC662_ECS] = {
15928                 .mixers = { alc662_ecs_mixer, alc662_capture_mixer },
15929                 .init_verbs = { alc662_init_verbs,
15930                                 alc662_ecs_init_verbs },
15931                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15932                 .dac_nids = alc662_dac_nids,
15933                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15934                 .channel_mode = alc662_3ST_2ch_modes,
15935                 .input_mux = &alc662_eeepc_capture_source,
15936                 .unsol_event = alc662_eeepc_unsol_event,
15937                 .init_hook = alc662_eeepc_inithook,
15938         },
15939         [ALC663_ASUS_M51VA] = {
15940                 .mixers = { alc663_m51va_mixer, alc662_capture_mixer},
15941                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
15942                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15943                 .dac_nids = alc662_dac_nids,
15944                 .dig_out_nid = ALC662_DIGOUT_NID,
15945                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15946                 .channel_mode = alc662_3ST_2ch_modes,
15947                 .input_mux = &alc663_m51va_capture_source,
15948                 .unsol_event = alc663_m51va_unsol_event,
15949                 .init_hook = alc663_m51va_inithook,
15950         },
15951         [ALC663_ASUS_G71V] = {
15952                 .mixers = { alc663_g71v_mixer, alc662_capture_mixer},
15953                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
15954                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15955                 .dac_nids = alc662_dac_nids,
15956                 .dig_out_nid = ALC662_DIGOUT_NID,
15957                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15958                 .channel_mode = alc662_3ST_2ch_modes,
15959                 .input_mux = &alc662_eeepc_capture_source,
15960                 .unsol_event = alc663_g71v_unsol_event,
15961                 .init_hook = alc663_g71v_inithook,
15962         },
15963         [ALC663_ASUS_H13] = {
15964                 .mixers = { alc663_m51va_mixer, alc662_capture_mixer},
15965                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
15966                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15967                 .dac_nids = alc662_dac_nids,
15968                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15969                 .channel_mode = alc662_3ST_2ch_modes,
15970                 .input_mux = &alc663_m51va_capture_source,
15971                 .unsol_event = alc663_m51va_unsol_event,
15972                 .init_hook = alc663_m51va_inithook,
15973         },
15974         [ALC663_ASUS_G50V] = {
15975                 .mixers = { alc663_g50v_mixer, alc662_capture_mixer},
15976                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
15977                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15978                 .dac_nids = alc662_dac_nids,
15979                 .dig_out_nid = ALC662_DIGOUT_NID,
15980                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
15981                 .channel_mode = alc662_3ST_6ch_modes,
15982                 .input_mux = &alc663_capture_source,
15983                 .unsol_event = alc663_g50v_unsol_event,
15984                 .init_hook = alc663_g50v_inithook,
15985         },
15986         [ALC663_ASUS_MODE1] = {
15987                 .mixers = { alc663_m51va_mixer, alc662_auto_capture_mixer },
15988                 .init_verbs = { alc662_init_verbs,
15989                                 alc663_21jd_amic_init_verbs },
15990                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
15991                 .hp_nid = 0x03,
15992                 .dac_nids = alc662_dac_nids,
15993                 .dig_out_nid = ALC662_DIGOUT_NID,
15994                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
15995                 .channel_mode = alc662_3ST_2ch_modes,
15996                 .input_mux = &alc662_eeepc_capture_source,
15997                 .unsol_event = alc663_mode1_unsol_event,
15998                 .init_hook = alc663_mode1_inithook,
15999         },
16000         [ALC662_ASUS_MODE2] = {
16001                 .mixers = { alc662_1bjd_mixer, alc662_auto_capture_mixer },
16002                 .init_verbs = { alc662_init_verbs,
16003                                 alc662_1bjd_amic_init_verbs },
16004                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16005                 .dac_nids = alc662_dac_nids,
16006                 .dig_out_nid = ALC662_DIGOUT_NID,
16007                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16008                 .channel_mode = alc662_3ST_2ch_modes,
16009                 .input_mux = &alc662_eeepc_capture_source,
16010                 .unsol_event = alc662_mode2_unsol_event,
16011                 .init_hook = alc662_mode2_inithook,
16012         },
16013         [ALC663_ASUS_MODE3] = {
16014                 .mixers = { alc663_two_hp_m1_mixer, alc662_auto_capture_mixer },
16015                 .init_verbs = { alc662_init_verbs,
16016                                 alc663_two_hp_amic_m1_init_verbs },
16017                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16018                 .hp_nid = 0x03,
16019                 .dac_nids = alc662_dac_nids,
16020                 .dig_out_nid = ALC662_DIGOUT_NID,
16021                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16022                 .channel_mode = alc662_3ST_2ch_modes,
16023                 .input_mux = &alc662_eeepc_capture_source,
16024                 .unsol_event = alc663_mode3_unsol_event,
16025                 .init_hook = alc663_mode3_inithook,
16026         },
16027         [ALC663_ASUS_MODE4] = {
16028                 .mixers = { alc663_asus_21jd_clfe_mixer,
16029                                 alc662_auto_capture_mixer},
16030                 .init_verbs = { alc662_init_verbs,
16031                                 alc663_21jd_amic_init_verbs},
16032                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16033                 .hp_nid = 0x03,
16034                 .dac_nids = alc662_dac_nids,
16035                 .dig_out_nid = ALC662_DIGOUT_NID,
16036                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16037                 .channel_mode = alc662_3ST_2ch_modes,
16038                 .input_mux = &alc662_eeepc_capture_source,
16039                 .unsol_event = alc663_mode4_unsol_event,
16040                 .init_hook = alc663_mode4_inithook,
16041         },
16042         [ALC663_ASUS_MODE5] = {
16043                 .mixers = { alc663_asus_15jd_clfe_mixer,
16044                                 alc662_auto_capture_mixer },
16045                 .init_verbs = { alc662_init_verbs,
16046                                 alc663_15jd_amic_init_verbs },
16047                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16048                 .hp_nid = 0x03,
16049                 .dac_nids = alc662_dac_nids,
16050                 .dig_out_nid = ALC662_DIGOUT_NID,
16051                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16052                 .channel_mode = alc662_3ST_2ch_modes,
16053                 .input_mux = &alc662_eeepc_capture_source,
16054                 .unsol_event = alc663_mode5_unsol_event,
16055                 .init_hook = alc663_mode5_inithook,
16056         },
16057         [ALC663_ASUS_MODE6] = {
16058                 .mixers = { alc663_two_hp_m2_mixer, alc662_auto_capture_mixer },
16059                 .init_verbs = { alc662_init_verbs,
16060                                 alc663_two_hp_amic_m2_init_verbs },
16061                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16062                 .hp_nid = 0x03,
16063                 .dac_nids = alc662_dac_nids,
16064                 .dig_out_nid = ALC662_DIGOUT_NID,
16065                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16066                 .channel_mode = alc662_3ST_2ch_modes,
16067                 .input_mux = &alc662_eeepc_capture_source,
16068                 .unsol_event = alc663_mode6_unsol_event,
16069                 .init_hook = alc663_mode6_inithook,
16070         },
16071 };
16072
16073
16074 /*
16075  * BIOS auto configuration
16076  */
16077
16078 /* add playback controls from the parsed DAC table */
16079 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
16080                                              const struct auto_pin_cfg *cfg)
16081 {
16082         char name[32];
16083         static const char *chname[4] = {
16084                 "Front", "Surround", NULL /*CLFE*/, "Side"
16085         };
16086         hda_nid_t nid;
16087         int i, err;
16088
16089         for (i = 0; i < cfg->line_outs; i++) {
16090                 if (!spec->multiout.dac_nids[i])
16091                         continue;
16092                 nid = alc880_idx_to_dac(i);
16093                 if (i == 2) {
16094                         /* Center/LFE */
16095                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16096                                           "Center Playback Volume",
16097                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
16098                                                               HDA_OUTPUT));
16099                         if (err < 0)
16100                                 return err;
16101                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16102                                           "LFE Playback Volume",
16103                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
16104                                                               HDA_OUTPUT));
16105                         if (err < 0)
16106                                 return err;
16107                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16108                                           "Center Playback Switch",
16109                                           HDA_COMPOSE_AMP_VAL(0x0e, 1, 0,
16110                                                               HDA_INPUT));
16111                         if (err < 0)
16112                                 return err;
16113                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16114                                           "LFE Playback Switch",
16115                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
16116                                                               HDA_INPUT));
16117                         if (err < 0)
16118                                 return err;
16119                 } else {
16120                         sprintf(name, "%s Playback Volume", chname[i]);
16121                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16122                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
16123                                                               HDA_OUTPUT));
16124                         if (err < 0)
16125                                 return err;
16126                         sprintf(name, "%s Playback Switch", chname[i]);
16127                         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16128                                 HDA_COMPOSE_AMP_VAL(alc880_idx_to_mixer(i),
16129                                                     3, 0, HDA_INPUT));
16130                         if (err < 0)
16131                                 return err;
16132                 }
16133         }
16134         return 0;
16135 }
16136
16137 /* add playback controls for speaker and HP outputs */
16138 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
16139                                         const char *pfx)
16140 {
16141         hda_nid_t nid;
16142         int err;
16143         char name[32];
16144
16145         if (!pin)
16146                 return 0;
16147
16148         if (pin == 0x17) {
16149                 /* ALC663 has a mono output pin on 0x17 */
16150                 sprintf(name, "%s Playback Switch", pfx);
16151                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16152                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
16153                 return err;
16154         }
16155
16156         if (alc880_is_fixed_pin(pin)) {
16157                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16158                 /* printk("DAC nid=%x\n",nid); */
16159                 /* specify the DAC as the extra output */
16160                 if (!spec->multiout.hp_nid)
16161                         spec->multiout.hp_nid = nid;
16162                 else
16163                         spec->multiout.extra_out_nid[0] = nid;
16164                 /* control HP volume/switch on the output mixer amp */
16165                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16166                 sprintf(name, "%s Playback Volume", pfx);
16167                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16168                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
16169                 if (err < 0)
16170                         return err;
16171                 sprintf(name, "%s Playback Switch", pfx);
16172                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
16173                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
16174                 if (err < 0)
16175                         return err;
16176         } else if (alc880_is_multi_pin(pin)) {
16177                 /* set manual connection */
16178                 /* we have only a switch on HP-out PIN */
16179                 sprintf(name, "%s Playback Switch", pfx);
16180                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16181                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
16182                 if (err < 0)
16183                         return err;
16184         }
16185         return 0;
16186 }
16187
16188 /* create playback/capture controls for input pins */
16189 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
16190                                                 const struct auto_pin_cfg *cfg)
16191 {
16192         struct hda_input_mux *imux = &spec->private_imux;
16193         int i, err, idx;
16194
16195         for (i = 0; i < AUTO_PIN_LAST; i++) {
16196                 if (alc880_is_input_pin(cfg->input_pins[i])) {
16197                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
16198                         err = new_analog_input(spec, cfg->input_pins[i],
16199                                                auto_pin_cfg_labels[i],
16200                                                idx, 0x0b);
16201                         if (err < 0)
16202                                 return err;
16203                         imux->items[imux->num_items].label =
16204                                 auto_pin_cfg_labels[i];
16205                         imux->items[imux->num_items].index =
16206                                 alc880_input_pin_idx(cfg->input_pins[i]);
16207                         imux->num_items++;
16208                 }
16209         }
16210         return 0;
16211 }
16212
16213 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
16214                                               hda_nid_t nid, int pin_type,
16215                                               int dac_idx)
16216 {
16217         alc_set_pin_output(codec, nid, pin_type);
16218         /* need the manual connection? */
16219         if (alc880_is_multi_pin(nid)) {
16220                 struct alc_spec *spec = codec->spec;
16221                 int idx = alc880_multi_pin_idx(nid);
16222                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
16223                                     AC_VERB_SET_CONNECT_SEL,
16224                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
16225         }
16226 }
16227
16228 static void alc662_auto_init_multi_out(struct hda_codec *codec)
16229 {
16230         struct alc_spec *spec = codec->spec;
16231         int i;
16232
16233         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
16234         for (i = 0; i <= HDA_SIDE; i++) {
16235                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
16236                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
16237                 if (nid)
16238                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
16239                                                           i);
16240         }
16241 }
16242
16243 static void alc662_auto_init_hp_out(struct hda_codec *codec)
16244 {
16245         struct alc_spec *spec = codec->spec;
16246         hda_nid_t pin;
16247
16248         pin = spec->autocfg.hp_pins[0];
16249         if (pin) /* connect to front */
16250                 /* use dac 0 */
16251                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
16252         pin = spec->autocfg.speaker_pins[0];
16253         if (pin)
16254                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
16255 }
16256
16257 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
16258 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
16259
16260 static void alc662_auto_init_analog_input(struct hda_codec *codec)
16261 {
16262         struct alc_spec *spec = codec->spec;
16263         int i;
16264
16265         for (i = 0; i < AUTO_PIN_LAST; i++) {
16266                 hda_nid_t nid = spec->autocfg.input_pins[i];
16267                 if (alc662_is_input_pin(nid)) {
16268                         snd_hda_codec_write(codec, nid, 0,
16269                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
16270                                             (i <= AUTO_PIN_FRONT_MIC ?
16271                                              PIN_VREF80 : PIN_IN));
16272                         if (nid != ALC662_PIN_CD_NID)
16273                                 snd_hda_codec_write(codec, nid, 0,
16274                                                     AC_VERB_SET_AMP_GAIN_MUTE,
16275                                                     AMP_OUT_MUTE);
16276                 }
16277         }
16278 }
16279
16280 #define alc662_auto_init_input_src      alc882_auto_init_input_src
16281
16282 static int alc662_parse_auto_config(struct hda_codec *codec)
16283 {
16284         struct alc_spec *spec = codec->spec;
16285         int err;
16286         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
16287
16288         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
16289                                            alc662_ignore);
16290         if (err < 0)
16291                 return err;
16292         if (!spec->autocfg.line_outs)
16293                 return 0; /* can't find valid BIOS pin config */
16294
16295         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
16296         if (err < 0)
16297                 return err;
16298         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
16299         if (err < 0)
16300                 return err;
16301         err = alc662_auto_create_extra_out(spec,
16302                                            spec->autocfg.speaker_pins[0],
16303                                            "Speaker");
16304         if (err < 0)
16305                 return err;
16306         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
16307                                            "Headphone");
16308         if (err < 0)
16309                 return err;
16310         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
16311         if (err < 0)
16312                 return err;
16313
16314         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
16315
16316         if (spec->autocfg.dig_out_pin)
16317                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
16318
16319         if (spec->kctl_alloc)
16320                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
16321
16322         spec->num_mux_defs = 1;
16323         spec->input_mux = &spec->private_imux;
16324
16325         spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs;
16326         if (codec->vendor_id == 0x10ec0663)
16327                 spec->init_verbs[spec->num_init_verbs++] =
16328                         alc663_auto_init_verbs;
16329
16330         err = alc_auto_add_mic_boost(codec);
16331         if (err < 0)
16332                 return err;
16333
16334         spec->mixers[spec->num_mixers] = alc662_capture_mixer;
16335         spec->num_mixers++;
16336
16337         store_pin_configs(codec);
16338         return 1;
16339 }
16340
16341 /* additional initialization for auto-configuration model */
16342 static void alc662_auto_init(struct hda_codec *codec)
16343 {
16344         struct alc_spec *spec = codec->spec;
16345         alc662_auto_init_multi_out(codec);
16346         alc662_auto_init_hp_out(codec);
16347         alc662_auto_init_analog_input(codec);
16348         alc662_auto_init_input_src(codec);
16349         if (spec->unsol_event)
16350                 alc_inithook(codec);
16351 }
16352
16353 static int patch_alc662(struct hda_codec *codec)
16354 {
16355         struct alc_spec *spec;
16356         int err, board_config;
16357
16358         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
16359         if (!spec)
16360                 return -ENOMEM;
16361
16362         codec->spec = spec;
16363
16364         alc_fix_pll_init(codec, 0x20, 0x04, 15);
16365
16366         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
16367                                                   alc662_models,
16368                                                   alc662_cfg_tbl);
16369         if (board_config < 0) {
16370                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
16371                        "trying auto-probe from BIOS...\n");
16372                 board_config = ALC662_AUTO;
16373         }
16374
16375         if (board_config == ALC662_AUTO) {
16376                 /* automatic parse from the BIOS config */
16377                 err = alc662_parse_auto_config(codec);
16378                 if (err < 0) {
16379                         alc_free(codec);
16380                         return err;
16381                 } else if (!err) {
16382                         printk(KERN_INFO
16383                                "hda_codec: Cannot set up configuration "
16384                                "from BIOS.  Using base mode...\n");
16385                         board_config = ALC662_3ST_2ch_DIG;
16386                 }
16387         }
16388
16389         if (board_config != ALC662_AUTO)
16390                 setup_preset(spec, &alc662_presets[board_config]);
16391
16392         if (codec->vendor_id == 0x10ec0663) {
16393                 spec->stream_name_analog = "ALC663 Analog";
16394                 spec->stream_name_digital = "ALC663 Digital";
16395         } else if (codec->vendor_id == 0x10ec0272) {
16396                 spec->stream_name_analog = "ALC272 Analog";
16397                 spec->stream_name_digital = "ALC272 Digital";
16398         } else {
16399                 spec->stream_name_analog = "ALC662 Analog";
16400                 spec->stream_name_digital = "ALC662 Digital";
16401         }
16402
16403         spec->stream_analog_playback = &alc662_pcm_analog_playback;
16404         spec->stream_analog_capture = &alc662_pcm_analog_capture;
16405
16406         spec->stream_digital_playback = &alc662_pcm_digital_playback;
16407         spec->stream_digital_capture = &alc662_pcm_digital_capture;
16408
16409         spec->adc_nids = alc662_adc_nids;
16410         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
16411         spec->capsrc_nids = alc662_capsrc_nids;
16412
16413         spec->vmaster_nid = 0x02;
16414
16415         codec->patch_ops = alc_patch_ops;
16416         if (board_config == ALC662_AUTO)
16417                 spec->init_hook = alc662_auto_init;
16418 #ifdef CONFIG_SND_HDA_POWER_SAVE
16419         if (!spec->loopback.amplist)
16420                 spec->loopback.amplist = alc662_loopbacks;
16421 #endif
16422
16423         return 0;
16424 }
16425
16426 /*
16427  * patch entries
16428  */
16429 struct hda_codec_preset snd_hda_preset_realtek[] = {
16430         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
16431         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
16432         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
16433         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
16434         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
16435         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
16436         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
16437           .patch = patch_alc861 },
16438         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
16439         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
16440         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
16441         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
16442           .patch = patch_alc883 },
16443         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
16444           .patch = patch_alc662 },
16445         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
16446         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
16447         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
16448         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
16449         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
16450           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16451         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
16452           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16453         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
16454         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc883 },
16455         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
16456         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
16457           .patch = patch_alc883 },
16458         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
16459         {} /* terminator */
16460 };