f1cdce4c8a63db0538972387a25f64c54728238b
[firefly-linux-kernel-4.4.55.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_3013,
76         ALC260_FUJITSU_S702X,
77         ALC260_ACER,
78         ALC260_WILL,
79         ALC260_REPLACER_672V,
80 #ifdef CONFIG_SND_DEBUG
81         ALC260_TEST,
82 #endif
83         ALC260_AUTO,
84         ALC260_MODEL_LAST /* last tag */
85 };
86
87 /* ALC262 models */
88 enum {
89         ALC262_BASIC,
90         ALC262_HIPPO,
91         ALC262_HIPPO_1,
92         ALC262_FUJITSU,
93         ALC262_HP_BPC,
94         ALC262_HP_BPC_D7000_WL,
95         ALC262_HP_BPC_D7000_WF,
96         ALC262_HP_TC_T5735,
97         ALC262_HP_RP5700,
98         ALC262_BENQ_ED8,
99         ALC262_SONY_ASSAMD,
100         ALC262_BENQ_T31,
101         ALC262_ULTRA,
102         ALC262_LENOVO_3000,
103         ALC262_AUTO,
104         ALC262_MODEL_LAST /* last tag */
105 };
106
107 /* ALC268 models */
108 enum {
109         ALC267_QUANTA_IL1,
110         ALC268_3ST,
111         ALC268_TOSHIBA,
112         ALC268_ACER,
113         ALC268_DELL,
114         ALC268_ZEPTO,
115 #ifdef CONFIG_SND_DEBUG
116         ALC268_TEST,
117 #endif
118         ALC268_AUTO,
119         ALC268_MODEL_LAST /* last tag */
120 };
121
122 /* ALC269 models */
123 enum {
124         ALC269_BASIC,
125         ALC269_ASUS_EEEPC_P703,
126         ALC269_ASUS_EEEPC_P901,
127         ALC269_AUTO,
128         ALC269_MODEL_LAST /* last tag */
129 };
130
131 /* ALC861 models */
132 enum {
133         ALC861_3ST,
134         ALC660_3ST,
135         ALC861_3ST_DIG,
136         ALC861_6ST_DIG,
137         ALC861_UNIWILL_M31,
138         ALC861_TOSHIBA,
139         ALC861_ASUS,
140         ALC861_ASUS_LAPTOP,
141         ALC861_AUTO,
142         ALC861_MODEL_LAST,
143 };
144
145 /* ALC861-VD models */
146 enum {
147         ALC660VD_3ST,
148         ALC660VD_3ST_DIG,
149         ALC861VD_3ST,
150         ALC861VD_3ST_DIG,
151         ALC861VD_6ST_DIG,
152         ALC861VD_LENOVO,
153         ALC861VD_DALLAS,
154         ALC861VD_HP,
155         ALC861VD_AUTO,
156         ALC861VD_MODEL_LAST,
157 };
158
159 /* ALC662 models */
160 enum {
161         ALC662_3ST_2ch_DIG,
162         ALC662_3ST_6ch_DIG,
163         ALC662_3ST_6ch,
164         ALC662_5ST_DIG,
165         ALC662_LENOVO_101E,
166         ALC662_ASUS_EEEPC_P701,
167         ALC662_ASUS_EEEPC_EP20,
168         ALC663_ASUS_M51VA,
169         ALC663_ASUS_G71V,
170         ALC663_ASUS_H13,
171         ALC663_ASUS_G50V,
172         ALC662_AUTO,
173         ALC662_MODEL_LAST,
174 };
175
176 /* ALC882 models */
177 enum {
178         ALC882_3ST_DIG,
179         ALC882_6ST_DIG,
180         ALC882_ARIMA,
181         ALC882_W2JC,
182         ALC882_TARGA,
183         ALC882_ASUS_A7J,
184         ALC882_ASUS_A7M,
185         ALC885_MACPRO,
186         ALC885_MBP3,
187         ALC885_IMAC24,
188         ALC882_AUTO,
189         ALC882_MODEL_LAST,
190 };
191
192 /* ALC883 models */
193 enum {
194         ALC883_3ST_2ch_DIG,
195         ALC883_3ST_6ch_DIG,
196         ALC883_3ST_6ch,
197         ALC883_6ST_DIG,
198         ALC883_TARGA_DIG,
199         ALC883_TARGA_2ch_DIG,
200         ALC883_ACER,
201         ALC883_ACER_ASPIRE,
202         ALC883_MEDION,
203         ALC883_MEDION_MD2,      
204         ALC883_LAPTOP_EAPD,
205         ALC883_LENOVO_101E_2ch,
206         ALC883_LENOVO_NB0763,
207         ALC888_LENOVO_MS7195_DIG,
208         ALC883_HAIER_W66,               
209         ALC888_3ST_HP,
210         ALC888_6ST_DELL,
211         ALC883_MITAC,
212         ALC883_CLEVO_M720,
213         ALC883_FUJITSU_PI2515,
214         ALC883_3ST_6ch_INTEL,
215         ALC883_AUTO,
216         ALC883_MODEL_LAST,
217 };
218
219 /* for GPIO Poll */
220 #define GPIO_MASK       0x03
221
222 struct alc_spec {
223         /* codec parameterization */
224         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
225         unsigned int num_mixers;
226
227         const struct hda_verb *init_verbs[5];   /* initialization verbs
228                                                  * don't forget NULL
229                                                  * termination!
230                                                  */
231         unsigned int num_init_verbs;
232
233         char *stream_name_analog;       /* analog PCM stream */
234         struct hda_pcm_stream *stream_analog_playback;
235         struct hda_pcm_stream *stream_analog_capture;
236         struct hda_pcm_stream *stream_analog_alt_playback;
237         struct hda_pcm_stream *stream_analog_alt_capture;
238
239         char *stream_name_digital;      /* digital PCM stream */
240         struct hda_pcm_stream *stream_digital_playback;
241         struct hda_pcm_stream *stream_digital_capture;
242
243         /* playback */
244         struct hda_multi_out multiout;  /* playback set-up
245                                          * max_channels, dacs must be set
246                                          * dig_out_nid and hp_nid are optional
247                                          */
248         hda_nid_t alt_dac_nid;
249
250         /* capture */
251         unsigned int num_adc_nids;
252         hda_nid_t *adc_nids;
253         hda_nid_t *capsrc_nids;
254         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
255
256         /* capture source */
257         unsigned int num_mux_defs;
258         const struct hda_input_mux *input_mux;
259         unsigned int cur_mux[3];
260
261         /* channel model */
262         const struct hda_channel_mode *channel_mode;
263         int num_channel_mode;
264         int need_dac_fix;
265
266         /* PCM information */
267         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
268
269         /* dynamic controls, init_verbs and input_mux */
270         struct auto_pin_cfg autocfg;
271         unsigned int num_kctl_alloc, num_kctl_used;
272         struct snd_kcontrol_new *kctl_alloc;
273         struct hda_input_mux private_imux;
274         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
275
276         /* hooks */
277         void (*init_hook)(struct hda_codec *codec);
278         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
279
280         /* for pin sensing */
281         unsigned int sense_updated: 1;
282         unsigned int jack_present: 1;
283         unsigned int master_sw: 1;
284
285         /* for virtual master */
286         hda_nid_t vmaster_nid;
287 #ifdef CONFIG_SND_HDA_POWER_SAVE
288         struct hda_loopback_check loopback;
289 #endif
290
291         /* for PLL fix */
292         hda_nid_t pll_nid;
293         unsigned int pll_coef_idx, pll_coef_bit;
294 };
295
296 /*
297  * configuration template - to be copied to the spec instance
298  */
299 struct alc_config_preset {
300         struct snd_kcontrol_new *mixers[5]; /* should be identical size
301                                              * with spec
302                                              */
303         const struct hda_verb *init_verbs[5];
304         unsigned int num_dacs;
305         hda_nid_t *dac_nids;
306         hda_nid_t dig_out_nid;          /* optional */
307         hda_nid_t hp_nid;               /* optional */
308         unsigned int num_adc_nids;
309         hda_nid_t *adc_nids;
310         hda_nid_t *capsrc_nids;
311         hda_nid_t dig_in_nid;
312         unsigned int num_channel_mode;
313         const struct hda_channel_mode *channel_mode;
314         int need_dac_fix;
315         unsigned int num_mux_defs;
316         const struct hda_input_mux *input_mux;
317         void (*unsol_event)(struct hda_codec *, unsigned int);
318         void (*init_hook)(struct hda_codec *);
319 #ifdef CONFIG_SND_HDA_POWER_SAVE
320         struct hda_amp_list *loopbacks;
321 #endif
322 };
323
324
325 /*
326  * input MUX handling
327  */
328 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
329                              struct snd_ctl_elem_info *uinfo)
330 {
331         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
332         struct alc_spec *spec = codec->spec;
333         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
334         if (mux_idx >= spec->num_mux_defs)
335                 mux_idx = 0;
336         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
337 }
338
339 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
340                             struct snd_ctl_elem_value *ucontrol)
341 {
342         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
343         struct alc_spec *spec = codec->spec;
344         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
345
346         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
347         return 0;
348 }
349
350 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
351                             struct snd_ctl_elem_value *ucontrol)
352 {
353         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
354         struct alc_spec *spec = codec->spec;
355         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
356         unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
357         hda_nid_t nid = spec->capsrc_nids ?
358                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
359         return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
360                                      nid, &spec->cur_mux[adc_idx]);
361 }
362
363
364 /*
365  * channel mode setting
366  */
367 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
368                             struct snd_ctl_elem_info *uinfo)
369 {
370         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
371         struct alc_spec *spec = codec->spec;
372         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
373                                     spec->num_channel_mode);
374 }
375
376 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
377                            struct snd_ctl_elem_value *ucontrol)
378 {
379         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
380         struct alc_spec *spec = codec->spec;
381         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
382                                    spec->num_channel_mode,
383                                    spec->multiout.max_channels);
384 }
385
386 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
387                            struct snd_ctl_elem_value *ucontrol)
388 {
389         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
390         struct alc_spec *spec = codec->spec;
391         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
392                                       spec->num_channel_mode,
393                                       &spec->multiout.max_channels);
394         if (err >= 0 && spec->need_dac_fix)
395                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
396         return err;
397 }
398
399 /*
400  * Control the mode of pin widget settings via the mixer.  "pc" is used
401  * instead of "%" to avoid consequences of accidently treating the % as 
402  * being part of a format specifier.  Maximum allowed length of a value is
403  * 63 characters plus NULL terminator.
404  *
405  * Note: some retasking pin complexes seem to ignore requests for input
406  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
407  * are requested.  Therefore order this list so that this behaviour will not
408  * cause problems when mixer clients move through the enum sequentially.
409  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
410  * March 2006.
411  */
412 static char *alc_pin_mode_names[] = {
413         "Mic 50pc bias", "Mic 80pc bias",
414         "Line in", "Line out", "Headphone out",
415 };
416 static unsigned char alc_pin_mode_values[] = {
417         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
418 };
419 /* The control can present all 5 options, or it can limit the options based
420  * in the pin being assumed to be exclusively an input or an output pin.  In
421  * addition, "input" pins may or may not process the mic bias option
422  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
423  * accept requests for bias as of chip versions up to March 2006) and/or
424  * wiring in the computer.
425  */
426 #define ALC_PIN_DIR_IN              0x00
427 #define ALC_PIN_DIR_OUT             0x01
428 #define ALC_PIN_DIR_INOUT           0x02
429 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
430 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
431
432 /* Info about the pin modes supported by the different pin direction modes. 
433  * For each direction the minimum and maximum values are given.
434  */
435 static signed char alc_pin_mode_dir_info[5][2] = {
436         { 0, 2 },    /* ALC_PIN_DIR_IN */
437         { 3, 4 },    /* ALC_PIN_DIR_OUT */
438         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
439         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
440         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
441 };
442 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
443 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
444 #define alc_pin_mode_n_items(_dir) \
445         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
446
447 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
448                              struct snd_ctl_elem_info *uinfo)
449 {
450         unsigned int item_num = uinfo->value.enumerated.item;
451         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
452
453         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
454         uinfo->count = 1;
455         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
456
457         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
458                 item_num = alc_pin_mode_min(dir);
459         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
460         return 0;
461 }
462
463 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
464                             struct snd_ctl_elem_value *ucontrol)
465 {
466         unsigned int i;
467         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
468         hda_nid_t nid = kcontrol->private_value & 0xffff;
469         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
470         long *valp = ucontrol->value.integer.value;
471         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
472                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
473                                                  0x00);
474
475         /* Find enumerated value for current pinctl setting */
476         i = alc_pin_mode_min(dir);
477         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
478                 i++;
479         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
480         return 0;
481 }
482
483 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
484                             struct snd_ctl_elem_value *ucontrol)
485 {
486         signed int change;
487         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
488         hda_nid_t nid = kcontrol->private_value & 0xffff;
489         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
490         long val = *ucontrol->value.integer.value;
491         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
492                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
493                                                  0x00);
494
495         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
496                 val = alc_pin_mode_min(dir);
497
498         change = pinctl != alc_pin_mode_values[val];
499         if (change) {
500                 /* Set pin mode to that requested */
501                 snd_hda_codec_write_cache(codec, nid, 0,
502                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
503                                           alc_pin_mode_values[val]);
504
505                 /* Also enable the retasking pin's input/output as required 
506                  * for the requested pin mode.  Enum values of 2 or less are
507                  * input modes.
508                  *
509                  * Dynamically switching the input/output buffers probably
510                  * reduces noise slightly (particularly on input) so we'll
511                  * do it.  However, having both input and output buffers
512                  * enabled simultaneously doesn't seem to be problematic if
513                  * this turns out to be necessary in the future.
514                  */
515                 if (val <= 2) {
516                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
517                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
518                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
519                                                  HDA_AMP_MUTE, 0);
520                 } else {
521                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
522                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
523                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
524                                                  HDA_AMP_MUTE, 0);
525                 }
526         }
527         return change;
528 }
529
530 #define ALC_PIN_MODE(xname, nid, dir) \
531         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
532           .info = alc_pin_mode_info, \
533           .get = alc_pin_mode_get, \
534           .put = alc_pin_mode_put, \
535           .private_value = nid | (dir<<16) }
536
537 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
538  * together using a mask with more than one bit set.  This control is
539  * currently used only by the ALC260 test model.  At this stage they are not
540  * needed for any "production" models.
541  */
542 #ifdef CONFIG_SND_DEBUG
543 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
544
545 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
546                              struct snd_ctl_elem_value *ucontrol)
547 {
548         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
549         hda_nid_t nid = kcontrol->private_value & 0xffff;
550         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
551         long *valp = ucontrol->value.integer.value;
552         unsigned int val = snd_hda_codec_read(codec, nid, 0,
553                                               AC_VERB_GET_GPIO_DATA, 0x00);
554
555         *valp = (val & mask) != 0;
556         return 0;
557 }
558 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
559                              struct snd_ctl_elem_value *ucontrol)
560 {
561         signed int change;
562         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
563         hda_nid_t nid = kcontrol->private_value & 0xffff;
564         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
565         long val = *ucontrol->value.integer.value;
566         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
567                                                     AC_VERB_GET_GPIO_DATA,
568                                                     0x00);
569
570         /* Set/unset the masked GPIO bit(s) as needed */
571         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
572         if (val == 0)
573                 gpio_data &= ~mask;
574         else
575                 gpio_data |= mask;
576         snd_hda_codec_write_cache(codec, nid, 0,
577                                   AC_VERB_SET_GPIO_DATA, gpio_data);
578
579         return change;
580 }
581 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
582         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
583           .info = alc_gpio_data_info, \
584           .get = alc_gpio_data_get, \
585           .put = alc_gpio_data_put, \
586           .private_value = nid | (mask<<16) }
587 #endif   /* CONFIG_SND_DEBUG */
588
589 /* A switch control to allow the enabling of the digital IO pins on the
590  * ALC260.  This is incredibly simplistic; the intention of this control is
591  * to provide something in the test model allowing digital outputs to be
592  * identified if present.  If models are found which can utilise these
593  * outputs a more complete mixer control can be devised for those models if
594  * necessary.
595  */
596 #ifdef CONFIG_SND_DEBUG
597 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
598
599 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
600                               struct snd_ctl_elem_value *ucontrol)
601 {
602         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
603         hda_nid_t nid = kcontrol->private_value & 0xffff;
604         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
605         long *valp = ucontrol->value.integer.value;
606         unsigned int val = snd_hda_codec_read(codec, nid, 0,
607                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
608
609         *valp = (val & mask) != 0;
610         return 0;
611 }
612 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
613                               struct snd_ctl_elem_value *ucontrol)
614 {
615         signed int change;
616         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
617         hda_nid_t nid = kcontrol->private_value & 0xffff;
618         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
619         long val = *ucontrol->value.integer.value;
620         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
621                                                     AC_VERB_GET_DIGI_CONVERT_1,
622                                                     0x00);
623
624         /* Set/unset the masked control bit(s) as needed */
625         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
626         if (val==0)
627                 ctrl_data &= ~mask;
628         else
629                 ctrl_data |= mask;
630         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
631                                   ctrl_data);
632
633         return change;
634 }
635 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
636         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
637           .info = alc_spdif_ctrl_info, \
638           .get = alc_spdif_ctrl_get, \
639           .put = alc_spdif_ctrl_put, \
640           .private_value = nid | (mask<<16) }
641 #endif   /* CONFIG_SND_DEBUG */
642
643 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
644  * Again, this is only used in the ALC26x test models to help identify when
645  * the EAPD line must be asserted for features to work.
646  */
647 #ifdef CONFIG_SND_DEBUG
648 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
649
650 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
651                               struct snd_ctl_elem_value *ucontrol)
652 {
653         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
654         hda_nid_t nid = kcontrol->private_value & 0xffff;
655         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
656         long *valp = ucontrol->value.integer.value;
657         unsigned int val = snd_hda_codec_read(codec, nid, 0,
658                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
659
660         *valp = (val & mask) != 0;
661         return 0;
662 }
663
664 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
665                               struct snd_ctl_elem_value *ucontrol)
666 {
667         int change;
668         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
669         hda_nid_t nid = kcontrol->private_value & 0xffff;
670         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
671         long val = *ucontrol->value.integer.value;
672         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
673                                                     AC_VERB_GET_EAPD_BTLENABLE,
674                                                     0x00);
675
676         /* Set/unset the masked control bit(s) as needed */
677         change = (!val ? 0 : mask) != (ctrl_data & mask);
678         if (!val)
679                 ctrl_data &= ~mask;
680         else
681                 ctrl_data |= mask;
682         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
683                                   ctrl_data);
684
685         return change;
686 }
687
688 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
689         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
690           .info = alc_eapd_ctrl_info, \
691           .get = alc_eapd_ctrl_get, \
692           .put = alc_eapd_ctrl_put, \
693           .private_value = nid | (mask<<16) }
694 #endif   /* CONFIG_SND_DEBUG */
695
696 /*
697  * set up from the preset table
698  */
699 static void setup_preset(struct alc_spec *spec,
700                          const struct alc_config_preset *preset)
701 {
702         int i;
703
704         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
705                 spec->mixers[spec->num_mixers++] = preset->mixers[i];
706         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
707              i++)
708                 spec->init_verbs[spec->num_init_verbs++] =
709                         preset->init_verbs[i];
710         
711         spec->channel_mode = preset->channel_mode;
712         spec->num_channel_mode = preset->num_channel_mode;
713         spec->need_dac_fix = preset->need_dac_fix;
714
715         spec->multiout.max_channels = spec->channel_mode[0].channels;
716
717         spec->multiout.num_dacs = preset->num_dacs;
718         spec->multiout.dac_nids = preset->dac_nids;
719         spec->multiout.dig_out_nid = preset->dig_out_nid;
720         spec->multiout.hp_nid = preset->hp_nid;
721         
722         spec->num_mux_defs = preset->num_mux_defs;
723         if (!spec->num_mux_defs)
724                 spec->num_mux_defs = 1;
725         spec->input_mux = preset->input_mux;
726
727         spec->num_adc_nids = preset->num_adc_nids;
728         spec->adc_nids = preset->adc_nids;
729         spec->capsrc_nids = preset->capsrc_nids;
730         spec->dig_in_nid = preset->dig_in_nid;
731
732         spec->unsol_event = preset->unsol_event;
733         spec->init_hook = preset->init_hook;
734 #ifdef CONFIG_SND_HDA_POWER_SAVE
735         spec->loopback.amplist = preset->loopbacks;
736 #endif
737 }
738
739 /* Enable GPIO mask and set output */
740 static struct hda_verb alc_gpio1_init_verbs[] = {
741         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
742         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
743         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
744         { }
745 };
746
747 static struct hda_verb alc_gpio2_init_verbs[] = {
748         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
749         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
750         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
751         { }
752 };
753
754 static struct hda_verb alc_gpio3_init_verbs[] = {
755         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
756         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
757         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
758         { }
759 };
760
761 /*
762  * Fix hardware PLL issue
763  * On some codecs, the analog PLL gating control must be off while
764  * the default value is 1.
765  */
766 static void alc_fix_pll(struct hda_codec *codec)
767 {
768         struct alc_spec *spec = codec->spec;
769         unsigned int val;
770
771         if (!spec->pll_nid)
772                 return;
773         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
774                             spec->pll_coef_idx);
775         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
776                                  AC_VERB_GET_PROC_COEF, 0);
777         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
778                             spec->pll_coef_idx);
779         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
780                             val & ~(1 << spec->pll_coef_bit));
781 }
782
783 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
784                              unsigned int coef_idx, unsigned int coef_bit)
785 {
786         struct alc_spec *spec = codec->spec;
787         spec->pll_nid = nid;
788         spec->pll_coef_idx = coef_idx;
789         spec->pll_coef_bit = coef_bit;
790         alc_fix_pll(codec);
791 }
792
793 static void alc_sku_automute(struct hda_codec *codec)
794 {
795         struct alc_spec *spec = codec->spec;
796         unsigned int present;
797         unsigned int hp_nid = spec->autocfg.hp_pins[0];
798         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
799
800         /* need to execute and sync at first */
801         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
802         present = snd_hda_codec_read(codec, hp_nid, 0,
803                                      AC_VERB_GET_PIN_SENSE, 0);
804         spec->jack_present = (present & 0x80000000) != 0;
805         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
806                             spec->jack_present ? 0 : PIN_OUT);
807 }
808
809 /* unsolicited event for HP jack sensing */
810 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
811 {
812         if (codec->vendor_id == 0x10ec0880)
813                 res >>= 28;
814         else
815                 res >>= 26;
816         if (res != ALC880_HP_EVENT)
817                 return;
818
819         alc_sku_automute(codec);
820 }
821
822 /* additional initialization for ALC888 variants */
823 static void alc888_coef_init(struct hda_codec *codec)
824 {
825         unsigned int tmp;
826
827         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
828         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
829         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
830         if ((tmp & 0xf0) == 2)
831                 /* alc888S-VC */
832                 snd_hda_codec_read(codec, 0x20, 0,
833                                    AC_VERB_SET_PROC_COEF, 0x830);
834          else
835                  /* alc888-VB */
836                  snd_hda_codec_read(codec, 0x20, 0,
837                                     AC_VERB_SET_PROC_COEF, 0x3030);
838 }
839
840 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
841  *      31 ~ 16 :       Manufacture ID
842  *      15 ~ 8  :       SKU ID
843  *      7  ~ 0  :       Assembly ID
844  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
845  */
846 static void alc_subsystem_id(struct hda_codec *codec,
847                              unsigned int porta, unsigned int porte,
848                              unsigned int portd)
849 {
850         unsigned int ass, tmp, i;
851         unsigned nid;
852         struct alc_spec *spec = codec->spec;
853
854         ass = codec->subsystem_id & 0xffff;
855         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
856                 goto do_sku;
857
858         /*      
859          * 31~30        : port conetcivity
860          * 29~21        : reserve
861          * 20           : PCBEEP input
862          * 19~16        : Check sum (15:1)
863          * 15~1         : Custom
864          * 0            : override
865         */
866         nid = 0x1d;
867         if (codec->vendor_id == 0x10ec0260)
868                 nid = 0x17;
869         ass = snd_hda_codec_read(codec, nid, 0,
870                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
871         if (!(ass & 1) && !(ass & 0x100000))
872                 return;
873         if ((ass >> 30) != 1)   /* no physical connection */
874                 return;
875
876         /* check sum */
877         tmp = 0;
878         for (i = 1; i < 16; i++) {
879                 if ((ass >> i) & 1)
880                         tmp++;
881         }
882         if (((ass >> 16) & 0xf) != tmp)
883                 return;
884 do_sku:
885         /*
886          * 0 : override
887          * 1 :  Swap Jack
888          * 2 : 0 --> Desktop, 1 --> Laptop
889          * 3~5 : External Amplifier control
890          * 7~6 : Reserved
891         */
892         tmp = (ass & 0x38) >> 3;        /* external Amp control */
893         switch (tmp) {
894         case 1:
895                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
896                 break;
897         case 3:
898                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
899                 break;
900         case 7:
901                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
902                 break;
903         case 5: /* set EAPD output high */
904                 switch (codec->vendor_id) {
905                 case 0x10ec0260:
906                         snd_hda_codec_write(codec, 0x0f, 0,
907                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
908                         snd_hda_codec_write(codec, 0x10, 0,
909                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
910                         break;
911                 case 0x10ec0262:
912                 case 0x10ec0267:
913                 case 0x10ec0268:
914                 case 0x10ec0269:
915                 case 0x10ec0660:
916                 case 0x10ec0662:
917                 case 0x10ec0663:
918                 case 0x10ec0862:
919                 case 0x10ec0889:
920                         snd_hda_codec_write(codec, 0x14, 0,
921                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
922                         snd_hda_codec_write(codec, 0x15, 0,
923                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
924                         break;
925                 }
926                 switch (codec->vendor_id) {
927                 case 0x10ec0260:
928                         snd_hda_codec_write(codec, 0x1a, 0,
929                                             AC_VERB_SET_COEF_INDEX, 7);
930                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
931                                                  AC_VERB_GET_PROC_COEF, 0);
932                         snd_hda_codec_write(codec, 0x1a, 0,
933                                             AC_VERB_SET_COEF_INDEX, 7);
934                         snd_hda_codec_write(codec, 0x1a, 0,
935                                             AC_VERB_SET_PROC_COEF,
936                                             tmp | 0x2010);
937                         break;
938                 case 0x10ec0262:
939                 case 0x10ec0880:
940                 case 0x10ec0882:
941                 case 0x10ec0883:
942                 case 0x10ec0885:
943                 case 0x10ec0889:
944                         snd_hda_codec_write(codec, 0x20, 0,
945                                             AC_VERB_SET_COEF_INDEX, 7);
946                         tmp = snd_hda_codec_read(codec, 0x20, 0,
947                                                  AC_VERB_GET_PROC_COEF, 0);
948                         snd_hda_codec_write(codec, 0x20, 0,
949                                             AC_VERB_SET_COEF_INDEX, 7); 
950                         snd_hda_codec_write(codec, 0x20, 0,
951                                             AC_VERB_SET_PROC_COEF,
952                                             tmp | 0x2010);
953                         break;
954                 case 0x10ec0888:
955                         alc888_coef_init(codec);
956                         break;
957                 case 0x10ec0267:
958                 case 0x10ec0268:
959                         snd_hda_codec_write(codec, 0x20, 0,
960                                             AC_VERB_SET_COEF_INDEX, 7);
961                         tmp = snd_hda_codec_read(codec, 0x20, 0,
962                                                  AC_VERB_GET_PROC_COEF, 0);
963                         snd_hda_codec_write(codec, 0x20, 0,
964                                             AC_VERB_SET_COEF_INDEX, 7); 
965                         snd_hda_codec_write(codec, 0x20, 0,
966                                             AC_VERB_SET_PROC_COEF,
967                                             tmp | 0x3000);
968                         break;
969                 }
970         default:
971                 break;
972         }
973         
974         /* is laptop or Desktop and enable the function "Mute internal speaker
975          * when the external headphone out jack is plugged"
976          */
977         if (!(ass & 0x8000))
978                 return;
979         /*
980          * 10~8 : Jack location
981          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
982          * 14~13: Resvered
983          * 15   : 1 --> enable the function "Mute internal speaker
984          *              when the external headphone out jack is plugged"
985          */
986         if (!spec->autocfg.speaker_pins[0]) {
987                 if (spec->autocfg.line_out_pins[0])
988                         spec->autocfg.speaker_pins[0] =
989                                 spec->autocfg.line_out_pins[0];
990                 else
991                         return;
992         }
993
994         if (!spec->autocfg.hp_pins[0]) {
995                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
996                 if (tmp == 0)
997                         spec->autocfg.hp_pins[0] = porta;
998                 else if (tmp == 1)
999                         spec->autocfg.hp_pins[0] = porte;
1000                 else if (tmp == 2)
1001                         spec->autocfg.hp_pins[0] = portd;
1002                 else
1003                         return;
1004         }
1005
1006         snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1007                             AC_VERB_SET_UNSOLICITED_ENABLE,
1008                             AC_USRSP_EN | ALC880_HP_EVENT);
1009         spec->unsol_event = alc_sku_unsol_event;
1010 }
1011
1012 /*
1013  * Fix-up pin default configurations
1014  */
1015
1016 struct alc_pincfg {
1017         hda_nid_t nid;
1018         u32 val;
1019 };
1020
1021 static void alc_fix_pincfg(struct hda_codec *codec,
1022                            const struct snd_pci_quirk *quirk,
1023                            const struct alc_pincfg **pinfix)
1024 {
1025         const struct alc_pincfg *cfg;
1026
1027         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1028         if (!quirk)
1029                 return;
1030
1031         cfg = pinfix[quirk->value];
1032         for (; cfg->nid; cfg++) {
1033                 int i;
1034                 u32 val = cfg->val;
1035                 for (i = 0; i < 4; i++) {
1036                         snd_hda_codec_write(codec, cfg->nid, 0,
1037                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
1038                                     val & 0xff);
1039                         val >>= 8;
1040                 }
1041         }
1042 }
1043
1044 /*
1045  * ALC880 3-stack model
1046  *
1047  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1048  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1049  *                 F-Mic = 0x1b, HP = 0x19
1050  */
1051
1052 static hda_nid_t alc880_dac_nids[4] = {
1053         /* front, rear, clfe, rear_surr */
1054         0x02, 0x05, 0x04, 0x03
1055 };
1056
1057 static hda_nid_t alc880_adc_nids[3] = {
1058         /* ADC0-2 */
1059         0x07, 0x08, 0x09,
1060 };
1061
1062 /* The datasheet says the node 0x07 is connected from inputs,
1063  * but it shows zero connection in the real implementation on some devices.
1064  * Note: this is a 915GAV bug, fixed on 915GLV
1065  */
1066 static hda_nid_t alc880_adc_nids_alt[2] = {
1067         /* ADC1-2 */
1068         0x08, 0x09,
1069 };
1070
1071 #define ALC880_DIGOUT_NID       0x06
1072 #define ALC880_DIGIN_NID        0x0a
1073
1074 static struct hda_input_mux alc880_capture_source = {
1075         .num_items = 4,
1076         .items = {
1077                 { "Mic", 0x0 },
1078                 { "Front Mic", 0x3 },
1079                 { "Line", 0x2 },
1080                 { "CD", 0x4 },
1081         },
1082 };
1083
1084 /* channel source setting (2/6 channel selection for 3-stack) */
1085 /* 2ch mode */
1086 static struct hda_verb alc880_threestack_ch2_init[] = {
1087         /* set line-in to input, mute it */
1088         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1089         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1090         /* set mic-in to input vref 80%, mute it */
1091         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1092         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1093         { } /* end */
1094 };
1095
1096 /* 6ch mode */
1097 static struct hda_verb alc880_threestack_ch6_init[] = {
1098         /* set line-in to output, unmute it */
1099         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1100         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1101         /* set mic-in to output, unmute it */
1102         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1103         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1104         { } /* end */
1105 };
1106
1107 static struct hda_channel_mode alc880_threestack_modes[2] = {
1108         { 2, alc880_threestack_ch2_init },
1109         { 6, alc880_threestack_ch6_init },
1110 };
1111
1112 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1113         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1114         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1115         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1116         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1117         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1118         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1119         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1120         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1121         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1122         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1123         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1124         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1125         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1126         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1127         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1128         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1129         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1130         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1131         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1132         {
1133                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1134                 .name = "Channel Mode",
1135                 .info = alc_ch_mode_info,
1136                 .get = alc_ch_mode_get,
1137                 .put = alc_ch_mode_put,
1138         },
1139         { } /* end */
1140 };
1141
1142 /* capture mixer elements */
1143 static struct snd_kcontrol_new alc880_capture_mixer[] = {
1144         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
1145         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
1146         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
1147         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
1148         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
1149         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
1150         {
1151                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1152                 /* The multiple "Capture Source" controls confuse alsamixer
1153                  * So call somewhat different..
1154                  */
1155                 /* .name = "Capture Source", */
1156                 .name = "Input Source",
1157                 .count = 3,
1158                 .info = alc_mux_enum_info,
1159                 .get = alc_mux_enum_get,
1160                 .put = alc_mux_enum_put,
1161         },
1162         { } /* end */
1163 };
1164
1165 /* capture mixer elements (in case NID 0x07 not available) */
1166 static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
1167         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1168         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1169         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
1170         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
1171         {
1172                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1173                 /* The multiple "Capture Source" controls confuse alsamixer
1174                  * So call somewhat different..
1175                  */
1176                 /* .name = "Capture Source", */
1177                 .name = "Input Source",
1178                 .count = 2,
1179                 .info = alc_mux_enum_info,
1180                 .get = alc_mux_enum_get,
1181                 .put = alc_mux_enum_put,
1182         },
1183         { } /* end */
1184 };
1185
1186
1187
1188 /*
1189  * ALC880 5-stack model
1190  *
1191  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1192  *      Side = 0x02 (0xd)
1193  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1194  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1195  */
1196
1197 /* additional mixers to alc880_three_stack_mixer */
1198 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1199         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1200         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1201         { } /* end */
1202 };
1203
1204 /* channel source setting (6/8 channel selection for 5-stack) */
1205 /* 6ch mode */
1206 static struct hda_verb alc880_fivestack_ch6_init[] = {
1207         /* set line-in to input, mute it */
1208         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1209         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1210         { } /* end */
1211 };
1212
1213 /* 8ch mode */
1214 static struct hda_verb alc880_fivestack_ch8_init[] = {
1215         /* set line-in to output, unmute it */
1216         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1217         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1218         { } /* end */
1219 };
1220
1221 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1222         { 6, alc880_fivestack_ch6_init },
1223         { 8, alc880_fivestack_ch8_init },
1224 };
1225
1226
1227 /*
1228  * ALC880 6-stack model
1229  *
1230  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1231  *      Side = 0x05 (0x0f)
1232  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1233  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1234  */
1235
1236 static hda_nid_t alc880_6st_dac_nids[4] = {
1237         /* front, rear, clfe, rear_surr */
1238         0x02, 0x03, 0x04, 0x05
1239 };
1240
1241 static struct hda_input_mux alc880_6stack_capture_source = {
1242         .num_items = 4,
1243         .items = {
1244                 { "Mic", 0x0 },
1245                 { "Front Mic", 0x1 },
1246                 { "Line", 0x2 },
1247                 { "CD", 0x4 },
1248         },
1249 };
1250
1251 /* fixed 8-channels */
1252 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1253         { 8, NULL },
1254 };
1255
1256 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1257         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1258         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1259         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1260         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1261         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1262         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1263         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1264         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1265         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1266         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1267         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1268         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1269         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1270         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1271         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1272         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1273         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1274         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1275         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1276         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1277         {
1278                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1279                 .name = "Channel Mode",
1280                 .info = alc_ch_mode_info,
1281                 .get = alc_ch_mode_get,
1282                 .put = alc_ch_mode_put,
1283         },
1284         { } /* end */
1285 };
1286
1287
1288 /*
1289  * ALC880 W810 model
1290  *
1291  * W810 has rear IO for:
1292  * Front (DAC 02)
1293  * Surround (DAC 03)
1294  * Center/LFE (DAC 04)
1295  * Digital out (06)
1296  *
1297  * The system also has a pair of internal speakers, and a headphone jack.
1298  * These are both connected to Line2 on the codec, hence to DAC 02.
1299  * 
1300  * There is a variable resistor to control the speaker or headphone
1301  * volume. This is a hardware-only device without a software API.
1302  *
1303  * Plugging headphones in will disable the internal speakers. This is
1304  * implemented in hardware, not via the driver using jack sense. In
1305  * a similar fashion, plugging into the rear socket marked "front" will
1306  * disable both the speakers and headphones.
1307  *
1308  * For input, there's a microphone jack, and an "audio in" jack.
1309  * These may not do anything useful with this driver yet, because I
1310  * haven't setup any initialization verbs for these yet...
1311  */
1312
1313 static hda_nid_t alc880_w810_dac_nids[3] = {
1314         /* front, rear/surround, clfe */
1315         0x02, 0x03, 0x04
1316 };
1317
1318 /* fixed 6 channels */
1319 static struct hda_channel_mode alc880_w810_modes[1] = {
1320         { 6, NULL }
1321 };
1322
1323 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1324 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1325         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1326         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1327         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1328         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1329         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1330         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1331         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1332         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1333         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1334         { } /* end */
1335 };
1336
1337
1338 /*
1339  * Z710V model
1340  *
1341  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1342  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1343  *                 Line = 0x1a
1344  */
1345
1346 static hda_nid_t alc880_z71v_dac_nids[1] = {
1347         0x02
1348 };
1349 #define ALC880_Z71V_HP_DAC      0x03
1350
1351 /* fixed 2 channels */
1352 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1353         { 2, NULL }
1354 };
1355
1356 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1357         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1358         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1359         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1360         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1361         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1362         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1363         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1364         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1365         { } /* end */
1366 };
1367
1368
1369 /*
1370  * ALC880 F1734 model
1371  *
1372  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1373  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1374  */
1375
1376 static hda_nid_t alc880_f1734_dac_nids[1] = {
1377         0x03
1378 };
1379 #define ALC880_F1734_HP_DAC     0x02
1380
1381 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1382         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1383         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1384         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1385         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1386         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1387         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1388         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1389         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1390         { } /* end */
1391 };
1392
1393 static struct hda_input_mux alc880_f1734_capture_source = {
1394         .num_items = 2,
1395         .items = {
1396                 { "Mic", 0x1 },
1397                 { "CD", 0x4 },
1398         },
1399 };
1400
1401
1402 /*
1403  * ALC880 ASUS model
1404  *
1405  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1406  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1407  *  Mic = 0x18, Line = 0x1a
1408  */
1409
1410 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1411 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1412
1413 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1414         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1415         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1416         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1417         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1418         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1419         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1420         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1421         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1422         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1423         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1424         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1425         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1426         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1427         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1428         {
1429                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1430                 .name = "Channel Mode",
1431                 .info = alc_ch_mode_info,
1432                 .get = alc_ch_mode_get,
1433                 .put = alc_ch_mode_put,
1434         },
1435         { } /* end */
1436 };
1437
1438 /*
1439  * ALC880 ASUS W1V model
1440  *
1441  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1442  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1443  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1444  */
1445
1446 /* additional mixers to alc880_asus_mixer */
1447 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1448         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1449         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1450         { } /* end */
1451 };
1452
1453 /* additional mixers to alc880_asus_mixer */
1454 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1455         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1456         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1457         { } /* end */
1458 };
1459
1460 /* TCL S700 */
1461 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1462         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1463         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1464         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1465         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1466         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1467         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1468         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1469         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1470         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1471         {
1472                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1473                 /* The multiple "Capture Source" controls confuse alsamixer
1474                  * So call somewhat different..
1475                  */
1476                 /* .name = "Capture Source", */
1477                 .name = "Input Source",
1478                 .count = 1,
1479                 .info = alc_mux_enum_info,
1480                 .get = alc_mux_enum_get,
1481                 .put = alc_mux_enum_put,
1482         },
1483         { } /* end */
1484 };
1485
1486 /* Uniwill */
1487 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1488         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1489         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1490         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1491         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1492         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1493         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1494         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1495         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1496         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1497         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1498         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1499         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1500         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1501         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1502         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1503         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1504         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1505         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1506         {
1507                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1508                 .name = "Channel Mode",
1509                 .info = alc_ch_mode_info,
1510                 .get = alc_ch_mode_get,
1511                 .put = alc_ch_mode_put,
1512         },
1513         { } /* end */
1514 };
1515
1516 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1517         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1518         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1519         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1520         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1521         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1522         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1523         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1524         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1525         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1526         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1527         { } /* end */
1528 };
1529
1530 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1531         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1532         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1533         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1534         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1535         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1536         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1537         { } /* end */
1538 };
1539
1540 /*
1541  * virtual master controls
1542  */
1543
1544 /*
1545  * slave controls for virtual master
1546  */
1547 static const char *alc_slave_vols[] = {
1548         "Front Playback Volume",
1549         "Surround Playback Volume",
1550         "Center Playback Volume",
1551         "LFE Playback Volume",
1552         "Side Playback Volume",
1553         "Headphone Playback Volume",
1554         "Speaker Playback Volume",
1555         "Mono Playback Volume",
1556         "Line-Out Playback Volume",
1557         NULL,
1558 };
1559
1560 static const char *alc_slave_sws[] = {
1561         "Front Playback Switch",
1562         "Surround Playback Switch",
1563         "Center Playback Switch",
1564         "LFE Playback Switch",
1565         "Side Playback Switch",
1566         "Headphone Playback Switch",
1567         "Speaker Playback Switch",
1568         "Mono Playback Switch",
1569         "IEC958 Playback Switch",
1570         NULL,
1571 };
1572
1573 /*
1574  * build control elements
1575  */
1576 static int alc_build_controls(struct hda_codec *codec)
1577 {
1578         struct alc_spec *spec = codec->spec;
1579         int err;
1580         int i;
1581
1582         for (i = 0; i < spec->num_mixers; i++) {
1583                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1584                 if (err < 0)
1585                         return err;
1586         }
1587
1588         if (spec->multiout.dig_out_nid) {
1589                 err = snd_hda_create_spdif_out_ctls(codec,
1590                                                     spec->multiout.dig_out_nid);
1591                 if (err < 0)
1592                         return err;
1593                 err = snd_hda_create_spdif_share_sw(codec,
1594                                                     &spec->multiout);
1595                 if (err < 0)
1596                         return err;
1597                 spec->multiout.share_spdif = 1;
1598         }
1599         if (spec->dig_in_nid) {
1600                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1601                 if (err < 0)
1602                         return err;
1603         }
1604
1605         /* if we have no master control, let's create it */
1606         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1607                 unsigned int vmaster_tlv[4];
1608                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1609                                         HDA_OUTPUT, vmaster_tlv);
1610                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1611                                           vmaster_tlv, alc_slave_vols);
1612                 if (err < 0)
1613                         return err;
1614         }
1615         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1616                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1617                                           NULL, alc_slave_sws);
1618                 if (err < 0)
1619                         return err;
1620         }
1621
1622         return 0;
1623 }
1624
1625
1626 /*
1627  * initialize the codec volumes, etc
1628  */
1629
1630 /*
1631  * generic initialization of ADC, input mixers and output mixers
1632  */
1633 static struct hda_verb alc880_volume_init_verbs[] = {
1634         /*
1635          * Unmute ADC0-2 and set the default input to mic-in
1636          */
1637         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
1638         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1639         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
1640         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1641         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1642         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1643
1644         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1645          * mixer widget
1646          * Note: PASD motherboards uses the Line In 2 as the input for front
1647          * panel mic (mic 2)
1648          */
1649         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
1650         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1651         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1652         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1653         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1654         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1655         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1656         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1657
1658         /*
1659          * Set up output mixers (0x0c - 0x0f)
1660          */
1661         /* set vol=0 to output mixers */
1662         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1663         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1664         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1665         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1666         /* set up input amps for analog loopback */
1667         /* Amp Indices: DAC = 0, mixer = 1 */
1668         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1669         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1670         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1671         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1672         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1673         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1674         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1675         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1676
1677         { }
1678 };
1679
1680 /*
1681  * 3-stack pin configuration:
1682  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
1683  */
1684 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
1685         /*
1686          * preset connection lists of input pins
1687          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1688          */
1689         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1690         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1691         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1692
1693         /*
1694          * Set pin mode and muting
1695          */
1696         /* set front pin widgets 0x14 for output */
1697         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1698         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1699         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1700         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1701         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1702         /* Mic2 (as headphone out) for HP output */
1703         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1704         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1705         /* Line In pin widget for input */
1706         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1707         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1708         /* Line2 (as front mic) pin widget for input and vref at 80% */
1709         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1710         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1711         /* CD pin widget for input */
1712         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1713
1714         { }
1715 };
1716
1717 /*
1718  * 5-stack pin configuration:
1719  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
1720  * line-in/side = 0x1a, f-mic = 0x1b
1721  */
1722 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
1723         /*
1724          * preset connection lists of input pins
1725          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1726          */
1727         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1728         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1729
1730         /*
1731          * Set pin mode and muting
1732          */
1733         /* set pin widgets 0x14-0x17 for output */
1734         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1735         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1736         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1737         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1738         /* unmute pins for output (no gain on this amp) */
1739         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1740         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1741         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1742         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1743
1744         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1745         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1746         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1747         /* Mic2 (as headphone out) for HP output */
1748         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1749         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1750         /* Line In pin widget for input */
1751         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1752         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1753         /* Line2 (as front mic) pin widget for input and vref at 80% */
1754         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1755         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1756         /* CD pin widget for input */
1757         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1758
1759         { }
1760 };
1761
1762 /*
1763  * W810 pin configuration:
1764  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
1765  */
1766 static struct hda_verb alc880_pin_w810_init_verbs[] = {
1767         /* hphone/speaker input selector: front DAC */
1768         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1769
1770         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1771         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1772         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1773         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1774         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1775         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1776
1777         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1778         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1779
1780         { }
1781 };
1782
1783 /*
1784  * Z71V pin configuration:
1785  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
1786  */
1787 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
1788         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1789         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1790         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1791         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1792
1793         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1794         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1795         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1796         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1797
1798         { }
1799 };
1800
1801 /*
1802  * 6-stack pin configuration:
1803  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
1804  * f-mic = 0x19, line = 0x1a, HP = 0x1b
1805  */
1806 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1807         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1808
1809         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1810         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1811         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1812         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1813         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1814         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1815         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1816         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1817
1818         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1819         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1820         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1821         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1822         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1823         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1824         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1825         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1826         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1827         
1828         { }
1829 };
1830
1831 /*
1832  * Uniwill pin configuration:
1833  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
1834  * line = 0x1a
1835  */
1836 static struct hda_verb alc880_uniwill_init_verbs[] = {
1837         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1838
1839         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1840         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1841         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1842         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1843         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1844         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1845         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1846         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1847         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1848         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1849         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1850         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1851         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1852         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1853
1854         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1855         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1856         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1857         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1858         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1859         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1860         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
1861         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
1862         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1863
1864         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1865         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
1866
1867         { }
1868 };
1869
1870 /*
1871 * Uniwill P53
1872 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19, 
1873  */
1874 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
1875         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1876
1877         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1878         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1879         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1880         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1881         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1882         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1883         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1884         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1885         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1886         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1887         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1888         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1889
1890         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1891         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1892         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1893         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1894         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1895         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1896
1897         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1898         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
1899
1900         { }
1901 };
1902
1903 static struct hda_verb alc880_beep_init_verbs[] = {
1904         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
1905         { }
1906 };
1907
1908 /* toggle speaker-output according to the hp-jack state */
1909 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
1910 {
1911         unsigned int present;
1912         unsigned char bits;
1913
1914         present = snd_hda_codec_read(codec, 0x14, 0,
1915                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1916         bits = present ? HDA_AMP_MUTE : 0;
1917         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1918                                  HDA_AMP_MUTE, bits);
1919         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
1920                                  HDA_AMP_MUTE, bits);
1921 }
1922
1923 /* auto-toggle front mic */
1924 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
1925 {
1926         unsigned int present;
1927         unsigned char bits;
1928
1929         present = snd_hda_codec_read(codec, 0x18, 0,
1930                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1931         bits = present ? HDA_AMP_MUTE : 0;
1932         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
1933 }
1934
1935 static void alc880_uniwill_automute(struct hda_codec *codec)
1936 {
1937         alc880_uniwill_hp_automute(codec);
1938         alc880_uniwill_mic_automute(codec);
1939 }
1940
1941 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
1942                                        unsigned int res)
1943 {
1944         /* Looks like the unsol event is incompatible with the standard
1945          * definition.  4bit tag is placed at 28 bit!
1946          */
1947         switch (res >> 28) {
1948         case ALC880_HP_EVENT:
1949                 alc880_uniwill_hp_automute(codec);
1950                 break;
1951         case ALC880_MIC_EVENT:
1952                 alc880_uniwill_mic_automute(codec);
1953                 break;
1954         }
1955 }
1956
1957 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
1958 {
1959         unsigned int present;
1960         unsigned char bits;
1961
1962         present = snd_hda_codec_read(codec, 0x14, 0,
1963                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1964         bits = present ? HDA_AMP_MUTE : 0;
1965         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
1966 }
1967
1968 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
1969 {
1970         unsigned int present;
1971         
1972         present = snd_hda_codec_read(codec, 0x21, 0,
1973                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
1974         present &= HDA_AMP_VOLMASK;
1975         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
1976                                  HDA_AMP_VOLMASK, present);
1977         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
1978                                  HDA_AMP_VOLMASK, present);
1979 }
1980
1981 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
1982                                            unsigned int res)
1983 {
1984         /* Looks like the unsol event is incompatible with the standard
1985          * definition.  4bit tag is placed at 28 bit!
1986          */
1987         if ((res >> 28) == ALC880_HP_EVENT)
1988                 alc880_uniwill_p53_hp_automute(codec);
1989         if ((res >> 28) == ALC880_DCVOL_EVENT)
1990                 alc880_uniwill_p53_dcvol_automute(codec);
1991 }
1992
1993 /*
1994  * F1734 pin configuration:
1995  * HP = 0x14, speaker-out = 0x15, mic = 0x18
1996  */
1997 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1998         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
1999         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2000         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2001         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2002         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2003
2004         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2005         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2006         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2007         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2008
2009         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2010         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2011         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2012         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2013         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2014         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2015         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2016         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2017         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2018
2019         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2020         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2021
2022         { }
2023 };
2024
2025 /*
2026  * ASUS pin configuration:
2027  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2028  */
2029 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2030         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2031         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2032         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2033         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2034
2035         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2036         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2037         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2038         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2039         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2040         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2041         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2042         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2043
2044         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2045         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2046         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2047         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2048         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2049         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2050         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2051         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2052         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2053         
2054         { }
2055 };
2056
2057 /* Enable GPIO mask and set output */
2058 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2059 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2060
2061 /* Clevo m520g init */
2062 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2063         /* headphone output */
2064         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2065         /* line-out */
2066         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2067         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2068         /* Line-in */
2069         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2070         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2071         /* CD */
2072         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2073         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2074         /* Mic1 (rear panel) */
2075         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2076         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2077         /* Mic2 (front panel) */
2078         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2079         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2080         /* headphone */
2081         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2082         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2083         /* change to EAPD mode */
2084         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2085         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2086
2087         { }
2088 };
2089
2090 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2091         /* change to EAPD mode */
2092         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2093         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2094
2095         /* Headphone output */
2096         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2097         /* Front output*/
2098         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2099         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2100
2101         /* Line In pin widget for input */
2102         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2103         /* CD pin widget for input */
2104         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2105         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2106         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2107
2108         /* change to EAPD mode */
2109         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2110         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2111
2112         { }
2113 };
2114
2115 /*
2116  * LG m1 express dual
2117  *
2118  * Pin assignment:
2119  *   Rear Line-In/Out (blue): 0x14
2120  *   Build-in Mic-In: 0x15
2121  *   Speaker-out: 0x17
2122  *   HP-Out (green): 0x1b
2123  *   Mic-In/Out (red): 0x19
2124  *   SPDIF-Out: 0x1e
2125  */
2126
2127 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2128 static hda_nid_t alc880_lg_dac_nids[3] = {
2129         0x05, 0x02, 0x03
2130 };
2131
2132 /* seems analog CD is not working */
2133 static struct hda_input_mux alc880_lg_capture_source = {
2134         .num_items = 3,
2135         .items = {
2136                 { "Mic", 0x1 },
2137                 { "Line", 0x5 },
2138                 { "Internal Mic", 0x6 },
2139         },
2140 };
2141
2142 /* 2,4,6 channel modes */
2143 static struct hda_verb alc880_lg_ch2_init[] = {
2144         /* set line-in and mic-in to input */
2145         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2146         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2147         { }
2148 };
2149
2150 static struct hda_verb alc880_lg_ch4_init[] = {
2151         /* set line-in to out and mic-in to input */
2152         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2153         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2154         { }
2155 };
2156
2157 static struct hda_verb alc880_lg_ch6_init[] = {
2158         /* set line-in and mic-in to output */
2159         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2160         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2161         { }
2162 };
2163
2164 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2165         { 2, alc880_lg_ch2_init },
2166         { 4, alc880_lg_ch4_init },
2167         { 6, alc880_lg_ch6_init },
2168 };
2169
2170 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2171         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2172         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2173         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2174         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2175         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2176         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2177         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2178         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2179         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2180         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2181         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2182         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2183         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2184         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2185         {
2186                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2187                 .name = "Channel Mode",
2188                 .info = alc_ch_mode_info,
2189                 .get = alc_ch_mode_get,
2190                 .put = alc_ch_mode_put,
2191         },
2192         { } /* end */
2193 };
2194
2195 static struct hda_verb alc880_lg_init_verbs[] = {
2196         /* set capture source to mic-in */
2197         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2198         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2199         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2200         /* mute all amp mixer inputs */
2201         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2202         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2203         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2204         /* line-in to input */
2205         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2206         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2207         /* built-in mic */
2208         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2209         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2210         /* speaker-out */
2211         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2212         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2213         /* mic-in to input */
2214         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2215         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2216         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2217         /* HP-out */
2218         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2219         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2220         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2221         /* jack sense */
2222         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2223         { }
2224 };
2225
2226 /* toggle speaker-output according to the hp-jack state */
2227 static void alc880_lg_automute(struct hda_codec *codec)
2228 {
2229         unsigned int present;
2230         unsigned char bits;
2231
2232         present = snd_hda_codec_read(codec, 0x1b, 0,
2233                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2234         bits = present ? HDA_AMP_MUTE : 0;
2235         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2236                                  HDA_AMP_MUTE, bits);
2237 }
2238
2239 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2240 {
2241         /* Looks like the unsol event is incompatible with the standard
2242          * definition.  4bit tag is placed at 28 bit!
2243          */
2244         if ((res >> 28) == 0x01)
2245                 alc880_lg_automute(codec);
2246 }
2247
2248 /*
2249  * LG LW20
2250  *
2251  * Pin assignment:
2252  *   Speaker-out: 0x14
2253  *   Mic-In: 0x18
2254  *   Built-in Mic-In: 0x19
2255  *   Line-In: 0x1b
2256  *   HP-Out: 0x1a
2257  *   SPDIF-Out: 0x1e
2258  */
2259
2260 static struct hda_input_mux alc880_lg_lw_capture_source = {
2261         .num_items = 3,
2262         .items = {
2263                 { "Mic", 0x0 },
2264                 { "Internal Mic", 0x1 },
2265                 { "Line In", 0x2 },
2266         },
2267 };
2268
2269 #define alc880_lg_lw_modes alc880_threestack_modes
2270
2271 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2272         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2273         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2274         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2275         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2276         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2277         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2278         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2279         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2280         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2281         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2282         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2283         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2284         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2285         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2286         {
2287                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2288                 .name = "Channel Mode",
2289                 .info = alc_ch_mode_info,
2290                 .get = alc_ch_mode_get,
2291                 .put = alc_ch_mode_put,
2292         },
2293         { } /* end */
2294 };
2295
2296 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2297         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2298         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2299         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2300
2301         /* set capture source to mic-in */
2302         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2303         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2304         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2305         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2306         /* speaker-out */
2307         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2308         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2309         /* HP-out */
2310         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2311         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2312         /* mic-in to input */
2313         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2314         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2315         /* built-in mic */
2316         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2317         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2318         /* jack sense */
2319         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2320         { }
2321 };
2322
2323 /* toggle speaker-output according to the hp-jack state */
2324 static void alc880_lg_lw_automute(struct hda_codec *codec)
2325 {
2326         unsigned int present;
2327         unsigned char bits;
2328
2329         present = snd_hda_codec_read(codec, 0x1b, 0,
2330                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2331         bits = present ? HDA_AMP_MUTE : 0;
2332         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2333                                  HDA_AMP_MUTE, bits);
2334 }
2335
2336 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2337 {
2338         /* Looks like the unsol event is incompatible with the standard
2339          * definition.  4bit tag is placed at 28 bit!
2340          */
2341         if ((res >> 28) == 0x01)
2342                 alc880_lg_lw_automute(codec);
2343 }
2344
2345 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2346         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2347         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2348         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2349         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2350         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2351         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2352         { } /* end */
2353 };
2354
2355 static struct hda_input_mux alc880_medion_rim_capture_source = {
2356         .num_items = 2,
2357         .items = {
2358                 { "Mic", 0x0 },
2359                 { "Internal Mic", 0x1 },
2360         },
2361 };
2362
2363 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2364         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2365
2366         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2367         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2368
2369         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2370         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2371         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2372         /* Mic2 (as headphone out) for HP output */
2373         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2374         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2375         /* Internal Speaker */
2376         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2377         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2378
2379         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2380         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2381
2382         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2383         { }
2384 };
2385
2386 /* toggle speaker-output according to the hp-jack state */
2387 static void alc880_medion_rim_automute(struct hda_codec *codec)
2388 {
2389         unsigned int present;
2390         unsigned char bits;
2391
2392         present = snd_hda_codec_read(codec, 0x14, 0,
2393                                      AC_VERB_GET_PIN_SENSE, 0)
2394                 & AC_PINSENSE_PRESENCE;
2395         bits = present ? HDA_AMP_MUTE : 0;
2396         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2397                                  HDA_AMP_MUTE, bits);
2398         if (present)
2399                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2400         else
2401                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2402 }
2403
2404 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2405                                           unsigned int res)
2406 {
2407         /* Looks like the unsol event is incompatible with the standard
2408          * definition.  4bit tag is placed at 28 bit!
2409          */
2410         if ((res >> 28) == ALC880_HP_EVENT)
2411                 alc880_medion_rim_automute(codec);
2412 }
2413
2414 #ifdef CONFIG_SND_HDA_POWER_SAVE
2415 static struct hda_amp_list alc880_loopbacks[] = {
2416         { 0x0b, HDA_INPUT, 0 },
2417         { 0x0b, HDA_INPUT, 1 },
2418         { 0x0b, HDA_INPUT, 2 },
2419         { 0x0b, HDA_INPUT, 3 },
2420         { 0x0b, HDA_INPUT, 4 },
2421         { } /* end */
2422 };
2423
2424 static struct hda_amp_list alc880_lg_loopbacks[] = {
2425         { 0x0b, HDA_INPUT, 1 },
2426         { 0x0b, HDA_INPUT, 6 },
2427         { 0x0b, HDA_INPUT, 7 },
2428         { } /* end */
2429 };
2430 #endif
2431
2432 /*
2433  * Common callbacks
2434  */
2435
2436 static int alc_init(struct hda_codec *codec)
2437 {
2438         struct alc_spec *spec = codec->spec;
2439         unsigned int i;
2440
2441         alc_fix_pll(codec);
2442
2443         for (i = 0; i < spec->num_init_verbs; i++)
2444                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2445
2446         if (spec->init_hook)
2447                 spec->init_hook(codec);
2448
2449         return 0;
2450 }
2451
2452 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2453 {
2454         struct alc_spec *spec = codec->spec;
2455
2456         if (spec->unsol_event)
2457                 spec->unsol_event(codec, res);
2458 }
2459
2460 #ifdef CONFIG_SND_HDA_POWER_SAVE
2461 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2462 {
2463         struct alc_spec *spec = codec->spec;
2464         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2465 }
2466 #endif
2467
2468 /*
2469  * Analog playback callbacks
2470  */
2471 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2472                                     struct hda_codec *codec,
2473                                     struct snd_pcm_substream *substream)
2474 {
2475         struct alc_spec *spec = codec->spec;
2476         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2477                                              hinfo);
2478 }
2479
2480 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2481                                        struct hda_codec *codec,
2482                                        unsigned int stream_tag,
2483                                        unsigned int format,
2484                                        struct snd_pcm_substream *substream)
2485 {
2486         struct alc_spec *spec = codec->spec;
2487         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2488                                                 stream_tag, format, substream);
2489 }
2490
2491 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2492                                        struct hda_codec *codec,
2493                                        struct snd_pcm_substream *substream)
2494 {
2495         struct alc_spec *spec = codec->spec;
2496         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2497 }
2498
2499 /*
2500  * Digital out
2501  */
2502 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2503                                         struct hda_codec *codec,
2504                                         struct snd_pcm_substream *substream)
2505 {
2506         struct alc_spec *spec = codec->spec;
2507         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2508 }
2509
2510 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2511                                            struct hda_codec *codec,
2512                                            unsigned int stream_tag,
2513                                            unsigned int format,
2514                                            struct snd_pcm_substream *substream)
2515 {
2516         struct alc_spec *spec = codec->spec;
2517         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2518                                              stream_tag, format, substream);
2519 }
2520
2521 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2522                                          struct hda_codec *codec,
2523                                          struct snd_pcm_substream *substream)
2524 {
2525         struct alc_spec *spec = codec->spec;
2526         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2527 }
2528
2529 /*
2530  * Analog capture
2531  */
2532 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2533                                       struct hda_codec *codec,
2534                                       unsigned int stream_tag,
2535                                       unsigned int format,
2536                                       struct snd_pcm_substream *substream)
2537 {
2538         struct alc_spec *spec = codec->spec;
2539
2540         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2541                                    stream_tag, 0, format);
2542         return 0;
2543 }
2544
2545 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2546                                       struct hda_codec *codec,
2547                                       struct snd_pcm_substream *substream)
2548 {
2549         struct alc_spec *spec = codec->spec;
2550
2551         snd_hda_codec_cleanup_stream(codec,
2552                                      spec->adc_nids[substream->number + 1]);
2553         return 0;
2554 }
2555
2556
2557 /*
2558  */
2559 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2560         .substreams = 1,
2561         .channels_min = 2,
2562         .channels_max = 8,
2563         /* NID is set in alc_build_pcms */
2564         .ops = {
2565                 .open = alc880_playback_pcm_open,
2566                 .prepare = alc880_playback_pcm_prepare,
2567                 .cleanup = alc880_playback_pcm_cleanup
2568         },
2569 };
2570
2571 static struct hda_pcm_stream alc880_pcm_analog_capture = {
2572         .substreams = 1,
2573         .channels_min = 2,
2574         .channels_max = 2,
2575         /* NID is set in alc_build_pcms */
2576 };
2577
2578 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
2579         .substreams = 1,
2580         .channels_min = 2,
2581         .channels_max = 2,
2582         /* NID is set in alc_build_pcms */
2583 };
2584
2585 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
2586         .substreams = 2, /* can be overridden */
2587         .channels_min = 2,
2588         .channels_max = 2,
2589         /* NID is set in alc_build_pcms */
2590         .ops = {
2591                 .prepare = alc880_alt_capture_pcm_prepare,
2592                 .cleanup = alc880_alt_capture_pcm_cleanup
2593         },
2594 };
2595
2596 static struct hda_pcm_stream alc880_pcm_digital_playback = {
2597         .substreams = 1,
2598         .channels_min = 2,
2599         .channels_max = 2,
2600         /* NID is set in alc_build_pcms */
2601         .ops = {
2602                 .open = alc880_dig_playback_pcm_open,
2603                 .close = alc880_dig_playback_pcm_close,
2604                 .prepare = alc880_dig_playback_pcm_prepare
2605         },
2606 };
2607
2608 static struct hda_pcm_stream alc880_pcm_digital_capture = {
2609         .substreams = 1,
2610         .channels_min = 2,
2611         .channels_max = 2,
2612         /* NID is set in alc_build_pcms */
2613 };
2614
2615 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2616 static struct hda_pcm_stream alc_pcm_null_stream = {
2617         .substreams = 0,
2618         .channels_min = 0,
2619         .channels_max = 0,
2620 };
2621
2622 static int alc_build_pcms(struct hda_codec *codec)
2623 {
2624         struct alc_spec *spec = codec->spec;
2625         struct hda_pcm *info = spec->pcm_rec;
2626         int i;
2627
2628         codec->num_pcms = 1;
2629         codec->pcm_info = info;
2630
2631         info->name = spec->stream_name_analog;
2632         if (spec->stream_analog_playback) {
2633                 snd_assert(spec->multiout.dac_nids, return -EINVAL);
2634                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
2635                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2636         }
2637         if (spec->stream_analog_capture) {
2638                 snd_assert(spec->adc_nids, return -EINVAL);
2639                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2640                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2641         }
2642
2643         if (spec->channel_mode) {
2644                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2645                 for (i = 0; i < spec->num_channel_mode; i++) {
2646                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2647                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2648                         }
2649                 }
2650         }
2651
2652         /* SPDIF for stream index #1 */
2653         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2654                 codec->num_pcms = 2;
2655                 info = spec->pcm_rec + 1;
2656                 info->name = spec->stream_name_digital;
2657                 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2658                 if (spec->multiout.dig_out_nid &&
2659                     spec->stream_digital_playback) {
2660                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
2661                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2662                 }
2663                 if (spec->dig_in_nid &&
2664                     spec->stream_digital_capture) {
2665                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
2666                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2667                 }
2668         }
2669
2670         /* If the use of more than one ADC is requested for the current
2671          * model, configure a second analog capture-only PCM.
2672          */
2673         /* Additional Analaog capture for index #2 */
2674         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
2675             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
2676                 codec->num_pcms = 3;
2677                 info = spec->pcm_rec + 2;
2678                 info->name = spec->stream_name_analog;
2679                 if (spec->alt_dac_nid) {
2680                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2681                                 *spec->stream_analog_alt_playback;
2682                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2683                                 spec->alt_dac_nid;
2684                 } else {
2685                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2686                                 alc_pcm_null_stream;
2687                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2688                 }
2689                 if (spec->num_adc_nids > 1) {
2690                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2691                                 *spec->stream_analog_alt_capture;
2692                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2693                                 spec->adc_nids[1];
2694                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2695                                 spec->num_adc_nids - 1;
2696                 } else {
2697                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2698                                 alc_pcm_null_stream;
2699                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2700                 }
2701         }
2702
2703         return 0;
2704 }
2705
2706 static void alc_free(struct hda_codec *codec)
2707 {
2708         struct alc_spec *spec = codec->spec;
2709         unsigned int i;
2710
2711         if (!spec)
2712                 return;
2713
2714         if (spec->kctl_alloc) {
2715                 for (i = 0; i < spec->num_kctl_used; i++)
2716                         kfree(spec->kctl_alloc[i].name);
2717                 kfree(spec->kctl_alloc);
2718         }
2719         kfree(spec);
2720         codec->spec = NULL; /* to be sure */
2721 }
2722
2723 /*
2724  */
2725 static struct hda_codec_ops alc_patch_ops = {
2726         .build_controls = alc_build_controls,
2727         .build_pcms = alc_build_pcms,
2728         .init = alc_init,
2729         .free = alc_free,
2730         .unsol_event = alc_unsol_event,
2731 #ifdef CONFIG_SND_HDA_POWER_SAVE
2732         .check_power_status = alc_check_power_status,
2733 #endif
2734 };
2735
2736
2737 /*
2738  * Test configuration for debugging
2739  *
2740  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
2741  * enum controls.
2742  */
2743 #ifdef CONFIG_SND_DEBUG
2744 static hda_nid_t alc880_test_dac_nids[4] = {
2745         0x02, 0x03, 0x04, 0x05
2746 };
2747
2748 static struct hda_input_mux alc880_test_capture_source = {
2749         .num_items = 7,
2750         .items = {
2751                 { "In-1", 0x0 },
2752                 { "In-2", 0x1 },
2753                 { "In-3", 0x2 },
2754                 { "In-4", 0x3 },
2755                 { "CD", 0x4 },
2756                 { "Front", 0x5 },
2757                 { "Surround", 0x6 },
2758         },
2759 };
2760
2761 static struct hda_channel_mode alc880_test_modes[4] = {
2762         { 2, NULL },
2763         { 4, NULL },
2764         { 6, NULL },
2765         { 8, NULL },
2766 };
2767
2768 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
2769                                  struct snd_ctl_elem_info *uinfo)
2770 {
2771         static char *texts[] = {
2772                 "N/A", "Line Out", "HP Out",
2773                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
2774         };
2775         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2776         uinfo->count = 1;
2777         uinfo->value.enumerated.items = 8;
2778         if (uinfo->value.enumerated.item >= 8)
2779                 uinfo->value.enumerated.item = 7;
2780         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2781         return 0;
2782 }
2783
2784 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
2785                                 struct snd_ctl_elem_value *ucontrol)
2786 {
2787         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2788         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2789         unsigned int pin_ctl, item = 0;
2790
2791         pin_ctl = snd_hda_codec_read(codec, nid, 0,
2792                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2793         if (pin_ctl & AC_PINCTL_OUT_EN) {
2794                 if (pin_ctl & AC_PINCTL_HP_EN)
2795                         item = 2;
2796                 else
2797                         item = 1;
2798         } else if (pin_ctl & AC_PINCTL_IN_EN) {
2799                 switch (pin_ctl & AC_PINCTL_VREFEN) {
2800                 case AC_PINCTL_VREF_HIZ: item = 3; break;
2801                 case AC_PINCTL_VREF_50:  item = 4; break;
2802                 case AC_PINCTL_VREF_GRD: item = 5; break;
2803                 case AC_PINCTL_VREF_80:  item = 6; break;
2804                 case AC_PINCTL_VREF_100: item = 7; break;
2805                 }
2806         }
2807         ucontrol->value.enumerated.item[0] = item;
2808         return 0;
2809 }
2810
2811 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
2812                                 struct snd_ctl_elem_value *ucontrol)
2813 {
2814         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2815         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2816         static unsigned int ctls[] = {
2817                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
2818                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
2819                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
2820                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
2821                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
2822                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
2823         };
2824         unsigned int old_ctl, new_ctl;
2825
2826         old_ctl = snd_hda_codec_read(codec, nid, 0,
2827                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2828         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
2829         if (old_ctl != new_ctl) {
2830                 int val;
2831                 snd_hda_codec_write_cache(codec, nid, 0,
2832                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
2833                                           new_ctl);
2834                 val = ucontrol->value.enumerated.item[0] >= 3 ?
2835                         HDA_AMP_MUTE : 0;
2836                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
2837                                          HDA_AMP_MUTE, val);
2838                 return 1;
2839         }
2840         return 0;
2841 }
2842
2843 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
2844                                  struct snd_ctl_elem_info *uinfo)
2845 {
2846         static char *texts[] = {
2847                 "Front", "Surround", "CLFE", "Side"
2848         };
2849         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2850         uinfo->count = 1;
2851         uinfo->value.enumerated.items = 4;
2852         if (uinfo->value.enumerated.item >= 4)
2853                 uinfo->value.enumerated.item = 3;
2854         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2855         return 0;
2856 }
2857
2858 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
2859                                 struct snd_ctl_elem_value *ucontrol)
2860 {
2861         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2862         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2863         unsigned int sel;
2864
2865         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
2866         ucontrol->value.enumerated.item[0] = sel & 3;
2867         return 0;
2868 }
2869
2870 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
2871                                 struct snd_ctl_elem_value *ucontrol)
2872 {
2873         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2874         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2875         unsigned int sel;
2876
2877         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
2878         if (ucontrol->value.enumerated.item[0] != sel) {
2879                 sel = ucontrol->value.enumerated.item[0] & 3;
2880                 snd_hda_codec_write_cache(codec, nid, 0,
2881                                           AC_VERB_SET_CONNECT_SEL, sel);
2882                 return 1;
2883         }
2884         return 0;
2885 }
2886
2887 #define PIN_CTL_TEST(xname,nid) {                       \
2888                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2889                         .name = xname,                 \
2890                         .info = alc_test_pin_ctl_info, \
2891                         .get = alc_test_pin_ctl_get,   \
2892                         .put = alc_test_pin_ctl_put,   \
2893                         .private_value = nid           \
2894                         }
2895
2896 #define PIN_SRC_TEST(xname,nid) {                       \
2897                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2898                         .name = xname,                 \
2899                         .info = alc_test_pin_src_info, \
2900                         .get = alc_test_pin_src_get,   \
2901                         .put = alc_test_pin_src_put,   \
2902                         .private_value = nid           \
2903                         }
2904
2905 static struct snd_kcontrol_new alc880_test_mixer[] = {
2906         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2907         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2908         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
2909         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2910         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2911         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2912         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
2913         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2914         PIN_CTL_TEST("Front Pin Mode", 0x14),
2915         PIN_CTL_TEST("Surround Pin Mode", 0x15),
2916         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
2917         PIN_CTL_TEST("Side Pin Mode", 0x17),
2918         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
2919         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
2920         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
2921         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
2922         PIN_SRC_TEST("In-1 Pin Source", 0x18),
2923         PIN_SRC_TEST("In-2 Pin Source", 0x19),
2924         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
2925         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
2926         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
2927         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
2928         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
2929         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
2930         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
2931         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
2932         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
2933         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
2934         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
2935         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
2936         {
2937                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2938                 .name = "Channel Mode",
2939                 .info = alc_ch_mode_info,
2940                 .get = alc_ch_mode_get,
2941                 .put = alc_ch_mode_put,
2942         },
2943         { } /* end */
2944 };
2945
2946 static struct hda_verb alc880_test_init_verbs[] = {
2947         /* Unmute inputs of 0x0c - 0x0f */
2948         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2949         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2950         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2951         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2952         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2953         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2954         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2955         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2956         /* Vol output for 0x0c-0x0f */
2957         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2958         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2959         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2960         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2961         /* Set output pins 0x14-0x17 */
2962         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2963         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2964         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2965         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2966         /* Unmute output pins 0x14-0x17 */
2967         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2968         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2969         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2970         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2971         /* Set input pins 0x18-0x1c */
2972         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2973         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2974         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2975         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2976         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2977         /* Mute input pins 0x18-0x1b */
2978         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2979         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2980         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2981         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2982         /* ADC set up */
2983         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2984         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2985         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2986         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2987         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2988         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2989         /* Analog input/passthru */
2990         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2991         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2992         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2993         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2994         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2995         { }
2996 };
2997 #endif
2998
2999 /*
3000  */
3001
3002 static const char *alc880_models[ALC880_MODEL_LAST] = {
3003         [ALC880_3ST]            = "3stack",
3004         [ALC880_TCL_S700]       = "tcl",
3005         [ALC880_3ST_DIG]        = "3stack-digout",
3006         [ALC880_CLEVO]          = "clevo",
3007         [ALC880_5ST]            = "5stack",
3008         [ALC880_5ST_DIG]        = "5stack-digout",
3009         [ALC880_W810]           = "w810",
3010         [ALC880_Z71V]           = "z71v",
3011         [ALC880_6ST]            = "6stack",
3012         [ALC880_6ST_DIG]        = "6stack-digout",
3013         [ALC880_ASUS]           = "asus",
3014         [ALC880_ASUS_W1V]       = "asus-w1v",
3015         [ALC880_ASUS_DIG]       = "asus-dig",
3016         [ALC880_ASUS_DIG2]      = "asus-dig2",
3017         [ALC880_UNIWILL_DIG]    = "uniwill",
3018         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3019         [ALC880_FUJITSU]        = "fujitsu",
3020         [ALC880_F1734]          = "F1734",
3021         [ALC880_LG]             = "lg",
3022         [ALC880_LG_LW]          = "lg-lw",
3023         [ALC880_MEDION_RIM]     = "medion",
3024 #ifdef CONFIG_SND_DEBUG
3025         [ALC880_TEST]           = "test",
3026 #endif
3027         [ALC880_AUTO]           = "auto",
3028 };
3029
3030 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3031         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3032         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3033         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3034         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3035         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3036         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3037         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3038         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3039         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3040         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3041         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3042         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3043         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3044         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3045         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3046         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3047         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3048         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3049         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3050         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3051         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3052         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3053         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3054         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3055         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3056         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
3057         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3058         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3059         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3060         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3061         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3062         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3063         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3064         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3065         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3066         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3067         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3068         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3069         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3070         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3071         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3072         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3073         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3074         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3075         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3076         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3077         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3078         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3079         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3080         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3081         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3082         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3083         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3084         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3085         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3086         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3087         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3088         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3089         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3090         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3091         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3092         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3093         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3094         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3095         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3096         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3097         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3098         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3099         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
3100         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3101         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3102         {}
3103 };
3104
3105 /*
3106  * ALC880 codec presets
3107  */
3108 static struct alc_config_preset alc880_presets[] = {
3109         [ALC880_3ST] = {
3110                 .mixers = { alc880_three_stack_mixer },
3111                 .init_verbs = { alc880_volume_init_verbs,
3112                                 alc880_pin_3stack_init_verbs },
3113                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3114                 .dac_nids = alc880_dac_nids,
3115                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3116                 .channel_mode = alc880_threestack_modes,
3117                 .need_dac_fix = 1,
3118                 .input_mux = &alc880_capture_source,
3119         },
3120         [ALC880_3ST_DIG] = {
3121                 .mixers = { alc880_three_stack_mixer },
3122                 .init_verbs = { alc880_volume_init_verbs,
3123                                 alc880_pin_3stack_init_verbs },
3124                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3125                 .dac_nids = alc880_dac_nids,
3126                 .dig_out_nid = ALC880_DIGOUT_NID,
3127                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3128                 .channel_mode = alc880_threestack_modes,
3129                 .need_dac_fix = 1,
3130                 .input_mux = &alc880_capture_source,
3131         },
3132         [ALC880_TCL_S700] = {
3133                 .mixers = { alc880_tcl_s700_mixer },
3134                 .init_verbs = { alc880_volume_init_verbs,
3135                                 alc880_pin_tcl_S700_init_verbs,
3136                                 alc880_gpio2_init_verbs },
3137                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3138                 .dac_nids = alc880_dac_nids,
3139                 .hp_nid = 0x03,
3140                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3141                 .channel_mode = alc880_2_jack_modes,
3142                 .input_mux = &alc880_capture_source,
3143         },
3144         [ALC880_5ST] = {
3145                 .mixers = { alc880_three_stack_mixer,
3146                             alc880_five_stack_mixer},
3147                 .init_verbs = { alc880_volume_init_verbs,
3148                                 alc880_pin_5stack_init_verbs },
3149                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3150                 .dac_nids = alc880_dac_nids,
3151                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3152                 .channel_mode = alc880_fivestack_modes,
3153                 .input_mux = &alc880_capture_source,
3154         },
3155         [ALC880_5ST_DIG] = {
3156                 .mixers = { alc880_three_stack_mixer,
3157                             alc880_five_stack_mixer },
3158                 .init_verbs = { alc880_volume_init_verbs,
3159                                 alc880_pin_5stack_init_verbs },
3160                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3161                 .dac_nids = alc880_dac_nids,
3162                 .dig_out_nid = ALC880_DIGOUT_NID,
3163                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3164                 .channel_mode = alc880_fivestack_modes,
3165                 .input_mux = &alc880_capture_source,
3166         },
3167         [ALC880_6ST] = {
3168                 .mixers = { alc880_six_stack_mixer },
3169                 .init_verbs = { alc880_volume_init_verbs,
3170                                 alc880_pin_6stack_init_verbs },
3171                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3172                 .dac_nids = alc880_6st_dac_nids,
3173                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3174                 .channel_mode = alc880_sixstack_modes,
3175                 .input_mux = &alc880_6stack_capture_source,
3176         },
3177         [ALC880_6ST_DIG] = {
3178                 .mixers = { alc880_six_stack_mixer },
3179                 .init_verbs = { alc880_volume_init_verbs,
3180                                 alc880_pin_6stack_init_verbs },
3181                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3182                 .dac_nids = alc880_6st_dac_nids,
3183                 .dig_out_nid = ALC880_DIGOUT_NID,
3184                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3185                 .channel_mode = alc880_sixstack_modes,
3186                 .input_mux = &alc880_6stack_capture_source,
3187         },
3188         [ALC880_W810] = {
3189                 .mixers = { alc880_w810_base_mixer },
3190                 .init_verbs = { alc880_volume_init_verbs,
3191                                 alc880_pin_w810_init_verbs,
3192                                 alc880_gpio2_init_verbs },
3193                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3194                 .dac_nids = alc880_w810_dac_nids,
3195                 .dig_out_nid = ALC880_DIGOUT_NID,
3196                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3197                 .channel_mode = alc880_w810_modes,
3198                 .input_mux = &alc880_capture_source,
3199         },
3200         [ALC880_Z71V] = {
3201                 .mixers = { alc880_z71v_mixer },
3202                 .init_verbs = { alc880_volume_init_verbs,
3203                                 alc880_pin_z71v_init_verbs },
3204                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3205                 .dac_nids = alc880_z71v_dac_nids,
3206                 .dig_out_nid = ALC880_DIGOUT_NID,
3207                 .hp_nid = 0x03,
3208                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3209                 .channel_mode = alc880_2_jack_modes,
3210                 .input_mux = &alc880_capture_source,
3211         },
3212         [ALC880_F1734] = {
3213                 .mixers = { alc880_f1734_mixer },
3214                 .init_verbs = { alc880_volume_init_verbs,
3215                                 alc880_pin_f1734_init_verbs },
3216                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3217                 .dac_nids = alc880_f1734_dac_nids,
3218                 .hp_nid = 0x02,
3219                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3220                 .channel_mode = alc880_2_jack_modes,
3221                 .input_mux = &alc880_f1734_capture_source,
3222                 .unsol_event = alc880_uniwill_p53_unsol_event,
3223                 .init_hook = alc880_uniwill_p53_hp_automute,
3224         },
3225         [ALC880_ASUS] = {
3226                 .mixers = { alc880_asus_mixer },
3227                 .init_verbs = { alc880_volume_init_verbs,
3228                                 alc880_pin_asus_init_verbs,
3229                                 alc880_gpio1_init_verbs },
3230                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3231                 .dac_nids = alc880_asus_dac_nids,
3232                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3233                 .channel_mode = alc880_asus_modes,
3234                 .need_dac_fix = 1,
3235                 .input_mux = &alc880_capture_source,
3236         },
3237         [ALC880_ASUS_DIG] = {
3238                 .mixers = { alc880_asus_mixer },
3239                 .init_verbs = { alc880_volume_init_verbs,
3240                                 alc880_pin_asus_init_verbs,
3241                                 alc880_gpio1_init_verbs },
3242                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3243                 .dac_nids = alc880_asus_dac_nids,
3244                 .dig_out_nid = ALC880_DIGOUT_NID,
3245                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3246                 .channel_mode = alc880_asus_modes,
3247                 .need_dac_fix = 1,
3248                 .input_mux = &alc880_capture_source,
3249         },
3250         [ALC880_ASUS_DIG2] = {
3251                 .mixers = { alc880_asus_mixer },
3252                 .init_verbs = { alc880_volume_init_verbs,
3253                                 alc880_pin_asus_init_verbs,
3254                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3255                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3256                 .dac_nids = alc880_asus_dac_nids,
3257                 .dig_out_nid = ALC880_DIGOUT_NID,
3258                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3259                 .channel_mode = alc880_asus_modes,
3260                 .need_dac_fix = 1,
3261                 .input_mux = &alc880_capture_source,
3262         },
3263         [ALC880_ASUS_W1V] = {
3264                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3265                 .init_verbs = { alc880_volume_init_verbs,
3266                                 alc880_pin_asus_init_verbs,
3267                                 alc880_gpio1_init_verbs },
3268                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3269                 .dac_nids = alc880_asus_dac_nids,
3270                 .dig_out_nid = ALC880_DIGOUT_NID,
3271                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3272                 .channel_mode = alc880_asus_modes,
3273                 .need_dac_fix = 1,
3274                 .input_mux = &alc880_capture_source,
3275         },
3276         [ALC880_UNIWILL_DIG] = {
3277                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3278                 .init_verbs = { alc880_volume_init_verbs,
3279                                 alc880_pin_asus_init_verbs },
3280                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3281                 .dac_nids = alc880_asus_dac_nids,
3282                 .dig_out_nid = ALC880_DIGOUT_NID,
3283                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3284                 .channel_mode = alc880_asus_modes,
3285                 .need_dac_fix = 1,
3286                 .input_mux = &alc880_capture_source,
3287         },
3288         [ALC880_UNIWILL] = {
3289                 .mixers = { alc880_uniwill_mixer },
3290                 .init_verbs = { alc880_volume_init_verbs,
3291                                 alc880_uniwill_init_verbs },
3292                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3293                 .dac_nids = alc880_asus_dac_nids,
3294                 .dig_out_nid = ALC880_DIGOUT_NID,
3295                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3296                 .channel_mode = alc880_threestack_modes,
3297                 .need_dac_fix = 1,
3298                 .input_mux = &alc880_capture_source,
3299                 .unsol_event = alc880_uniwill_unsol_event,
3300                 .init_hook = alc880_uniwill_automute,
3301         },
3302         [ALC880_UNIWILL_P53] = {
3303                 .mixers = { alc880_uniwill_p53_mixer },
3304                 .init_verbs = { alc880_volume_init_verbs,
3305                                 alc880_uniwill_p53_init_verbs },
3306                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3307                 .dac_nids = alc880_asus_dac_nids,
3308                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3309                 .channel_mode = alc880_threestack_modes,
3310                 .input_mux = &alc880_capture_source,
3311                 .unsol_event = alc880_uniwill_p53_unsol_event,
3312                 .init_hook = alc880_uniwill_p53_hp_automute,
3313         },
3314         [ALC880_FUJITSU] = {
3315                 .mixers = { alc880_fujitsu_mixer,
3316                             alc880_pcbeep_mixer, },
3317                 .init_verbs = { alc880_volume_init_verbs,
3318                                 alc880_uniwill_p53_init_verbs,
3319                                 alc880_beep_init_verbs },
3320                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3321                 .dac_nids = alc880_dac_nids,
3322                 .dig_out_nid = ALC880_DIGOUT_NID,
3323                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3324                 .channel_mode = alc880_2_jack_modes,
3325                 .input_mux = &alc880_capture_source,
3326                 .unsol_event = alc880_uniwill_p53_unsol_event,
3327                 .init_hook = alc880_uniwill_p53_hp_automute,
3328         },
3329         [ALC880_CLEVO] = {
3330                 .mixers = { alc880_three_stack_mixer },
3331                 .init_verbs = { alc880_volume_init_verbs,
3332                                 alc880_pin_clevo_init_verbs },
3333                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3334                 .dac_nids = alc880_dac_nids,
3335                 .hp_nid = 0x03,
3336                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3337                 .channel_mode = alc880_threestack_modes,
3338                 .need_dac_fix = 1,
3339                 .input_mux = &alc880_capture_source,
3340         },
3341         [ALC880_LG] = {
3342                 .mixers = { alc880_lg_mixer },
3343                 .init_verbs = { alc880_volume_init_verbs,
3344                                 alc880_lg_init_verbs },
3345                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3346                 .dac_nids = alc880_lg_dac_nids,
3347                 .dig_out_nid = ALC880_DIGOUT_NID,
3348                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3349                 .channel_mode = alc880_lg_ch_modes,
3350                 .need_dac_fix = 1,
3351                 .input_mux = &alc880_lg_capture_source,
3352                 .unsol_event = alc880_lg_unsol_event,
3353                 .init_hook = alc880_lg_automute,
3354 #ifdef CONFIG_SND_HDA_POWER_SAVE
3355                 .loopbacks = alc880_lg_loopbacks,
3356 #endif
3357         },
3358         [ALC880_LG_LW] = {
3359                 .mixers = { alc880_lg_lw_mixer },
3360                 .init_verbs = { alc880_volume_init_verbs,
3361                                 alc880_lg_lw_init_verbs },
3362                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3363                 .dac_nids = alc880_dac_nids,
3364                 .dig_out_nid = ALC880_DIGOUT_NID,
3365                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3366                 .channel_mode = alc880_lg_lw_modes,
3367                 .input_mux = &alc880_lg_lw_capture_source,
3368                 .unsol_event = alc880_lg_lw_unsol_event,
3369                 .init_hook = alc880_lg_lw_automute,
3370         },
3371         [ALC880_MEDION_RIM] = {
3372                 .mixers = { alc880_medion_rim_mixer },
3373                 .init_verbs = { alc880_volume_init_verbs,
3374                                 alc880_medion_rim_init_verbs,
3375                                 alc_gpio2_init_verbs },
3376                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3377                 .dac_nids = alc880_dac_nids,
3378                 .dig_out_nid = ALC880_DIGOUT_NID,
3379                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3380                 .channel_mode = alc880_2_jack_modes,
3381                 .input_mux = &alc880_medion_rim_capture_source,
3382                 .unsol_event = alc880_medion_rim_unsol_event,
3383                 .init_hook = alc880_medion_rim_automute,
3384         },
3385 #ifdef CONFIG_SND_DEBUG
3386         [ALC880_TEST] = {
3387                 .mixers = { alc880_test_mixer },
3388                 .init_verbs = { alc880_test_init_verbs },
3389                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3390                 .dac_nids = alc880_test_dac_nids,
3391                 .dig_out_nid = ALC880_DIGOUT_NID,
3392                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3393                 .channel_mode = alc880_test_modes,
3394                 .input_mux = &alc880_test_capture_source,
3395         },
3396 #endif
3397 };
3398
3399 /*
3400  * Automatic parse of I/O pins from the BIOS configuration
3401  */
3402
3403 #define NUM_CONTROL_ALLOC       32
3404 #define NUM_VERB_ALLOC          32
3405
3406 enum {
3407         ALC_CTL_WIDGET_VOL,
3408         ALC_CTL_WIDGET_MUTE,
3409         ALC_CTL_BIND_MUTE,
3410 };
3411 static struct snd_kcontrol_new alc880_control_templates[] = {
3412         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3413         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3414         HDA_BIND_MUTE(NULL, 0, 0, 0),
3415 };
3416
3417 /* add dynamic controls */
3418 static int add_control(struct alc_spec *spec, int type, const char *name,
3419                        unsigned long val)
3420 {
3421         struct snd_kcontrol_new *knew;
3422
3423         if (spec->num_kctl_used >= spec->num_kctl_alloc) {
3424                 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
3425
3426                 /* array + terminator */
3427                 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
3428                 if (!knew)
3429                         return -ENOMEM;
3430                 if (spec->kctl_alloc) {
3431                         memcpy(knew, spec->kctl_alloc,
3432                                sizeof(*knew) * spec->num_kctl_alloc);
3433                         kfree(spec->kctl_alloc);
3434                 }
3435                 spec->kctl_alloc = knew;
3436                 spec->num_kctl_alloc = num;
3437         }
3438
3439         knew = &spec->kctl_alloc[spec->num_kctl_used];
3440         *knew = alc880_control_templates[type];
3441         knew->name = kstrdup(name, GFP_KERNEL);
3442         if (!knew->name)
3443                 return -ENOMEM;
3444         knew->private_value = val;
3445         spec->num_kctl_used++;
3446         return 0;
3447 }
3448
3449 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3450 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3451 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3452 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3453 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3454 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3455 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3456 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3457 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3458 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3459 #define ALC880_PIN_CD_NID               0x1c
3460
3461 /* fill in the dac_nids table from the parsed pin configuration */
3462 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3463                                      const struct auto_pin_cfg *cfg)
3464 {
3465         hda_nid_t nid;
3466         int assigned[4];
3467         int i, j;
3468
3469         memset(assigned, 0, sizeof(assigned));
3470         spec->multiout.dac_nids = spec->private_dac_nids;
3471
3472         /* check the pins hardwired to audio widget */
3473         for (i = 0; i < cfg->line_outs; i++) {
3474                 nid = cfg->line_out_pins[i];
3475                 if (alc880_is_fixed_pin(nid)) {
3476                         int idx = alc880_fixed_pin_idx(nid);
3477                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3478                         assigned[idx] = 1;
3479                 }
3480         }
3481         /* left pins can be connect to any audio widget */
3482         for (i = 0; i < cfg->line_outs; i++) {
3483                 nid = cfg->line_out_pins[i];
3484                 if (alc880_is_fixed_pin(nid))
3485                         continue;
3486                 /* search for an empty channel */
3487                 for (j = 0; j < cfg->line_outs; j++) {
3488                         if (!assigned[j]) {
3489                                 spec->multiout.dac_nids[i] =
3490                                         alc880_idx_to_dac(j);
3491                                 assigned[j] = 1;
3492                                 break;
3493                         }
3494                 }
3495         }
3496         spec->multiout.num_dacs = cfg->line_outs;
3497         return 0;
3498 }
3499
3500 /* add playback controls from the parsed DAC table */
3501 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3502                                              const struct auto_pin_cfg *cfg)
3503 {
3504         char name[32];
3505         static const char *chname[4] = {
3506                 "Front", "Surround", NULL /*CLFE*/, "Side"
3507         };
3508         hda_nid_t nid;
3509         int i, err;
3510
3511         for (i = 0; i < cfg->line_outs; i++) {
3512                 if (!spec->multiout.dac_nids[i])
3513                         continue;
3514                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3515                 if (i == 2) {
3516                         /* Center/LFE */
3517                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3518                                           "Center Playback Volume",
3519                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3520                                                               HDA_OUTPUT));
3521                         if (err < 0)
3522                                 return err;
3523                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3524                                           "LFE Playback Volume",
3525                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3526                                                               HDA_OUTPUT));
3527                         if (err < 0)
3528                                 return err;
3529                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3530                                           "Center Playback Switch",
3531                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
3532                                                               HDA_INPUT));
3533                         if (err < 0)
3534                                 return err;
3535                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3536                                           "LFE Playback Switch",
3537                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
3538                                                               HDA_INPUT));
3539                         if (err < 0)
3540                                 return err;
3541                 } else {
3542                         sprintf(name, "%s Playback Volume", chname[i]);
3543                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3544                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3545                                                               HDA_OUTPUT));
3546                         if (err < 0)
3547                                 return err;
3548                         sprintf(name, "%s Playback Switch", chname[i]);
3549                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3550                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
3551                                                               HDA_INPUT));
3552                         if (err < 0)
3553                                 return err;
3554                 }
3555         }
3556         return 0;
3557 }
3558
3559 /* add playback controls for speaker and HP outputs */
3560 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
3561                                         const char *pfx)
3562 {
3563         hda_nid_t nid;
3564         int err;
3565         char name[32];
3566
3567         if (!pin)
3568                 return 0;
3569
3570         if (alc880_is_fixed_pin(pin)) {
3571                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
3572                 /* specify the DAC as the extra output */
3573                 if (!spec->multiout.hp_nid)
3574                         spec->multiout.hp_nid = nid;
3575                 else
3576                         spec->multiout.extra_out_nid[0] = nid;
3577                 /* control HP volume/switch on the output mixer amp */
3578                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
3579                 sprintf(name, "%s Playback Volume", pfx);
3580                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3581                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3582                 if (err < 0)
3583                         return err;
3584                 sprintf(name, "%s Playback Switch", pfx);
3585                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3586                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
3587                 if (err < 0)
3588                         return err;
3589         } else if (alc880_is_multi_pin(pin)) {
3590                 /* set manual connection */
3591                 /* we have only a switch on HP-out PIN */
3592                 sprintf(name, "%s Playback Switch", pfx);
3593                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3594                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3595                 if (err < 0)
3596                         return err;
3597         }
3598         return 0;
3599 }
3600
3601 /* create input playback/capture controls for the given pin */
3602 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
3603                             const char *ctlname,
3604                             int idx, hda_nid_t mix_nid)
3605 {
3606         char name[32];
3607         int err;
3608
3609         sprintf(name, "%s Playback Volume", ctlname);
3610         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3611                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3612         if (err < 0)
3613                 return err;
3614         sprintf(name, "%s Playback Switch", ctlname);
3615         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3616                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3617         if (err < 0)
3618                 return err;
3619         return 0;
3620 }
3621
3622 /* create playback/capture controls for input pins */
3623 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3624                                                 const struct auto_pin_cfg *cfg)
3625 {
3626         struct hda_input_mux *imux = &spec->private_imux;
3627         int i, err, idx;
3628
3629         for (i = 0; i < AUTO_PIN_LAST; i++) {
3630                 if (alc880_is_input_pin(cfg->input_pins[i])) {
3631                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
3632                         err = new_analog_input(spec, cfg->input_pins[i],
3633                                                auto_pin_cfg_labels[i],
3634                                                idx, 0x0b);
3635                         if (err < 0)
3636                                 return err;
3637                         imux->items[imux->num_items].label =
3638                                 auto_pin_cfg_labels[i];
3639                         imux->items[imux->num_items].index =
3640                                 alc880_input_pin_idx(cfg->input_pins[i]);
3641                         imux->num_items++;
3642                 }
3643         }
3644         return 0;
3645 }
3646
3647 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
3648                                unsigned int pin_type)
3649 {
3650         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3651                             pin_type);
3652         /* unmute pin */
3653         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3654                             AMP_OUT_UNMUTE);
3655 }
3656
3657 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3658                                               hda_nid_t nid, int pin_type,
3659                                               int dac_idx)
3660 {
3661         alc_set_pin_output(codec, nid, pin_type);
3662         /* need the manual connection? */
3663         if (alc880_is_multi_pin(nid)) {
3664                 struct alc_spec *spec = codec->spec;
3665                 int idx = alc880_multi_pin_idx(nid);
3666                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
3667                                     AC_VERB_SET_CONNECT_SEL,
3668                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
3669         }
3670 }
3671
3672 static int get_pin_type(int line_out_type)
3673 {
3674         if (line_out_type == AUTO_PIN_HP_OUT)
3675                 return PIN_HP;
3676         else
3677                 return PIN_OUT;
3678 }
3679
3680 static void alc880_auto_init_multi_out(struct hda_codec *codec)
3681 {
3682         struct alc_spec *spec = codec->spec;
3683         int i;
3684         
3685         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
3686         for (i = 0; i < spec->autocfg.line_outs; i++) {
3687                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3688                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3689                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
3690         }
3691 }
3692
3693 static void alc880_auto_init_extra_out(struct hda_codec *codec)
3694 {
3695         struct alc_spec *spec = codec->spec;
3696         hda_nid_t pin;
3697
3698         pin = spec->autocfg.speaker_pins[0];
3699         if (pin) /* connect to front */
3700                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
3701         pin = spec->autocfg.hp_pins[0];
3702         if (pin) /* connect to front */
3703                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3704 }
3705
3706 static void alc880_auto_init_analog_input(struct hda_codec *codec)
3707 {
3708         struct alc_spec *spec = codec->spec;
3709         int i;
3710
3711         for (i = 0; i < AUTO_PIN_LAST; i++) {
3712                 hda_nid_t nid = spec->autocfg.input_pins[i];
3713                 if (alc880_is_input_pin(nid)) {
3714                         snd_hda_codec_write(codec, nid, 0,
3715                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
3716                                             i <= AUTO_PIN_FRONT_MIC ?
3717                                             PIN_VREF80 : PIN_IN);
3718                         if (nid != ALC880_PIN_CD_NID)
3719                                 snd_hda_codec_write(codec, nid, 0,
3720                                                     AC_VERB_SET_AMP_GAIN_MUTE,
3721                                                     AMP_OUT_MUTE);
3722                 }
3723         }
3724 }
3725
3726 /* parse the BIOS configuration and set up the alc_spec */
3727 /* return 1 if successful, 0 if the proper config is not found,
3728  * or a negative error code
3729  */
3730 static int alc880_parse_auto_config(struct hda_codec *codec)
3731 {
3732         struct alc_spec *spec = codec->spec;
3733         int err;
3734         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3735
3736         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3737                                            alc880_ignore);
3738         if (err < 0)
3739                 return err;
3740         if (!spec->autocfg.line_outs)
3741                 return 0; /* can't find valid BIOS pin config */
3742
3743         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
3744         if (err < 0)
3745                 return err;
3746         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
3747         if (err < 0)
3748                 return err;
3749         err = alc880_auto_create_extra_out(spec,
3750                                            spec->autocfg.speaker_pins[0],
3751                                            "Speaker");
3752         if (err < 0)
3753                 return err;
3754         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
3755                                            "Headphone");
3756         if (err < 0)
3757                 return err;
3758         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
3759         if (err < 0)
3760                 return err;
3761
3762         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3763
3764         if (spec->autocfg.dig_out_pin)
3765                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
3766         if (spec->autocfg.dig_in_pin)
3767                 spec->dig_in_nid = ALC880_DIGIN_NID;
3768
3769         if (spec->kctl_alloc)
3770                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3771
3772         spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
3773
3774         spec->num_mux_defs = 1;
3775         spec->input_mux = &spec->private_imux;
3776
3777         return 1;
3778 }
3779
3780 /* additional initialization for auto-configuration model */
3781 static void alc880_auto_init(struct hda_codec *codec)
3782 {
3783         struct alc_spec *spec = codec->spec;
3784         alc880_auto_init_multi_out(codec);
3785         alc880_auto_init_extra_out(codec);
3786         alc880_auto_init_analog_input(codec);
3787         if (spec->unsol_event)
3788                 alc_sku_automute(codec);
3789 }
3790
3791 /*
3792  * OK, here we have finally the patch for ALC880
3793  */
3794
3795 static int patch_alc880(struct hda_codec *codec)
3796 {
3797         struct alc_spec *spec;
3798         int board_config;
3799         int err;
3800
3801         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3802         if (spec == NULL)
3803                 return -ENOMEM;
3804
3805         codec->spec = spec;
3806
3807         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
3808                                                   alc880_models,
3809                                                   alc880_cfg_tbl);
3810         if (board_config < 0) {
3811                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
3812                        "trying auto-probe from BIOS...\n");
3813                 board_config = ALC880_AUTO;
3814         }
3815
3816         if (board_config == ALC880_AUTO) {
3817                 /* automatic parse from the BIOS config */
3818                 err = alc880_parse_auto_config(codec);
3819                 if (err < 0) {
3820                         alc_free(codec);
3821                         return err;
3822                 } else if (!err) {
3823                         printk(KERN_INFO
3824                                "hda_codec: Cannot set up configuration "
3825                                "from BIOS.  Using 3-stack mode...\n");
3826                         board_config = ALC880_3ST;
3827                 }
3828         }
3829
3830         if (board_config != ALC880_AUTO)
3831                 setup_preset(spec, &alc880_presets[board_config]);
3832
3833         spec->stream_name_analog = "ALC880 Analog";
3834         spec->stream_analog_playback = &alc880_pcm_analog_playback;
3835         spec->stream_analog_capture = &alc880_pcm_analog_capture;
3836         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
3837
3838         spec->stream_name_digital = "ALC880 Digital";
3839         spec->stream_digital_playback = &alc880_pcm_digital_playback;
3840         spec->stream_digital_capture = &alc880_pcm_digital_capture;
3841
3842         if (!spec->adc_nids && spec->input_mux) {
3843                 /* check whether NID 0x07 is valid */
3844                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
3845                 /* get type */
3846                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3847                 if (wcap != AC_WID_AUD_IN) {
3848                         spec->adc_nids = alc880_adc_nids_alt;
3849                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
3850                         spec->mixers[spec->num_mixers] =
3851                                 alc880_capture_alt_mixer;
3852                         spec->num_mixers++;
3853                 } else {
3854                         spec->adc_nids = alc880_adc_nids;
3855                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
3856                         spec->mixers[spec->num_mixers] = alc880_capture_mixer;
3857                         spec->num_mixers++;
3858                 }
3859         }
3860
3861         spec->vmaster_nid = 0x0c;
3862
3863         codec->patch_ops = alc_patch_ops;
3864         if (board_config == ALC880_AUTO)
3865                 spec->init_hook = alc880_auto_init;
3866 #ifdef CONFIG_SND_HDA_POWER_SAVE
3867         if (!spec->loopback.amplist)
3868                 spec->loopback.amplist = alc880_loopbacks;
3869 #endif
3870
3871         return 0;
3872 }
3873
3874
3875 /*
3876  * ALC260 support
3877  */
3878
3879 static hda_nid_t alc260_dac_nids[1] = {
3880         /* front */
3881         0x02,
3882 };
3883
3884 static hda_nid_t alc260_adc_nids[1] = {
3885         /* ADC0 */
3886         0x04,
3887 };
3888
3889 static hda_nid_t alc260_adc_nids_alt[1] = {
3890         /* ADC1 */
3891         0x05,
3892 };
3893
3894 static hda_nid_t alc260_hp_adc_nids[2] = {
3895         /* ADC1, 0 */
3896         0x05, 0x04
3897 };
3898
3899 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
3900  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
3901  */
3902 static hda_nid_t alc260_dual_adc_nids[2] = {
3903         /* ADC0, ADC1 */
3904         0x04, 0x05
3905 };
3906
3907 #define ALC260_DIGOUT_NID       0x03
3908 #define ALC260_DIGIN_NID        0x06
3909
3910 static struct hda_input_mux alc260_capture_source = {
3911         .num_items = 4,
3912         .items = {
3913                 { "Mic", 0x0 },
3914                 { "Front Mic", 0x1 },
3915                 { "Line", 0x2 },
3916                 { "CD", 0x4 },
3917         },
3918 };
3919
3920 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
3921  * headphone jack and the internal CD lines since these are the only pins at
3922  * which audio can appear.  For flexibility, also allow the option of
3923  * recording the mixer output on the second ADC (ADC0 doesn't have a
3924  * connection to the mixer output).
3925  */
3926 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
3927         {
3928                 .num_items = 3,
3929                 .items = {
3930                         { "Mic/Line", 0x0 },
3931                         { "CD", 0x4 },
3932                         { "Headphone", 0x2 },
3933                 },
3934         },
3935         {
3936                 .num_items = 4,
3937                 .items = {
3938                         { "Mic/Line", 0x0 },
3939                         { "CD", 0x4 },
3940                         { "Headphone", 0x2 },
3941                         { "Mixer", 0x5 },
3942                 },
3943         },
3944
3945 };
3946
3947 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
3948  * the Fujitsu S702x, but jacks are marked differently.
3949  */
3950 static struct hda_input_mux alc260_acer_capture_sources[2] = {
3951         {
3952                 .num_items = 4,
3953                 .items = {
3954                         { "Mic", 0x0 },
3955                         { "Line", 0x2 },
3956                         { "CD", 0x4 },
3957                         { "Headphone", 0x5 },
3958                 },
3959         },
3960         {
3961                 .num_items = 5,
3962                 .items = {
3963                         { "Mic", 0x0 },
3964                         { "Line", 0x2 },
3965                         { "CD", 0x4 },
3966                         { "Headphone", 0x6 },
3967                         { "Mixer", 0x5 },
3968                 },
3969         },
3970 };
3971 /*
3972  * This is just place-holder, so there's something for alc_build_pcms to look
3973  * at when it calculates the maximum number of channels. ALC260 has no mixer
3974  * element which allows changing the channel mode, so the verb list is
3975  * never used.
3976  */
3977 static struct hda_channel_mode alc260_modes[1] = {
3978         { 2, NULL },
3979 };
3980
3981
3982 /* Mixer combinations
3983  *
3984  * basic: base_output + input + pc_beep + capture
3985  * HP: base_output + input + capture_alt
3986  * HP_3013: hp_3013 + input + capture
3987  * fujitsu: fujitsu + capture
3988  * acer: acer + capture
3989  */
3990
3991 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
3992         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3993         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
3994         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3995         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
3996         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3997         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
3998         { } /* end */
3999 };
4000
4001 static struct snd_kcontrol_new alc260_input_mixer[] = {
4002         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4003         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4004         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4005         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4006         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4007         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4008         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4009         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4010         { } /* end */
4011 };
4012
4013 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
4014         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
4015         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
4016         { } /* end */
4017 };
4018
4019 /* update HP, line and mono out pins according to the master switch */
4020 static void alc260_hp_master_update(struct hda_codec *codec,
4021                                     hda_nid_t hp, hda_nid_t line,
4022                                     hda_nid_t mono)
4023 {
4024         struct alc_spec *spec = codec->spec;
4025         unsigned int val = spec->master_sw ? PIN_HP : 0;
4026         /* change HP and line-out pins */
4027         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4028                             val);
4029         snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4030                             val);
4031         /* mono (speaker) depending on the HP jack sense */
4032         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4033         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4034                             val);
4035 }
4036
4037 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4038                                    struct snd_ctl_elem_value *ucontrol)
4039 {
4040         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4041         struct alc_spec *spec = codec->spec;
4042         *ucontrol->value.integer.value = spec->master_sw;
4043         return 0;
4044 }
4045
4046 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4047                                    struct snd_ctl_elem_value *ucontrol)
4048 {
4049         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4050         struct alc_spec *spec = codec->spec;
4051         int val = !!*ucontrol->value.integer.value;
4052         hda_nid_t hp, line, mono;
4053
4054         if (val == spec->master_sw)
4055                 return 0;
4056         spec->master_sw = val;
4057         hp = (kcontrol->private_value >> 16) & 0xff;
4058         line = (kcontrol->private_value >> 8) & 0xff;
4059         mono = kcontrol->private_value & 0xff;
4060         alc260_hp_master_update(codec, hp, line, mono);
4061         return 1;
4062 }
4063
4064 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4065         {
4066                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4067                 .name = "Master Playback Switch",
4068                 .info = snd_ctl_boolean_mono_info,
4069                 .get = alc260_hp_master_sw_get,
4070                 .put = alc260_hp_master_sw_put,
4071                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4072         },
4073         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4074         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4075         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4076         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4077         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4078                               HDA_OUTPUT),
4079         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4080         { } /* end */
4081 };
4082
4083 static struct hda_verb alc260_hp_unsol_verbs[] = {
4084         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4085         {},
4086 };
4087
4088 static void alc260_hp_automute(struct hda_codec *codec)
4089 {
4090         struct alc_spec *spec = codec->spec;
4091         unsigned int present;
4092
4093         present = snd_hda_codec_read(codec, 0x10, 0,
4094                                      AC_VERB_GET_PIN_SENSE, 0);
4095         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4096         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4097 }
4098
4099 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4100 {
4101         if ((res >> 26) == ALC880_HP_EVENT)
4102                 alc260_hp_automute(codec);
4103 }
4104
4105 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4106         {
4107                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4108                 .name = "Master Playback Switch",
4109                 .info = snd_ctl_boolean_mono_info,
4110                 .get = alc260_hp_master_sw_get,
4111                 .put = alc260_hp_master_sw_put,
4112                 .private_value = (0x10 << 16) | (0x15 << 8) | 0x11
4113         },
4114         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4115         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4116         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4117         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4118         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4119         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4120         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4121         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4122         { } /* end */
4123 };
4124
4125 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4126         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4127         {},
4128 };
4129
4130 static void alc260_hp_3013_automute(struct hda_codec *codec)
4131 {
4132         struct alc_spec *spec = codec->spec;
4133         unsigned int present;
4134
4135         present = snd_hda_codec_read(codec, 0x15, 0,
4136                                      AC_VERB_GET_PIN_SENSE, 0);
4137         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4138         alc260_hp_master_update(codec, 0x10, 0x15, 0x11);
4139 }
4140
4141 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4142                                        unsigned int res)
4143 {
4144         if ((res >> 26) == ALC880_HP_EVENT)
4145                 alc260_hp_3013_automute(codec);
4146 }
4147
4148 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12, 
4149  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4150  */
4151 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4152         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4153         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4154         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4155         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4156         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4157         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4158         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4159         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4160         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4161         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4162         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4163         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4164         { } /* end */
4165 };
4166
4167 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4168  * versions of the ALC260 don't act on requests to enable mic bias from NID
4169  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4170  * datasheet doesn't mention this restriction.  At this stage it's not clear
4171  * whether this behaviour is intentional or is a hardware bug in chip
4172  * revisions available in early 2006.  Therefore for now allow the
4173  * "Headphone Jack Mode" control to span all choices, but if it turns out
4174  * that the lack of mic bias for this NID is intentional we could change the
4175  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4176  *
4177  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4178  * don't appear to make the mic bias available from the "line" jack, even
4179  * though the NID used for this jack (0x14) can supply it.  The theory is
4180  * that perhaps Acer have included blocking capacitors between the ALC260
4181  * and the output jack.  If this turns out to be the case for all such
4182  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4183  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4184  *
4185  * The C20x Tablet series have a mono internal speaker which is controlled
4186  * via the chip's Mono sum widget and pin complex, so include the necessary
4187  * controls for such models.  On models without a "mono speaker" the control
4188  * won't do anything.
4189  */
4190 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4191         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4192         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4193         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4194         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4195                               HDA_OUTPUT),
4196         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4197                            HDA_INPUT),
4198         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4199         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4200         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4201         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4202         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4203         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4204         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4205         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4206         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4207         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4208         { } /* end */
4209 };
4210
4211 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4212  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4213  */
4214 static struct snd_kcontrol_new alc260_will_mixer[] = {
4215         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4216         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4217         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4218         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4219         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4220         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4221         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4222         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4223         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4224         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4225         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4226         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4227         { } /* end */
4228 };
4229
4230 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4231  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4232  */
4233 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4234         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4235         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4236         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4237         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4238         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4239         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4240         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4241         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4242         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4243         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4244         { } /* end */
4245 };
4246
4247 /* capture mixer elements */
4248 static struct snd_kcontrol_new alc260_capture_mixer[] = {
4249         HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
4250         HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
4251         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
4252         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),
4253         {
4254                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4255                 /* The multiple "Capture Source" controls confuse alsamixer
4256                  * So call somewhat different..
4257                  */
4258                 /* .name = "Capture Source", */
4259                 .name = "Input Source",
4260                 .count = 2,
4261                 .info = alc_mux_enum_info,
4262                 .get = alc_mux_enum_get,
4263                 .put = alc_mux_enum_put,
4264         },
4265         { } /* end */
4266 };
4267
4268 static struct snd_kcontrol_new alc260_capture_alt_mixer[] = {
4269         HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
4270         HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
4271         {
4272                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4273                 /* The multiple "Capture Source" controls confuse alsamixer
4274                  * So call somewhat different..
4275                  */
4276                 /* .name = "Capture Source", */
4277                 .name = "Input Source",
4278                 .count = 1,
4279                 .info = alc_mux_enum_info,
4280                 .get = alc_mux_enum_get,
4281                 .put = alc_mux_enum_put,
4282         },
4283         { } /* end */
4284 };
4285
4286 /*
4287  * initialization verbs
4288  */
4289 static struct hda_verb alc260_init_verbs[] = {
4290         /* Line In pin widget for input */
4291         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4292         /* CD pin widget for input */
4293         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4294         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4295         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4296         /* Mic2 (front panel) pin widget for input and vref at 80% */
4297         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4298         /* LINE-2 is used for line-out in rear */
4299         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4300         /* select line-out */
4301         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4302         /* LINE-OUT pin */
4303         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4304         /* enable HP */
4305         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4306         /* enable Mono */
4307         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4308         /* mute capture amp left and right */
4309         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4310         /* set connection select to line in (default select for this ADC) */
4311         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4312         /* mute capture amp left and right */
4313         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4314         /* set connection select to line in (default select for this ADC) */
4315         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4316         /* set vol=0 Line-Out mixer amp left and right */
4317         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4318         /* unmute pin widget amp left and right (no gain on this amp) */
4319         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4320         /* set vol=0 HP mixer amp left and right */
4321         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4322         /* unmute pin widget amp left and right (no gain on this amp) */
4323         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4324         /* set vol=0 Mono mixer amp left and right */
4325         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4326         /* unmute pin widget amp left and right (no gain on this amp) */
4327         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4328         /* unmute LINE-2 out pin */
4329         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4330         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4331          * Line In 2 = 0x03
4332          */
4333         /* mute analog inputs */
4334         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4335         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4336         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4337         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4338         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4339         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4340         /* mute Front out path */
4341         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4342         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4343         /* mute Headphone out path */
4344         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4345         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4346         /* mute Mono out path */
4347         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4348         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4349         { }
4350 };
4351
4352 #if 0 /* should be identical with alc260_init_verbs? */
4353 static struct hda_verb alc260_hp_init_verbs[] = {
4354         /* Headphone and output */
4355         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4356         /* mono output */
4357         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4358         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4359         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4360         /* Mic2 (front panel) pin widget for input and vref at 80% */
4361         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4362         /* Line In pin widget for input */
4363         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4364         /* Line-2 pin widget for output */
4365         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4366         /* CD pin widget for input */
4367         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4368         /* unmute amp left and right */
4369         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4370         /* set connection select to line in (default select for this ADC) */
4371         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4372         /* unmute Line-Out mixer amp left and right (volume = 0) */
4373         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4374         /* mute pin widget amp left and right (no gain on this amp) */
4375         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4376         /* unmute HP mixer amp left and right (volume = 0) */
4377         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4378         /* mute pin widget amp left and right (no gain on this amp) */
4379         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4380         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4381          * Line In 2 = 0x03
4382          */
4383         /* mute analog inputs */
4384         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4385         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4386         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4387         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4388         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4389         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4390         /* Unmute Front out path */
4391         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4392         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4393         /* Unmute Headphone out path */
4394         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4395         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4396         /* Unmute Mono out path */
4397         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4398         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4399         { }
4400 };
4401 #endif
4402
4403 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4404         /* Line out and output */
4405         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4406         /* mono output */
4407         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4408         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4409         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4410         /* Mic2 (front panel) pin widget for input and vref at 80% */
4411         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4412         /* Line In pin widget for input */
4413         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4414         /* Headphone pin widget for output */
4415         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4416         /* CD pin widget for input */
4417         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4418         /* unmute amp left and right */
4419         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4420         /* set connection select to line in (default select for this ADC) */
4421         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4422         /* unmute Line-Out mixer amp left and right (volume = 0) */
4423         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4424         /* mute pin widget amp left and right (no gain on this amp) */
4425         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4426         /* unmute HP mixer amp left and right (volume = 0) */
4427         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4428         /* mute pin widget amp left and right (no gain on this amp) */
4429         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4430         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4431          * Line In 2 = 0x03
4432          */
4433         /* mute analog inputs */
4434         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4435         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4436         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4437         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4438         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4439         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4440         /* Unmute Front out path */
4441         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4442         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4443         /* Unmute Headphone out path */
4444         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4445         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4446         /* Unmute Mono out path */
4447         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4448         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4449         { }
4450 };
4451
4452 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4453  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4454  * audio = 0x16, internal speaker = 0x10.
4455  */
4456 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4457         /* Disable all GPIOs */
4458         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4459         /* Internal speaker is connected to headphone pin */
4460         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4461         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4462         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4463         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4464         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4465         /* Ensure all other unused pins are disabled and muted. */
4466         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4467         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4468         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4469         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4470         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4471         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4472         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4473         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4474
4475         /* Disable digital (SPDIF) pins */
4476         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4477         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4478
4479         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus 
4480          * when acting as an output.
4481          */
4482         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4483
4484         /* Start with output sum widgets muted and their output gains at min */
4485         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4486         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4487         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4488         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4489         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4490         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4491         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4492         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4493         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4494
4495         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
4496         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4497         /* Unmute Line1 pin widget output buffer since it starts as an output.
4498          * If the pin mode is changed by the user the pin mode control will
4499          * take care of enabling the pin's input/output buffers as needed.
4500          * Therefore there's no need to enable the input buffer at this
4501          * stage.
4502          */
4503         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4504         /* Unmute input buffer of pin widget used for Line-in (no equiv 
4505          * mixer ctrl)
4506          */
4507         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4508
4509         /* Mute capture amp left and right */
4510         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4511         /* Set ADC connection select to match default mixer setting - line 
4512          * in (on mic1 pin)
4513          */
4514         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4515
4516         /* Do the same for the second ADC: mute capture input amp and
4517          * set ADC connection to line in (on mic1 pin)
4518          */
4519         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4520         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4521
4522         /* Mute all inputs to mixer widget (even unconnected ones) */
4523         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4524         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4525         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4526         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4527         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4528         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4529         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4530         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4531
4532         { }
4533 };
4534
4535 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
4536  * similar laptops (adapted from Fujitsu init verbs).
4537  */
4538 static struct hda_verb alc260_acer_init_verbs[] = {
4539         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
4540          * the headphone jack.  Turn this on and rely on the standard mute
4541          * methods whenever the user wants to turn these outputs off.
4542          */
4543         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4544         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4545         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
4546         /* Internal speaker/Headphone jack is connected to Line-out pin */
4547         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4548         /* Internal microphone/Mic jack is connected to Mic1 pin */
4549         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
4550         /* Line In jack is connected to Line1 pin */
4551         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4552         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
4553         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4554         /* Ensure all other unused pins are disabled and muted. */
4555         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4556         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4557         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4558         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4559         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4560         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4561         /* Disable digital (SPDIF) pins */
4562         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4563         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4564
4565         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum 
4566          * bus when acting as outputs.
4567          */
4568         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4569         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4570
4571         /* Start with output sum widgets muted and their output gains at min */
4572         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4573         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4574         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4575         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4576         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4577         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4578         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4579         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4580         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4581
4582         /* Unmute Line-out pin widget amp left and right
4583          * (no equiv mixer ctrl)
4584          */
4585         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4586         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
4587         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4588         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
4589          * inputs. If the pin mode is changed by the user the pin mode control
4590          * will take care of enabling the pin's input/output buffers as needed.
4591          * Therefore there's no need to enable the input buffer at this
4592          * stage.
4593          */
4594         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4595         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4596
4597         /* Mute capture amp left and right */
4598         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4599         /* Set ADC connection select to match default mixer setting - mic
4600          * (on mic1 pin)
4601          */
4602         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4603
4604         /* Do similar with the second ADC: mute capture input amp and
4605          * set ADC connection to mic to match ALSA's default state.
4606          */
4607         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4608         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4609
4610         /* Mute all inputs to mixer widget (even unconnected ones) */
4611         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4612         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4613         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4614         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4615         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4616         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4617         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4618         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4619
4620         { }
4621 };
4622
4623 static struct hda_verb alc260_will_verbs[] = {
4624         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4625         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
4626         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
4627         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4628         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4629         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
4630         {}
4631 };
4632
4633 static struct hda_verb alc260_replacer_672v_verbs[] = {
4634         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4635         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4636         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
4637
4638         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4639         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4640         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4641
4642         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4643         {}
4644 };
4645
4646 /* toggle speaker-output according to the hp-jack state */
4647 static void alc260_replacer_672v_automute(struct hda_codec *codec)
4648 {
4649         unsigned int present;
4650
4651         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
4652         present = snd_hda_codec_read(codec, 0x0f, 0,
4653                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
4654         if (present) {
4655                 snd_hda_codec_write_cache(codec, 0x01, 0,
4656                                           AC_VERB_SET_GPIO_DATA, 1);
4657                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4658                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4659                                           PIN_HP);
4660         } else {
4661                 snd_hda_codec_write_cache(codec, 0x01, 0,
4662                                           AC_VERB_SET_GPIO_DATA, 0);
4663                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4664                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4665                                           PIN_OUT);
4666         }
4667 }
4668
4669 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
4670                                        unsigned int res)
4671 {
4672         if ((res >> 26) == ALC880_HP_EVENT)
4673                 alc260_replacer_672v_automute(codec);
4674 }
4675
4676 /* Test configuration for debugging, modelled after the ALC880 test
4677  * configuration.
4678  */
4679 #ifdef CONFIG_SND_DEBUG
4680 static hda_nid_t alc260_test_dac_nids[1] = {
4681         0x02,
4682 };
4683 static hda_nid_t alc260_test_adc_nids[2] = {
4684         0x04, 0x05,
4685 };
4686 /* For testing the ALC260, each input MUX needs its own definition since
4687  * the signal assignments are different.  This assumes that the first ADC 
4688  * is NID 0x04.
4689  */
4690 static struct hda_input_mux alc260_test_capture_sources[2] = {
4691         {
4692                 .num_items = 7,
4693                 .items = {
4694                         { "MIC1 pin", 0x0 },
4695                         { "MIC2 pin", 0x1 },
4696                         { "LINE1 pin", 0x2 },
4697                         { "LINE2 pin", 0x3 },
4698                         { "CD pin", 0x4 },
4699                         { "LINE-OUT pin", 0x5 },
4700                         { "HP-OUT pin", 0x6 },
4701                 },
4702         },
4703         {
4704                 .num_items = 8,
4705                 .items = {
4706                         { "MIC1 pin", 0x0 },
4707                         { "MIC2 pin", 0x1 },
4708                         { "LINE1 pin", 0x2 },
4709                         { "LINE2 pin", 0x3 },
4710                         { "CD pin", 0x4 },
4711                         { "Mixer", 0x5 },
4712                         { "LINE-OUT pin", 0x6 },
4713                         { "HP-OUT pin", 0x7 },
4714                 },
4715         },
4716 };
4717 static struct snd_kcontrol_new alc260_test_mixer[] = {
4718         /* Output driver widgets */
4719         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4720         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4721         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4722         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
4723         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4724         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
4725
4726         /* Modes for retasking pin widgets
4727          * Note: the ALC260 doesn't seem to act on requests to enable mic
4728          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
4729          * mention this restriction.  At this stage it's not clear whether
4730          * this behaviour is intentional or is a hardware bug in chip
4731          * revisions available at least up until early 2006.  Therefore for
4732          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
4733          * choices, but if it turns out that the lack of mic bias for these
4734          * NIDs is intentional we could change their modes from
4735          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4736          */
4737         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
4738         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
4739         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
4740         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
4741         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
4742         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
4743
4744         /* Loopback mixer controls */
4745         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
4746         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
4747         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
4748         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
4749         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
4750         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
4751         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
4752         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
4753         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4754         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4755         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4756         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4757         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
4758         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
4759         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
4760         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
4761
4762         /* Controls for GPIO pins, assuming they are configured as outputs */
4763         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
4764         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
4765         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
4766         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
4767
4768         /* Switches to allow the digital IO pins to be enabled.  The datasheet
4769          * is ambigious as to which NID is which; testing on laptops which
4770          * make this output available should provide clarification. 
4771          */
4772         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
4773         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
4774
4775         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
4776          * this output to turn on an external amplifier.
4777          */
4778         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
4779         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
4780
4781         { } /* end */
4782 };
4783 static struct hda_verb alc260_test_init_verbs[] = {
4784         /* Enable all GPIOs as outputs with an initial value of 0 */
4785         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
4786         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4787         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
4788
4789         /* Enable retasking pins as output, initially without power amp */
4790         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4791         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4792         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4793         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4794         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4795         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4796
4797         /* Disable digital (SPDIF) pins initially, but users can enable
4798          * them via a mixer switch.  In the case of SPDIF-out, this initverb
4799          * payload also sets the generation to 0, output to be in "consumer"
4800          * PCM format, copyright asserted, no pre-emphasis and no validity
4801          * control.
4802          */
4803         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4804         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4805
4806         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the 
4807          * OUT1 sum bus when acting as an output.
4808          */
4809         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4810         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
4811         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4812         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
4813
4814         /* Start with output sum widgets muted and their output gains at min */
4815         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4816         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4817         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4818         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4819         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4820         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4821         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4822         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4823         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4824
4825         /* Unmute retasking pin widget output buffers since the default
4826          * state appears to be output.  As the pin mode is changed by the
4827          * user the pin mode control will take care of enabling the pin's
4828          * input/output buffers as needed.
4829          */
4830         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4831         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4832         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4833         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4834         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4835         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4836         /* Also unmute the mono-out pin widget */
4837         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4838
4839         /* Mute capture amp left and right */
4840         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4841         /* Set ADC connection select to match default mixer setting (mic1
4842          * pin)
4843          */
4844         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4845
4846         /* Do the same for the second ADC: mute capture input amp and
4847          * set ADC connection to mic1 pin
4848          */
4849         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4850         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4851
4852         /* Mute all inputs to mixer widget (even unconnected ones) */
4853         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4854         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4855         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4856         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4857         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4858         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4859         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4860         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4861
4862         { }
4863 };
4864 #endif
4865
4866 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
4867 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
4868
4869 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
4870 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
4871
4872 /*
4873  * for BIOS auto-configuration
4874  */
4875
4876 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
4877                                         const char *pfx)
4878 {
4879         hda_nid_t nid_vol;
4880         unsigned long vol_val, sw_val;
4881         char name[32];
4882         int err;
4883
4884         if (nid >= 0x0f && nid < 0x11) {
4885                 nid_vol = nid - 0x7;
4886                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4887                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4888         } else if (nid == 0x11) {
4889                 nid_vol = nid - 0x7;
4890                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
4891                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
4892         } else if (nid >= 0x12 && nid <= 0x15) {
4893                 nid_vol = 0x08;
4894                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4895                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4896         } else
4897                 return 0; /* N/A */
4898         
4899         snprintf(name, sizeof(name), "%s Playback Volume", pfx);
4900         err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
4901         if (err < 0)
4902                 return err;
4903         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
4904         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
4905         if (err < 0)
4906                 return err;
4907         return 1;
4908 }
4909
4910 /* add playback controls from the parsed DAC table */
4911 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
4912                                              const struct auto_pin_cfg *cfg)
4913 {
4914         hda_nid_t nid;
4915         int err;
4916
4917         spec->multiout.num_dacs = 1;
4918         spec->multiout.dac_nids = spec->private_dac_nids;
4919         spec->multiout.dac_nids[0] = 0x02;
4920
4921         nid = cfg->line_out_pins[0];
4922         if (nid) {
4923                 err = alc260_add_playback_controls(spec, nid, "Front");
4924                 if (err < 0)
4925                         return err;
4926         }
4927
4928         nid = cfg->speaker_pins[0];
4929         if (nid) {
4930                 err = alc260_add_playback_controls(spec, nid, "Speaker");
4931                 if (err < 0)
4932                         return err;
4933         }
4934
4935         nid = cfg->hp_pins[0];
4936         if (nid) {
4937                 err = alc260_add_playback_controls(spec, nid, "Headphone");
4938                 if (err < 0)
4939                         return err;
4940         }
4941         return 0;
4942 }
4943
4944 /* create playback/capture controls for input pins */
4945 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
4946                                                 const struct auto_pin_cfg *cfg)
4947 {
4948         struct hda_input_mux *imux = &spec->private_imux;
4949         int i, err, idx;
4950
4951         for (i = 0; i < AUTO_PIN_LAST; i++) {
4952                 if (cfg->input_pins[i] >= 0x12) {
4953                         idx = cfg->input_pins[i] - 0x12;
4954                         err = new_analog_input(spec, cfg->input_pins[i],
4955                                                auto_pin_cfg_labels[i], idx,
4956                                                0x07);
4957                         if (err < 0)
4958                                 return err;
4959                         imux->items[imux->num_items].label =
4960                                 auto_pin_cfg_labels[i];
4961                         imux->items[imux->num_items].index = idx;
4962                         imux->num_items++;
4963                 }
4964                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
4965                         idx = cfg->input_pins[i] - 0x09;
4966                         err = new_analog_input(spec, cfg->input_pins[i],
4967                                                auto_pin_cfg_labels[i], idx,
4968                                                0x07);
4969                         if (err < 0)
4970                                 return err;
4971                         imux->items[imux->num_items].label =
4972                                 auto_pin_cfg_labels[i];
4973                         imux->items[imux->num_items].index = idx;
4974                         imux->num_items++;
4975                 }
4976         }
4977         return 0;
4978 }
4979
4980 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
4981                                               hda_nid_t nid, int pin_type,
4982                                               int sel_idx)
4983 {
4984         alc_set_pin_output(codec, nid, pin_type);
4985         /* need the manual connection? */
4986         if (nid >= 0x12) {
4987                 int idx = nid - 0x12;
4988                 snd_hda_codec_write(codec, idx + 0x0b, 0,
4989                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
4990         }
4991 }
4992
4993 static void alc260_auto_init_multi_out(struct hda_codec *codec)
4994 {
4995         struct alc_spec *spec = codec->spec;
4996         hda_nid_t nid;
4997
4998         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
4999         nid = spec->autocfg.line_out_pins[0];
5000         if (nid) {
5001                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5002                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5003         }
5004         
5005         nid = spec->autocfg.speaker_pins[0];
5006         if (nid)
5007                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5008
5009         nid = spec->autocfg.hp_pins[0];
5010         if (nid)
5011                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5012 }
5013
5014 #define ALC260_PIN_CD_NID               0x16
5015 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5016 {
5017         struct alc_spec *spec = codec->spec;
5018         int i;
5019
5020         for (i = 0; i < AUTO_PIN_LAST; i++) {
5021                 hda_nid_t nid = spec->autocfg.input_pins[i];
5022                 if (nid >= 0x12) {
5023                         snd_hda_codec_write(codec, nid, 0,
5024                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5025                                             i <= AUTO_PIN_FRONT_MIC ?
5026                                             PIN_VREF80 : PIN_IN);
5027                         if (nid != ALC260_PIN_CD_NID)
5028                                 snd_hda_codec_write(codec, nid, 0,
5029                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5030                                                     AMP_OUT_MUTE);
5031                 }
5032         }
5033 }
5034
5035 /*
5036  * generic initialization of ADC, input mixers and output mixers
5037  */
5038 static struct hda_verb alc260_volume_init_verbs[] = {
5039         /*
5040          * Unmute ADC0-1 and set the default input to mic-in
5041          */
5042         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5043         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5044         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5045         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5046         
5047         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5048          * mixer widget
5049          * Note: PASD motherboards uses the Line In 2 as the input for
5050          * front panel mic (mic 2)
5051          */
5052         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5053         /* mute analog inputs */
5054         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5055         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5056         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5057         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5058         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5059
5060         /*
5061          * Set up output mixers (0x08 - 0x0a)
5062          */
5063         /* set vol=0 to output mixers */
5064         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5065         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5066         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5067         /* set up input amps for analog loopback */
5068         /* Amp Indices: DAC = 0, mixer = 1 */
5069         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5070         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5071         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5072         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5073         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5074         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5075         
5076         { }
5077 };
5078
5079 static int alc260_parse_auto_config(struct hda_codec *codec)
5080 {
5081         struct alc_spec *spec = codec->spec;
5082         unsigned int wcap;
5083         int err;
5084         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5085
5086         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5087                                            alc260_ignore);
5088         if (err < 0)
5089                 return err;
5090         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5091         if (err < 0)
5092                 return err;
5093         if (!spec->kctl_alloc)
5094                 return 0; /* can't find valid BIOS pin config */
5095         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5096         if (err < 0)
5097                 return err;
5098
5099         spec->multiout.max_channels = 2;
5100
5101         if (spec->autocfg.dig_out_pin)
5102                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5103         if (spec->kctl_alloc)
5104                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
5105
5106         spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs;
5107
5108         spec->num_mux_defs = 1;
5109         spec->input_mux = &spec->private_imux;
5110
5111         /* check whether NID 0x04 is valid */
5112         wcap = get_wcaps(codec, 0x04);
5113         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
5114         if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
5115                 spec->adc_nids = alc260_adc_nids_alt;
5116                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
5117                 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
5118         } else {
5119                 spec->adc_nids = alc260_adc_nids;
5120                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
5121                 spec->mixers[spec->num_mixers] = alc260_capture_mixer;
5122         }
5123         spec->num_mixers++;
5124
5125         return 1;
5126 }
5127
5128 /* additional initialization for auto-configuration model */
5129 static void alc260_auto_init(struct hda_codec *codec)
5130 {
5131         struct alc_spec *spec = codec->spec;
5132         alc260_auto_init_multi_out(codec);
5133         alc260_auto_init_analog_input(codec);
5134         if (spec->unsol_event)
5135                 alc_sku_automute(codec);
5136 }
5137
5138 #ifdef CONFIG_SND_HDA_POWER_SAVE
5139 static struct hda_amp_list alc260_loopbacks[] = {
5140         { 0x07, HDA_INPUT, 0 },
5141         { 0x07, HDA_INPUT, 1 },
5142         { 0x07, HDA_INPUT, 2 },
5143         { 0x07, HDA_INPUT, 3 },
5144         { 0x07, HDA_INPUT, 4 },
5145         { } /* end */
5146 };
5147 #endif
5148
5149 /*
5150  * ALC260 configurations
5151  */
5152 static const char *alc260_models[ALC260_MODEL_LAST] = {
5153         [ALC260_BASIC]          = "basic",
5154         [ALC260_HP]             = "hp",
5155         [ALC260_HP_3013]        = "hp-3013",
5156         [ALC260_FUJITSU_S702X]  = "fujitsu",
5157         [ALC260_ACER]           = "acer",
5158         [ALC260_WILL]           = "will",
5159         [ALC260_REPLACER_672V]  = "replacer",
5160 #ifdef CONFIG_SND_DEBUG
5161         [ALC260_TEST]           = "test",
5162 #endif
5163         [ALC260_AUTO]           = "auto",
5164 };
5165
5166 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5167         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5168         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5169         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5170         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5171         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5172         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
5173         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_3013),
5174         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5175         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5176         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5177         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5178         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5179         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5180         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5181         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5182         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5183         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5184         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5185         {}
5186 };
5187
5188 static struct alc_config_preset alc260_presets[] = {
5189         [ALC260_BASIC] = {
5190                 .mixers = { alc260_base_output_mixer,
5191                             alc260_input_mixer,
5192                             alc260_pc_beep_mixer,
5193                             alc260_capture_mixer },
5194                 .init_verbs = { alc260_init_verbs },
5195                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5196                 .dac_nids = alc260_dac_nids,
5197                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5198                 .adc_nids = alc260_adc_nids,
5199                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5200                 .channel_mode = alc260_modes,
5201                 .input_mux = &alc260_capture_source,
5202         },
5203         [ALC260_HP] = {
5204                 .mixers = { alc260_hp_output_mixer,
5205                             alc260_input_mixer,
5206                             alc260_capture_alt_mixer },
5207                 .init_verbs = { alc260_init_verbs,
5208                                 alc260_hp_unsol_verbs },
5209                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5210                 .dac_nids = alc260_dac_nids,
5211                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5212                 .adc_nids = alc260_hp_adc_nids,
5213                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5214                 .channel_mode = alc260_modes,
5215                 .input_mux = &alc260_capture_source,
5216                 .unsol_event = alc260_hp_unsol_event,
5217                 .init_hook = alc260_hp_automute,
5218         },
5219         [ALC260_HP_3013] = {
5220                 .mixers = { alc260_hp_3013_mixer,
5221                             alc260_input_mixer,
5222                             alc260_capture_alt_mixer },
5223                 .init_verbs = { alc260_hp_3013_init_verbs,
5224                                 alc260_hp_3013_unsol_verbs },
5225                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5226                 .dac_nids = alc260_dac_nids,
5227                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5228                 .adc_nids = alc260_hp_adc_nids,
5229                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5230                 .channel_mode = alc260_modes,
5231                 .input_mux = &alc260_capture_source,
5232                 .unsol_event = alc260_hp_3013_unsol_event,
5233                 .init_hook = alc260_hp_3013_automute,
5234         },
5235         [ALC260_FUJITSU_S702X] = {
5236                 .mixers = { alc260_fujitsu_mixer,
5237                             alc260_capture_mixer },
5238                 .init_verbs = { alc260_fujitsu_init_verbs },
5239                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5240                 .dac_nids = alc260_dac_nids,
5241                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5242                 .adc_nids = alc260_dual_adc_nids,
5243                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5244                 .channel_mode = alc260_modes,
5245                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5246                 .input_mux = alc260_fujitsu_capture_sources,
5247         },
5248         [ALC260_ACER] = {
5249                 .mixers = { alc260_acer_mixer,
5250                             alc260_capture_mixer },
5251                 .init_verbs = { alc260_acer_init_verbs },
5252                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5253                 .dac_nids = alc260_dac_nids,
5254                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5255                 .adc_nids = alc260_dual_adc_nids,
5256                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5257                 .channel_mode = alc260_modes,
5258                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5259                 .input_mux = alc260_acer_capture_sources,
5260         },
5261         [ALC260_WILL] = {
5262                 .mixers = { alc260_will_mixer,
5263                             alc260_capture_mixer },
5264                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5265                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5266                 .dac_nids = alc260_dac_nids,
5267                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5268                 .adc_nids = alc260_adc_nids,
5269                 .dig_out_nid = ALC260_DIGOUT_NID,
5270                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5271                 .channel_mode = alc260_modes,
5272                 .input_mux = &alc260_capture_source,
5273         },
5274         [ALC260_REPLACER_672V] = {
5275                 .mixers = { alc260_replacer_672v_mixer,
5276                             alc260_capture_mixer },
5277                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5278                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5279                 .dac_nids = alc260_dac_nids,
5280                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5281                 .adc_nids = alc260_adc_nids,
5282                 .dig_out_nid = ALC260_DIGOUT_NID,
5283                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5284                 .channel_mode = alc260_modes,
5285                 .input_mux = &alc260_capture_source,
5286                 .unsol_event = alc260_replacer_672v_unsol_event,
5287                 .init_hook = alc260_replacer_672v_automute,
5288         },
5289 #ifdef CONFIG_SND_DEBUG
5290         [ALC260_TEST] = {
5291                 .mixers = { alc260_test_mixer,
5292                             alc260_capture_mixer },
5293                 .init_verbs = { alc260_test_init_verbs },
5294                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5295                 .dac_nids = alc260_test_dac_nids,
5296                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5297                 .adc_nids = alc260_test_adc_nids,
5298                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5299                 .channel_mode = alc260_modes,
5300                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5301                 .input_mux = alc260_test_capture_sources,
5302         },
5303 #endif
5304 };
5305
5306 static int patch_alc260(struct hda_codec *codec)
5307 {
5308         struct alc_spec *spec;
5309         int err, board_config;
5310
5311         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5312         if (spec == NULL)
5313                 return -ENOMEM;
5314
5315         codec->spec = spec;
5316
5317         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
5318                                                   alc260_models,
5319                                                   alc260_cfg_tbl);
5320         if (board_config < 0) {
5321                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
5322                            "trying auto-probe from BIOS...\n");
5323                 board_config = ALC260_AUTO;
5324         }
5325
5326         if (board_config == ALC260_AUTO) {
5327                 /* automatic parse from the BIOS config */
5328                 err = alc260_parse_auto_config(codec);
5329                 if (err < 0) {
5330                         alc_free(codec);
5331                         return err;
5332                 } else if (!err) {
5333                         printk(KERN_INFO
5334                                "hda_codec: Cannot set up configuration "
5335                                "from BIOS.  Using base mode...\n");
5336                         board_config = ALC260_BASIC;
5337                 }
5338         }
5339
5340         if (board_config != ALC260_AUTO)
5341                 setup_preset(spec, &alc260_presets[board_config]);
5342
5343         spec->stream_name_analog = "ALC260 Analog";
5344         spec->stream_analog_playback = &alc260_pcm_analog_playback;
5345         spec->stream_analog_capture = &alc260_pcm_analog_capture;
5346
5347         spec->stream_name_digital = "ALC260 Digital";
5348         spec->stream_digital_playback = &alc260_pcm_digital_playback;
5349         spec->stream_digital_capture = &alc260_pcm_digital_capture;
5350
5351         spec->vmaster_nid = 0x08;
5352
5353         codec->patch_ops = alc_patch_ops;
5354         if (board_config == ALC260_AUTO)
5355                 spec->init_hook = alc260_auto_init;
5356 #ifdef CONFIG_SND_HDA_POWER_SAVE
5357         if (!spec->loopback.amplist)
5358                 spec->loopback.amplist = alc260_loopbacks;
5359 #endif
5360
5361         return 0;
5362 }
5363
5364
5365 /*
5366  * ALC882 support
5367  *
5368  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5369  * configuration.  Each pin widget can choose any input DACs and a mixer.
5370  * Each ADC is connected from a mixer of all inputs.  This makes possible
5371  * 6-channel independent captures.
5372  *
5373  * In addition, an independent DAC for the multi-playback (not used in this
5374  * driver yet).
5375  */
5376 #define ALC882_DIGOUT_NID       0x06
5377 #define ALC882_DIGIN_NID        0x0a
5378
5379 static struct hda_channel_mode alc882_ch_modes[1] = {
5380         { 8, NULL }
5381 };
5382
5383 static hda_nid_t alc882_dac_nids[4] = {
5384         /* front, rear, clfe, rear_surr */
5385         0x02, 0x03, 0x04, 0x05
5386 };
5387
5388 /* identical with ALC880 */
5389 #define alc882_adc_nids         alc880_adc_nids
5390 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5391
5392 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5393 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5394
5395 /* input MUX */
5396 /* FIXME: should be a matrix-type input source selection */
5397
5398 static struct hda_input_mux alc882_capture_source = {
5399         .num_items = 4,
5400         .items = {
5401                 { "Mic", 0x0 },
5402                 { "Front Mic", 0x1 },
5403                 { "Line", 0x2 },
5404                 { "CD", 0x4 },
5405         },
5406 };
5407 #define alc882_mux_enum_info alc_mux_enum_info
5408 #define alc882_mux_enum_get alc_mux_enum_get
5409
5410 static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol,
5411                                struct snd_ctl_elem_value *ucontrol)
5412 {
5413         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5414         struct alc_spec *spec = codec->spec;
5415         const struct hda_input_mux *imux = spec->input_mux;
5416         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
5417         hda_nid_t nid = spec->capsrc_nids ?
5418                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
5419         unsigned int *cur_val = &spec->cur_mux[adc_idx];
5420         unsigned int i, idx;
5421
5422         idx = ucontrol->value.enumerated.item[0];
5423         if (idx >= imux->num_items)
5424                 idx = imux->num_items - 1;
5425         if (*cur_val == idx)
5426                 return 0;
5427         for (i = 0; i < imux->num_items; i++) {
5428                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
5429                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
5430                                          imux->items[i].index,
5431                                          HDA_AMP_MUTE, v);
5432         }
5433         *cur_val = idx;
5434         return 1;
5435 }
5436
5437 /*
5438  * 2ch mode
5439  */
5440 static struct hda_verb alc882_3ST_ch2_init[] = {
5441         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5442         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5443         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5444         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5445         { } /* end */
5446 };
5447
5448 /*
5449  * 6ch mode
5450  */
5451 static struct hda_verb alc882_3ST_ch6_init[] = {
5452         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5453         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5454         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5455         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5456         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5457         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5458         { } /* end */
5459 };
5460
5461 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5462         { 2, alc882_3ST_ch2_init },
5463         { 6, alc882_3ST_ch6_init },
5464 };
5465
5466 /*
5467  * 6ch mode
5468  */
5469 static struct hda_verb alc882_sixstack_ch6_init[] = {
5470         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5471         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5472         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5473         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5474         { } /* end */
5475 };
5476
5477 /*
5478  * 8ch mode
5479  */
5480 static struct hda_verb alc882_sixstack_ch8_init[] = {
5481         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5482         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5483         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5484         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5485         { } /* end */
5486 };
5487
5488 static struct hda_channel_mode alc882_sixstack_modes[2] = {
5489         { 6, alc882_sixstack_ch6_init },
5490         { 8, alc882_sixstack_ch8_init },
5491 };
5492
5493 /*
5494  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
5495  */
5496
5497 /*
5498  * 2ch mode
5499  */
5500 static struct hda_verb alc885_mbp_ch2_init[] = {
5501         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5502         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5503         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5504         { } /* end */
5505 };
5506
5507 /*
5508  * 6ch mode
5509  */
5510 static struct hda_verb alc885_mbp_ch6_init[] = {
5511         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5512         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5513         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5514         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5515         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5516         { } /* end */
5517 };
5518
5519 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
5520         { 2, alc885_mbp_ch2_init },
5521         { 6, alc885_mbp_ch6_init },
5522 };
5523
5524
5525 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
5526  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
5527  */
5528 static struct snd_kcontrol_new alc882_base_mixer[] = {
5529         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5530         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5531         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5532         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5533         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5534         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5535         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5536         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5537         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
5538         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
5539         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5540         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5541         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5542         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5543         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5544         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5545         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5546         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5547         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5548         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5549         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5550         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5551         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5552         { } /* end */
5553 };
5554
5555 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
5556         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5557         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
5558         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
5559         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
5560         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5561         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5562         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
5563         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
5564         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
5565         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
5566         { } /* end */
5567 };
5568 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
5569         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5570         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5571         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5572         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5573         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5574         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5575         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5576         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5577         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5578         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5579         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5580         { } /* end */
5581 };
5582
5583 static struct snd_kcontrol_new alc882_targa_mixer[] = {
5584         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5585         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5586         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5587         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5588         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5589         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5590         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5591         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5592         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5593         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5594         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5595         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5596         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5597         { } /* end */
5598 };
5599
5600 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
5601  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
5602  */
5603 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
5604         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5605         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5606         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5607         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
5608         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5609         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5610         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5611         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5612         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
5613         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
5614         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5615         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5616         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5617         { } /* end */
5618 };
5619
5620 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
5621         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5622         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5623         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5624         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5625         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5626         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5627         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5628         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5629         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5630         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5631         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5632         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5633         { } /* end */
5634 };
5635
5636 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
5637         {
5638                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5639                 .name = "Channel Mode",
5640                 .info = alc_ch_mode_info,
5641                 .get = alc_ch_mode_get,
5642                 .put = alc_ch_mode_put,
5643         },
5644         { } /* end */
5645 };
5646
5647 static struct hda_verb alc882_init_verbs[] = {
5648         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5649         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5650         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5651         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5652         /* Rear mixer */
5653         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5654         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5655         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5656         /* CLFE mixer */
5657         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5658         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5659         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5660         /* Side mixer */
5661         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5662         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5663         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5664
5665         /* Front Pin: output 0 (0x0c) */
5666         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5667         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5668         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5669         /* Rear Pin: output 1 (0x0d) */
5670         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5671         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5672         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5673         /* CLFE Pin: output 2 (0x0e) */
5674         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5675         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5676         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
5677         /* Side Pin: output 3 (0x0f) */
5678         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5679         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5680         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
5681         /* Mic (rear) pin: input vref at 80% */
5682         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5683         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5684         /* Front Mic pin: input vref at 80% */
5685         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5686         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5687         /* Line In pin: input */
5688         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5689         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5690         /* Line-2 In: Headphone output (output 0 - 0x0c) */
5691         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5692         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5693         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
5694         /* CD pin widget for input */
5695         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5696
5697         /* FIXME: use matrix-type input source selection */
5698         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5699         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5700         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5701         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5702         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5703         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5704         /* Input mixer2 */
5705         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5706         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5707         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5708         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5709         /* Input mixer3 */
5710         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5711         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5712         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5713         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5714         /* ADC1: mute amp left and right */
5715         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5716         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5717         /* ADC2: mute amp left and right */
5718         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5719         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5720         /* ADC3: mute amp left and right */
5721         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5722         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5723
5724         { }
5725 };
5726
5727 static struct hda_verb alc882_eapd_verbs[] = {
5728         /* change to EAPD mode */
5729         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5730         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
5731         { }
5732 };
5733
5734 /* Mac Pro test */
5735 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
5736         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5737         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5738         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
5739         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
5740         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
5741         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
5742         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
5743         { } /* end */
5744 };
5745
5746 static struct hda_verb alc882_macpro_init_verbs[] = {
5747         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5748         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5749         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5750         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5751         /* Front Pin: output 0 (0x0c) */
5752         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5753         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5754         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5755         /* Front Mic pin: input vref at 80% */
5756         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5757         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5758         /* Speaker:  output */
5759         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5760         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5761         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
5762         /* Headphone output (output 0 - 0x0c) */
5763         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5764         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5765         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5766
5767         /* FIXME: use matrix-type input source selection */
5768         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5769         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5770         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5771         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5772         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5773         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5774         /* Input mixer2 */
5775         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5776         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5777         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5778         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5779         /* Input mixer3 */
5780         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5781         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5782         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5783         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5784         /* ADC1: mute amp left and right */
5785         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5786         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5787         /* ADC2: mute amp left and right */
5788         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5789         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5790         /* ADC3: mute amp left and right */
5791         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5792         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5793
5794         { }
5795 };
5796
5797 /* Macbook Pro rev3 */
5798 static struct hda_verb alc885_mbp3_init_verbs[] = {
5799         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5800         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5801         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5802         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5803         /* Rear mixer */
5804         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5805         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5806         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5807         /* Front Pin: output 0 (0x0c) */
5808         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5809         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5810         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5811         /* HP Pin: output 0 (0x0d) */
5812         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
5813         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5814         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5815         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5816         /* Mic (rear) pin: input vref at 80% */
5817         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5818         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5819         /* Front Mic pin: input vref at 80% */
5820         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5821         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5822         /* Line In pin: use output 1 when in LineOut mode */
5823         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5824         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5825         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
5826
5827         /* FIXME: use matrix-type input source selection */
5828         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5829         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5830         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5831         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5832         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5833         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5834         /* Input mixer2 */
5835         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5836         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5837         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5838         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5839         /* Input mixer3 */
5840         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5841         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5842         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5843         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5844         /* ADC1: mute amp left and right */
5845         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5846         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5847         /* ADC2: mute amp left and right */
5848         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5849         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5850         /* ADC3: mute amp left and right */
5851         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5852         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5853
5854         { }
5855 };
5856
5857 /* iMac 24 mixer. */
5858 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
5859         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5860         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
5861         { } /* end */
5862 };
5863
5864 /* iMac 24 init verbs. */
5865 static struct hda_verb alc885_imac24_init_verbs[] = {
5866         /* Internal speakers: output 0 (0x0c) */
5867         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5868         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5869         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5870         /* Internal speakers: output 0 (0x0c) */
5871         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5872         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5873         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
5874         /* Headphone: output 0 (0x0c) */
5875         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5876         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5877         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5878         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5879         /* Front Mic: input vref at 80% */
5880         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5881         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5882         { }
5883 };
5884
5885 /* Toggle speaker-output according to the hp-jack state */
5886 static void alc885_imac24_automute(struct hda_codec *codec)
5887 {
5888         unsigned int present;
5889
5890         present = snd_hda_codec_read(codec, 0x14, 0,
5891                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5892         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
5893                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5894         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
5895                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5896 }
5897
5898 /* Processes unsolicited events. */
5899 static void alc885_imac24_unsol_event(struct hda_codec *codec,
5900                                       unsigned int res)
5901 {
5902         /* Headphone insertion or removal. */
5903         if ((res >> 26) == ALC880_HP_EVENT)
5904                 alc885_imac24_automute(codec);
5905 }
5906
5907 static void alc885_mbp3_automute(struct hda_codec *codec)
5908 {
5909         unsigned int present;
5910
5911         present = snd_hda_codec_read(codec, 0x15, 0,
5912                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5913         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
5914                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5915         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
5916                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
5917
5918 }
5919 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
5920                                     unsigned int res)
5921 {
5922         /* Headphone insertion or removal. */
5923         if ((res >> 26) == ALC880_HP_EVENT)
5924                 alc885_mbp3_automute(codec);
5925 }
5926
5927
5928 static struct hda_verb alc882_targa_verbs[] = {
5929         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5930         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5931
5932         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5933         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5934         
5935         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5936         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5937         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5938
5939         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5940         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5941         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
5942         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
5943         { } /* end */
5944 };
5945
5946 /* toggle speaker-output according to the hp-jack state */
5947 static void alc882_targa_automute(struct hda_codec *codec)
5948 {
5949         unsigned int present;
5950  
5951         present = snd_hda_codec_read(codec, 0x14, 0,
5952                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5953         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
5954                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5955         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
5956                                   present ? 1 : 3);
5957 }
5958
5959 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
5960 {
5961         /* Looks like the unsol event is incompatible with the standard
5962          * definition.  4bit tag is placed at 26 bit!
5963          */
5964         if (((res >> 26) == ALC880_HP_EVENT)) {
5965                 alc882_targa_automute(codec);
5966         }
5967 }
5968
5969 static struct hda_verb alc882_asus_a7j_verbs[] = {
5970         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5971         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5972
5973         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5974         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5975         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5976         
5977         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5978         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5979         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5980
5981         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5982         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5983         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5984         { } /* end */
5985 };
5986
5987 static struct hda_verb alc882_asus_a7m_verbs[] = {
5988         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5989         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5990
5991         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5992         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5993         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5994         
5995         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5996         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5997         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5998
5999         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6000         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6001         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6002         { } /* end */
6003 };
6004
6005 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6006 {
6007         unsigned int gpiostate, gpiomask, gpiodir;
6008
6009         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6010                                        AC_VERB_GET_GPIO_DATA, 0);
6011
6012         if (!muted)
6013                 gpiostate |= (1 << pin);
6014         else
6015                 gpiostate &= ~(1 << pin);
6016
6017         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
6018                                       AC_VERB_GET_GPIO_MASK, 0);
6019         gpiomask |= (1 << pin);
6020
6021         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
6022                                      AC_VERB_GET_GPIO_DIRECTION, 0);
6023         gpiodir |= (1 << pin);
6024
6025
6026         snd_hda_codec_write(codec, codec->afg, 0,
6027                             AC_VERB_SET_GPIO_MASK, gpiomask);
6028         snd_hda_codec_write(codec, codec->afg, 0,
6029                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
6030
6031         msleep(1);
6032
6033         snd_hda_codec_write(codec, codec->afg, 0,
6034                             AC_VERB_SET_GPIO_DATA, gpiostate);
6035 }
6036
6037 /* set up GPIO at initialization */
6038 static void alc885_macpro_init_hook(struct hda_codec *codec)
6039 {
6040         alc882_gpio_mute(codec, 0, 0);
6041         alc882_gpio_mute(codec, 1, 0);
6042 }
6043
6044 /* set up GPIO and update auto-muting at initialization */
6045 static void alc885_imac24_init_hook(struct hda_codec *codec)
6046 {
6047         alc885_macpro_init_hook(codec);
6048         alc885_imac24_automute(codec);
6049 }
6050
6051 /*
6052  * generic initialization of ADC, input mixers and output mixers
6053  */
6054 static struct hda_verb alc882_auto_init_verbs[] = {
6055         /*
6056          * Unmute ADC0-2 and set the default input to mic-in
6057          */
6058         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6059         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6060         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6061         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6062         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6063         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6064
6065         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6066          * mixer widget
6067          * Note: PASD motherboards uses the Line In 2 as the input for
6068          * front panel mic (mic 2)
6069          */
6070         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6071         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6072         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6073         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6074         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6075         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6076
6077         /*
6078          * Set up output mixers (0x0c - 0x0f)
6079          */
6080         /* set vol=0 to output mixers */
6081         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6082         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6083         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6084         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6085         /* set up input amps for analog loopback */
6086         /* Amp Indices: DAC = 0, mixer = 1 */
6087         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6088         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6089         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6090         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6091         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6092         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6093         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6094         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6095         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6096         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6097
6098         /* FIXME: use matrix-type input source selection */
6099         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6100         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6101         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6102         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6103         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6104         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6105         /* Input mixer2 */
6106         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6107         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6108         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6109         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6110         /* Input mixer3 */
6111         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6112         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6113         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6114         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6115
6116         { }
6117 };
6118
6119 /* capture mixer elements */
6120 static struct snd_kcontrol_new alc882_capture_alt_mixer[] = {
6121         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6122         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6123         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6124         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6125         {
6126                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6127                 /* The multiple "Capture Source" controls confuse alsamixer
6128                  * So call somewhat different..
6129                  */
6130                 /* .name = "Capture Source", */
6131                 .name = "Input Source",
6132                 .count = 2,
6133                 .info = alc882_mux_enum_info,
6134                 .get = alc882_mux_enum_get,
6135                 .put = alc882_mux_enum_put,
6136         },
6137         { } /* end */
6138 };
6139
6140 static struct snd_kcontrol_new alc882_capture_mixer[] = {
6141         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
6142         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
6143         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
6144         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
6145         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
6146         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
6147         {
6148                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6149                 /* The multiple "Capture Source" controls confuse alsamixer
6150                  * So call somewhat different..
6151                  */
6152                 /* .name = "Capture Source", */
6153                 .name = "Input Source",
6154                 .count = 3,
6155                 .info = alc882_mux_enum_info,
6156                 .get = alc882_mux_enum_get,
6157                 .put = alc882_mux_enum_put,
6158         },
6159         { } /* end */
6160 };
6161
6162 #ifdef CONFIG_SND_HDA_POWER_SAVE
6163 #define alc882_loopbacks        alc880_loopbacks
6164 #endif
6165
6166 /* pcm configuration: identiacal with ALC880 */
6167 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6168 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6169 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6170 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6171
6172 /*
6173  * configuration and preset
6174  */
6175 static const char *alc882_models[ALC882_MODEL_LAST] = {
6176         [ALC882_3ST_DIG]        = "3stack-dig",
6177         [ALC882_6ST_DIG]        = "6stack-dig",
6178         [ALC882_ARIMA]          = "arima",
6179         [ALC882_W2JC]           = "w2jc",
6180         [ALC882_TARGA]          = "targa",
6181         [ALC882_ASUS_A7J]       = "asus-a7j",
6182         [ALC882_ASUS_A7M]       = "asus-a7m",
6183         [ALC885_MACPRO]         = "macpro",
6184         [ALC885_MBP3]           = "mbp3",
6185         [ALC885_IMAC24]         = "imac24",
6186         [ALC882_AUTO]           = "auto",
6187 };
6188
6189 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6190         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6191         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6192         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6193         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6194         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6195         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6196         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6197         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6198         SND_PCI_QUIRK(0x106b, 0x00a0, "Apple iMac 24''", ALC885_IMAC24),
6199         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6200         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6201         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6202         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6203         {}
6204 };
6205
6206 static struct alc_config_preset alc882_presets[] = {
6207         [ALC882_3ST_DIG] = {
6208                 .mixers = { alc882_base_mixer },
6209                 .init_verbs = { alc882_init_verbs },
6210                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6211                 .dac_nids = alc882_dac_nids,
6212                 .dig_out_nid = ALC882_DIGOUT_NID,
6213                 .dig_in_nid = ALC882_DIGIN_NID,
6214                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6215                 .channel_mode = alc882_ch_modes,
6216                 .need_dac_fix = 1,
6217                 .input_mux = &alc882_capture_source,
6218         },
6219         [ALC882_6ST_DIG] = {
6220                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6221                 .init_verbs = { alc882_init_verbs },
6222                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6223                 .dac_nids = alc882_dac_nids,
6224                 .dig_out_nid = ALC882_DIGOUT_NID,
6225                 .dig_in_nid = ALC882_DIGIN_NID,
6226                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6227                 .channel_mode = alc882_sixstack_modes,
6228                 .input_mux = &alc882_capture_source,
6229         },
6230         [ALC882_ARIMA] = {
6231                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6232                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6233                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6234                 .dac_nids = alc882_dac_nids,
6235                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6236                 .channel_mode = alc882_sixstack_modes,
6237                 .input_mux = &alc882_capture_source,
6238         },
6239         [ALC882_W2JC] = {
6240                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6241                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6242                                 alc880_gpio1_init_verbs },
6243                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6244                 .dac_nids = alc882_dac_nids,
6245                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6246                 .channel_mode = alc880_threestack_modes,
6247                 .need_dac_fix = 1,
6248                 .input_mux = &alc882_capture_source,
6249                 .dig_out_nid = ALC882_DIGOUT_NID,
6250         },
6251         [ALC885_MBP3] = {
6252                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6253                 .init_verbs = { alc885_mbp3_init_verbs,
6254                                 alc880_gpio1_init_verbs },
6255                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6256                 .dac_nids = alc882_dac_nids,
6257                 .channel_mode = alc885_mbp_6ch_modes,
6258                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
6259                 .input_mux = &alc882_capture_source,
6260                 .dig_out_nid = ALC882_DIGOUT_NID,
6261                 .dig_in_nid = ALC882_DIGIN_NID,
6262                 .unsol_event = alc885_mbp3_unsol_event,
6263                 .init_hook = alc885_mbp3_automute,
6264         },
6265         [ALC885_MACPRO] = {
6266                 .mixers = { alc882_macpro_mixer },
6267                 .init_verbs = { alc882_macpro_init_verbs },
6268                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6269                 .dac_nids = alc882_dac_nids,
6270                 .dig_out_nid = ALC882_DIGOUT_NID,
6271                 .dig_in_nid = ALC882_DIGIN_NID,
6272                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6273                 .channel_mode = alc882_ch_modes,
6274                 .input_mux = &alc882_capture_source,
6275                 .init_hook = alc885_macpro_init_hook,
6276         },
6277         [ALC885_IMAC24] = {
6278                 .mixers = { alc885_imac24_mixer },
6279                 .init_verbs = { alc885_imac24_init_verbs },
6280                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6281                 .dac_nids = alc882_dac_nids,
6282                 .dig_out_nid = ALC882_DIGOUT_NID,
6283                 .dig_in_nid = ALC882_DIGIN_NID,
6284                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6285                 .channel_mode = alc882_ch_modes,
6286                 .input_mux = &alc882_capture_source,
6287                 .unsol_event = alc885_imac24_unsol_event,
6288                 .init_hook = alc885_imac24_init_hook,
6289         },
6290         [ALC882_TARGA] = {
6291                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer,
6292                             alc882_capture_mixer },
6293                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6294                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6295                 .dac_nids = alc882_dac_nids,
6296                 .dig_out_nid = ALC882_DIGOUT_NID,
6297                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6298                 .adc_nids = alc882_adc_nids,
6299                 .capsrc_nids = alc882_capsrc_nids,
6300                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6301                 .channel_mode = alc882_3ST_6ch_modes,
6302                 .need_dac_fix = 1,
6303                 .input_mux = &alc882_capture_source,
6304                 .unsol_event = alc882_targa_unsol_event,
6305                 .init_hook = alc882_targa_automute,
6306         },
6307         [ALC882_ASUS_A7J] = {
6308                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer,
6309                             alc882_capture_mixer },
6310                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6311                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6312                 .dac_nids = alc882_dac_nids,
6313                 .dig_out_nid = ALC882_DIGOUT_NID,
6314                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6315                 .adc_nids = alc882_adc_nids,
6316                 .capsrc_nids = alc882_capsrc_nids,
6317                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6318                 .channel_mode = alc882_3ST_6ch_modes,
6319                 .need_dac_fix = 1,
6320                 .input_mux = &alc882_capture_source,
6321         },      
6322         [ALC882_ASUS_A7M] = {
6323                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6324                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6325                                 alc880_gpio1_init_verbs,
6326                                 alc882_asus_a7m_verbs },
6327                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6328                 .dac_nids = alc882_dac_nids,
6329                 .dig_out_nid = ALC882_DIGOUT_NID,
6330                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6331                 .channel_mode = alc880_threestack_modes,
6332                 .need_dac_fix = 1,
6333                 .input_mux = &alc882_capture_source,
6334         },      
6335 };
6336
6337
6338 /*
6339  * Pin config fixes
6340  */
6341 enum { 
6342         PINFIX_ABIT_AW9D_MAX
6343 };
6344
6345 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6346         { 0x15, 0x01080104 }, /* side */
6347         { 0x16, 0x01011012 }, /* rear */
6348         { 0x17, 0x01016011 }, /* clfe */
6349         { }
6350 };
6351
6352 static const struct alc_pincfg *alc882_pin_fixes[] = {
6353         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6354 };
6355
6356 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6357         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6358         {}
6359 };
6360
6361 /*
6362  * BIOS auto configuration
6363  */
6364 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6365                                               hda_nid_t nid, int pin_type,
6366                                               int dac_idx)
6367 {
6368         /* set as output */
6369         struct alc_spec *spec = codec->spec;
6370         int idx;
6371
6372         alc_set_pin_output(codec, nid, pin_type);
6373         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6374                 idx = 4;
6375         else
6376                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6377         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6378
6379 }
6380
6381 static void alc882_auto_init_multi_out(struct hda_codec *codec)
6382 {
6383         struct alc_spec *spec = codec->spec;
6384         int i;
6385
6386         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6387         for (i = 0; i <= HDA_SIDE; i++) {
6388                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6389                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6390                 if (nid)
6391                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6392                                                           i);
6393         }
6394 }
6395
6396 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6397 {
6398         struct alc_spec *spec = codec->spec;
6399         hda_nid_t pin;
6400
6401         pin = spec->autocfg.hp_pins[0];
6402         if (pin) /* connect to front */
6403                 /* use dac 0 */
6404                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6405         pin = spec->autocfg.speaker_pins[0];
6406         if (pin)
6407                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6408 }
6409
6410 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6411 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6412
6413 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6414 {
6415         struct alc_spec *spec = codec->spec;
6416         int i;
6417
6418         for (i = 0; i < AUTO_PIN_LAST; i++) {
6419                 hda_nid_t nid = spec->autocfg.input_pins[i];
6420                 unsigned int vref;
6421                 if (!nid)
6422                         continue;
6423                 vref = PIN_IN;
6424                 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6425                         unsigned int pincap;
6426                         pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
6427                         if ((pincap >> AC_PINCAP_VREF_SHIFT) &
6428                             AC_PINCAP_VREF_80)
6429                                 vref = PIN_VREF80;
6430                 }
6431                 snd_hda_codec_write(codec, nid, 0,
6432                                     AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6433                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6434                         snd_hda_codec_write(codec, nid, 0,
6435                                             AC_VERB_SET_AMP_GAIN_MUTE,
6436                                             AMP_OUT_MUTE);
6437         }
6438 }
6439
6440 /* add mic boosts if needed */
6441 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6442 {
6443         struct alc_spec *spec = codec->spec;
6444         int err;
6445         hda_nid_t nid;
6446
6447         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6448         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6449                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6450                                   "Mic Boost",
6451                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6452                 if (err < 0)
6453                         return err;
6454         }
6455         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6456         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6457                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6458                                   "Front Mic Boost",
6459                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6460                 if (err < 0)
6461                         return err;
6462         }
6463         return 0;
6464 }
6465
6466 /* almost identical with ALC880 parser... */
6467 static int alc882_parse_auto_config(struct hda_codec *codec)
6468 {
6469         struct alc_spec *spec = codec->spec;
6470         int err = alc880_parse_auto_config(codec);
6471
6472         if (err < 0)
6473                 return err;
6474         else if (!err)
6475                 return 0; /* no config found */
6476
6477         err = alc_auto_add_mic_boost(codec);
6478         if (err < 0)
6479                 return err;
6480
6481         /* hack - override the init verbs */
6482         spec->init_verbs[0] = alc882_auto_init_verbs;
6483
6484         return 1; /* config found */
6485 }
6486
6487 /* additional initialization for auto-configuration model */
6488 static void alc882_auto_init(struct hda_codec *codec)
6489 {
6490         struct alc_spec *spec = codec->spec;
6491         alc882_auto_init_multi_out(codec);
6492         alc882_auto_init_hp_out(codec);
6493         alc882_auto_init_analog_input(codec);
6494         if (spec->unsol_event)
6495                 alc_sku_automute(codec);
6496 }
6497
6498 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
6499
6500 static int patch_alc882(struct hda_codec *codec)
6501 {
6502         struct alc_spec *spec;
6503         int err, board_config;
6504
6505         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6506         if (spec == NULL)
6507                 return -ENOMEM;
6508
6509         codec->spec = spec;
6510
6511         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
6512                                                   alc882_models,
6513                                                   alc882_cfg_tbl);
6514
6515         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
6516                 /* Pick up systems that don't supply PCI SSID */
6517                 switch (codec->subsystem_id) {
6518                 case 0x106b0c00: /* Mac Pro */
6519                         board_config = ALC885_MACPRO;
6520                         break;
6521                 case 0x106b1000: /* iMac 24 */
6522                         board_config = ALC885_IMAC24;
6523                         break;
6524                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
6525                 case 0x106b2c00: /* Macbook Pro rev3 */
6526                 case 0x106b3600: /* Macbook 3.1 */
6527                         board_config = ALC885_MBP3;
6528                         break;
6529                 default:
6530                         /* ALC889A is handled better as ALC888-compatible */
6531                         if (codec->revision_id == 0x100103) {
6532                                 alc_free(codec);
6533                                 return patch_alc883(codec);
6534                         }
6535                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
6536                                          "trying auto-probe from BIOS...\n");
6537                         board_config = ALC882_AUTO;
6538                 }
6539         }
6540
6541         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
6542
6543         if (board_config == ALC882_AUTO) {
6544                 /* automatic parse from the BIOS config */
6545                 err = alc882_parse_auto_config(codec);
6546                 if (err < 0) {
6547                         alc_free(codec);
6548                         return err;
6549                 } else if (!err) {
6550                         printk(KERN_INFO
6551                                "hda_codec: Cannot set up configuration "
6552                                "from BIOS.  Using base mode...\n");
6553                         board_config = ALC882_3ST_DIG;
6554                 }
6555         }
6556
6557         if (board_config != ALC882_AUTO)
6558                 setup_preset(spec, &alc882_presets[board_config]);
6559
6560         if (codec->vendor_id == 0x10ec0885) {
6561                 spec->stream_name_analog = "ALC885 Analog";
6562                 spec->stream_name_digital = "ALC885 Digital";
6563         } else {
6564                 spec->stream_name_analog = "ALC882 Analog";
6565                 spec->stream_name_digital = "ALC882 Digital";
6566         }
6567
6568         spec->stream_analog_playback = &alc882_pcm_analog_playback;
6569         spec->stream_analog_capture = &alc882_pcm_analog_capture;
6570         /* FIXME: setup DAC5 */
6571         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
6572         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
6573
6574         spec->stream_digital_playback = &alc882_pcm_digital_playback;
6575         spec->stream_digital_capture = &alc882_pcm_digital_capture;
6576
6577         if (!spec->adc_nids && spec->input_mux) {
6578                 /* check whether NID 0x07 is valid */
6579                 unsigned int wcap = get_wcaps(codec, 0x07);
6580                 /* get type */
6581                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
6582                 if (wcap != AC_WID_AUD_IN) {
6583                         spec->adc_nids = alc882_adc_nids_alt;
6584                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
6585                         spec->capsrc_nids = alc882_capsrc_nids_alt;
6586                         spec->mixers[spec->num_mixers] =
6587                                 alc882_capture_alt_mixer;
6588                         spec->num_mixers++;
6589                 } else {
6590                         spec->adc_nids = alc882_adc_nids;
6591                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
6592                         spec->capsrc_nids = alc882_capsrc_nids;
6593                         spec->mixers[spec->num_mixers] = alc882_capture_mixer;
6594                         spec->num_mixers++;
6595                 }
6596         }
6597
6598         spec->vmaster_nid = 0x0c;
6599
6600         codec->patch_ops = alc_patch_ops;
6601         if (board_config == ALC882_AUTO)
6602                 spec->init_hook = alc882_auto_init;
6603 #ifdef CONFIG_SND_HDA_POWER_SAVE
6604         if (!spec->loopback.amplist)
6605                 spec->loopback.amplist = alc882_loopbacks;
6606 #endif
6607
6608         return 0;
6609 }
6610
6611 /*
6612  * ALC883 support
6613  *
6614  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
6615  * configuration.  Each pin widget can choose any input DACs and a mixer.
6616  * Each ADC is connected from a mixer of all inputs.  This makes possible
6617  * 6-channel independent captures.
6618  *
6619  * In addition, an independent DAC for the multi-playback (not used in this
6620  * driver yet).
6621  */
6622 #define ALC883_DIGOUT_NID       0x06
6623 #define ALC883_DIGIN_NID        0x0a
6624
6625 static hda_nid_t alc883_dac_nids[4] = {
6626         /* front, rear, clfe, rear_surr */
6627         0x02, 0x03, 0x04, 0x05
6628 };
6629
6630 static hda_nid_t alc883_adc_nids[2] = {
6631         /* ADC1-2 */
6632         0x08, 0x09,
6633 };
6634
6635 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
6636
6637 /* input MUX */
6638 /* FIXME: should be a matrix-type input source selection */
6639
6640 static struct hda_input_mux alc883_capture_source = {
6641         .num_items = 4,
6642         .items = {
6643                 { "Mic", 0x0 },
6644                 { "Front Mic", 0x1 },
6645                 { "Line", 0x2 },
6646                 { "CD", 0x4 },
6647         },
6648 };
6649
6650 static struct hda_input_mux alc883_3stack_6ch_intel = {
6651         .num_items = 4,
6652         .items = {
6653                 { "Mic", 0x1 },
6654                 { "Front Mic", 0x0 },
6655                 { "Line", 0x2 },
6656                 { "CD", 0x4 },
6657         },
6658 };
6659
6660 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6661         .num_items = 2,
6662         .items = {
6663                 { "Mic", 0x1 },
6664                 { "Line", 0x2 },
6665         },
6666 };
6667
6668 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6669         .num_items = 4,
6670         .items = {
6671                 { "Mic", 0x0 },
6672                 { "iMic", 0x1 },
6673                 { "Line", 0x2 },
6674                 { "CD", 0x4 },
6675         },
6676 };
6677
6678 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6679         .num_items = 2,
6680         .items = {
6681                 { "Mic", 0x0 },
6682                 { "Int Mic", 0x1 },
6683         },
6684 };
6685
6686 #define alc883_mux_enum_info alc_mux_enum_info
6687 #define alc883_mux_enum_get alc_mux_enum_get
6688 /* ALC883 has the ALC882-type input selection */
6689 #define alc883_mux_enum_put alc882_mux_enum_put
6690
6691 /*
6692  * 2ch mode
6693  */
6694 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6695         { 2, NULL }
6696 };
6697
6698 /*
6699  * 2ch mode
6700  */
6701 static struct hda_verb alc883_3ST_ch2_init[] = {
6702         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6703         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6704         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6705         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6706         { } /* end */
6707 };
6708
6709 /*
6710  * 4ch mode
6711  */
6712 static struct hda_verb alc883_3ST_ch4_init[] = {
6713         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6714         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6715         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6716         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6717         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6718         { } /* end */
6719 };
6720
6721 /*
6722  * 6ch mode
6723  */
6724 static struct hda_verb alc883_3ST_ch6_init[] = {
6725         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6726         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6727         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6728         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6729         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6730         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6731         { } /* end */
6732 };
6733
6734 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
6735         { 2, alc883_3ST_ch2_init },
6736         { 4, alc883_3ST_ch4_init },
6737         { 6, alc883_3ST_ch6_init },
6738 };
6739
6740 /*
6741  * 2ch mode
6742  */
6743 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
6744         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6745         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6746         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6747         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6748         { } /* end */
6749 };
6750
6751 /*
6752  * 4ch mode
6753  */
6754 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
6755         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6756         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6757         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6758         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6759         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6760         { } /* end */
6761 };
6762
6763 /*
6764  * 6ch mode
6765  */
6766 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
6767         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6768         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6769         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
6770         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6771         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6772         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6773         { } /* end */
6774 };
6775
6776 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
6777         { 2, alc883_3ST_ch2_intel_init },
6778         { 4, alc883_3ST_ch4_intel_init },
6779         { 6, alc883_3ST_ch6_intel_init },
6780 };
6781
6782 /*
6783  * 6ch mode
6784  */
6785 static struct hda_verb alc883_sixstack_ch6_init[] = {
6786         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6787         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6788         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6789         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6790         { } /* end */
6791 };
6792
6793 /*
6794  * 8ch mode
6795  */
6796 static struct hda_verb alc883_sixstack_ch8_init[] = {
6797         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6798         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6799         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6800         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6801         { } /* end */
6802 };
6803
6804 static struct hda_channel_mode alc883_sixstack_modes[2] = {
6805         { 6, alc883_sixstack_ch6_init },
6806         { 8, alc883_sixstack_ch8_init },
6807 };
6808
6809 static struct hda_verb alc883_medion_eapd_verbs[] = {
6810         /* eanable EAPD on medion laptop */
6811         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6812         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
6813         { }
6814 };
6815
6816 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6817  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6818  */
6819
6820 static struct snd_kcontrol_new alc883_base_mixer[] = {
6821         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6822         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6823         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6824         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6825         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6826         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6827         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6828         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6829         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6830         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6831         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6832         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6833         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6834         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6835         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6836         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6837         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6838         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6839         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6840         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6841         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6842         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6843         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6844         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6845         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6846         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6847         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6848         {
6849                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6850                 /* .name = "Capture Source", */
6851                 .name = "Input Source",
6852                 .count = 2,
6853                 .info = alc883_mux_enum_info,
6854                 .get = alc883_mux_enum_get,
6855                 .put = alc883_mux_enum_put,
6856         },
6857         { } /* end */
6858 };
6859
6860 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
6861         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6862         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6863         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6864         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6865         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6866         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6867         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6868         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6869         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6870         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6871         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6872         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6873         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6874         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6875         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6876         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6877         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6878         {
6879                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6880                 /* .name = "Capture Source", */
6881                 .name = "Input Source",
6882                 .count = 2,
6883                 .info = alc883_mux_enum_info,
6884                 .get = alc883_mux_enum_get,
6885                 .put = alc883_mux_enum_put,
6886         },
6887         { } /* end */
6888 };
6889
6890 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
6891         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6892         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
6893         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6894         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6895         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6896         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6897         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6898         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6899         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6900         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6901         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6902         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6903         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6904         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6905         {
6906                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6907                 /* .name = "Capture Source", */
6908                 .name = "Input Source",
6909                 .count = 2,
6910                 .info = alc883_mux_enum_info,
6911                 .get = alc883_mux_enum_get,
6912                 .put = alc883_mux_enum_put,
6913         },
6914         { } /* end */
6915 };
6916
6917 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
6918         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6919         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
6920         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6921         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6922         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6923         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6924         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6925         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6926         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6927         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6928         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6929         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6930         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6931         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6932         {
6933                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6934                 /* .name = "Capture Source", */
6935                 .name = "Input Source",
6936                 .count = 2,
6937                 .info = alc883_mux_enum_info,
6938                 .get = alc883_mux_enum_get,
6939                 .put = alc883_mux_enum_put,
6940         },
6941         { } /* end */
6942 };
6943
6944 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
6945         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6946         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6947         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6948         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6949         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6950         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6951         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6952         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6953         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6954         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6955         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6956         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6957         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6958         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6959         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6960         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6961         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6962         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6963         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6964         {
6965                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6966                 /* .name = "Capture Source", */
6967                 .name = "Input Source",
6968                 .count = 2,
6969                 .info = alc883_mux_enum_info,
6970                 .get = alc883_mux_enum_get,
6971                 .put = alc883_mux_enum_put,
6972         },
6973         { } /* end */
6974 };
6975
6976 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
6977         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6978         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6979         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6980         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6981         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6982         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6983         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6984         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6985         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6986         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6987         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6988         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6989         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6990         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6991         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6992         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6993         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6994         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6995         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6996         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6997         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6998         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6999         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7000         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7001         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7002         {
7003                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7004                 /* .name = "Capture Source", */
7005                 .name = "Input Source",
7006                 .count = 2,
7007                 .info = alc883_mux_enum_info,
7008                 .get = alc883_mux_enum_get,
7009                 .put = alc883_mux_enum_put,
7010         },
7011         { } /* end */
7012 };
7013
7014 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7015         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7016         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7017         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7018         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7019         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7020                               HDA_OUTPUT),
7021         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7022         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7023         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7024         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7025         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7026         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7027         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7028         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7029         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7030         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7031         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7032         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7033         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7034         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7035         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7036         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7037         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7038         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7039         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7040         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7041         {
7042                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7043                 /* .name = "Capture Source", */
7044                 .name = "Input Source",
7045                 .count = 2,
7046                 .info = alc883_mux_enum_info,
7047                 .get = alc883_mux_enum_get,
7048                 .put = alc883_mux_enum_put,
7049         },
7050         { } /* end */
7051 };
7052
7053 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7054         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7055         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7056         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7057         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7058         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7059         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7060         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7061         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7062         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7063         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7064         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7065         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7066         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7067         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7068         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7069         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7070         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7071         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7072         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7073         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7074         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7075         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7076         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7077
7078         {
7079                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7080                 /* .name = "Capture Source", */
7081                 .name = "Input Source",
7082                 .count = 1,
7083                 .info = alc883_mux_enum_info,
7084                 .get = alc883_mux_enum_get,
7085                 .put = alc883_mux_enum_put,
7086         },
7087         { } /* end */
7088 };
7089
7090 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
7091         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7092         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7093         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7094         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7095         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7096         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7097         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7098         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7099         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
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("Capture Volume", 0x08, 0x0, HDA_INPUT),
7108         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7109         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7110         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7111         {
7112                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7113                 /* .name = "Capture Source", */
7114                 .name = "Input Source",
7115                 .count = 2,
7116                 .info = alc883_mux_enum_info,
7117                 .get = alc883_mux_enum_get,
7118                 .put = alc883_mux_enum_put,
7119         },
7120         { } /* end */
7121 };
7122
7123 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
7124         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7125         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7126         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7127         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7128         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7129         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7130         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7131         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7132         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7133         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7134         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7135         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7136         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7137         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7138         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7139         {
7140                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7141                 /* .name = "Capture Source", */
7142                 .name = "Input Source",
7143                 .count = 2,
7144                 .info = alc883_mux_enum_info,
7145                 .get = alc883_mux_enum_get,
7146                 .put = alc883_mux_enum_put,
7147         },
7148         { } /* end */
7149 };
7150
7151 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7152         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7153         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7154         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7155         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7156         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7157         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7158         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7159         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7160         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7161         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7162         {
7163                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7164                 /* .name = "Capture Source", */
7165                 .name = "Input Source",
7166                 .count = 1,
7167                 .info = alc883_mux_enum_info,
7168                 .get = alc883_mux_enum_get,
7169                 .put = alc883_mux_enum_put,
7170         },
7171         { } /* end */
7172 };
7173
7174 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7175         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7176         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7177         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7178         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7179         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7180         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7181         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7182         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7183         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7184         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7185         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7186         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7187         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7188         {
7189                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7190                 /* .name = "Capture Source", */
7191                 .name = "Input Source",
7192                 .count = 2,
7193                 .info = alc883_mux_enum_info,
7194                 .get = alc883_mux_enum_get,
7195                 .put = alc883_mux_enum_put,
7196         },
7197         { } /* end */
7198 };
7199
7200 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7201         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7202         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7203         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7204         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7205         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7206         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7207         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7208         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7209         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7210         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7211         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7212         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7213         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7214         {
7215                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7216                 /* .name = "Capture Source", */
7217                 .name = "Input Source",
7218                 .count = 2,
7219                 .info = alc883_mux_enum_info,
7220                 .get = alc883_mux_enum_get,
7221                 .put = alc883_mux_enum_put,
7222         },
7223         { } /* end */
7224 };      
7225
7226 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7227         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7228         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7229         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7230         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7231         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7232         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7233         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7234         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7235         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7236         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7237         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7238         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7239         {
7240                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7241                 /* .name = "Capture Source", */
7242                 .name = "Input Source",
7243                 .count = 2,
7244                 .info = alc883_mux_enum_info,
7245                 .get = alc883_mux_enum_get,
7246                 .put = alc883_mux_enum_put,
7247         },
7248         { } /* end */
7249 };
7250
7251 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7252         {
7253                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7254                 .name = "Channel Mode",
7255                 .info = alc_ch_mode_info,
7256                 .get = alc_ch_mode_get,
7257                 .put = alc_ch_mode_put,
7258         },
7259         { } /* end */
7260 };
7261
7262 static struct hda_verb alc883_init_verbs[] = {
7263         /* ADC1: mute amp left and right */
7264         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7265         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7266         /* ADC2: mute amp left and right */
7267         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7268         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7269         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7270         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7271         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7272         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7273         /* Rear mixer */
7274         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7275         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7276         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7277         /* CLFE mixer */
7278         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7279         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7280         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7281         /* Side mixer */
7282         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7283         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7284         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7285
7286         /* mute analog input loopbacks */
7287         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7288         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7289         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7290         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7291         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7292
7293         /* Front Pin: output 0 (0x0c) */
7294         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7295         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7296         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7297         /* Rear Pin: output 1 (0x0d) */
7298         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7299         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7300         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7301         /* CLFE Pin: output 2 (0x0e) */
7302         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7303         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7304         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7305         /* Side Pin: output 3 (0x0f) */
7306         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7307         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7308         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7309         /* Mic (rear) pin: input vref at 80% */
7310         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7311         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7312         /* Front Mic pin: input vref at 80% */
7313         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7314         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7315         /* Line In pin: input */
7316         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7317         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7318         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7319         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7320         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7321         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7322         /* CD pin widget for input */
7323         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7324
7325         /* FIXME: use matrix-type input source selection */
7326         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7327         /* Input mixer2 */
7328         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7329         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7330         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7331         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7332         /* Input mixer3 */
7333         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7334         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7335         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7336         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7337         { }
7338 };
7339
7340 /* toggle speaker-output according to the hp-jack state */
7341 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7342 {
7343         unsigned int present;
7344
7345         present = snd_hda_codec_read(codec, 0x15, 0,
7346                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7347         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7348                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7349         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7350                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7351 }
7352
7353 /* auto-toggle front mic */
7354 /*
7355 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7356 {
7357         unsigned int present;
7358         unsigned char bits;
7359
7360         present = snd_hda_codec_read(codec, 0x18, 0,
7361                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7362         bits = present ? HDA_AMP_MUTE : 0;
7363         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7364 }
7365 */
7366
7367 static void alc883_mitac_automute(struct hda_codec *codec)
7368 {
7369         alc883_mitac_hp_automute(codec);
7370         /* alc883_mitac_mic_automute(codec); */
7371 }
7372
7373 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7374                                            unsigned int res)
7375 {
7376         switch (res >> 26) {
7377         case ALC880_HP_EVENT:
7378                 alc883_mitac_hp_automute(codec);
7379                 break;
7380         case ALC880_MIC_EVENT:
7381                 /* alc883_mitac_mic_automute(codec); */
7382                 break;
7383         }
7384 }
7385
7386 static struct hda_verb alc883_mitac_verbs[] = {
7387         /* HP */
7388         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7389         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7390         /* Subwoofer */
7391         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7392         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7393
7394         /* enable unsolicited event */
7395         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7396         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7397
7398         { } /* end */
7399 };
7400
7401 static struct hda_verb alc883_clevo_m720_verbs[] = {
7402         /* HP */
7403         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7404         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7405         /* Int speaker */
7406         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7407         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7408
7409         /* enable unsolicited event */
7410         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7411         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7412
7413         { } /* end */
7414 };
7415
7416 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7417         /* HP */
7418         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7419         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7420         /* Subwoofer */
7421         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7422         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7423
7424         /* enable unsolicited event */
7425         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7426
7427         { } /* end */
7428 };
7429
7430 static struct hda_verb alc883_tagra_verbs[] = {
7431         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7432         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7433
7434         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7435         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7436         
7437         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7438         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7439         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7440
7441         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7442         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7443         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7444         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7445
7446         { } /* end */
7447 };
7448
7449 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7450         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7451         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7452         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7453         { } /* end */
7454 };
7455
7456 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7457         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7458         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7459         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7460         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7461         { } /* end */
7462 };
7463
7464 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7465         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7466         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7467         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7468         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7469         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7470         { } /* end */
7471 };
7472
7473 static struct hda_verb alc883_haier_w66_verbs[] = {
7474         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7475         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7476
7477         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7478
7479         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7480         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7481         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7482         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7483         { } /* end */
7484 };
7485
7486 static struct hda_verb alc888_3st_hp_verbs[] = {
7487         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7488         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7489         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7490         { }
7491 };
7492
7493 static struct hda_verb alc888_6st_dell_verbs[] = {
7494         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7495         { }
7496 };
7497
7498 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7499         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7500         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7501         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7502         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7503         { }
7504 };
7505
7506 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7507         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7508         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7509         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7510         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7511         { }
7512 };
7513
7514 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7515         { 2, alc888_3st_hp_2ch_init },
7516         { 6, alc888_3st_hp_6ch_init },
7517 };
7518
7519 /* toggle front-jack and RCA according to the hp-jack state */
7520 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7521 {
7522         unsigned int present;
7523  
7524         present = snd_hda_codec_read(codec, 0x1b, 0,
7525                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7526         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7527                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7528         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7529                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7530 }
7531
7532 /* toggle RCA according to the front-jack state */
7533 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7534 {
7535         unsigned int present;
7536  
7537         present = snd_hda_codec_read(codec, 0x14, 0,
7538                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7539         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7540                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7541 }
7542
7543 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7544                                              unsigned int res)
7545 {
7546         if ((res >> 26) == ALC880_HP_EVENT)
7547                 alc888_lenovo_ms7195_front_automute(codec);
7548         if ((res >> 26) == ALC880_FRONT_EVENT)
7549                 alc888_lenovo_ms7195_rca_automute(codec);
7550 }
7551
7552 static struct hda_verb alc883_medion_md2_verbs[] = {
7553         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7554         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7555
7556         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7557
7558         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7559         { } /* end */
7560 };
7561
7562 /* toggle speaker-output according to the hp-jack state */
7563 static void alc883_medion_md2_automute(struct hda_codec *codec)
7564 {
7565         unsigned int present;
7566  
7567         present = snd_hda_codec_read(codec, 0x14, 0,
7568                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7569         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7570                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7571 }
7572
7573 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
7574                                           unsigned int res)
7575 {
7576         if ((res >> 26) == ALC880_HP_EVENT)
7577                 alc883_medion_md2_automute(codec);
7578 }
7579
7580 /* toggle speaker-output according to the hp-jack state */
7581 static void alc883_tagra_automute(struct hda_codec *codec)
7582 {
7583         unsigned int present;
7584         unsigned char bits;
7585
7586         present = snd_hda_codec_read(codec, 0x14, 0,
7587                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7588         bits = present ? HDA_AMP_MUTE : 0;
7589         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
7590                                  HDA_AMP_MUTE, bits);
7591         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7592                                   present ? 1 : 3);
7593 }
7594
7595 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
7596 {
7597         if ((res >> 26) == ALC880_HP_EVENT)
7598                 alc883_tagra_automute(codec);
7599 }
7600
7601 /* toggle speaker-output according to the hp-jack state */
7602 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
7603 {
7604         unsigned int present;
7605         unsigned char bits;
7606
7607         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
7608                 & AC_PINSENSE_PRESENCE;
7609         bits = present ? HDA_AMP_MUTE : 0;
7610         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7611                                  HDA_AMP_MUTE, bits);
7612 }
7613
7614 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
7615 {
7616         unsigned int present;
7617
7618         present = snd_hda_codec_read(codec, 0x18, 0,
7619                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7620         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
7621                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7622 }
7623
7624 static void alc883_clevo_m720_automute(struct hda_codec *codec)
7625 {
7626         alc883_clevo_m720_hp_automute(codec);
7627         alc883_clevo_m720_mic_automute(codec);
7628 }
7629
7630 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
7631                                            unsigned int res)
7632 {
7633         switch (res >> 26) {
7634         case ALC880_HP_EVENT:
7635                 alc883_clevo_m720_hp_automute(codec);
7636                 break;
7637         case ALC880_MIC_EVENT:
7638                 alc883_clevo_m720_mic_automute(codec);
7639                 break;
7640         }
7641 }
7642
7643 /* toggle speaker-output according to the hp-jack state */
7644 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
7645 {
7646         unsigned int present;
7647         unsigned char bits;
7648
7649         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
7650                 & AC_PINSENSE_PRESENCE;
7651         bits = present ? HDA_AMP_MUTE : 0;
7652         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7653                                  HDA_AMP_MUTE, bits);
7654 }
7655
7656 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
7657                                                   unsigned int res)
7658 {
7659         if ((res >> 26) == ALC880_HP_EVENT)
7660                 alc883_2ch_fujitsu_pi2515_automute(codec);
7661 }
7662
7663 static void alc883_haier_w66_automute(struct hda_codec *codec)
7664 {
7665         unsigned int present;
7666         unsigned char bits;
7667
7668         present = snd_hda_codec_read(codec, 0x1b, 0,
7669                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7670         bits = present ? 0x80 : 0;
7671         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7672                                  0x80, bits);
7673 }
7674
7675 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
7676                                          unsigned int res)
7677 {
7678         if ((res >> 26) == ALC880_HP_EVENT)
7679                 alc883_haier_w66_automute(codec);
7680 }
7681
7682 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
7683 {
7684         unsigned int present;
7685         unsigned char bits;
7686
7687         present = snd_hda_codec_read(codec, 0x14, 0,
7688                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7689         bits = present ? HDA_AMP_MUTE : 0;
7690         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7691                                  HDA_AMP_MUTE, bits);
7692 }
7693
7694 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
7695 {
7696         unsigned int present;
7697         unsigned char bits;
7698
7699         present = snd_hda_codec_read(codec, 0x1b, 0,
7700                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7701         bits = present ? HDA_AMP_MUTE : 0;
7702         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7703                                  HDA_AMP_MUTE, bits);
7704         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7705                                  HDA_AMP_MUTE, bits);
7706 }
7707
7708 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
7709                                            unsigned int res)
7710 {
7711         if ((res >> 26) == ALC880_HP_EVENT)
7712                 alc883_lenovo_101e_all_automute(codec);
7713         if ((res >> 26) == ALC880_FRONT_EVENT)
7714                 alc883_lenovo_101e_ispeaker_automute(codec);
7715 }
7716
7717 /* toggle speaker-output according to the hp-jack state */
7718 static void alc883_acer_aspire_automute(struct hda_codec *codec)
7719 {
7720         unsigned int present;
7721  
7722         present = snd_hda_codec_read(codec, 0x14, 0,
7723                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7724         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7725                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7726         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7727                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7728 }
7729
7730 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
7731                                            unsigned int res)
7732 {
7733         if ((res >> 26) == ALC880_HP_EVENT)
7734                 alc883_acer_aspire_automute(codec);
7735 }
7736
7737 static struct hda_verb alc883_acer_eapd_verbs[] = {
7738         /* HP Pin: output 0 (0x0c) */
7739         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7740         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7741         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7742         /* Front Pin: output 0 (0x0c) */
7743         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7744         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7745         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7746         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
7747         /* eanable EAPD on medion laptop */
7748         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7749         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
7750         /* enable unsolicited event */
7751         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7752         { }
7753 };
7754
7755 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
7756 {
7757         unsigned int present;
7758  
7759         present = snd_hda_codec_read(codec, 0x1b, 0,
7760                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7761         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7762                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7763         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7764                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7765         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7766                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7767         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7768                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7769 }
7770
7771 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
7772                                              unsigned int res)
7773 {
7774         switch (res >> 26) {
7775         case ALC880_HP_EVENT:
7776                 printk("hp_event\n");
7777                 alc888_6st_dell_front_automute(codec);
7778                 break;
7779         }
7780 }
7781
7782 /*
7783  * generic initialization of ADC, input mixers and output mixers
7784  */
7785 static struct hda_verb alc883_auto_init_verbs[] = {
7786         /*
7787          * Unmute ADC0-2 and set the default input to mic-in
7788          */
7789         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7790         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7791         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7792         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7793
7794         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7795          * mixer widget
7796          * Note: PASD motherboards uses the Line In 2 as the input for
7797          * front panel mic (mic 2)
7798          */
7799         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7800         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7801         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7802         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7803         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7804         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7805
7806         /*
7807          * Set up output mixers (0x0c - 0x0f)
7808          */
7809         /* set vol=0 to output mixers */
7810         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7811         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7812         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7813         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7814         /* set up input amps for analog loopback */
7815         /* Amp Indices: DAC = 0, mixer = 1 */
7816         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7817         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7818         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7819         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7820         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7821         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7822         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7823         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7824         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7825         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7826
7827         /* FIXME: use matrix-type input source selection */
7828         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7829         /* Input mixer1 */
7830         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7831         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7832         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7833         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
7834         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7835         /* Input mixer2 */
7836         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7837         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7838         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7839         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
7840         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7841
7842         { }
7843 };
7844
7845 /* capture mixer elements */
7846 static struct snd_kcontrol_new alc883_capture_mixer[] = {
7847         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7848         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7849         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7850         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7851         {
7852                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7853                 /* The multiple "Capture Source" controls confuse alsamixer
7854                  * So call somewhat different..
7855                  */
7856                 /* .name = "Capture Source", */
7857                 .name = "Input Source",
7858                 .count = 2,
7859                 .info = alc882_mux_enum_info,
7860                 .get = alc882_mux_enum_get,
7861                 .put = alc882_mux_enum_put,
7862         },
7863         { } /* end */
7864 };
7865
7866 #ifdef CONFIG_SND_HDA_POWER_SAVE
7867 #define alc883_loopbacks        alc880_loopbacks
7868 #endif
7869
7870 /* pcm configuration: identiacal with ALC880 */
7871 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
7872 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
7873 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
7874 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
7875 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
7876
7877 /*
7878  * configuration and preset
7879  */
7880 static const char *alc883_models[ALC883_MODEL_LAST] = {
7881         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
7882         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
7883         [ALC883_3ST_6ch]        = "3stack-6ch",
7884         [ALC883_6ST_DIG]        = "6stack-dig",
7885         [ALC883_TARGA_DIG]      = "targa-dig",
7886         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
7887         [ALC883_ACER]           = "acer",
7888         [ALC883_ACER_ASPIRE]    = "acer-aspire",
7889         [ALC883_MEDION]         = "medion",
7890         [ALC883_MEDION_MD2]     = "medion-md2",
7891         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
7892         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
7893         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
7894         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
7895         [ALC883_HAIER_W66]      = "haier-w66",
7896         [ALC888_3ST_HP]         = "3stack-hp",
7897         [ALC888_6ST_DELL]       = "6stack-dell",
7898         [ALC883_MITAC]          = "mitac",
7899         [ALC883_CLEVO_M720]     = "clevo-m720",
7900         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
7901         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
7902         [ALC883_AUTO]           = "auto",
7903 };
7904
7905 static struct snd_pci_quirk alc883_cfg_tbl[] = {
7906         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
7907         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
7908         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
7909         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
7910         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
7911         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
7912         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
7913         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
7914         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
7915         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
7916         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
7917         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
7918         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
7919         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
7920         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
7921         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
7922         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
7923         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
7924         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
7925         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
7926         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
7927         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
7928         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
7929         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
7930         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
7931         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
7932         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
7933         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
7934         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
7935         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
7936         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
7937         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
7938         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
7939         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
7940         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
7941         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
7942         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
7943         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
7944         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
7945         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
7946         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
7947         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
7948         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
7949         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
7950         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
7951         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
7952         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
7953         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7954         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7955         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7956         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
7957         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
7958         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
7959         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
7960         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
7961         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
7962         {}
7963 };
7964
7965 static struct alc_config_preset alc883_presets[] = {
7966         [ALC883_3ST_2ch_DIG] = {
7967                 .mixers = { alc883_3ST_2ch_mixer },
7968                 .init_verbs = { alc883_init_verbs },
7969                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7970                 .dac_nids = alc883_dac_nids,
7971                 .dig_out_nid = ALC883_DIGOUT_NID,
7972                 .dig_in_nid = ALC883_DIGIN_NID,
7973                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7974                 .channel_mode = alc883_3ST_2ch_modes,
7975                 .input_mux = &alc883_capture_source,
7976         },
7977         [ALC883_3ST_6ch_DIG] = {
7978                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7979                 .init_verbs = { alc883_init_verbs },
7980                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7981                 .dac_nids = alc883_dac_nids,
7982                 .dig_out_nid = ALC883_DIGOUT_NID,
7983                 .dig_in_nid = ALC883_DIGIN_NID,
7984                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7985                 .channel_mode = alc883_3ST_6ch_modes,
7986                 .need_dac_fix = 1,
7987                 .input_mux = &alc883_capture_source,
7988         },
7989         [ALC883_3ST_6ch] = {
7990                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7991                 .init_verbs = { alc883_init_verbs },
7992                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7993                 .dac_nids = alc883_dac_nids,
7994                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7995                 .channel_mode = alc883_3ST_6ch_modes,
7996                 .need_dac_fix = 1,
7997                 .input_mux = &alc883_capture_source,
7998         },
7999         [ALC883_3ST_6ch_INTEL] = {
8000                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
8001                 .init_verbs = { alc883_init_verbs },
8002                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8003                 .dac_nids = alc883_dac_nids,
8004                 .dig_out_nid = ALC883_DIGOUT_NID,
8005                 .dig_in_nid = ALC883_DIGIN_NID,
8006                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
8007                 .channel_mode = alc883_3ST_6ch_intel_modes,
8008                 .need_dac_fix = 1,
8009                 .input_mux = &alc883_3stack_6ch_intel,
8010         },
8011         [ALC883_6ST_DIG] = {
8012                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8013                 .init_verbs = { alc883_init_verbs },
8014                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8015                 .dac_nids = alc883_dac_nids,
8016                 .dig_out_nid = ALC883_DIGOUT_NID,
8017                 .dig_in_nid = ALC883_DIGIN_NID,
8018                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8019                 .channel_mode = alc883_sixstack_modes,
8020                 .input_mux = &alc883_capture_source,
8021         },
8022         [ALC883_TARGA_DIG] = {
8023                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
8024                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8025                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8026                 .dac_nids = alc883_dac_nids,
8027                 .dig_out_nid = ALC883_DIGOUT_NID,
8028                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8029                 .channel_mode = alc883_3ST_6ch_modes,
8030                 .need_dac_fix = 1,
8031                 .input_mux = &alc883_capture_source,
8032                 .unsol_event = alc883_tagra_unsol_event,
8033                 .init_hook = alc883_tagra_automute,
8034         },
8035         [ALC883_TARGA_2ch_DIG] = {
8036                 .mixers = { alc883_tagra_2ch_mixer},
8037                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8038                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8039                 .dac_nids = alc883_dac_nids,
8040                 .dig_out_nid = ALC883_DIGOUT_NID,
8041                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8042                 .channel_mode = alc883_3ST_2ch_modes,
8043                 .input_mux = &alc883_capture_source,
8044                 .unsol_event = alc883_tagra_unsol_event,
8045                 .init_hook = alc883_tagra_automute,
8046         },
8047         [ALC883_ACER] = {
8048                 .mixers = { alc883_base_mixer },
8049                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
8050                  * and the headphone jack.  Turn this on and rely on the
8051                  * standard mute methods whenever the user wants to turn
8052                  * these outputs off.
8053                  */
8054                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
8055                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8056                 .dac_nids = alc883_dac_nids,
8057                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8058                 .channel_mode = alc883_3ST_2ch_modes,
8059                 .input_mux = &alc883_capture_source,
8060         },
8061         [ALC883_ACER_ASPIRE] = {
8062                 .mixers = { alc883_acer_aspire_mixer },
8063                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
8064                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8065                 .dac_nids = alc883_dac_nids,
8066                 .dig_out_nid = ALC883_DIGOUT_NID,
8067                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8068                 .channel_mode = alc883_3ST_2ch_modes,
8069                 .input_mux = &alc883_capture_source,
8070                 .unsol_event = alc883_acer_aspire_unsol_event,
8071                 .init_hook = alc883_acer_aspire_automute,
8072         },
8073         [ALC883_MEDION] = {
8074                 .mixers = { alc883_fivestack_mixer,
8075                             alc883_chmode_mixer },
8076                 .init_verbs = { alc883_init_verbs,
8077                                 alc883_medion_eapd_verbs },
8078                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8079                 .dac_nids = alc883_dac_nids,
8080                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8081                 .channel_mode = alc883_sixstack_modes,
8082                 .input_mux = &alc883_capture_source,
8083         },
8084         [ALC883_MEDION_MD2] = {
8085                 .mixers = { alc883_medion_md2_mixer},
8086                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
8087                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8088                 .dac_nids = alc883_dac_nids,
8089                 .dig_out_nid = ALC883_DIGOUT_NID,
8090                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8091                 .channel_mode = alc883_3ST_2ch_modes,
8092                 .input_mux = &alc883_capture_source,
8093                 .unsol_event = alc883_medion_md2_unsol_event,
8094                 .init_hook = alc883_medion_md2_automute,
8095         },      
8096         [ALC883_LAPTOP_EAPD] = {
8097                 .mixers = { alc883_base_mixer },
8098                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
8099                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8100                 .dac_nids = alc883_dac_nids,
8101                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8102                 .channel_mode = alc883_3ST_2ch_modes,
8103                 .input_mux = &alc883_capture_source,
8104         },
8105         [ALC883_CLEVO_M720] = {
8106                 .mixers = { alc883_clevo_m720_mixer },
8107                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
8108                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8109                 .dac_nids = alc883_dac_nids,
8110                 .dig_out_nid = ALC883_DIGOUT_NID,
8111                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8112                 .channel_mode = alc883_3ST_2ch_modes,
8113                 .input_mux = &alc883_capture_source,
8114                 .unsol_event = alc883_clevo_m720_unsol_event,
8115                 .init_hook = alc883_clevo_m720_automute,
8116         },
8117         [ALC883_LENOVO_101E_2ch] = {
8118                 .mixers = { alc883_lenovo_101e_2ch_mixer},
8119                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
8120                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8121                 .dac_nids = alc883_dac_nids,
8122                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8123                 .channel_mode = alc883_3ST_2ch_modes,
8124                 .input_mux = &alc883_lenovo_101e_capture_source,
8125                 .unsol_event = alc883_lenovo_101e_unsol_event,
8126                 .init_hook = alc883_lenovo_101e_all_automute,
8127         },
8128         [ALC883_LENOVO_NB0763] = {
8129                 .mixers = { alc883_lenovo_nb0763_mixer },
8130                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
8131                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8132                 .dac_nids = alc883_dac_nids,
8133                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8134                 .channel_mode = alc883_3ST_2ch_modes,
8135                 .need_dac_fix = 1,
8136                 .input_mux = &alc883_lenovo_nb0763_capture_source,
8137                 .unsol_event = alc883_medion_md2_unsol_event,
8138                 .init_hook = alc883_medion_md2_automute,
8139         },
8140         [ALC888_LENOVO_MS7195_DIG] = {
8141                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8142                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
8143                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8144                 .dac_nids = alc883_dac_nids,
8145                 .dig_out_nid = ALC883_DIGOUT_NID,
8146                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8147                 .channel_mode = alc883_3ST_6ch_modes,
8148                 .need_dac_fix = 1,
8149                 .input_mux = &alc883_capture_source,
8150                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
8151                 .init_hook = alc888_lenovo_ms7195_front_automute,
8152         },
8153         [ALC883_HAIER_W66] = {
8154                 .mixers = { alc883_tagra_2ch_mixer},
8155                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
8156                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8157                 .dac_nids = alc883_dac_nids,
8158                 .dig_out_nid = ALC883_DIGOUT_NID,
8159                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8160                 .channel_mode = alc883_3ST_2ch_modes,
8161                 .input_mux = &alc883_capture_source,
8162                 .unsol_event = alc883_haier_w66_unsol_event,
8163                 .init_hook = alc883_haier_w66_automute,
8164         },
8165         [ALC888_3ST_HP] = {
8166                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8167                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
8168                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8169                 .dac_nids = alc883_dac_nids,
8170                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
8171                 .channel_mode = alc888_3st_hp_modes,
8172                 .need_dac_fix = 1,
8173                 .input_mux = &alc883_capture_source,
8174         },
8175         [ALC888_6ST_DELL] = {
8176                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8177                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
8178                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8179                 .dac_nids = alc883_dac_nids,
8180                 .dig_out_nid = ALC883_DIGOUT_NID,
8181                 .dig_in_nid = ALC883_DIGIN_NID,
8182                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8183                 .channel_mode = alc883_sixstack_modes,
8184                 .input_mux = &alc883_capture_source,
8185                 .unsol_event = alc888_6st_dell_unsol_event,
8186                 .init_hook = alc888_6st_dell_front_automute,
8187         },
8188         [ALC883_MITAC] = {
8189                 .mixers = { alc883_mitac_mixer },
8190                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
8191                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8192                 .dac_nids = alc883_dac_nids,
8193                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8194                 .channel_mode = alc883_3ST_2ch_modes,
8195                 .input_mux = &alc883_capture_source,
8196                 .unsol_event = alc883_mitac_unsol_event,
8197                 .init_hook = alc883_mitac_automute,
8198         },
8199         [ALC883_FUJITSU_PI2515] = {
8200                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
8201                 .init_verbs = { alc883_init_verbs,
8202                                 alc883_2ch_fujitsu_pi2515_verbs},
8203                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8204                 .dac_nids = alc883_dac_nids,
8205                 .dig_out_nid = ALC883_DIGOUT_NID,
8206                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8207                 .channel_mode = alc883_3ST_2ch_modes,
8208                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8209                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8210                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8211         },
8212 };
8213
8214
8215 /*
8216  * BIOS auto configuration
8217  */
8218 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
8219                                               hda_nid_t nid, int pin_type,
8220                                               int dac_idx)
8221 {
8222         /* set as output */
8223         struct alc_spec *spec = codec->spec;
8224         int idx;
8225
8226         alc_set_pin_output(codec, nid, pin_type);
8227         if (spec->multiout.dac_nids[dac_idx] == 0x25)
8228                 idx = 4;
8229         else
8230                 idx = spec->multiout.dac_nids[dac_idx] - 2;
8231         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
8232
8233 }
8234
8235 static void alc883_auto_init_multi_out(struct hda_codec *codec)
8236 {
8237         struct alc_spec *spec = codec->spec;
8238         int i;
8239
8240         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
8241         for (i = 0; i <= HDA_SIDE; i++) {
8242                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
8243                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
8244                 if (nid)
8245                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
8246                                                           i);
8247         }
8248 }
8249
8250 static void alc883_auto_init_hp_out(struct hda_codec *codec)
8251 {
8252         struct alc_spec *spec = codec->spec;
8253         hda_nid_t pin;
8254
8255         pin = spec->autocfg.hp_pins[0];
8256         if (pin) /* connect to front */
8257                 /* use dac 0 */
8258                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8259         pin = spec->autocfg.speaker_pins[0];
8260         if (pin)
8261                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
8262 }
8263
8264 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
8265 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
8266
8267 static void alc883_auto_init_analog_input(struct hda_codec *codec)
8268 {
8269         struct alc_spec *spec = codec->spec;
8270         int i;
8271
8272         for (i = 0; i < AUTO_PIN_LAST; i++) {
8273                 hda_nid_t nid = spec->autocfg.input_pins[i];
8274                 if (alc883_is_input_pin(nid)) {
8275                         snd_hda_codec_write(codec, nid, 0,
8276                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
8277                                             (i <= AUTO_PIN_FRONT_MIC ?
8278                                              PIN_VREF80 : PIN_IN));
8279                         if (nid != ALC883_PIN_CD_NID)
8280                                 snd_hda_codec_write(codec, nid, 0,
8281                                                     AC_VERB_SET_AMP_GAIN_MUTE,
8282                                                     AMP_OUT_MUTE);
8283                 }
8284         }
8285 }
8286
8287 /* almost identical with ALC880 parser... */
8288 static int alc883_parse_auto_config(struct hda_codec *codec)
8289 {
8290         struct alc_spec *spec = codec->spec;
8291         int err = alc880_parse_auto_config(codec);
8292
8293         if (err < 0)
8294                 return err;
8295         else if (!err)
8296                 return 0; /* no config found */
8297
8298         err = alc_auto_add_mic_boost(codec);
8299         if (err < 0)
8300                 return err;
8301
8302         /* hack - override the init verbs */
8303         spec->init_verbs[0] = alc883_auto_init_verbs;
8304         spec->mixers[spec->num_mixers] = alc883_capture_mixer;
8305         spec->num_mixers++;
8306
8307         return 1; /* config found */
8308 }
8309
8310 /* additional initialization for auto-configuration model */
8311 static void alc883_auto_init(struct hda_codec *codec)
8312 {
8313         struct alc_spec *spec = codec->spec;
8314         alc883_auto_init_multi_out(codec);
8315         alc883_auto_init_hp_out(codec);
8316         alc883_auto_init_analog_input(codec);
8317         if (spec->unsol_event)
8318                 alc_sku_automute(codec);
8319 }
8320
8321 static int patch_alc883(struct hda_codec *codec)
8322 {
8323         struct alc_spec *spec;
8324         int err, board_config;
8325
8326         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8327         if (spec == NULL)
8328                 return -ENOMEM;
8329
8330         codec->spec = spec;
8331
8332         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
8333
8334         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
8335                                                   alc883_models,
8336                                                   alc883_cfg_tbl);
8337         if (board_config < 0) {
8338                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
8339                        "trying auto-probe from BIOS...\n");
8340                 board_config = ALC883_AUTO;
8341         }
8342
8343         if (board_config == ALC883_AUTO) {
8344                 /* automatic parse from the BIOS config */
8345                 err = alc883_parse_auto_config(codec);
8346                 if (err < 0) {
8347                         alc_free(codec);
8348                         return err;
8349                 } else if (!err) {
8350                         printk(KERN_INFO
8351                                "hda_codec: Cannot set up configuration "
8352                                "from BIOS.  Using base mode...\n");
8353                         board_config = ALC883_3ST_2ch_DIG;
8354                 }
8355         }
8356
8357         if (board_config != ALC883_AUTO)
8358                 setup_preset(spec, &alc883_presets[board_config]);
8359
8360         switch (codec->vendor_id) {
8361         case 0x10ec0888:
8362                 spec->stream_name_analog = "ALC888 Analog";
8363                 spec->stream_name_digital = "ALC888 Digital";
8364                 break;
8365         case 0x10ec0889:
8366                 spec->stream_name_analog = "ALC889 Analog";
8367                 spec->stream_name_digital = "ALC889 Digital";
8368                 break;
8369         default:
8370                 spec->stream_name_analog = "ALC883 Analog";
8371                 spec->stream_name_digital = "ALC883 Digital";
8372                 break;
8373         }
8374
8375         spec->stream_analog_playback = &alc883_pcm_analog_playback;
8376         spec->stream_analog_capture = &alc883_pcm_analog_capture;
8377         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
8378
8379         spec->stream_digital_playback = &alc883_pcm_digital_playback;
8380         spec->stream_digital_capture = &alc883_pcm_digital_capture;
8381
8382         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
8383         spec->adc_nids = alc883_adc_nids;
8384         spec->capsrc_nids = alc883_capsrc_nids;
8385
8386         spec->vmaster_nid = 0x0c;
8387
8388         codec->patch_ops = alc_patch_ops;
8389         if (board_config == ALC883_AUTO)
8390                 spec->init_hook = alc883_auto_init;
8391         else if (codec->vendor_id == 0x10ec0888)
8392                 spec->init_hook = alc888_coef_init;
8393
8394 #ifdef CONFIG_SND_HDA_POWER_SAVE
8395         if (!spec->loopback.amplist)
8396                 spec->loopback.amplist = alc883_loopbacks;
8397 #endif
8398
8399         return 0;
8400 }
8401
8402 /*
8403  * ALC262 support
8404  */
8405
8406 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
8407 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
8408
8409 #define alc262_dac_nids         alc260_dac_nids
8410 #define alc262_adc_nids         alc882_adc_nids
8411 #define alc262_adc_nids_alt     alc882_adc_nids_alt
8412 #define alc262_capsrc_nids      alc882_capsrc_nids
8413 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
8414
8415 #define alc262_modes            alc260_modes
8416 #define alc262_capture_source   alc882_capture_source
8417
8418 static struct snd_kcontrol_new alc262_base_mixer[] = {
8419         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8420         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8421         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8422         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8423         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8424         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8425         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8426         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8427         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8428         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8429         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8430         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8431         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8432            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8433         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
8434         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8435         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8436         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
8437         { } /* end */
8438 };
8439
8440 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
8441         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8442         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8443         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8444         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8445         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8446         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8447         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8448         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8449         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8450         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8451         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8452         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8453         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8454            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8455         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
8456         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8457         { } /* end */
8458 };
8459
8460 /* update HP, line and mono-out pins according to the master switch */
8461 static void alc262_hp_master_update(struct hda_codec *codec)
8462 {
8463         struct alc_spec *spec = codec->spec;
8464         int val = spec->master_sw;
8465
8466         /* HP & line-out */
8467         snd_hda_codec_write_cache(codec, 0x1b, 0,
8468                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8469                                   val ? PIN_HP : 0);
8470         snd_hda_codec_write_cache(codec, 0x15, 0,
8471                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8472                                   val ? PIN_HP : 0);
8473         /* mono (speaker) depending on the HP jack sense */
8474         val = val && !spec->jack_present;
8475         snd_hda_codec_write_cache(codec, 0x16, 0,
8476                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8477                                   val ? PIN_OUT : 0);
8478 }
8479
8480 static void alc262_hp_bpc_automute(struct hda_codec *codec)
8481 {
8482         struct alc_spec *spec = codec->spec;
8483         unsigned int presence;
8484         presence = snd_hda_codec_read(codec, 0x1b, 0,
8485                                       AC_VERB_GET_PIN_SENSE, 0);
8486         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8487         alc262_hp_master_update(codec);
8488 }
8489
8490 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
8491 {
8492         if ((res >> 26) != ALC880_HP_EVENT)
8493                 return;
8494         alc262_hp_bpc_automute(codec);
8495 }
8496
8497 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
8498 {
8499         struct alc_spec *spec = codec->spec;
8500         unsigned int presence;
8501         presence = snd_hda_codec_read(codec, 0x15, 0,
8502                                       AC_VERB_GET_PIN_SENSE, 0);
8503         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8504         alc262_hp_master_update(codec);
8505 }
8506
8507 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
8508                                            unsigned int res)
8509 {
8510         if ((res >> 26) != ALC880_HP_EVENT)
8511                 return;
8512         alc262_hp_wildwest_automute(codec);
8513 }
8514
8515 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
8516                                    struct snd_ctl_elem_value *ucontrol)
8517 {
8518         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8519         struct alc_spec *spec = codec->spec;
8520         *ucontrol->value.integer.value = spec->master_sw;
8521         return 0;
8522 }
8523
8524 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
8525                                    struct snd_ctl_elem_value *ucontrol)
8526 {
8527         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8528         struct alc_spec *spec = codec->spec;
8529         int val = !!*ucontrol->value.integer.value;
8530
8531         if (val == spec->master_sw)
8532                 return 0;
8533         spec->master_sw = val;
8534         alc262_hp_master_update(codec);
8535         return 1;
8536 }
8537
8538 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
8539         {
8540                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8541                 .name = "Master Playback Switch",
8542                 .info = snd_ctl_boolean_mono_info,
8543                 .get = alc262_hp_master_sw_get,
8544                 .put = alc262_hp_master_sw_put,
8545         },
8546         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8547         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8548         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8549         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
8550                               HDA_OUTPUT),
8551         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
8552                             HDA_OUTPUT),
8553         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8554         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8555         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8556         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8557         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8558         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8559         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8560         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8561         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8562         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8563         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8564         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
8565         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
8566         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
8567         { } /* end */
8568 };
8569
8570 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
8571         {
8572                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8573                 .name = "Master Playback Switch",
8574                 .info = snd_ctl_boolean_mono_info,
8575                 .get = alc262_hp_master_sw_get,
8576                 .put = alc262_hp_master_sw_put,
8577         },
8578         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8579         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8580         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8581         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8582         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
8583                               HDA_OUTPUT),
8584         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
8585                             HDA_OUTPUT),
8586         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
8587         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
8588         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
8589         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8590         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8591         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8592         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8593         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8594         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
8595         { } /* end */
8596 };
8597
8598 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
8599         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8600         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8601         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
8602         { } /* end */
8603 };
8604
8605 /* mute/unmute internal speaker according to the hp jack and mute state */
8606 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
8607 {
8608         struct alc_spec *spec = codec->spec;
8609
8610         if (force || !spec->sense_updated) {
8611                 unsigned int present;
8612                 present = snd_hda_codec_read(codec, 0x15, 0,
8613                                              AC_VERB_GET_PIN_SENSE, 0);
8614                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
8615                 spec->sense_updated = 1;
8616         }
8617         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
8618                                  spec->jack_present ? HDA_AMP_MUTE : 0);
8619 }
8620
8621 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
8622                                         unsigned int res)
8623 {
8624         if ((res >> 26) != ALC880_HP_EVENT)
8625                 return;
8626         alc262_hp_t5735_automute(codec, 1);
8627 }
8628
8629 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
8630 {
8631         alc262_hp_t5735_automute(codec, 1);
8632 }
8633
8634 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
8635         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8636         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8637         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8638         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8639         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8640         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8641         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8642         { } /* end */
8643 };
8644
8645 static struct hda_verb alc262_hp_t5735_verbs[] = {
8646         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8647         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8648
8649         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8650         { }
8651 };
8652
8653 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
8654         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8655         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8656         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
8657         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
8658         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8659         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8660         { } /* end */
8661 };
8662
8663 static struct hda_verb alc262_hp_rp5700_verbs[] = {
8664         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8665         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8666         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8667         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8668         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8669         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8670         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8671         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8672         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
8673         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
8674         {}
8675 };
8676
8677 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
8678         .num_items = 1,
8679         .items = {
8680                 { "Line", 0x1 },
8681         },
8682 };
8683
8684 /* bind hp and internal speaker mute (with plug check) */
8685 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
8686                                      struct snd_ctl_elem_value *ucontrol)
8687 {
8688         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8689         long *valp = ucontrol->value.integer.value;
8690         int change;
8691
8692         /* change hp mute */
8693         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
8694                                           HDA_AMP_MUTE,
8695                                           valp[0] ? 0 : HDA_AMP_MUTE);
8696         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
8697                                            HDA_AMP_MUTE,
8698                                            valp[1] ? 0 : HDA_AMP_MUTE);
8699         if (change) {
8700                 /* change speaker according to HP jack state */
8701                 struct alc_spec *spec = codec->spec;
8702                 unsigned int mute;
8703                 if (spec->jack_present)
8704                         mute = HDA_AMP_MUTE;
8705                 else
8706                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
8707                                                       HDA_OUTPUT, 0);
8708                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8709                                          HDA_AMP_MUTE, mute);
8710         }
8711         return change;
8712 }
8713
8714 static struct snd_kcontrol_new alc262_sony_mixer[] = {
8715         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8716         {
8717                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8718                 .name = "Master Playback Switch",
8719                 .info = snd_hda_mixer_amp_switch_info,
8720                 .get = snd_hda_mixer_amp_switch_get,
8721                 .put = alc262_sony_master_sw_put,
8722                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
8723         },
8724         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8725         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8726         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8727         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8728         { } /* end */
8729 };
8730
8731 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
8732         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8733         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8734         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8735         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8736         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8737         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8738         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8739         { } /* end */
8740 };
8741
8742 #define alc262_capture_mixer            alc882_capture_mixer
8743 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
8744
8745 /*
8746  * generic initialization of ADC, input mixers and output mixers
8747  */
8748 static struct hda_verb alc262_init_verbs[] = {
8749         /*
8750          * Unmute ADC0-2 and set the default input to mic-in
8751          */
8752         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8753         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8754         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8755         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8756         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8757         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8758
8759         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8760          * mixer widget
8761          * Note: PASD motherboards uses the Line In 2 as the input for
8762          * front panel mic (mic 2)
8763          */
8764         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8765         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8766         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8767         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8768         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8769         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8770
8771         /*
8772          * Set up output mixers (0x0c - 0x0e)
8773          */
8774         /* set vol=0 to output mixers */
8775         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8776         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8777         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8778         /* set up input amps for analog loopback */
8779         /* Amp Indices: DAC = 0, mixer = 1 */
8780         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8781         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8782         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8783         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8784         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8785         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8786
8787         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8788         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8789         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8790         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8791         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8792         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8793
8794         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8795         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8796         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8797         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8798         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8799         
8800         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8801         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8802         
8803         /* FIXME: use matrix-type input source selection */
8804         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8805         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8806         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8807         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8808         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8809         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8810         /* Input mixer2 */
8811         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8812         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8813         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8814         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8815         /* Input mixer3 */
8816         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8817         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8818         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8819         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8820
8821         { }
8822 };
8823
8824 static struct hda_verb alc262_hippo_unsol_verbs[] = {
8825         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8826         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8827         {}
8828 };
8829
8830 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
8831         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8832         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8833         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8834
8835         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8836         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8837         {}
8838 };
8839
8840 static struct hda_verb alc262_sony_unsol_verbs[] = {
8841         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8842         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8843         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
8844
8845         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8846         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8847         {}
8848 };
8849
8850 /* mute/unmute internal speaker according to the hp jack and mute state */
8851 static void alc262_hippo_automute(struct hda_codec *codec)
8852 {
8853         struct alc_spec *spec = codec->spec;
8854         unsigned int mute;
8855         unsigned int present;
8856
8857         /* need to execute and sync at first */
8858         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
8859         present = snd_hda_codec_read(codec, 0x15, 0,
8860                                      AC_VERB_GET_PIN_SENSE, 0);
8861         spec->jack_present = (present & 0x80000000) != 0;
8862         if (spec->jack_present) {
8863                 /* mute internal speaker */
8864                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8865                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8866         } else {
8867                 /* unmute internal speaker if necessary */
8868                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
8869                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8870                                          HDA_AMP_MUTE, mute);
8871         }
8872 }
8873
8874 /* unsolicited event for HP jack sensing */
8875 static void alc262_hippo_unsol_event(struct hda_codec *codec,
8876                                        unsigned int res)
8877 {
8878         if ((res >> 26) != ALC880_HP_EVENT)
8879                 return;
8880         alc262_hippo_automute(codec);
8881 }
8882
8883 static void alc262_hippo1_automute(struct hda_codec *codec)
8884 {
8885         unsigned int mute;
8886         unsigned int present;
8887
8888         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8889         present = snd_hda_codec_read(codec, 0x1b, 0,
8890                                      AC_VERB_GET_PIN_SENSE, 0);
8891         present = (present & 0x80000000) != 0;
8892         if (present) {
8893                 /* mute internal speaker */
8894                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8895                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8896         } else {
8897                 /* unmute internal speaker if necessary */
8898                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8899                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8900                                          HDA_AMP_MUTE, mute);
8901         }
8902 }
8903
8904 /* unsolicited event for HP jack sensing */
8905 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
8906                                        unsigned int res)
8907 {
8908         if ((res >> 26) != ALC880_HP_EVENT)
8909                 return;
8910         alc262_hippo1_automute(codec);
8911 }
8912
8913 /*
8914  * fujitsu model
8915  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
8916  *  0x1b = port replicator headphone out
8917  */
8918
8919 #define ALC_HP_EVENT    0x37
8920
8921 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
8922         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8923         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8924         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8925         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8926         {}
8927 };
8928
8929 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
8930         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8931         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8932         {}
8933 };
8934
8935 static struct hda_input_mux alc262_fujitsu_capture_source = {
8936         .num_items = 3,
8937         .items = {
8938                 { "Mic", 0x0 },
8939                 { "Int Mic", 0x1 },
8940                 { "CD", 0x4 },
8941         },
8942 };
8943
8944 static struct hda_input_mux alc262_HP_capture_source = {
8945         .num_items = 5,
8946         .items = {
8947                 { "Mic", 0x0 },
8948                 { "Front Mic", 0x1 },
8949                 { "Line", 0x2 },
8950                 { "CD", 0x4 },
8951                 { "AUX IN", 0x6 },
8952         },
8953 };
8954
8955 static struct hda_input_mux alc262_HP_D7000_capture_source = {
8956         .num_items = 4,
8957         .items = {
8958                 { "Mic", 0x0 },
8959                 { "Front Mic", 0x2 },
8960                 { "Line", 0x1 },
8961                 { "CD", 0x4 },
8962         },
8963 };
8964
8965 /* mute/unmute internal speaker according to the hp jacks and mute state */
8966 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
8967 {
8968         struct alc_spec *spec = codec->spec;
8969         unsigned int mute;
8970
8971         if (force || !spec->sense_updated) {
8972                 unsigned int present;
8973                 /* need to execute and sync at first */
8974                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
8975                 /* check laptop HP jack */
8976                 present = snd_hda_codec_read(codec, 0x14, 0,
8977                                              AC_VERB_GET_PIN_SENSE, 0);
8978                 /* need to execute and sync at first */
8979                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8980                 /* check docking HP jack */
8981                 present |= snd_hda_codec_read(codec, 0x1b, 0,
8982                                               AC_VERB_GET_PIN_SENSE, 0);
8983                 if (present & AC_PINSENSE_PRESENCE)
8984                         spec->jack_present = 1;
8985                 else
8986                         spec->jack_present = 0;
8987                 spec->sense_updated = 1;
8988         }
8989         /* unmute internal speaker only if both HPs are unplugged and
8990          * master switch is on
8991          */
8992         if (spec->jack_present)
8993                 mute = HDA_AMP_MUTE;
8994         else
8995                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
8996         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8997                                  HDA_AMP_MUTE, mute);
8998 }
8999
9000 /* unsolicited event for HP jack sensing */
9001 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
9002                                        unsigned int res)
9003 {
9004         if ((res >> 26) != ALC_HP_EVENT)
9005                 return;
9006         alc262_fujitsu_automute(codec, 1);
9007 }
9008
9009 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
9010 {
9011         alc262_fujitsu_automute(codec, 1);
9012 }
9013
9014 /* bind volumes of both NID 0x0c and 0x0d */
9015 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
9016         .ops = &snd_hda_bind_vol,
9017         .values = {
9018                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
9019                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
9020                 0
9021         },
9022 };
9023
9024 /* mute/unmute internal speaker according to the hp jack and mute state */
9025 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
9026 {
9027         struct alc_spec *spec = codec->spec;
9028         unsigned int mute;
9029
9030         if (force || !spec->sense_updated) {
9031                 unsigned int present_int_hp;
9032                 /* need to execute and sync at first */
9033                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9034                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
9035                                         AC_VERB_GET_PIN_SENSE, 0);
9036                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
9037                 spec->sense_updated = 1;
9038         }
9039         if (spec->jack_present) {
9040                 /* mute internal speaker */
9041                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9042                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9043                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9044                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9045         } else {
9046                 /* unmute internal speaker if necessary */
9047                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9048                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9049                                          HDA_AMP_MUTE, mute);
9050                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9051                                          HDA_AMP_MUTE, mute);
9052         }
9053 }
9054
9055 /* unsolicited event for HP jack sensing */
9056 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
9057                                        unsigned int res)
9058 {
9059         if ((res >> 26) != ALC_HP_EVENT)
9060                 return;
9061         alc262_lenovo_3000_automute(codec, 1);
9062 }
9063
9064 /* bind hp and internal speaker mute (with plug check) */
9065 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
9066                                          struct snd_ctl_elem_value *ucontrol)
9067 {
9068         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9069         long *valp = ucontrol->value.integer.value;
9070         int change;
9071
9072         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9073                                                  HDA_AMP_MUTE,
9074                                                  valp ? 0 : HDA_AMP_MUTE);
9075         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9076                                                  HDA_AMP_MUTE,
9077                                                  valp ? 0 : HDA_AMP_MUTE);
9078
9079         if (change)
9080                 alc262_fujitsu_automute(codec, 0);
9081         return change;
9082 }
9083
9084 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
9085         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9086         {
9087                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9088                 .name = "Master Playback Switch",
9089                 .info = snd_hda_mixer_amp_switch_info,
9090                 .get = snd_hda_mixer_amp_switch_get,
9091                 .put = alc262_fujitsu_master_sw_put,
9092                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9093         },
9094         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9095         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9096         HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
9097         HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
9098         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9099         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9100         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9101         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9102         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9103         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9104         { } /* end */
9105 };
9106
9107 /* bind hp and internal speaker mute (with plug check) */
9108 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
9109                                          struct snd_ctl_elem_value *ucontrol)
9110 {
9111         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9112         long *valp = ucontrol->value.integer.value;
9113         int change;
9114
9115         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9116                                                  HDA_AMP_MUTE,
9117                                                  valp ? 0 : HDA_AMP_MUTE);
9118
9119         if (change)
9120                 alc262_lenovo_3000_automute(codec, 0);
9121         return change;
9122 }
9123
9124 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
9125         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9126         {
9127                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9128                 .name = "Master Playback Switch",
9129                 .info = snd_hda_mixer_amp_switch_info,
9130                 .get = snd_hda_mixer_amp_switch_get,
9131                 .put = alc262_lenovo_3000_master_sw_put,
9132                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
9133         },
9134         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9135         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9136         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9137         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9138         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9139         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9140         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9141         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9142         { } /* end */
9143 };
9144
9145 /* additional init verbs for Benq laptops */
9146 static struct hda_verb alc262_EAPD_verbs[] = {
9147         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9148         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
9149         {}
9150 };
9151
9152 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
9153         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9154         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9155
9156         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9157         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
9158         {}
9159 };
9160
9161 /* Samsung Q1 Ultra Vista model setup */
9162 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
9163         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9164         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
9165         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9166         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9167         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
9168         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
9169         { } /* end */
9170 };
9171
9172 static struct hda_verb alc262_ultra_verbs[] = {
9173         /* output mixer */
9174         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9175         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9176         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9177         /* speaker */
9178         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9179         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9180         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9181         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9182         /* HP */
9183         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9184         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9185         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9186         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9187         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9188         /* internal mic */
9189         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9190         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9191         /* ADC, choose mic */
9192         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9193         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9194         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9195         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9196         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9197         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9198         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9199         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9200         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
9201         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
9202         {}
9203 };
9204
9205 /* mute/unmute internal speaker according to the hp jack and mute state */
9206 static void alc262_ultra_automute(struct hda_codec *codec)
9207 {
9208         struct alc_spec *spec = codec->spec;
9209         unsigned int mute;
9210
9211         mute = 0;
9212         /* auto-mute only when HP is used as HP */
9213         if (!spec->cur_mux[0]) {
9214                 unsigned int present;
9215                 /* need to execute and sync at first */
9216                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9217                 present = snd_hda_codec_read(codec, 0x15, 0,
9218                                              AC_VERB_GET_PIN_SENSE, 0);
9219                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9220                 if (spec->jack_present)
9221                         mute = HDA_AMP_MUTE;
9222         }
9223         /* mute/unmute internal speaker */
9224         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9225                                  HDA_AMP_MUTE, mute);
9226         /* mute/unmute HP */
9227         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9228                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
9229 }
9230
9231 /* unsolicited event for HP jack sensing */
9232 static void alc262_ultra_unsol_event(struct hda_codec *codec,
9233                                        unsigned int res)
9234 {
9235         if ((res >> 26) != ALC880_HP_EVENT)
9236                 return;
9237         alc262_ultra_automute(codec);
9238 }
9239
9240 static struct hda_input_mux alc262_ultra_capture_source = {
9241         .num_items = 2,
9242         .items = {
9243                 { "Mic", 0x1 },
9244                 { "Headphone", 0x7 },
9245         },
9246 };
9247
9248 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
9249                                      struct snd_ctl_elem_value *ucontrol)
9250 {
9251         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9252         struct alc_spec *spec = codec->spec;
9253         int ret;
9254
9255         ret = alc882_mux_enum_put(kcontrol, ucontrol);
9256         if (!ret)
9257                 return 0;
9258         /* reprogram the HP pin as mic or HP according to the input source */
9259         snd_hda_codec_write_cache(codec, 0x15, 0,
9260                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9261                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
9262         alc262_ultra_automute(codec); /* mute/unmute HP */
9263         return ret;
9264 }
9265
9266 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
9267         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
9268         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
9269         {
9270                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9271                 .name = "Capture Source",
9272                 .info = alc882_mux_enum_info,
9273                 .get = alc882_mux_enum_get,
9274                 .put = alc262_ultra_mux_enum_put,
9275         },
9276         { } /* end */
9277 };
9278
9279 /* add playback controls from the parsed DAC table */
9280 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
9281                                              const struct auto_pin_cfg *cfg)
9282 {
9283         hda_nid_t nid;
9284         int err;
9285
9286         spec->multiout.num_dacs = 1;    /* only use one dac */
9287         spec->multiout.dac_nids = spec->private_dac_nids;
9288         spec->multiout.dac_nids[0] = 2;
9289
9290         nid = cfg->line_out_pins[0];
9291         if (nid) {
9292                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9293                                   "Front Playback Volume",
9294                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
9295                 if (err < 0)
9296                         return err;
9297                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9298                                   "Front Playback Switch",
9299                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
9300                 if (err < 0)
9301                         return err;
9302         }
9303
9304         nid = cfg->speaker_pins[0];
9305         if (nid) {
9306                 if (nid == 0x16) {
9307                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9308                                           "Speaker Playback Volume",
9309                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9310                                                               HDA_OUTPUT));
9311                         if (err < 0)
9312                                 return err;
9313                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9314                                           "Speaker Playback Switch",
9315                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9316                                                               HDA_OUTPUT));
9317                         if (err < 0)
9318                                 return err;
9319                 } else {
9320                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9321                                           "Speaker Playback Switch",
9322                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9323                                                               HDA_OUTPUT));
9324                         if (err < 0)
9325                                 return err;
9326                 }
9327         }
9328         nid = cfg->hp_pins[0];
9329         if (nid) {
9330                 /* spec->multiout.hp_nid = 2; */
9331                 if (nid == 0x16) {
9332                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9333                                           "Headphone Playback Volume",
9334                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9335                                                               HDA_OUTPUT));
9336                         if (err < 0)
9337                                 return err;
9338                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9339                                           "Headphone Playback Switch",
9340                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9341                                                               HDA_OUTPUT));
9342                         if (err < 0)
9343                                 return err;
9344                 } else {
9345                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9346                                           "Headphone Playback Switch",
9347                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9348                                                               HDA_OUTPUT));
9349                         if (err < 0)
9350                                 return err;
9351                 }
9352         }
9353         return 0;
9354 }
9355
9356 /* identical with ALC880 */
9357 #define alc262_auto_create_analog_input_ctls \
9358         alc880_auto_create_analog_input_ctls
9359
9360 /*
9361  * generic initialization of ADC, input mixers and output mixers
9362  */
9363 static struct hda_verb alc262_volume_init_verbs[] = {
9364         /*
9365          * Unmute ADC0-2 and set the default input to mic-in
9366          */
9367         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9368         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9369         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9370         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9371         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9372         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9373
9374         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9375          * mixer widget
9376          * Note: PASD motherboards uses the Line In 2 as the input for
9377          * front panel mic (mic 2)
9378          */
9379         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9380         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9381         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9382         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9383         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9384         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9385
9386         /*
9387          * Set up output mixers (0x0c - 0x0f)
9388          */
9389         /* set vol=0 to output mixers */
9390         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9391         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9392         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9393         
9394         /* set up input amps for analog loopback */
9395         /* Amp Indices: DAC = 0, mixer = 1 */
9396         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9397         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9398         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9399         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9400         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9401         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9402
9403         /* FIXME: use matrix-type input source selection */
9404         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9405         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9406         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9407         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9408         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9409         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9410         /* Input mixer2 */
9411         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9412         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9413         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9414         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9415         /* Input mixer3 */
9416         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9417         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9418         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9419         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9420
9421         { }
9422 };
9423
9424 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
9425         /*
9426          * Unmute ADC0-2 and set the default input to mic-in
9427          */
9428         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9429         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9430         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9431         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9432         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9433         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9434
9435         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9436          * mixer widget
9437          * Note: PASD motherboards uses the Line In 2 as the input for
9438          * front panel mic (mic 2)
9439          */
9440         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9441         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9442         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9443         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9444         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9445         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9446         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9447         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9448         
9449         /*
9450          * Set up output mixers (0x0c - 0x0e)
9451          */
9452         /* set vol=0 to output mixers */
9453         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9454         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9455         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9456
9457         /* set up input amps for analog loopback */
9458         /* Amp Indices: DAC = 0, mixer = 1 */
9459         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9460         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9461         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9462         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9463         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9464         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9465
9466         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9467         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9468         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9469
9470         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9471         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9472
9473         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9474         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9475
9476         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9477         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9478         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9479         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9480         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9481
9482         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9483         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9484         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9485         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9486         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9487         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9488
9489
9490         /* FIXME: use matrix-type input source selection */
9491         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9492         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9493         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9494         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9495         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9496         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9497         /* Input mixer2 */
9498         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9499         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9500         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9501         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9502         /* Input mixer3 */
9503         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9504         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9505         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9506         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9507
9508         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9509
9510         { }
9511 };
9512
9513 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
9514         /*
9515          * Unmute ADC0-2 and set the default input to mic-in
9516          */
9517         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9518         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9519         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9520         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9521         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9522         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9523
9524         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9525          * mixer widget
9526          * Note: PASD motherboards uses the Line In 2 as the input for front
9527          * panel mic (mic 2)
9528          */
9529         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9530         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9531         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9532         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9533         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9534         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9535         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9536         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9537         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
9538         /*
9539          * Set up output mixers (0x0c - 0x0e)
9540          */
9541         /* set vol=0 to output mixers */
9542         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9543         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9544         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9545
9546         /* set up input amps for analog loopback */
9547         /* Amp Indices: DAC = 0, mixer = 1 */
9548         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9549         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9550         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9551         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9552         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9553         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9554
9555
9556         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
9557         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
9558         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
9559         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
9560         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
9561         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
9562         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
9563
9564         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9565         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9566
9567         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9568         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9569
9570         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
9571         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9572         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9573         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9574         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9575         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9576
9577         /* FIXME: use matrix-type input source selection */
9578         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9579         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9580         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
9581         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
9582         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
9583         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
9584         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
9585         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
9586         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
9587         /* Input mixer2 */
9588         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9589         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9590         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9591         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9592         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9593         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
9594         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
9595         /* Input mixer3 */
9596         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9597         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9598         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9599         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9600         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9601         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
9602         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
9603
9604         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9605
9606         { }
9607 };
9608
9609 #ifdef CONFIG_SND_HDA_POWER_SAVE
9610 #define alc262_loopbacks        alc880_loopbacks
9611 #endif
9612
9613 /* pcm configuration: identiacal with ALC880 */
9614 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
9615 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
9616 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
9617 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
9618
9619 /*
9620  * BIOS auto configuration
9621  */
9622 static int alc262_parse_auto_config(struct hda_codec *codec)
9623 {
9624         struct alc_spec *spec = codec->spec;
9625         int err;
9626         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
9627
9628         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9629                                            alc262_ignore);
9630         if (err < 0)
9631                 return err;
9632         if (!spec->autocfg.line_outs)
9633                 return 0; /* can't find valid BIOS pin config */
9634         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
9635         if (err < 0)
9636                 return err;
9637         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
9638         if (err < 0)
9639                 return err;
9640
9641         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
9642
9643         if (spec->autocfg.dig_out_pin)
9644                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
9645         if (spec->autocfg.dig_in_pin)
9646                 spec->dig_in_nid = ALC262_DIGIN_NID;
9647
9648         if (spec->kctl_alloc)
9649                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
9650
9651         spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs;
9652         spec->num_mux_defs = 1;
9653         spec->input_mux = &spec->private_imux;
9654
9655         err = alc_auto_add_mic_boost(codec);
9656         if (err < 0)
9657                 return err;
9658
9659         return 1;
9660 }
9661
9662 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
9663 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
9664 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
9665
9666
9667 /* init callback for auto-configuration model -- overriding the default init */
9668 static void alc262_auto_init(struct hda_codec *codec)
9669 {
9670         struct alc_spec *spec = codec->spec;
9671         alc262_auto_init_multi_out(codec);
9672         alc262_auto_init_hp_out(codec);
9673         alc262_auto_init_analog_input(codec);
9674         if (spec->unsol_event)
9675                 alc_sku_automute(codec);
9676 }
9677
9678 /*
9679  * configuration and preset
9680  */
9681 static const char *alc262_models[ALC262_MODEL_LAST] = {
9682         [ALC262_BASIC]          = "basic",
9683         [ALC262_HIPPO]          = "hippo",
9684         [ALC262_HIPPO_1]        = "hippo_1",
9685         [ALC262_FUJITSU]        = "fujitsu",
9686         [ALC262_HP_BPC]         = "hp-bpc",
9687         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
9688         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
9689         [ALC262_HP_RP5700]      = "hp-rp5700",
9690         [ALC262_BENQ_ED8]       = "benq",
9691         [ALC262_BENQ_T31]       = "benq-t31",
9692         [ALC262_SONY_ASSAMD]    = "sony-assamd",
9693         [ALC262_ULTRA]          = "ultra",
9694         [ALC262_LENOVO_3000]    = "lenovo-3000",
9695         [ALC262_AUTO]           = "auto",
9696 };
9697
9698 static struct snd_pci_quirk alc262_cfg_tbl[] = {
9699         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
9700         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
9701         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
9702         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
9703         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
9704         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
9705         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
9706         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
9707         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
9708         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
9709         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
9710         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
9711         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
9712         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
9713         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
9714         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
9715         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
9716         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
9717         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
9718         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
9719         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
9720                       ALC262_HP_TC_T5735),
9721         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
9722         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9723         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
9724         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9725         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9726         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
9727         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
9728                       ALC262_SONY_ASSAMD),
9729         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
9730         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
9731         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
9732         SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
9733         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
9734         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
9735         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
9736         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
9737         {}
9738 };
9739
9740 static struct alc_config_preset alc262_presets[] = {
9741         [ALC262_BASIC] = {
9742                 .mixers = { alc262_base_mixer },
9743                 .init_verbs = { alc262_init_verbs },
9744                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9745                 .dac_nids = alc262_dac_nids,
9746                 .hp_nid = 0x03,
9747                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9748                 .channel_mode = alc262_modes,
9749                 .input_mux = &alc262_capture_source,
9750         },
9751         [ALC262_HIPPO] = {
9752                 .mixers = { alc262_base_mixer },
9753                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
9754                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9755                 .dac_nids = alc262_dac_nids,
9756                 .hp_nid = 0x03,
9757                 .dig_out_nid = ALC262_DIGOUT_NID,
9758                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9759                 .channel_mode = alc262_modes,
9760                 .input_mux = &alc262_capture_source,
9761                 .unsol_event = alc262_hippo_unsol_event,
9762                 .init_hook = alc262_hippo_automute,
9763         },
9764         [ALC262_HIPPO_1] = {
9765                 .mixers = { alc262_hippo1_mixer },
9766                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
9767                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9768                 .dac_nids = alc262_dac_nids,
9769                 .hp_nid = 0x02,
9770                 .dig_out_nid = ALC262_DIGOUT_NID,
9771                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9772                 .channel_mode = alc262_modes,
9773                 .input_mux = &alc262_capture_source,
9774                 .unsol_event = alc262_hippo1_unsol_event,
9775                 .init_hook = alc262_hippo1_automute,
9776         },
9777         [ALC262_FUJITSU] = {
9778                 .mixers = { alc262_fujitsu_mixer },
9779                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
9780                                 alc262_fujitsu_unsol_verbs },
9781                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9782                 .dac_nids = alc262_dac_nids,
9783                 .hp_nid = 0x03,
9784                 .dig_out_nid = ALC262_DIGOUT_NID,
9785                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9786                 .channel_mode = alc262_modes,
9787                 .input_mux = &alc262_fujitsu_capture_source,
9788                 .unsol_event = alc262_fujitsu_unsol_event,
9789                 .init_hook = alc262_fujitsu_init_hook,
9790         },
9791         [ALC262_HP_BPC] = {
9792                 .mixers = { alc262_HP_BPC_mixer },
9793                 .init_verbs = { alc262_HP_BPC_init_verbs },
9794                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9795                 .dac_nids = alc262_dac_nids,
9796                 .hp_nid = 0x03,
9797                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9798                 .channel_mode = alc262_modes,
9799                 .input_mux = &alc262_HP_capture_source,
9800                 .unsol_event = alc262_hp_bpc_unsol_event,
9801                 .init_hook = alc262_hp_bpc_automute,
9802         },
9803         [ALC262_HP_BPC_D7000_WF] = {
9804                 .mixers = { alc262_HP_BPC_WildWest_mixer },
9805                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
9806                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9807                 .dac_nids = alc262_dac_nids,
9808                 .hp_nid = 0x03,
9809                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9810                 .channel_mode = alc262_modes,
9811                 .input_mux = &alc262_HP_D7000_capture_source,
9812                 .unsol_event = alc262_hp_wildwest_unsol_event,
9813                 .init_hook = alc262_hp_wildwest_automute,
9814         },
9815         [ALC262_HP_BPC_D7000_WL] = {
9816                 .mixers = { alc262_HP_BPC_WildWest_mixer,
9817                             alc262_HP_BPC_WildWest_option_mixer },
9818                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
9819                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9820                 .dac_nids = alc262_dac_nids,
9821                 .hp_nid = 0x03,
9822                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9823                 .channel_mode = alc262_modes,
9824                 .input_mux = &alc262_HP_D7000_capture_source,
9825                 .unsol_event = alc262_hp_wildwest_unsol_event,
9826                 .init_hook = alc262_hp_wildwest_automute,
9827         },
9828         [ALC262_HP_TC_T5735] = {
9829                 .mixers = { alc262_hp_t5735_mixer },
9830                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
9831                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9832                 .dac_nids = alc262_dac_nids,
9833                 .hp_nid = 0x03,
9834                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9835                 .channel_mode = alc262_modes,
9836                 .input_mux = &alc262_capture_source,
9837                 .unsol_event = alc262_hp_t5735_unsol_event,
9838                 .init_hook = alc262_hp_t5735_init_hook,
9839         },
9840         [ALC262_HP_RP5700] = {
9841                 .mixers = { alc262_hp_rp5700_mixer },
9842                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
9843                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9844                 .dac_nids = alc262_dac_nids,
9845                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9846                 .channel_mode = alc262_modes,
9847                 .input_mux = &alc262_hp_rp5700_capture_source,
9848         },
9849         [ALC262_BENQ_ED8] = {
9850                 .mixers = { alc262_base_mixer },
9851                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
9852                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9853                 .dac_nids = alc262_dac_nids,
9854                 .hp_nid = 0x03,
9855                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9856                 .channel_mode = alc262_modes,
9857                 .input_mux = &alc262_capture_source,
9858         },
9859         [ALC262_SONY_ASSAMD] = {
9860                 .mixers = { alc262_sony_mixer },
9861                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
9862                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9863                 .dac_nids = alc262_dac_nids,
9864                 .hp_nid = 0x02,
9865                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9866                 .channel_mode = alc262_modes,
9867                 .input_mux = &alc262_capture_source,
9868                 .unsol_event = alc262_hippo_unsol_event,
9869                 .init_hook = alc262_hippo_automute,
9870         },
9871         [ALC262_BENQ_T31] = {
9872                 .mixers = { alc262_benq_t31_mixer },
9873                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
9874                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9875                 .dac_nids = alc262_dac_nids,
9876                 .hp_nid = 0x03,
9877                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9878                 .channel_mode = alc262_modes,
9879                 .input_mux = &alc262_capture_source,
9880                 .unsol_event = alc262_hippo_unsol_event,
9881                 .init_hook = alc262_hippo_automute,
9882         },      
9883         [ALC262_ULTRA] = {
9884                 .mixers = { alc262_ultra_mixer, alc262_ultra_capture_mixer },
9885                 .init_verbs = { alc262_ultra_verbs },
9886                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9887                 .dac_nids = alc262_dac_nids,
9888                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9889                 .channel_mode = alc262_modes,
9890                 .input_mux = &alc262_ultra_capture_source,
9891                 .adc_nids = alc262_adc_nids, /* ADC0 */
9892                 .capsrc_nids = alc262_capsrc_nids,
9893                 .num_adc_nids = 1, /* single ADC */
9894                 .unsol_event = alc262_ultra_unsol_event,
9895                 .init_hook = alc262_ultra_automute,
9896         },
9897         [ALC262_LENOVO_3000] = {
9898                 .mixers = { alc262_lenovo_3000_mixer },
9899                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
9900                                 alc262_lenovo_3000_unsol_verbs },
9901                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9902                 .dac_nids = alc262_dac_nids,
9903                 .hp_nid = 0x03,
9904                 .dig_out_nid = ALC262_DIGOUT_NID,
9905                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9906                 .channel_mode = alc262_modes,
9907                 .input_mux = &alc262_fujitsu_capture_source,
9908                 .unsol_event = alc262_lenovo_3000_unsol_event,
9909         },
9910 };
9911
9912 static int patch_alc262(struct hda_codec *codec)
9913 {
9914         struct alc_spec *spec;
9915         int board_config;
9916         int err;
9917
9918         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9919         if (spec == NULL)
9920                 return -ENOMEM;
9921
9922         codec->spec = spec;
9923 #if 0
9924         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
9925          * under-run
9926          */
9927         {
9928         int tmp;
9929         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
9930         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
9931         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
9932         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
9933         }
9934 #endif
9935
9936         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
9937
9938         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
9939                                                   alc262_models,
9940                                                   alc262_cfg_tbl);
9941
9942         if (board_config < 0) {
9943                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
9944                        "trying auto-probe from BIOS...\n");
9945                 board_config = ALC262_AUTO;
9946         }
9947
9948         if (board_config == ALC262_AUTO) {
9949                 /* automatic parse from the BIOS config */
9950                 err = alc262_parse_auto_config(codec);
9951                 if (err < 0) {
9952                         alc_free(codec);
9953                         return err;
9954                 } else if (!err) {
9955                         printk(KERN_INFO
9956                                "hda_codec: Cannot set up configuration "
9957                                "from BIOS.  Using base mode...\n");
9958                         board_config = ALC262_BASIC;
9959                 }
9960         }
9961
9962         if (board_config != ALC262_AUTO)
9963                 setup_preset(spec, &alc262_presets[board_config]);
9964
9965         spec->stream_name_analog = "ALC262 Analog";
9966         spec->stream_analog_playback = &alc262_pcm_analog_playback;
9967         spec->stream_analog_capture = &alc262_pcm_analog_capture;
9968                 
9969         spec->stream_name_digital = "ALC262 Digital";
9970         spec->stream_digital_playback = &alc262_pcm_digital_playback;
9971         spec->stream_digital_capture = &alc262_pcm_digital_capture;
9972
9973         if (!spec->adc_nids && spec->input_mux) {
9974                 /* check whether NID 0x07 is valid */
9975                 unsigned int wcap = get_wcaps(codec, 0x07);
9976
9977                 /* get type */
9978                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
9979                 if (wcap != AC_WID_AUD_IN) {
9980                         spec->adc_nids = alc262_adc_nids_alt;
9981                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
9982                         spec->capsrc_nids = alc262_capsrc_nids_alt;
9983                         spec->mixers[spec->num_mixers] =
9984                                 alc262_capture_alt_mixer;
9985                         spec->num_mixers++;
9986                 } else {
9987                         spec->adc_nids = alc262_adc_nids;
9988                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
9989                         spec->capsrc_nids = alc262_capsrc_nids;
9990                         spec->mixers[spec->num_mixers] = alc262_capture_mixer;
9991                         spec->num_mixers++;
9992                 }
9993         }
9994
9995         spec->vmaster_nid = 0x0c;
9996
9997         codec->patch_ops = alc_patch_ops;
9998         if (board_config == ALC262_AUTO)
9999                 spec->init_hook = alc262_auto_init;
10000 #ifdef CONFIG_SND_HDA_POWER_SAVE
10001         if (!spec->loopback.amplist)
10002                 spec->loopback.amplist = alc262_loopbacks;
10003 #endif
10004                 
10005         return 0;
10006 }
10007
10008 /*
10009  *  ALC268 channel source setting (2 channel)
10010  */
10011 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
10012 #define alc268_modes            alc260_modes
10013         
10014 static hda_nid_t alc268_dac_nids[2] = {
10015         /* front, hp */
10016         0x02, 0x03
10017 };
10018
10019 static hda_nid_t alc268_adc_nids[2] = {
10020         /* ADC0-1 */
10021         0x08, 0x07
10022 };
10023
10024 static hda_nid_t alc268_adc_nids_alt[1] = {
10025         /* ADC0 */
10026         0x08
10027 };
10028
10029 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
10030
10031 static struct snd_kcontrol_new alc268_base_mixer[] = {
10032         /* output mixer control */
10033         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10034         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10035         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10036         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10037         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10038         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10039         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10040         { }
10041 };
10042
10043 /* bind Beep switches of both NID 0x0f and 0x10 */
10044 static struct hda_bind_ctls alc268_bind_beep_sw = {
10045         .ops = &snd_hda_bind_sw,
10046         .values = {
10047                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
10048                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
10049                 0
10050         },
10051 };
10052
10053 static struct snd_kcontrol_new alc268_beep_mixer[] = {
10054         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
10055         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
10056         { }
10057 };
10058
10059 static struct hda_verb alc268_eapd_verbs[] = {
10060         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10061         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10062         { }
10063 };
10064
10065 /* Toshiba specific */
10066 #define alc268_toshiba_automute alc262_hippo_automute
10067
10068 static struct hda_verb alc268_toshiba_verbs[] = {
10069         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10070         { } /* end */
10071 };
10072
10073 /* Acer specific */
10074 /* bind volumes of both NID 0x02 and 0x03 */
10075 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
10076         .ops = &snd_hda_bind_vol,
10077         .values = {
10078                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
10079                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
10080                 0
10081         },
10082 };
10083
10084 /* mute/unmute internal speaker according to the hp jack and mute state */
10085 static void alc268_acer_automute(struct hda_codec *codec, int force)
10086 {
10087         struct alc_spec *spec = codec->spec;
10088         unsigned int mute;
10089
10090         if (force || !spec->sense_updated) {
10091                 unsigned int present;
10092                 present = snd_hda_codec_read(codec, 0x14, 0,
10093                                          AC_VERB_GET_PIN_SENSE, 0);
10094                 spec->jack_present = (present & 0x80000000) != 0;
10095                 spec->sense_updated = 1;
10096         }
10097         if (spec->jack_present)
10098                 mute = HDA_AMP_MUTE; /* mute internal speaker */
10099         else /* unmute internal speaker if necessary */
10100                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10101         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10102                                  HDA_AMP_MUTE, mute);
10103 }
10104
10105
10106 /* bind hp and internal speaker mute (with plug check) */
10107 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
10108                                      struct snd_ctl_elem_value *ucontrol)
10109 {
10110         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10111         long *valp = ucontrol->value.integer.value;
10112         int change;
10113
10114         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
10115                                           HDA_AMP_MUTE,
10116                                           valp[0] ? 0 : HDA_AMP_MUTE);
10117         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
10118                                            HDA_AMP_MUTE,
10119                                            valp[1] ? 0 : HDA_AMP_MUTE);
10120         if (change)
10121                 alc268_acer_automute(codec, 0);
10122         return change;
10123 }
10124
10125 static struct snd_kcontrol_new alc268_acer_mixer[] = {
10126         /* output mixer control */
10127         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
10128         {
10129                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10130                 .name = "Master Playback Switch",
10131                 .info = snd_hda_mixer_amp_switch_info,
10132                 .get = snd_hda_mixer_amp_switch_get,
10133                 .put = alc268_acer_master_sw_put,
10134                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10135         },
10136         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10137         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
10138         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10139         { }
10140 };
10141
10142 static struct hda_verb alc268_acer_verbs[] = {
10143         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
10144         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10145         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10146         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10147         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10148         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10149
10150         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10151         { }
10152 };
10153
10154 /* unsolicited event for HP jack sensing */
10155 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
10156                                        unsigned int res)
10157 {
10158         if ((res >> 26) != ALC880_HP_EVENT)
10159                 return;
10160         alc268_toshiba_automute(codec);
10161 }
10162
10163 static void alc268_acer_unsol_event(struct hda_codec *codec,
10164                                        unsigned int res)
10165 {
10166         if ((res >> 26) != ALC880_HP_EVENT)
10167                 return;
10168         alc268_acer_automute(codec, 1);
10169 }
10170
10171 static void alc268_acer_init_hook(struct hda_codec *codec)
10172 {
10173         alc268_acer_automute(codec, 1);
10174 }
10175
10176 static struct snd_kcontrol_new alc268_dell_mixer[] = {
10177         /* output mixer control */
10178         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10179         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10180         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10181         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10182         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10183         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
10184         { }
10185 };
10186
10187 static struct hda_verb alc268_dell_verbs[] = {
10188         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10189         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10190         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10191         { }
10192 };
10193
10194 /* mute/unmute internal speaker according to the hp jack and mute state */
10195 static void alc268_dell_automute(struct hda_codec *codec)
10196 {
10197         unsigned int present;
10198         unsigned int mute;
10199
10200         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
10201         if (present & 0x80000000)
10202                 mute = HDA_AMP_MUTE;
10203         else
10204                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
10205         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10206                                  HDA_AMP_MUTE, mute);
10207 }
10208
10209 static void alc268_dell_unsol_event(struct hda_codec *codec,
10210                                     unsigned int res)
10211 {
10212         if ((res >> 26) != ALC880_HP_EVENT)
10213                 return;
10214         alc268_dell_automute(codec);
10215 }
10216
10217 #define alc268_dell_init_hook   alc268_dell_automute
10218
10219 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
10220         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10221         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10222         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10223         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10224         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10225         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
10226         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
10227         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10228         { }
10229 };
10230
10231 static struct hda_verb alc267_quanta_il1_verbs[] = {
10232         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10233         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
10234         { }
10235 };
10236
10237 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
10238 {
10239         unsigned int present;
10240
10241         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
10242                 & AC_PINSENSE_PRESENCE;
10243         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
10244                             present ? 0 : PIN_OUT);
10245 }
10246
10247 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
10248 {
10249         unsigned int present;
10250
10251         present = snd_hda_codec_read(codec, 0x18, 0,
10252                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10253         snd_hda_codec_write(codec, 0x23, 0,
10254                             AC_VERB_SET_CONNECT_SEL,
10255                             present ? 0x00 : 0x01);
10256 }
10257
10258 static void alc267_quanta_il1_automute(struct hda_codec *codec)
10259 {
10260         alc267_quanta_il1_hp_automute(codec);
10261         alc267_quanta_il1_mic_automute(codec);
10262 }
10263
10264 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
10265                                            unsigned int res)
10266 {
10267         switch (res >> 26) {
10268         case ALC880_HP_EVENT:
10269                 alc267_quanta_il1_hp_automute(codec);
10270                 break;
10271         case ALC880_MIC_EVENT:
10272                 alc267_quanta_il1_mic_automute(codec);
10273                 break;
10274         }
10275 }
10276
10277 /*
10278  * generic initialization of ADC, input mixers and output mixers
10279  */
10280 static struct hda_verb alc268_base_init_verbs[] = {
10281         /* Unmute DAC0-1 and set vol = 0 */
10282         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10283         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10284         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10285         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10286         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10287         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10288
10289         /*
10290          * Set up output mixers (0x0c - 0x0e)
10291          */
10292         /* set vol=0 to output mixers */
10293         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10294         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10295         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10296         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
10297
10298         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10299         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10300
10301         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10302         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10303         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10304         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10305         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10306         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10307         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10308         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10309
10310         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10311         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10312         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10313         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10314         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10315         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10316         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10317
10318         /* set PCBEEP vol = 0, mute connections */
10319         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10320         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10321         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10322
10323         /* Unmute Selector 23h,24h and set the default input to mic-in */
10324         
10325         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
10326         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10327         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
10328         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10329
10330         { }
10331 };
10332
10333 /*
10334  * generic initialization of ADC, input mixers and output mixers
10335  */
10336 static struct hda_verb alc268_volume_init_verbs[] = {
10337         /* set output DAC */
10338         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10339         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10340         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10341         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10342
10343         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10344         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10345         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10346         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10347         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10348
10349         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10350         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10351         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10352         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10353         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10354
10355         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10356         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10357         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10358         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10359
10360         /* set PCBEEP vol = 0, mute connections */
10361         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10362         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10363         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10364
10365         { }
10366 };
10367
10368 #define alc268_mux_enum_info alc_mux_enum_info
10369 #define alc268_mux_enum_get alc_mux_enum_get
10370 #define alc268_mux_enum_put alc_mux_enum_put
10371
10372 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
10373         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10374         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
10375         {
10376                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10377                 /* The multiple "Capture Source" controls confuse alsamixer
10378                  * So call somewhat different..
10379                  */
10380                 /* .name = "Capture Source", */
10381                 .name = "Input Source",
10382                 .count = 1,
10383                 .info = alc268_mux_enum_info,
10384                 .get = alc268_mux_enum_get,
10385                 .put = alc268_mux_enum_put,
10386         },
10387         { } /* end */
10388 };
10389
10390 static struct snd_kcontrol_new alc268_capture_mixer[] = {
10391         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10392         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
10393         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
10394         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
10395         {
10396                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10397                 /* The multiple "Capture Source" controls confuse alsamixer
10398                  * So call somewhat different..
10399                  */
10400                 /* .name = "Capture Source", */
10401                 .name = "Input Source",
10402                 .count = 2,
10403                 .info = alc268_mux_enum_info,
10404                 .get = alc268_mux_enum_get,
10405                 .put = alc268_mux_enum_put,
10406         },
10407         { } /* end */
10408 };
10409
10410 static struct hda_input_mux alc268_capture_source = {
10411         .num_items = 4,
10412         .items = {
10413                 { "Mic", 0x0 },
10414                 { "Front Mic", 0x1 },
10415                 { "Line", 0x2 },
10416                 { "CD", 0x3 },
10417         },
10418 };
10419
10420 static struct hda_input_mux alc268_acer_capture_source = {
10421         .num_items = 3,
10422         .items = {
10423                 { "Mic", 0x0 },
10424                 { "Internal Mic", 0x6 },
10425                 { "Line", 0x2 },
10426         },
10427 };
10428
10429 #ifdef CONFIG_SND_DEBUG
10430 static struct snd_kcontrol_new alc268_test_mixer[] = {
10431         /* Volume widgets */
10432         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10433         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10434         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
10435         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
10436         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
10437         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
10438         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
10439         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
10440         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
10441         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
10442         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
10443         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
10444         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
10445         /* The below appears problematic on some hardwares */
10446         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
10447         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10448         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
10449         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
10450         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
10451
10452         /* Modes for retasking pin widgets */
10453         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
10454         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
10455         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
10456         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
10457
10458         /* Controls for GPIO pins, assuming they are configured as outputs */
10459         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
10460         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
10461         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
10462         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
10463
10464         /* Switches to allow the digital SPDIF output pin to be enabled.
10465          * The ALC268 does not have an SPDIF input.
10466          */
10467         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
10468
10469         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
10470          * this output to turn on an external amplifier.
10471          */
10472         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
10473         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
10474
10475         { } /* end */
10476 };
10477 #endif
10478
10479 /* create input playback/capture controls for the given pin */
10480 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
10481                                     const char *ctlname, int idx)
10482 {
10483         char name[32];
10484         int err;
10485
10486         sprintf(name, "%s Playback Volume", ctlname);
10487         if (nid == 0x14) {
10488                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
10489                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
10490                                                       HDA_OUTPUT));
10491                 if (err < 0)
10492                         return err;
10493         } else if (nid == 0x15) {
10494                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
10495                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
10496                                                       HDA_OUTPUT));
10497                 if (err < 0)
10498                         return err;
10499         } else
10500                 return -1;
10501         sprintf(name, "%s Playback Switch", ctlname);
10502         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
10503                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
10504         if (err < 0)
10505                 return err;
10506         return 0;
10507 }
10508
10509 /* add playback controls from the parsed DAC table */
10510 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
10511                                              const struct auto_pin_cfg *cfg)
10512 {
10513         hda_nid_t nid;
10514         int err;
10515
10516         spec->multiout.num_dacs = 2;    /* only use one dac */
10517         spec->multiout.dac_nids = spec->private_dac_nids;
10518         spec->multiout.dac_nids[0] = 2;
10519         spec->multiout.dac_nids[1] = 3;
10520
10521         nid = cfg->line_out_pins[0];
10522         if (nid)
10523                 alc268_new_analog_output(spec, nid, "Front", 0);        
10524
10525         nid = cfg->speaker_pins[0];
10526         if (nid == 0x1d) {
10527                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10528                                   "Speaker Playback Volume",
10529                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
10530                 if (err < 0)
10531                         return err;
10532         }
10533         nid = cfg->hp_pins[0];
10534         if (nid)
10535                 alc268_new_analog_output(spec, nid, "Headphone", 0);
10536
10537         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
10538         if (nid == 0x16) {
10539                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10540                                   "Mono Playback Switch",
10541                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
10542                 if (err < 0)
10543                         return err;
10544         }
10545         return 0;       
10546 }
10547
10548 /* create playback/capture controls for input pins */
10549 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
10550                                                 const struct auto_pin_cfg *cfg)
10551 {
10552         struct hda_input_mux *imux = &spec->private_imux;
10553         int i, idx1;
10554
10555         for (i = 0; i < AUTO_PIN_LAST; i++) {
10556                 switch(cfg->input_pins[i]) {
10557                 case 0x18:
10558                         idx1 = 0;       /* Mic 1 */
10559                         break;
10560                 case 0x19:
10561                         idx1 = 1;       /* Mic 2 */
10562                         break;
10563                 case 0x1a:
10564                         idx1 = 2;       /* Line In */
10565                         break;
10566                 case 0x1c:      
10567                         idx1 = 3;       /* CD */
10568                         break;
10569                 case 0x12:
10570                 case 0x13:
10571                         idx1 = 6;       /* digital mics */
10572                         break;
10573                 default:
10574                         continue;
10575                 }
10576                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
10577                 imux->items[imux->num_items].index = idx1;
10578                 imux->num_items++;      
10579         }
10580         return 0;
10581 }
10582
10583 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
10584 {
10585         struct alc_spec *spec = codec->spec;
10586         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
10587         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10588         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
10589         unsigned int    dac_vol1, dac_vol2;
10590
10591         if (speaker_nid) {
10592                 snd_hda_codec_write(codec, speaker_nid, 0,
10593                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
10594                 snd_hda_codec_write(codec, 0x0f, 0,
10595                                     AC_VERB_SET_AMP_GAIN_MUTE,
10596                                     AMP_IN_UNMUTE(1));
10597                 snd_hda_codec_write(codec, 0x10, 0,
10598                                     AC_VERB_SET_AMP_GAIN_MUTE,
10599                                     AMP_IN_UNMUTE(1));
10600         } else {
10601                 snd_hda_codec_write(codec, 0x0f, 0,
10602                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
10603                 snd_hda_codec_write(codec, 0x10, 0,
10604                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
10605         }
10606
10607         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
10608         if (line_nid == 0x14)   
10609                 dac_vol2 = AMP_OUT_ZERO;
10610         else if (line_nid == 0x15)
10611                 dac_vol1 = AMP_OUT_ZERO;
10612         if (hp_nid == 0x14)     
10613                 dac_vol2 = AMP_OUT_ZERO;
10614         else if (hp_nid == 0x15)
10615                 dac_vol1 = AMP_OUT_ZERO;
10616         if (line_nid != 0x16 || hp_nid != 0x16 ||
10617             spec->autocfg.line_out_pins[1] != 0x16 ||
10618             spec->autocfg.line_out_pins[2] != 0x16)
10619                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
10620
10621         snd_hda_codec_write(codec, 0x02, 0,
10622                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
10623         snd_hda_codec_write(codec, 0x03, 0,
10624                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
10625 }
10626
10627 /* pcm configuration: identiacal with ALC880 */
10628 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
10629 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
10630 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
10631 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
10632
10633 /*
10634  * BIOS auto configuration
10635  */
10636 static int alc268_parse_auto_config(struct hda_codec *codec)
10637 {
10638         struct alc_spec *spec = codec->spec;
10639         int err;
10640         static hda_nid_t alc268_ignore[] = { 0 };
10641
10642         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10643                                            alc268_ignore);
10644         if (err < 0)
10645                 return err;
10646         if (!spec->autocfg.line_outs)
10647                 return 0; /* can't find valid BIOS pin config */
10648
10649         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
10650         if (err < 0)
10651                 return err;
10652         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
10653         if (err < 0)
10654                 return err;
10655
10656         spec->multiout.max_channels = 2;
10657
10658         /* digital only support output */
10659         if (spec->autocfg.dig_out_pin)
10660                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
10661
10662         if (spec->kctl_alloc)
10663                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10664
10665         if (spec->autocfg.speaker_pins[0] != 0x1d)
10666                 spec->mixers[spec->num_mixers++] = alc268_beep_mixer;
10667
10668         spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs;
10669         spec->num_mux_defs = 1;
10670         spec->input_mux = &spec->private_imux;
10671
10672         err = alc_auto_add_mic_boost(codec);
10673         if (err < 0)
10674                 return err;
10675
10676         return 1;
10677 }
10678
10679 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
10680 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
10681 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
10682
10683 /* init callback for auto-configuration model -- overriding the default init */
10684 static void alc268_auto_init(struct hda_codec *codec)
10685 {
10686         struct alc_spec *spec = codec->spec;
10687         alc268_auto_init_multi_out(codec);
10688         alc268_auto_init_hp_out(codec);
10689         alc268_auto_init_mono_speaker_out(codec);
10690         alc268_auto_init_analog_input(codec);
10691         if (spec->unsol_event)
10692                 alc_sku_automute(codec);
10693 }
10694
10695 /*
10696  * configuration and preset
10697  */
10698 static const char *alc268_models[ALC268_MODEL_LAST] = {
10699         [ALC267_QUANTA_IL1]     = "quanta-il1",
10700         [ALC268_3ST]            = "3stack",
10701         [ALC268_TOSHIBA]        = "toshiba",
10702         [ALC268_ACER]           = "acer",
10703         [ALC268_DELL]           = "dell",
10704         [ALC268_ZEPTO]          = "zepto",
10705 #ifdef CONFIG_SND_DEBUG
10706         [ALC268_TEST]           = "test",
10707 #endif
10708         [ALC268_AUTO]           = "auto",
10709 };
10710
10711 static struct snd_pci_quirk alc268_cfg_tbl[] = {
10712         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
10713         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
10714         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
10715         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
10716         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
10717         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
10718         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
10719         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
10720         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
10721         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
10722         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
10723         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
10724         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
10725         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
10726         {}
10727 };
10728
10729 static struct alc_config_preset alc268_presets[] = {
10730         [ALC267_QUANTA_IL1] = {
10731                 .mixers = { alc267_quanta_il1_mixer },
10732                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10733                                 alc267_quanta_il1_verbs },
10734                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10735                 .dac_nids = alc268_dac_nids,
10736                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10737                 .adc_nids = alc268_adc_nids_alt,
10738                 .hp_nid = 0x03,
10739                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10740                 .channel_mode = alc268_modes,
10741                 .input_mux = &alc268_capture_source,
10742                 .unsol_event = alc267_quanta_il1_unsol_event,
10743                 .init_hook = alc267_quanta_il1_automute,
10744         },
10745         [ALC268_3ST] = {
10746                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10747                             alc268_beep_mixer },
10748                 .init_verbs = { alc268_base_init_verbs },
10749                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10750                 .dac_nids = alc268_dac_nids,
10751                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10752                 .adc_nids = alc268_adc_nids_alt,
10753                 .capsrc_nids = alc268_capsrc_nids,
10754                 .hp_nid = 0x03,
10755                 .dig_out_nid = ALC268_DIGOUT_NID,
10756                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10757                 .channel_mode = alc268_modes,
10758                 .input_mux = &alc268_capture_source,
10759         },
10760         [ALC268_TOSHIBA] = {
10761                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10762                             alc268_beep_mixer },
10763                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10764                                 alc268_toshiba_verbs },
10765                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10766                 .dac_nids = alc268_dac_nids,
10767                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10768                 .adc_nids = alc268_adc_nids_alt,
10769                 .capsrc_nids = alc268_capsrc_nids,
10770                 .hp_nid = 0x03,
10771                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10772                 .channel_mode = alc268_modes,
10773                 .input_mux = &alc268_capture_source,
10774                 .unsol_event = alc268_toshiba_unsol_event,
10775                 .init_hook = alc268_toshiba_automute,
10776         },
10777         [ALC268_ACER] = {
10778                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
10779                             alc268_beep_mixer },
10780                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10781                                 alc268_acer_verbs },
10782                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10783                 .dac_nids = alc268_dac_nids,
10784                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10785                 .adc_nids = alc268_adc_nids_alt,
10786                 .capsrc_nids = alc268_capsrc_nids,
10787                 .hp_nid = 0x02,
10788                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10789                 .channel_mode = alc268_modes,
10790                 .input_mux = &alc268_acer_capture_source,
10791                 .unsol_event = alc268_acer_unsol_event,
10792                 .init_hook = alc268_acer_init_hook,
10793         },
10794         [ALC268_DELL] = {
10795                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
10796                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10797                                 alc268_dell_verbs },
10798                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10799                 .dac_nids = alc268_dac_nids,
10800                 .hp_nid = 0x02,
10801                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10802                 .channel_mode = alc268_modes,
10803                 .unsol_event = alc268_dell_unsol_event,
10804                 .init_hook = alc268_dell_init_hook,
10805                 .input_mux = &alc268_capture_source,
10806         },
10807         [ALC268_ZEPTO] = {
10808                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10809                             alc268_beep_mixer },
10810                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10811                                 alc268_toshiba_verbs },
10812                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10813                 .dac_nids = alc268_dac_nids,
10814                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10815                 .adc_nids = alc268_adc_nids_alt,
10816                 .capsrc_nids = alc268_capsrc_nids,
10817                 .hp_nid = 0x03,
10818                 .dig_out_nid = ALC268_DIGOUT_NID,
10819                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10820                 .channel_mode = alc268_modes,
10821                 .input_mux = &alc268_capture_source,
10822                 .unsol_event = alc268_toshiba_unsol_event,
10823                 .init_hook = alc268_toshiba_automute
10824         },
10825 #ifdef CONFIG_SND_DEBUG
10826         [ALC268_TEST] = {
10827                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
10828                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10829                                 alc268_volume_init_verbs },
10830                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10831                 .dac_nids = alc268_dac_nids,
10832                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10833                 .adc_nids = alc268_adc_nids_alt,
10834                 .capsrc_nids = alc268_capsrc_nids,
10835                 .hp_nid = 0x03,
10836                 .dig_out_nid = ALC268_DIGOUT_NID,
10837                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10838                 .channel_mode = alc268_modes,
10839                 .input_mux = &alc268_capture_source,
10840         },
10841 #endif
10842 };
10843
10844 static int patch_alc268(struct hda_codec *codec)
10845 {
10846         struct alc_spec *spec;
10847         int board_config;
10848         int err;
10849
10850         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
10851         if (spec == NULL)
10852                 return -ENOMEM;
10853
10854         codec->spec = spec;
10855
10856         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
10857                                                   alc268_models,
10858                                                   alc268_cfg_tbl);
10859
10860         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
10861                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
10862                        "trying auto-probe from BIOS...\n");
10863                 board_config = ALC268_AUTO;
10864         }
10865
10866         if (board_config == ALC268_AUTO) {
10867                 /* automatic parse from the BIOS config */
10868                 err = alc268_parse_auto_config(codec);
10869                 if (err < 0) {
10870                         alc_free(codec);
10871                         return err;
10872                 } else if (!err) {
10873                         printk(KERN_INFO
10874                                "hda_codec: Cannot set up configuration "
10875                                "from BIOS.  Using base mode...\n");
10876                         board_config = ALC268_3ST;
10877                 }
10878         }
10879
10880         if (board_config != ALC268_AUTO)
10881                 setup_preset(spec, &alc268_presets[board_config]);
10882
10883         if (codec->vendor_id == 0x10ec0267) {
10884                 spec->stream_name_analog = "ALC267 Analog";
10885                 spec->stream_name_digital = "ALC267 Digital";
10886         } else {
10887                 spec->stream_name_analog = "ALC268 Analog";
10888                 spec->stream_name_digital = "ALC268 Digital";
10889         }
10890
10891         spec->stream_analog_playback = &alc268_pcm_analog_playback;
10892         spec->stream_analog_capture = &alc268_pcm_analog_capture;
10893         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
10894
10895         spec->stream_digital_playback = &alc268_pcm_digital_playback;
10896
10897         if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
10898                 /* override the amp caps for beep generator */
10899                 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
10900                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
10901                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
10902                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
10903                                           (0 << AC_AMPCAP_MUTE_SHIFT));
10904
10905         if (!spec->adc_nids && spec->input_mux) {
10906                 /* check whether NID 0x07 is valid */
10907                 unsigned int wcap = get_wcaps(codec, 0x07);
10908                 int i;
10909
10910                 /* get type */
10911                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10912                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
10913                         spec->adc_nids = alc268_adc_nids_alt;
10914                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
10915                         spec->mixers[spec->num_mixers] =
10916                                         alc268_capture_alt_mixer;
10917                         spec->num_mixers++;
10918                 } else {
10919                         spec->adc_nids = alc268_adc_nids;
10920                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
10921                         spec->mixers[spec->num_mixers] =
10922                                 alc268_capture_mixer;
10923                         spec->num_mixers++;
10924                 }
10925                 spec->capsrc_nids = alc268_capsrc_nids;
10926                 /* set default input source */
10927                 for (i = 0; i < spec->num_adc_nids; i++)
10928                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
10929                                 0, AC_VERB_SET_CONNECT_SEL,
10930                                 spec->input_mux->items[0].index);
10931         }
10932
10933         spec->vmaster_nid = 0x02;
10934
10935         codec->patch_ops = alc_patch_ops;
10936         if (board_config == ALC268_AUTO)
10937                 spec->init_hook = alc268_auto_init;
10938                 
10939         return 0;
10940 }
10941
10942 /*
10943  *  ALC269 channel source setting (2 channel)
10944  */
10945 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
10946
10947 #define alc269_dac_nids         alc260_dac_nids
10948
10949 static hda_nid_t alc269_adc_nids[1] = {
10950         /* ADC1 */
10951         0x08,
10952 };
10953
10954 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
10955         .num_items = 2,
10956         .items = {
10957                 { "i-Mic", 0x5 },
10958                 { "e-Mic", 0x0 },
10959         },
10960 };
10961
10962 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
10963         .num_items = 2,
10964         .items = {
10965                 { "i-Mic", 0x1 },
10966                 { "e-Mic", 0x0 },
10967         },
10968 };
10969
10970 #define alc269_modes            alc260_modes
10971 #define alc269_capture_source   alc880_lg_lw_capture_source
10972
10973 static struct snd_kcontrol_new alc269_base_mixer[] = {
10974         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10975         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10976         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10977         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10978         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10979         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10980         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10981         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10982         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10983         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10984         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10985         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
10986         { } /* end */
10987 };
10988
10989 /* bind volumes of both NID 0x0c and 0x0d */
10990 static struct hda_bind_ctls alc269_epc_bind_vol = {
10991         .ops = &snd_hda_bind_vol,
10992         .values = {
10993                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
10994                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
10995                 0
10996         },
10997 };
10998
10999 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
11000         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11001         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
11002         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11003         { } /* end */
11004 };
11005
11006 /* capture mixer elements */
11007 static struct snd_kcontrol_new alc269_capture_mixer[] = {
11008         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11009         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11010         {
11011                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11012                 /* The multiple "Capture Source" controls confuse alsamixer
11013                  * So call somewhat different..
11014                  */
11015                 /* .name = "Capture Source", */
11016                 .name = "Input Source",
11017                 .count = 1,
11018                 .info = alc_mux_enum_info,
11019                 .get = alc_mux_enum_get,
11020                 .put = alc_mux_enum_put,
11021         },
11022         { } /* end */
11023 };
11024
11025 /* capture mixer elements */
11026 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
11027         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11028         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11029         { } /* end */
11030 };
11031
11032 /*
11033  * generic initialization of ADC, input mixers and output mixers
11034  */
11035 static struct hda_verb alc269_init_verbs[] = {
11036         /*
11037          * Unmute ADC0 and set the default input to mic-in
11038          */
11039         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11040
11041         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
11042          * analog-loopback mixer widget
11043          * Note: PASD motherboards uses the Line In 2 as the input for
11044          * front panel mic (mic 2)
11045          */
11046         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11047         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11048         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11049         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11050         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11051         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11052
11053         /*
11054          * Set up output mixers (0x0c - 0x0e)
11055          */
11056         /* set vol=0 to output mixers */
11057         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11058         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11059
11060         /* set up input amps for analog loopback */
11061         /* Amp Indices: DAC = 0, mixer = 1 */
11062         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11063         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11064         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11065         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11066         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11067         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11068
11069         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11070         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11071         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11072         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11073         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11074         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11075         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11076
11077         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11078         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11079         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11080         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11081         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11082         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11083         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11084
11085         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
11086         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11087
11088         /* FIXME: use matrix-type input source selection */
11089         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
11090         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11091         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11092         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11093         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11094         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11095
11096         /* set EAPD */
11097         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11098         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
11099         { }
11100 };
11101
11102 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
11103         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11104         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
11105         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
11106         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
11107         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11108         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11109         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11110         {}
11111 };
11112
11113 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
11114         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11115         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
11116         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
11117         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
11118         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11119         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11120         {}
11121 };
11122
11123 /* toggle speaker-output according to the hp-jack state */
11124 static void alc269_speaker_automute(struct hda_codec *codec)
11125 {
11126         unsigned int present;
11127         unsigned int bits;
11128
11129         present = snd_hda_codec_read(codec, 0x15, 0,
11130                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11131         bits = present ? AMP_IN_MUTE(0) : 0;
11132         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
11133                                  AMP_IN_MUTE(0), bits);
11134         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
11135                                  AMP_IN_MUTE(0), bits);
11136 }
11137
11138 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
11139 {
11140         unsigned int present;
11141
11142         present = snd_hda_codec_read(codec, 0x18, 0, AC_VERB_GET_PIN_SENSE, 0)
11143                 & AC_PINSENSE_PRESENCE;
11144         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
11145                             present ? 0 : 5);
11146 }
11147
11148 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
11149 {
11150         unsigned int present;
11151
11152         present = snd_hda_codec_read(codec, 0x18, 0, AC_VERB_GET_PIN_SENSE, 0)
11153                 & AC_PINSENSE_PRESENCE;
11154         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11155                             present ? AMP_IN_UNMUTE(0) : AMP_IN_MUTE(0));
11156         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11157                             present ? AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1));
11158 }
11159
11160 /* unsolicited event for HP jack sensing */
11161 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
11162                                           unsigned int res)
11163 {
11164         if ((res >> 26) == ALC880_HP_EVENT)
11165                 alc269_speaker_automute(codec);
11166
11167         if ((res >> 26) == ALC880_MIC_EVENT)
11168                 alc269_eeepc_dmic_automute(codec);
11169 }
11170
11171 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
11172 {
11173         alc269_speaker_automute(codec);
11174         alc269_eeepc_dmic_automute(codec);
11175 }
11176
11177 /* unsolicited event for HP jack sensing */
11178 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
11179                                           unsigned int res)
11180 {
11181         if ((res >> 26) == ALC880_HP_EVENT)
11182                 alc269_speaker_automute(codec);
11183
11184         if ((res >> 26) == ALC880_MIC_EVENT)
11185                 alc269_eeepc_amic_automute(codec);
11186 }
11187
11188 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
11189 {
11190         alc269_speaker_automute(codec);
11191         alc269_eeepc_amic_automute(codec);
11192 }
11193
11194 /* add playback controls from the parsed DAC table */
11195 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
11196                                              const struct auto_pin_cfg *cfg)
11197 {
11198         hda_nid_t nid;
11199         int err;
11200
11201         spec->multiout.num_dacs = 1;    /* only use one dac */
11202         spec->multiout.dac_nids = spec->private_dac_nids;
11203         spec->multiout.dac_nids[0] = 2;
11204
11205         nid = cfg->line_out_pins[0];
11206         if (nid) {
11207                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
11208                                   "Front Playback Volume",
11209                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
11210                 if (err < 0)
11211                         return err;
11212                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11213                                   "Front Playback Switch",
11214                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
11215                 if (err < 0)
11216                         return err;
11217         }
11218
11219         nid = cfg->speaker_pins[0];
11220         if (nid) {
11221                 if (!cfg->line_out_pins[0]) {
11222                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11223                                           "Speaker Playback Volume",
11224                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
11225                                                               HDA_OUTPUT));
11226                         if (err < 0)
11227                                 return err;
11228                 }
11229                 if (nid == 0x16) {
11230                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11231                                           "Speaker Playback Switch",
11232                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
11233                                                               HDA_OUTPUT));
11234                         if (err < 0)
11235                                 return err;
11236                 } else {
11237                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11238                                           "Speaker Playback Switch",
11239                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
11240                                                               HDA_OUTPUT));
11241                         if (err < 0)
11242                                 return err;
11243                 }
11244         }
11245         nid = cfg->hp_pins[0];
11246         if (nid) {
11247                 /* spec->multiout.hp_nid = 2; */
11248                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
11249                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11250                                           "Headphone Playback Volume",
11251                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
11252                                                               HDA_OUTPUT));
11253                         if (err < 0)
11254                                 return err;
11255                 }
11256                 if (nid == 0x16) {
11257                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11258                                           "Headphone Playback Switch",
11259                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
11260                                                               HDA_OUTPUT));
11261                         if (err < 0)
11262                                 return err;
11263                 } else {
11264                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11265                                           "Headphone Playback Switch",
11266                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
11267                                                               HDA_OUTPUT));
11268                         if (err < 0)
11269                                 return err;
11270                 }
11271         }
11272         return 0;
11273 }
11274
11275 #define alc269_auto_create_analog_input_ctls \
11276         alc880_auto_create_analog_input_ctls
11277
11278 #ifdef CONFIG_SND_HDA_POWER_SAVE
11279 #define alc269_loopbacks        alc880_loopbacks
11280 #endif
11281
11282 /* pcm configuration: identiacal with ALC880 */
11283 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
11284 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
11285 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
11286 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
11287
11288 /*
11289  * BIOS auto configuration
11290  */
11291 static int alc269_parse_auto_config(struct hda_codec *codec)
11292 {
11293         struct alc_spec *spec = codec->spec;
11294         int err;
11295         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
11296
11297         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11298                                            alc269_ignore);
11299         if (err < 0)
11300                 return err;
11301
11302         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
11303         if (err < 0)
11304                 return err;
11305         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
11306         if (err < 0)
11307                 return err;
11308
11309         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11310
11311         if (spec->autocfg.dig_out_pin)
11312                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
11313
11314         if (spec->kctl_alloc)
11315                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
11316
11317         spec->init_verbs[spec->num_init_verbs++] = alc269_init_verbs;
11318         spec->num_mux_defs = 1;
11319         spec->input_mux = &spec->private_imux;
11320
11321         err = alc_auto_add_mic_boost(codec);
11322         if (err < 0)
11323                 return err;
11324
11325         spec->mixers[spec->num_mixers] = alc269_capture_mixer;
11326         spec->num_mixers++;
11327
11328         return 1;
11329 }
11330
11331 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
11332 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
11333 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
11334
11335
11336 /* init callback for auto-configuration model -- overriding the default init */
11337 static void alc269_auto_init(struct hda_codec *codec)
11338 {
11339         struct alc_spec *spec = codec->spec;
11340         alc269_auto_init_multi_out(codec);
11341         alc269_auto_init_hp_out(codec);
11342         alc269_auto_init_analog_input(codec);
11343         if (spec->unsol_event)
11344                 alc_sku_automute(codec);
11345 }
11346
11347 /*
11348  * configuration and preset
11349  */
11350 static const char *alc269_models[ALC269_MODEL_LAST] = {
11351         [ALC269_BASIC]          = "basic",
11352 };
11353
11354 static struct snd_pci_quirk alc269_cfg_tbl[] = {
11355         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
11356                       ALC269_ASUS_EEEPC_P703),
11357         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
11358                       ALC269_ASUS_EEEPC_P901),
11359         {}
11360 };
11361
11362 static struct alc_config_preset alc269_presets[] = {
11363         [ALC269_BASIC] = {
11364                 .mixers = { alc269_base_mixer, alc269_capture_mixer },
11365                 .init_verbs = { alc269_init_verbs },
11366                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
11367                 .dac_nids = alc269_dac_nids,
11368                 .hp_nid = 0x03,
11369                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
11370                 .channel_mode = alc269_modes,
11371                 .input_mux = &alc269_capture_source,
11372         },
11373         [ALC269_ASUS_EEEPC_P703] = {
11374                 .mixers = { alc269_eeepc_mixer, alc269_epc_capture_mixer },
11375                 .init_verbs = { alc269_init_verbs,
11376                                 alc269_eeepc_amic_init_verbs },
11377                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
11378                 .dac_nids = alc269_dac_nids,
11379                 .hp_nid = 0x03,
11380                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
11381                 .channel_mode = alc269_modes,
11382                 .input_mux = &alc269_eeepc_amic_capture_source,
11383                 .unsol_event = alc269_eeepc_amic_unsol_event,
11384                 .init_hook = alc269_eeepc_amic_inithook,
11385         },
11386         [ALC269_ASUS_EEEPC_P901] = {
11387                 .mixers = { alc269_eeepc_mixer, alc269_epc_capture_mixer},
11388                 .init_verbs = { alc269_init_verbs,
11389                                 alc269_eeepc_dmic_init_verbs },
11390                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
11391                 .dac_nids = alc269_dac_nids,
11392                 .hp_nid = 0x03,
11393                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
11394                 .channel_mode = alc269_modes,
11395                 .input_mux = &alc269_eeepc_dmic_capture_source,
11396                 .unsol_event = alc269_eeepc_dmic_unsol_event,
11397                 .init_hook = alc269_eeepc_dmic_inithook,
11398         },
11399 };
11400
11401 static int patch_alc269(struct hda_codec *codec)
11402 {
11403         struct alc_spec *spec;
11404         int board_config;
11405         int err;
11406
11407         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11408         if (spec == NULL)
11409                 return -ENOMEM;
11410
11411         codec->spec = spec;
11412
11413         alc_fix_pll_init(codec, 0x20, 0x04, 15);
11414
11415         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
11416                                                   alc269_models,
11417                                                   alc269_cfg_tbl);
11418
11419         if (board_config < 0) {
11420                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
11421                        "trying auto-probe from BIOS...\n");
11422                 board_config = ALC269_AUTO;
11423         }
11424
11425         if (board_config == ALC269_AUTO) {
11426                 /* automatic parse from the BIOS config */
11427                 err = alc269_parse_auto_config(codec);
11428                 if (err < 0) {
11429                         alc_free(codec);
11430                         return err;
11431                 } else if (!err) {
11432                         printk(KERN_INFO
11433                                "hda_codec: Cannot set up configuration "
11434                                "from BIOS.  Using base mode...\n");
11435                         board_config = ALC269_BASIC;
11436                 }
11437         }
11438
11439         if (board_config != ALC269_AUTO)
11440                 setup_preset(spec, &alc269_presets[board_config]);
11441
11442         spec->stream_name_analog = "ALC269 Analog";
11443         spec->stream_analog_playback = &alc269_pcm_analog_playback;
11444         spec->stream_analog_capture = &alc269_pcm_analog_capture;
11445
11446         spec->stream_name_digital = "ALC269 Digital";
11447         spec->stream_digital_playback = &alc269_pcm_digital_playback;
11448         spec->stream_digital_capture = &alc269_pcm_digital_capture;
11449
11450         spec->adc_nids = alc269_adc_nids;
11451         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
11452
11453         codec->patch_ops = alc_patch_ops;
11454         if (board_config == ALC269_AUTO)
11455                 spec->init_hook = alc269_auto_init;
11456 #ifdef CONFIG_SND_HDA_POWER_SAVE
11457         if (!spec->loopback.amplist)
11458                 spec->loopback.amplist = alc269_loopbacks;
11459 #endif
11460
11461         return 0;
11462 }
11463
11464 /*
11465  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
11466  */
11467
11468 /*
11469  * set the path ways for 2 channel output
11470  * need to set the codec line out and mic 1 pin widgets to inputs
11471  */
11472 static struct hda_verb alc861_threestack_ch2_init[] = {
11473         /* set pin widget 1Ah (line in) for input */
11474         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11475         /* set pin widget 18h (mic1/2) for input, for mic also enable
11476          * the vref
11477          */
11478         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11479
11480         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
11481 #if 0
11482         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
11483         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
11484 #endif
11485         { } /* end */
11486 };
11487 /*
11488  * 6ch mode
11489  * need to set the codec line out and mic 1 pin widgets to outputs
11490  */
11491 static struct hda_verb alc861_threestack_ch6_init[] = {
11492         /* set pin widget 1Ah (line in) for output (Back Surround)*/
11493         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11494         /* set pin widget 18h (mic1) for output (CLFE)*/
11495         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11496
11497         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
11498         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
11499
11500         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
11501 #if 0
11502         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
11503         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
11504 #endif
11505         { } /* end */
11506 };
11507
11508 static struct hda_channel_mode alc861_threestack_modes[2] = {
11509         { 2, alc861_threestack_ch2_init },
11510         { 6, alc861_threestack_ch6_init },
11511 };
11512 /* Set mic1 as input and unmute the mixer */
11513 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
11514         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11515         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
11516         { } /* end */
11517 };
11518 /* Set mic1 as output and mute mixer */
11519 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
11520         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11521         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
11522         { } /* end */
11523 };
11524
11525 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
11526         { 2, alc861_uniwill_m31_ch2_init },
11527         { 4, alc861_uniwill_m31_ch4_init },
11528 };
11529
11530 /* Set mic1 and line-in as input and unmute the mixer */
11531 static struct hda_verb alc861_asus_ch2_init[] = {
11532         /* set pin widget 1Ah (line in) for input */
11533         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11534         /* set pin widget 18h (mic1/2) for input, for mic also enable
11535          * the vref
11536          */
11537         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11538
11539         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
11540 #if 0
11541         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
11542         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
11543 #endif
11544         { } /* end */
11545 };
11546 /* Set mic1 nad line-in as output and mute mixer */
11547 static struct hda_verb alc861_asus_ch6_init[] = {
11548         /* set pin widget 1Ah (line in) for output (Back Surround)*/
11549         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11550         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
11551         /* set pin widget 18h (mic1) for output (CLFE)*/
11552         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11553         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
11554         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
11555         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
11556
11557         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
11558 #if 0
11559         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
11560         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
11561 #endif
11562         { } /* end */
11563 };
11564
11565 static struct hda_channel_mode alc861_asus_modes[2] = {
11566         { 2, alc861_asus_ch2_init },
11567         { 6, alc861_asus_ch6_init },
11568 };
11569
11570 /* patch-ALC861 */
11571
11572 static struct snd_kcontrol_new alc861_base_mixer[] = {
11573         /* output mixer control */
11574         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11575         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11576         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11577         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11578         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
11579
11580         /*Input mixer control */
11581         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11582            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11583         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11584         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11585         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11586         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11587         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11588         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11589         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11590         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11591
11592         /* Capture mixer control */
11593         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11594         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11595         {
11596                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11597                 .name = "Capture Source",
11598                 .count = 1,
11599                 .info = alc_mux_enum_info,
11600                 .get = alc_mux_enum_get,
11601                 .put = alc_mux_enum_put,
11602         },
11603         { } /* end */
11604 };
11605
11606 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
11607         /* output mixer control */
11608         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11609         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11610         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11611         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11612         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
11613
11614         /* Input mixer control */
11615         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11616            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11617         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11618         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11619         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11620         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11621         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11622         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11623         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11624         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11625
11626         /* Capture mixer control */
11627         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11628         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11629         {
11630                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11631                 .name = "Capture Source",
11632                 .count = 1,
11633                 .info = alc_mux_enum_info,
11634                 .get = alc_mux_enum_get,
11635                 .put = alc_mux_enum_put,
11636         },
11637         {
11638                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11639                 .name = "Channel Mode",
11640                 .info = alc_ch_mode_info,
11641                 .get = alc_ch_mode_get,
11642                 .put = alc_ch_mode_put,
11643                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
11644         },
11645         { } /* end */
11646 };
11647
11648 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
11649         /* output mixer control */
11650         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11651         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11652         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11653         
11654         /*Capture mixer control */
11655         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11656         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11657         {
11658                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11659                 .name = "Capture Source",
11660                 .count = 1,
11661                 .info = alc_mux_enum_info,
11662                 .get = alc_mux_enum_get,
11663                 .put = alc_mux_enum_put,
11664         },
11665
11666         { } /* end */
11667 };
11668
11669 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
11670         /* output mixer control */
11671         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11672         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11673         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11674         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11675         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
11676
11677         /* Input mixer control */
11678         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11679            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11680         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11681         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11682         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11683         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11684         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11685         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11686         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11687         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11688
11689         /* Capture mixer control */
11690         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11691         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11692         {
11693                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11694                 .name = "Capture Source",
11695                 .count = 1,
11696                 .info = alc_mux_enum_info,
11697                 .get = alc_mux_enum_get,
11698                 .put = alc_mux_enum_put,
11699         },
11700         {
11701                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11702                 .name = "Channel Mode",
11703                 .info = alc_ch_mode_info,
11704                 .get = alc_ch_mode_get,
11705                 .put = alc_ch_mode_put,
11706                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
11707         },
11708         { } /* end */
11709 };
11710
11711 static struct snd_kcontrol_new alc861_asus_mixer[] = {
11712         /* output mixer control */
11713         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11714         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11715         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11716         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11717         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
11718
11719         /* Input mixer control */
11720         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11721         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11722         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11723         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11724         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11725         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11726         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11727         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11728         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11729         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
11730
11731         /* Capture mixer control */
11732         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11733         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11734         {
11735                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11736                 .name = "Capture Source",
11737                 .count = 1,
11738                 .info = alc_mux_enum_info,
11739                 .get = alc_mux_enum_get,
11740                 .put = alc_mux_enum_put,
11741         },
11742         {
11743                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11744                 .name = "Channel Mode",
11745                 .info = alc_ch_mode_info,
11746                 .get = alc_ch_mode_get,
11747                 .put = alc_ch_mode_put,
11748                 .private_value = ARRAY_SIZE(alc861_asus_modes),
11749         },
11750         { }
11751 };
11752
11753 /* additional mixer */
11754 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
11755         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11756         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11757         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
11758         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
11759         { }
11760 };
11761
11762 /*
11763  * generic initialization of ADC, input mixers and output mixers
11764  */
11765 static struct hda_verb alc861_base_init_verbs[] = {
11766         /*
11767          * Unmute ADC0 and set the default input to mic-in
11768          */
11769         /* port-A for surround (rear panel) */
11770         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11771         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
11772         /* port-B for mic-in (rear panel) with vref */
11773         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11774         /* port-C for line-in (rear panel) */
11775         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11776         /* port-D for Front */
11777         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11778         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11779         /* port-E for HP out (front panel) */
11780         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
11781         /* route front PCM to HP */
11782         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11783         /* port-F for mic-in (front panel) with vref */
11784         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11785         /* port-G for CLFE (rear panel) */
11786         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11787         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11788         /* port-H for side (rear panel) */
11789         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11790         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
11791         /* CD-in */
11792         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11793         /* route front mic to ADC1*/
11794         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11795         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11796         
11797         /* Unmute DAC0~3 & spdif out*/
11798         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11799         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11800         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11801         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11802         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11803         
11804         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11805         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11806         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11807         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11808         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11809         
11810         /* Unmute Stereo Mixer 15 */
11811         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11812         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11813         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11814         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
11815
11816         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11817         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11818         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11819         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11820         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11821         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11822         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11823         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11824         /* hp used DAC 3 (Front) */
11825         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11826         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11827
11828         { }
11829 };
11830
11831 static struct hda_verb alc861_threestack_init_verbs[] = {
11832         /*
11833          * Unmute ADC0 and set the default input to mic-in
11834          */
11835         /* port-A for surround (rear panel) */
11836         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11837         /* port-B for mic-in (rear panel) with vref */
11838         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11839         /* port-C for line-in (rear panel) */
11840         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11841         /* port-D for Front */
11842         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11843         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11844         /* port-E for HP out (front panel) */
11845         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
11846         /* route front PCM to HP */
11847         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11848         /* port-F for mic-in (front panel) with vref */
11849         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11850         /* port-G for CLFE (rear panel) */
11851         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11852         /* port-H for side (rear panel) */
11853         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11854         /* CD-in */
11855         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11856         /* route front mic to ADC1*/
11857         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11858         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11859         /* Unmute DAC0~3 & spdif out*/
11860         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11861         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11862         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11863         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11864         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11865         
11866         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11867         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11868         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11869         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11870         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11871         
11872         /* Unmute Stereo Mixer 15 */
11873         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11874         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11875         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11876         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
11877
11878         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11879         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11880         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11881         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11882         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11883         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11884         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11885         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11886         /* hp used DAC 3 (Front) */
11887         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11888         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11889         { }
11890 };
11891
11892 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
11893         /*
11894          * Unmute ADC0 and set the default input to mic-in
11895          */
11896         /* port-A for surround (rear panel) */
11897         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11898         /* port-B for mic-in (rear panel) with vref */
11899         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11900         /* port-C for line-in (rear panel) */
11901         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11902         /* port-D for Front */
11903         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11904         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11905         /* port-E for HP out (front panel) */
11906         /* this has to be set to VREF80 */
11907         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11908         /* route front PCM to HP */
11909         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11910         /* port-F for mic-in (front panel) with vref */
11911         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11912         /* port-G for CLFE (rear panel) */
11913         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11914         /* port-H for side (rear panel) */
11915         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11916         /* CD-in */
11917         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11918         /* route front mic to ADC1*/
11919         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11920         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11921         /* Unmute DAC0~3 & spdif out*/
11922         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11923         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11924         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11925         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11926         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11927         
11928         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11929         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11930         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11931         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11932         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11933         
11934         /* Unmute Stereo Mixer 15 */
11935         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11936         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11937         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11938         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
11939
11940         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11941         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11942         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11943         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11944         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11945         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11946         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11947         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11948         /* hp used DAC 3 (Front) */
11949         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11950         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11951         { }
11952 };
11953
11954 static struct hda_verb alc861_asus_init_verbs[] = {
11955         /*
11956          * Unmute ADC0 and set the default input to mic-in
11957          */
11958         /* port-A for surround (rear panel)
11959          * according to codec#0 this is the HP jack
11960          */
11961         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
11962         /* route front PCM to HP */
11963         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
11964         /* port-B for mic-in (rear panel) with vref */
11965         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11966         /* port-C for line-in (rear panel) */
11967         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11968         /* port-D for Front */
11969         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11970         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11971         /* port-E for HP out (front panel) */
11972         /* this has to be set to VREF80 */
11973         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11974         /* route front PCM to HP */
11975         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11976         /* port-F for mic-in (front panel) with vref */
11977         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11978         /* port-G for CLFE (rear panel) */
11979         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11980         /* port-H for side (rear panel) */
11981         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11982         /* CD-in */
11983         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11984         /* route front mic to ADC1*/
11985         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11986         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11987         /* Unmute DAC0~3 & spdif out*/
11988         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11989         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11990         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11991         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11992         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11993         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11994         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11995         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11996         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11997         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11998         
11999         /* Unmute Stereo Mixer 15 */
12000         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12001         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12002         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12003         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12004
12005         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12006         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12007         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12008         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12009         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12010         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12011         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12012         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12013         /* hp used DAC 3 (Front) */
12014         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12015         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12016         { }
12017 };
12018
12019 /* additional init verbs for ASUS laptops */
12020 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
12021         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
12022         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
12023         { }
12024 };
12025
12026 /*
12027  * generic initialization of ADC, input mixers and output mixers
12028  */
12029 static struct hda_verb alc861_auto_init_verbs[] = {
12030         /*
12031          * Unmute ADC0 and set the default input to mic-in
12032          */
12033         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
12034         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12035         
12036         /* Unmute DAC0~3 & spdif out*/
12037         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12038         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12039         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12040         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12041         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12042         
12043         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12044         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12045         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12046         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12047         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12048         
12049         /* Unmute Stereo Mixer 15 */
12050         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12051         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12052         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12053         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
12054
12055         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12056         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12057         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12058         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12059         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12060         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12061         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12062         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12063
12064         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12065         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12066         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12067         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12068         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12069         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12070         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12071         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12072
12073         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
12074
12075         { }
12076 };
12077
12078 static struct hda_verb alc861_toshiba_init_verbs[] = {
12079         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12080
12081         { }
12082 };
12083
12084 /* toggle speaker-output according to the hp-jack state */
12085 static void alc861_toshiba_automute(struct hda_codec *codec)
12086 {
12087         unsigned int present;
12088
12089         present = snd_hda_codec_read(codec, 0x0f, 0,
12090                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12091         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
12092                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
12093         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
12094                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
12095 }
12096
12097 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
12098                                        unsigned int res)
12099 {
12100         if ((res >> 26) == ALC880_HP_EVENT)
12101                 alc861_toshiba_automute(codec);
12102 }
12103
12104 /* pcm configuration: identiacal with ALC880 */
12105 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
12106 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
12107 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
12108 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
12109
12110
12111 #define ALC861_DIGOUT_NID       0x07
12112
12113 static struct hda_channel_mode alc861_8ch_modes[1] = {
12114         { 8, NULL }
12115 };
12116
12117 static hda_nid_t alc861_dac_nids[4] = {
12118         /* front, surround, clfe, side */
12119         0x03, 0x06, 0x05, 0x04
12120 };
12121
12122 static hda_nid_t alc660_dac_nids[3] = {
12123         /* front, clfe, surround */
12124         0x03, 0x05, 0x06
12125 };
12126
12127 static hda_nid_t alc861_adc_nids[1] = {
12128         /* ADC0-2 */
12129         0x08,
12130 };
12131
12132 static struct hda_input_mux alc861_capture_source = {
12133         .num_items = 5,
12134         .items = {
12135                 { "Mic", 0x0 },
12136                 { "Front Mic", 0x3 },
12137                 { "Line", 0x1 },
12138                 { "CD", 0x4 },
12139                 { "Mixer", 0x5 },
12140         },
12141 };
12142
12143 /* fill in the dac_nids table from the parsed pin configuration */
12144 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
12145                                      const struct auto_pin_cfg *cfg)
12146 {
12147         int i;
12148         hda_nid_t nid;
12149
12150         spec->multiout.dac_nids = spec->private_dac_nids;
12151         for (i = 0; i < cfg->line_outs; i++) {
12152                 nid = cfg->line_out_pins[i];
12153                 if (nid) {
12154                         if (i >= ARRAY_SIZE(alc861_dac_nids))
12155                                 continue;
12156                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
12157                 }
12158         }
12159         spec->multiout.num_dacs = cfg->line_outs;
12160         return 0;
12161 }
12162
12163 /* add playback controls from the parsed DAC table */
12164 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
12165                                              const struct auto_pin_cfg *cfg)
12166 {
12167         char name[32];
12168         static const char *chname[4] = {
12169                 "Front", "Surround", NULL /*CLFE*/, "Side"
12170         };
12171         hda_nid_t nid;
12172         int i, idx, err;
12173
12174         for (i = 0; i < cfg->line_outs; i++) {
12175                 nid = spec->multiout.dac_nids[i];
12176                 if (!nid)
12177                         continue;
12178                 if (nid == 0x05) {
12179                         /* Center/LFE */
12180                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12181                                           "Center Playback Switch",
12182                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
12183                                                               HDA_OUTPUT));
12184                         if (err < 0)
12185                                 return err;
12186                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12187                                           "LFE Playback Switch",
12188                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12189                                                               HDA_OUTPUT));
12190                         if (err < 0)
12191                                 return err;
12192                 } else {
12193                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
12194                              idx++)
12195                                 if (nid == alc861_dac_nids[idx])
12196                                         break;
12197                         sprintf(name, "%s Playback Switch", chname[idx]);
12198                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
12199                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12200                                                               HDA_OUTPUT));
12201                         if (err < 0)
12202                                 return err;
12203                 }
12204         }
12205         return 0;
12206 }
12207
12208 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
12209 {
12210         int err;
12211         hda_nid_t nid;
12212
12213         if (!pin)
12214                 return 0;
12215
12216         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
12217                 nid = 0x03;
12218                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12219                                   "Headphone Playback Switch",
12220                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12221                 if (err < 0)
12222                         return err;
12223                 spec->multiout.hp_nid = nid;
12224         }
12225         return 0;
12226 }
12227
12228 /* create playback/capture controls for input pins */
12229 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
12230                                                 const struct auto_pin_cfg *cfg)
12231 {
12232         struct hda_input_mux *imux = &spec->private_imux;
12233         int i, err, idx, idx1;
12234
12235         for (i = 0; i < AUTO_PIN_LAST; i++) {
12236                 switch (cfg->input_pins[i]) {
12237                 case 0x0c:
12238                         idx1 = 1;
12239                         idx = 2;        /* Line In */
12240                         break;
12241                 case 0x0f:
12242                         idx1 = 2;
12243                         idx = 2;        /* Line In */
12244                         break;
12245                 case 0x0d:
12246                         idx1 = 0;
12247                         idx = 1;        /* Mic In */
12248                         break;
12249                 case 0x10:
12250                         idx1 = 3;
12251                         idx = 1;        /* Mic In */
12252                         break;
12253                 case 0x11:
12254                         idx1 = 4;
12255                         idx = 0;        /* CD */
12256                         break;
12257                 default:
12258                         continue;
12259                 }
12260
12261                 err = new_analog_input(spec, cfg->input_pins[i],
12262                                        auto_pin_cfg_labels[i], idx, 0x15);
12263                 if (err < 0)
12264                         return err;
12265
12266                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
12267                 imux->items[imux->num_items].index = idx1;
12268                 imux->num_items++;
12269         }
12270         return 0;
12271 }
12272
12273 static struct snd_kcontrol_new alc861_capture_mixer[] = {
12274         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12275         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12276
12277         {
12278                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12279                 /* The multiple "Capture Source" controls confuse alsamixer
12280                  * So call somewhat different..
12281                  */
12282                 /* .name = "Capture Source", */
12283                 .name = "Input Source",
12284                 .count = 1,
12285                 .info = alc_mux_enum_info,
12286                 .get = alc_mux_enum_get,
12287                 .put = alc_mux_enum_put,
12288         },
12289         { } /* end */
12290 };
12291
12292 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
12293                                               hda_nid_t nid,
12294                                               int pin_type, int dac_idx)
12295 {
12296         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
12297                             pin_type);
12298         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12299                             AMP_OUT_UNMUTE);
12300 }
12301
12302 static void alc861_auto_init_multi_out(struct hda_codec *codec)
12303 {
12304         struct alc_spec *spec = codec->spec;
12305         int i;
12306
12307         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
12308         for (i = 0; i < spec->autocfg.line_outs; i++) {
12309                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
12310                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
12311                 if (nid)
12312                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
12313                                                           spec->multiout.dac_nids[i]);
12314         }
12315 }
12316
12317 static void alc861_auto_init_hp_out(struct hda_codec *codec)
12318 {
12319         struct alc_spec *spec = codec->spec;
12320         hda_nid_t pin;
12321
12322         pin = spec->autocfg.hp_pins[0];
12323         if (pin) /* connect to front */
12324                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
12325                                                   spec->multiout.dac_nids[0]);
12326         pin = spec->autocfg.speaker_pins[0];
12327         if (pin)
12328                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
12329 }
12330
12331 static void alc861_auto_init_analog_input(struct hda_codec *codec)
12332 {
12333         struct alc_spec *spec = codec->spec;
12334         int i;
12335
12336         for (i = 0; i < AUTO_PIN_LAST; i++) {
12337                 hda_nid_t nid = spec->autocfg.input_pins[i];
12338                 if (nid >= 0x0c && nid <= 0x11) {
12339                         snd_hda_codec_write(codec, nid, 0,
12340                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
12341                                             i <= AUTO_PIN_FRONT_MIC ?
12342                                             PIN_VREF80 : PIN_IN);
12343                 }
12344         }
12345 }
12346
12347 /* parse the BIOS configuration and set up the alc_spec */
12348 /* return 1 if successful, 0 if the proper config is not found,
12349  * or a negative error code
12350  */
12351 static int alc861_parse_auto_config(struct hda_codec *codec)
12352 {
12353         struct alc_spec *spec = codec->spec;
12354         int err;
12355         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
12356
12357         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12358                                            alc861_ignore);
12359         if (err < 0)
12360                 return err;
12361         if (!spec->autocfg.line_outs)
12362                 return 0; /* can't find valid BIOS pin config */
12363
12364         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
12365         if (err < 0)
12366                 return err;
12367         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
12368         if (err < 0)
12369                 return err;
12370         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
12371         if (err < 0)
12372                 return err;
12373         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
12374         if (err < 0)
12375                 return err;
12376
12377         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12378
12379         if (spec->autocfg.dig_out_pin)
12380                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
12381
12382         if (spec->kctl_alloc)
12383                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
12384
12385         spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs;
12386
12387         spec->num_mux_defs = 1;
12388         spec->input_mux = &spec->private_imux;
12389
12390         spec->adc_nids = alc861_adc_nids;
12391         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
12392         spec->mixers[spec->num_mixers] = alc861_capture_mixer;
12393         spec->num_mixers++;
12394
12395         return 1;
12396 }
12397
12398 /* additional initialization for auto-configuration model */
12399 static void alc861_auto_init(struct hda_codec *codec)
12400 {
12401         struct alc_spec *spec = codec->spec;
12402         alc861_auto_init_multi_out(codec);
12403         alc861_auto_init_hp_out(codec);
12404         alc861_auto_init_analog_input(codec);
12405         if (spec->unsol_event)
12406                 alc_sku_automute(codec);
12407 }
12408
12409 #ifdef CONFIG_SND_HDA_POWER_SAVE
12410 static struct hda_amp_list alc861_loopbacks[] = {
12411         { 0x15, HDA_INPUT, 0 },
12412         { 0x15, HDA_INPUT, 1 },
12413         { 0x15, HDA_INPUT, 2 },
12414         { 0x15, HDA_INPUT, 3 },
12415         { } /* end */
12416 };
12417 #endif
12418
12419
12420 /*
12421  * configuration and preset
12422  */
12423 static const char *alc861_models[ALC861_MODEL_LAST] = {
12424         [ALC861_3ST]            = "3stack",
12425         [ALC660_3ST]            = "3stack-660",
12426         [ALC861_3ST_DIG]        = "3stack-dig",
12427         [ALC861_6ST_DIG]        = "6stack-dig",
12428         [ALC861_UNIWILL_M31]    = "uniwill-m31",
12429         [ALC861_TOSHIBA]        = "toshiba",
12430         [ALC861_ASUS]           = "asus",
12431         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
12432         [ALC861_AUTO]           = "auto",
12433 };
12434
12435 static struct snd_pci_quirk alc861_cfg_tbl[] = {
12436         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
12437         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
12438         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
12439         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
12440         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
12441         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
12442         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
12443         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
12444          *        Any other models that need this preset?
12445          */
12446         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
12447         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
12448         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
12449         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
12450         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
12451         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
12452         /* FIXME: the below seems conflict */
12453         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
12454         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
12455         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
12456         {}
12457 };
12458
12459 static struct alc_config_preset alc861_presets[] = {
12460         [ALC861_3ST] = {
12461                 .mixers = { alc861_3ST_mixer },
12462                 .init_verbs = { alc861_threestack_init_verbs },
12463                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12464                 .dac_nids = alc861_dac_nids,
12465                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
12466                 .channel_mode = alc861_threestack_modes,
12467                 .need_dac_fix = 1,
12468                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12469                 .adc_nids = alc861_adc_nids,
12470                 .input_mux = &alc861_capture_source,
12471         },
12472         [ALC861_3ST_DIG] = {
12473                 .mixers = { alc861_base_mixer },
12474                 .init_verbs = { alc861_threestack_init_verbs },
12475                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12476                 .dac_nids = alc861_dac_nids,
12477                 .dig_out_nid = ALC861_DIGOUT_NID,
12478                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
12479                 .channel_mode = alc861_threestack_modes,
12480                 .need_dac_fix = 1,
12481                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12482                 .adc_nids = alc861_adc_nids,
12483                 .input_mux = &alc861_capture_source,
12484         },
12485         [ALC861_6ST_DIG] = {
12486                 .mixers = { alc861_base_mixer },
12487                 .init_verbs = { alc861_base_init_verbs },
12488                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12489                 .dac_nids = alc861_dac_nids,
12490                 .dig_out_nid = ALC861_DIGOUT_NID,
12491                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
12492                 .channel_mode = alc861_8ch_modes,
12493                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12494                 .adc_nids = alc861_adc_nids,
12495                 .input_mux = &alc861_capture_source,
12496         },
12497         [ALC660_3ST] = {
12498                 .mixers = { alc861_3ST_mixer },
12499                 .init_verbs = { alc861_threestack_init_verbs },
12500                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
12501                 .dac_nids = alc660_dac_nids,
12502                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
12503                 .channel_mode = alc861_threestack_modes,
12504                 .need_dac_fix = 1,
12505                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12506                 .adc_nids = alc861_adc_nids,
12507                 .input_mux = &alc861_capture_source,
12508         },
12509         [ALC861_UNIWILL_M31] = {
12510                 .mixers = { alc861_uniwill_m31_mixer },
12511                 .init_verbs = { alc861_uniwill_m31_init_verbs },
12512                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12513                 .dac_nids = alc861_dac_nids,
12514                 .dig_out_nid = ALC861_DIGOUT_NID,
12515                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
12516                 .channel_mode = alc861_uniwill_m31_modes,
12517                 .need_dac_fix = 1,
12518                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12519                 .adc_nids = alc861_adc_nids,
12520                 .input_mux = &alc861_capture_source,
12521         },
12522         [ALC861_TOSHIBA] = {
12523                 .mixers = { alc861_toshiba_mixer },
12524                 .init_verbs = { alc861_base_init_verbs,
12525                                 alc861_toshiba_init_verbs },
12526                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12527                 .dac_nids = alc861_dac_nids,
12528                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
12529                 .channel_mode = alc883_3ST_2ch_modes,
12530                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12531                 .adc_nids = alc861_adc_nids,
12532                 .input_mux = &alc861_capture_source,
12533                 .unsol_event = alc861_toshiba_unsol_event,
12534                 .init_hook = alc861_toshiba_automute,
12535         },
12536         [ALC861_ASUS] = {
12537                 .mixers = { alc861_asus_mixer },
12538                 .init_verbs = { alc861_asus_init_verbs },
12539                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12540                 .dac_nids = alc861_dac_nids,
12541                 .dig_out_nid = ALC861_DIGOUT_NID,
12542                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
12543                 .channel_mode = alc861_asus_modes,
12544                 .need_dac_fix = 1,
12545                 .hp_nid = 0x06,
12546                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12547                 .adc_nids = alc861_adc_nids,
12548                 .input_mux = &alc861_capture_source,
12549         },
12550         [ALC861_ASUS_LAPTOP] = {
12551                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
12552                 .init_verbs = { alc861_asus_init_verbs,
12553                                 alc861_asus_laptop_init_verbs },
12554                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12555                 .dac_nids = alc861_dac_nids,
12556                 .dig_out_nid = ALC861_DIGOUT_NID,
12557                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
12558                 .channel_mode = alc883_3ST_2ch_modes,
12559                 .need_dac_fix = 1,
12560                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12561                 .adc_nids = alc861_adc_nids,
12562                 .input_mux = &alc861_capture_source,
12563         },
12564 };
12565
12566
12567 static int patch_alc861(struct hda_codec *codec)
12568 {
12569         struct alc_spec *spec;
12570         int board_config;
12571         int err;
12572
12573         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12574         if (spec == NULL)
12575                 return -ENOMEM;
12576
12577         codec->spec = spec;
12578
12579         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
12580                                                   alc861_models,
12581                                                   alc861_cfg_tbl);
12582
12583         if (board_config < 0) {
12584                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
12585                        "trying auto-probe from BIOS...\n");
12586                 board_config = ALC861_AUTO;
12587         }
12588
12589         if (board_config == ALC861_AUTO) {
12590                 /* automatic parse from the BIOS config */
12591                 err = alc861_parse_auto_config(codec);
12592                 if (err < 0) {
12593                         alc_free(codec);
12594                         return err;
12595                 } else if (!err) {
12596                         printk(KERN_INFO
12597                                "hda_codec: Cannot set up configuration "
12598                                "from BIOS.  Using base mode...\n");
12599                    board_config = ALC861_3ST_DIG;
12600                 }
12601         }
12602
12603         if (board_config != ALC861_AUTO)
12604                 setup_preset(spec, &alc861_presets[board_config]);
12605
12606         spec->stream_name_analog = "ALC861 Analog";
12607         spec->stream_analog_playback = &alc861_pcm_analog_playback;
12608         spec->stream_analog_capture = &alc861_pcm_analog_capture;
12609
12610         spec->stream_name_digital = "ALC861 Digital";
12611         spec->stream_digital_playback = &alc861_pcm_digital_playback;
12612         spec->stream_digital_capture = &alc861_pcm_digital_capture;
12613
12614         spec->vmaster_nid = 0x03;
12615
12616         codec->patch_ops = alc_patch_ops;
12617         if (board_config == ALC861_AUTO)
12618                 spec->init_hook = alc861_auto_init;
12619 #ifdef CONFIG_SND_HDA_POWER_SAVE
12620         if (!spec->loopback.amplist)
12621                 spec->loopback.amplist = alc861_loopbacks;
12622 #endif
12623                 
12624         return 0;
12625 }
12626
12627 /*
12628  * ALC861-VD support
12629  *
12630  * Based on ALC882
12631  *
12632  * In addition, an independent DAC
12633  */
12634 #define ALC861VD_DIGOUT_NID     0x06
12635
12636 static hda_nid_t alc861vd_dac_nids[4] = {
12637         /* front, surr, clfe, side surr */
12638         0x02, 0x03, 0x04, 0x05
12639 };
12640
12641 /* dac_nids for ALC660vd are in a different order - according to
12642  * Realtek's driver.
12643  * This should probably tesult in a different mixer for 6stack models
12644  * of ALC660vd codecs, but for now there is only 3stack mixer
12645  * - and it is the same as in 861vd.
12646  * adc_nids in ALC660vd are (is) the same as in 861vd
12647  */
12648 static hda_nid_t alc660vd_dac_nids[3] = {
12649         /* front, rear, clfe, rear_surr */
12650         0x02, 0x04, 0x03
12651 };
12652
12653 static hda_nid_t alc861vd_adc_nids[1] = {
12654         /* ADC0 */
12655         0x09,
12656 };
12657
12658 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
12659
12660 /* input MUX */
12661 /* FIXME: should be a matrix-type input source selection */
12662 static struct hda_input_mux alc861vd_capture_source = {
12663         .num_items = 4,
12664         .items = {
12665                 { "Mic", 0x0 },
12666                 { "Front Mic", 0x1 },
12667                 { "Line", 0x2 },
12668                 { "CD", 0x4 },
12669         },
12670 };
12671
12672 static struct hda_input_mux alc861vd_dallas_capture_source = {
12673         .num_items = 2,
12674         .items = {
12675                 { "Ext Mic", 0x0 },
12676                 { "Int Mic", 0x1 },
12677         },
12678 };
12679
12680 static struct hda_input_mux alc861vd_hp_capture_source = {
12681         .num_items = 2,
12682         .items = {
12683                 { "Front Mic", 0x0 },
12684                 { "ATAPI Mic", 0x1 },
12685         },
12686 };
12687
12688 #define alc861vd_mux_enum_info alc_mux_enum_info
12689 #define alc861vd_mux_enum_get alc_mux_enum_get
12690 /* ALC861VD has the ALC882-type input selection (but has only one ADC) */
12691 #define alc861vd_mux_enum_put alc882_mux_enum_put
12692
12693 /*
12694  * 2ch mode
12695  */
12696 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
12697         { 2, NULL }
12698 };
12699
12700 /*
12701  * 6ch mode
12702  */
12703 static struct hda_verb alc861vd_6stack_ch6_init[] = {
12704         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12705         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12706         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12707         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12708         { } /* end */
12709 };
12710
12711 /*
12712  * 8ch mode
12713  */
12714 static struct hda_verb alc861vd_6stack_ch8_init[] = {
12715         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12716         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12717         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12718         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12719         { } /* end */
12720 };
12721
12722 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
12723         { 6, alc861vd_6stack_ch6_init },
12724         { 8, alc861vd_6stack_ch8_init },
12725 };
12726
12727 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
12728         {
12729                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12730                 .name = "Channel Mode",
12731                 .info = alc_ch_mode_info,
12732                 .get = alc_ch_mode_get,
12733                 .put = alc_ch_mode_put,
12734         },
12735         { } /* end */
12736 };
12737
12738 static struct snd_kcontrol_new alc861vd_capture_mixer[] = {
12739         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
12740         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
12741
12742         {
12743                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12744                 /* The multiple "Capture Source" controls confuse alsamixer
12745                  * So call somewhat different..
12746                  */
12747                 /* .name = "Capture Source", */
12748                 .name = "Input Source",
12749                 .count = 1,
12750                 .info = alc861vd_mux_enum_info,
12751                 .get = alc861vd_mux_enum_get,
12752                 .put = alc861vd_mux_enum_put,
12753         },
12754         { } /* end */
12755 };
12756
12757 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
12758  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
12759  */
12760 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
12761         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12762         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12763
12764         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12765         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
12766
12767         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
12768                                 HDA_OUTPUT),
12769         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
12770                                 HDA_OUTPUT),
12771         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
12772         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
12773
12774         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
12775         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
12776
12777         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12778
12779         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12780         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12781         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12782
12783         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12784         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12785         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12786
12787         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12788         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12789
12790         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12791         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12792
12793         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
12794         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
12795
12796         { } /* end */
12797 };
12798
12799 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
12800         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12801         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12802
12803         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12804
12805         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12806         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12807         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12808
12809         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12810         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12811         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12812
12813         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12814         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12815
12816         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12817         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12818
12819         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
12820         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
12821
12822         { } /* end */
12823 };
12824
12825 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
12826         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12827         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
12828         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12829
12830         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12831
12832         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12833         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12834         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12835
12836         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12837         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12838         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12839
12840         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12841         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12842
12843         { } /* end */
12844 };
12845
12846 /* Pin assignment: Speaker=0x14, HP = 0x15,
12847  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
12848  */
12849 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
12850         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12851         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
12852         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12853         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
12854         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
12855         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12856         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12857         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
12858         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12859         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12860         HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
12861         HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
12862         { } /* end */
12863 };
12864
12865 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
12866  *                 Front Mic=0x18, ATAPI Mic = 0x19,
12867  */
12868 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
12869         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12870         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12871         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12872         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
12873         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12874         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12875         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12876         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12877         
12878         { } /* end */
12879 };
12880
12881 /*
12882  * generic initialization of ADC, input mixers and output mixers
12883  */
12884 static struct hda_verb alc861vd_volume_init_verbs[] = {
12885         /*
12886          * Unmute ADC0 and set the default input to mic-in
12887          */
12888         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
12889         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12890
12891         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
12892          * the analog-loopback mixer widget
12893          */
12894         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12895         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12896         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12897         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12898         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12899         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12900
12901         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
12902         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12903         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12904         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12905         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
12906
12907         /*
12908          * Set up output mixers (0x02 - 0x05)
12909          */
12910         /* set vol=0 to output mixers */
12911         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12912         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12913         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12914         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12915
12916         /* set up input amps for analog loopback */
12917         /* Amp Indices: DAC = 0, mixer = 1 */
12918         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12919         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12920         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12921         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12922         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12923         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12924         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12925         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12926
12927         { }
12928 };
12929
12930 /*
12931  * 3-stack pin configuration:
12932  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
12933  */
12934 static struct hda_verb alc861vd_3stack_init_verbs[] = {
12935         /*
12936          * Set pin mode and muting
12937          */
12938         /* set front pin widgets 0x14 for output */
12939         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12940         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12941         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12942
12943         /* Mic (rear) pin: input vref at 80% */
12944         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12945         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12946         /* Front Mic pin: input vref at 80% */
12947         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12948         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12949         /* Line In pin: input */
12950         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12951         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12952         /* Line-2 In: Headphone output (output 0 - 0x0c) */
12953         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12954         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12955         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
12956         /* CD pin widget for input */
12957         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12958
12959         { }
12960 };
12961
12962 /*
12963  * 6-stack pin configuration:
12964  */
12965 static struct hda_verb alc861vd_6stack_init_verbs[] = {
12966         /*
12967          * Set pin mode and muting
12968          */
12969         /* set front pin widgets 0x14 for output */
12970         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12971         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12972         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12973
12974         /* Rear Pin: output 1 (0x0d) */
12975         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12976         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12977         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12978         /* CLFE Pin: output 2 (0x0e) */
12979         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12980         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12981         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
12982         /* Side Pin: output 3 (0x0f) */
12983         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12984         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12985         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
12986
12987         /* Mic (rear) pin: input vref at 80% */
12988         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12989         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12990         /* Front Mic pin: input vref at 80% */
12991         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12992         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12993         /* Line In pin: input */
12994         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12995         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12996         /* Line-2 In: Headphone output (output 0 - 0x0c) */
12997         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12998         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12999         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13000         /* CD pin widget for input */
13001         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13002
13003         { }
13004 };
13005
13006 static struct hda_verb alc861vd_eapd_verbs[] = {
13007         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13008         { }
13009 };
13010
13011 static struct hda_verb alc660vd_eapd_verbs[] = {
13012         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13013         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
13014         { }
13015 };
13016
13017 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
13018         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13019         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13020         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
13021         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13022         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT}, 
13023         {}
13024 };
13025
13026 /* toggle speaker-output according to the hp-jack state */
13027 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
13028 {
13029         unsigned int present;
13030         unsigned char bits;
13031
13032         present = snd_hda_codec_read(codec, 0x1b, 0,
13033                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13034         bits = present ? HDA_AMP_MUTE : 0;
13035         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
13036                                  HDA_AMP_MUTE, bits);
13037 }
13038
13039 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
13040 {
13041         unsigned int present;
13042         unsigned char bits;
13043
13044         present = snd_hda_codec_read(codec, 0x18, 0,
13045                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13046         bits = present ? HDA_AMP_MUTE : 0;
13047         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
13048                                  HDA_AMP_MUTE, bits);
13049 }
13050
13051 static void alc861vd_lenovo_automute(struct hda_codec *codec)
13052 {
13053         alc861vd_lenovo_hp_automute(codec);
13054         alc861vd_lenovo_mic_automute(codec);
13055 }
13056
13057 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
13058                                         unsigned int res)
13059 {
13060         switch (res >> 26) {
13061         case ALC880_HP_EVENT:
13062                 alc861vd_lenovo_hp_automute(codec);
13063                 break;
13064         case ALC880_MIC_EVENT:
13065                 alc861vd_lenovo_mic_automute(codec);
13066                 break;
13067         }
13068 }
13069
13070 static struct hda_verb alc861vd_dallas_verbs[] = {
13071         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13072         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13073         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13074         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13075
13076         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13077         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13078         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13079         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13080         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13081         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13082         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13083         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13084         
13085         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13086         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13087         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13088         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13089         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13090         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13091         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13092         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13093
13094         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
13095         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13096         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
13097         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13098         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13099         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13100         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13101         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13102
13103         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13104         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13105         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13106         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13107
13108         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13109         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},  
13110         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13111
13112         { } /* end */
13113 };
13114
13115 /* toggle speaker-output according to the hp-jack state */
13116 static void alc861vd_dallas_automute(struct hda_codec *codec)
13117 {
13118         unsigned int present;
13119
13120         present = snd_hda_codec_read(codec, 0x15, 0,
13121                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13122         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
13123                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
13124 }
13125
13126 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
13127 {
13128         if ((res >> 26) == ALC880_HP_EVENT)
13129                 alc861vd_dallas_automute(codec);
13130 }
13131
13132 #ifdef CONFIG_SND_HDA_POWER_SAVE
13133 #define alc861vd_loopbacks      alc880_loopbacks
13134 #endif
13135
13136 /* pcm configuration: identiacal with ALC880 */
13137 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
13138 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
13139 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
13140 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
13141
13142 /*
13143  * configuration and preset
13144  */
13145 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
13146         [ALC660VD_3ST]          = "3stack-660",
13147         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
13148         [ALC861VD_3ST]          = "3stack",
13149         [ALC861VD_3ST_DIG]      = "3stack-digout",
13150         [ALC861VD_6ST_DIG]      = "6stack-digout",
13151         [ALC861VD_LENOVO]       = "lenovo",
13152         [ALC861VD_DALLAS]       = "dallas",
13153         [ALC861VD_HP]           = "hp",
13154         [ALC861VD_AUTO]         = "auto",
13155 };
13156
13157 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
13158         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
13159         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
13160         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
13161         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
13162         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC861VD_LENOVO),
13163         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
13164         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
13165         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
13166         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
13167         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
13168         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
13169         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
13170         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
13171         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
13172         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
13173         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 N200", ALC861VD_LENOVO),
13174         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
13175         {}
13176 };
13177
13178 static struct alc_config_preset alc861vd_presets[] = {
13179         [ALC660VD_3ST] = {
13180                 .mixers = { alc861vd_3st_mixer },
13181                 .init_verbs = { alc861vd_volume_init_verbs,
13182                                  alc861vd_3stack_init_verbs },
13183                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
13184                 .dac_nids = alc660vd_dac_nids,
13185                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13186                 .channel_mode = alc861vd_3stack_2ch_modes,
13187                 .input_mux = &alc861vd_capture_source,
13188         },
13189         [ALC660VD_3ST_DIG] = {
13190                 .mixers = { alc861vd_3st_mixer },
13191                 .init_verbs = { alc861vd_volume_init_verbs,
13192                                  alc861vd_3stack_init_verbs },
13193                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
13194                 .dac_nids = alc660vd_dac_nids,
13195                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13196                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13197                 .channel_mode = alc861vd_3stack_2ch_modes,
13198                 .input_mux = &alc861vd_capture_source,
13199         },
13200         [ALC861VD_3ST] = {
13201                 .mixers = { alc861vd_3st_mixer },
13202                 .init_verbs = { alc861vd_volume_init_verbs,
13203                                  alc861vd_3stack_init_verbs },
13204                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13205                 .dac_nids = alc861vd_dac_nids,
13206                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13207                 .channel_mode = alc861vd_3stack_2ch_modes,
13208                 .input_mux = &alc861vd_capture_source,
13209         },
13210         [ALC861VD_3ST_DIG] = {
13211                 .mixers = { alc861vd_3st_mixer },
13212                 .init_verbs = { alc861vd_volume_init_verbs,
13213                                  alc861vd_3stack_init_verbs },
13214                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13215                 .dac_nids = alc861vd_dac_nids,
13216                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13217                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13218                 .channel_mode = alc861vd_3stack_2ch_modes,
13219                 .input_mux = &alc861vd_capture_source,
13220         },
13221         [ALC861VD_6ST_DIG] = {
13222                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
13223                 .init_verbs = { alc861vd_volume_init_verbs,
13224                                 alc861vd_6stack_init_verbs },
13225                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13226                 .dac_nids = alc861vd_dac_nids,
13227                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13228                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
13229                 .channel_mode = alc861vd_6stack_modes,
13230                 .input_mux = &alc861vd_capture_source,
13231         },
13232         [ALC861VD_LENOVO] = {
13233                 .mixers = { alc861vd_lenovo_mixer },
13234                 .init_verbs = { alc861vd_volume_init_verbs,
13235                                 alc861vd_3stack_init_verbs,
13236                                 alc861vd_eapd_verbs,
13237                                 alc861vd_lenovo_unsol_verbs },
13238                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
13239                 .dac_nids = alc660vd_dac_nids,
13240                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13241                 .channel_mode = alc861vd_3stack_2ch_modes,
13242                 .input_mux = &alc861vd_capture_source,
13243                 .unsol_event = alc861vd_lenovo_unsol_event,
13244                 .init_hook = alc861vd_lenovo_automute,
13245         },
13246         [ALC861VD_DALLAS] = {
13247                 .mixers = { alc861vd_dallas_mixer },
13248                 .init_verbs = { alc861vd_dallas_verbs },
13249                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13250                 .dac_nids = alc861vd_dac_nids,
13251                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13252                 .channel_mode = alc861vd_3stack_2ch_modes,
13253                 .input_mux = &alc861vd_dallas_capture_source,
13254                 .unsol_event = alc861vd_dallas_unsol_event,
13255                 .init_hook = alc861vd_dallas_automute,
13256         },
13257         [ALC861VD_HP] = {
13258                 .mixers = { alc861vd_hp_mixer },
13259                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
13260                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13261                 .dac_nids = alc861vd_dac_nids,
13262                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13263                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13264                 .channel_mode = alc861vd_3stack_2ch_modes,
13265                 .input_mux = &alc861vd_hp_capture_source,
13266                 .unsol_event = alc861vd_dallas_unsol_event,
13267                 .init_hook = alc861vd_dallas_automute,
13268         },              
13269 };
13270
13271 /*
13272  * BIOS auto configuration
13273  */
13274 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
13275                                 hda_nid_t nid, int pin_type, int dac_idx)
13276 {
13277         alc_set_pin_output(codec, nid, pin_type);
13278 }
13279
13280 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
13281 {
13282         struct alc_spec *spec = codec->spec;
13283         int i;
13284
13285         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
13286         for (i = 0; i <= HDA_SIDE; i++) {
13287                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13288                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13289                 if (nid)
13290                         alc861vd_auto_set_output_and_unmute(codec, nid,
13291                                                             pin_type, i);
13292         }
13293 }
13294
13295
13296 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
13297 {
13298         struct alc_spec *spec = codec->spec;
13299         hda_nid_t pin;
13300
13301         pin = spec->autocfg.hp_pins[0];
13302         if (pin) /* connect to front and  use dac 0 */
13303                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
13304         pin = spec->autocfg.speaker_pins[0];
13305         if (pin)
13306                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13307 }
13308
13309 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
13310 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
13311
13312 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
13313 {
13314         struct alc_spec *spec = codec->spec;
13315         int i;
13316
13317         for (i = 0; i < AUTO_PIN_LAST; i++) {
13318                 hda_nid_t nid = spec->autocfg.input_pins[i];
13319                 if (alc861vd_is_input_pin(nid)) {
13320                         snd_hda_codec_write(codec, nid, 0,
13321                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
13322                                         i <= AUTO_PIN_FRONT_MIC ?
13323                                                         PIN_VREF80 : PIN_IN);
13324                         if (nid != ALC861VD_PIN_CD_NID)
13325                                 snd_hda_codec_write(codec, nid, 0,
13326                                                 AC_VERB_SET_AMP_GAIN_MUTE,
13327                                                 AMP_OUT_MUTE);
13328                 }
13329         }
13330 }
13331
13332 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
13333 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
13334
13335 /* add playback controls from the parsed DAC table */
13336 /* Based on ALC880 version. But ALC861VD has separate,
13337  * different NIDs for mute/unmute switch and volume control */
13338 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
13339                                              const struct auto_pin_cfg *cfg)
13340 {
13341         char name[32];
13342         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
13343         hda_nid_t nid_v, nid_s;
13344         int i, err;
13345
13346         for (i = 0; i < cfg->line_outs; i++) {
13347                 if (!spec->multiout.dac_nids[i])
13348                         continue;
13349                 nid_v = alc861vd_idx_to_mixer_vol(
13350                                 alc880_dac_to_idx(
13351                                         spec->multiout.dac_nids[i]));
13352                 nid_s = alc861vd_idx_to_mixer_switch(
13353                                 alc880_dac_to_idx(
13354                                         spec->multiout.dac_nids[i]));
13355
13356                 if (i == 2) {
13357                         /* Center/LFE */
13358                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13359                                           "Center Playback Volume",
13360                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
13361                                                               HDA_OUTPUT));
13362                         if (err < 0)
13363                                 return err;
13364                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13365                                           "LFE Playback Volume",
13366                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
13367                                                               HDA_OUTPUT));
13368                         if (err < 0)
13369                                 return err;
13370                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13371                                           "Center Playback Switch",
13372                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
13373                                                               HDA_INPUT));
13374                         if (err < 0)
13375                                 return err;
13376                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13377                                           "LFE Playback Switch",
13378                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
13379                                                               HDA_INPUT));
13380                         if (err < 0)
13381                                 return err;
13382                 } else {
13383                         sprintf(name, "%s Playback Volume", chname[i]);
13384                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
13385                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
13386                                                               HDA_OUTPUT));
13387                         if (err < 0)
13388                                 return err;
13389                         sprintf(name, "%s Playback Switch", chname[i]);
13390                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13391                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
13392                                                               HDA_INPUT));
13393                         if (err < 0)
13394                                 return err;
13395                 }
13396         }
13397         return 0;
13398 }
13399
13400 /* add playback controls for speaker and HP outputs */
13401 /* Based on ALC880 version. But ALC861VD has separate,
13402  * different NIDs for mute/unmute switch and volume control */
13403 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
13404                                         hda_nid_t pin, const char *pfx)
13405 {
13406         hda_nid_t nid_v, nid_s;
13407         int err;
13408         char name[32];
13409
13410         if (!pin)
13411                 return 0;
13412
13413         if (alc880_is_fixed_pin(pin)) {
13414                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
13415                 /* specify the DAC as the extra output */
13416                 if (!spec->multiout.hp_nid)
13417                         spec->multiout.hp_nid = nid_v;
13418                 else
13419                         spec->multiout.extra_out_nid[0] = nid_v;
13420                 /* control HP volume/switch on the output mixer amp */
13421                 nid_v = alc861vd_idx_to_mixer_vol(
13422                                 alc880_fixed_pin_idx(pin));
13423                 nid_s = alc861vd_idx_to_mixer_switch(
13424                                 alc880_fixed_pin_idx(pin));
13425
13426                 sprintf(name, "%s Playback Volume", pfx);
13427                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
13428                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
13429                 if (err < 0)
13430                         return err;
13431                 sprintf(name, "%s Playback Switch", pfx);
13432                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13433                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
13434                 if (err < 0)
13435                         return err;
13436         } else if (alc880_is_multi_pin(pin)) {
13437                 /* set manual connection */
13438                 /* we have only a switch on HP-out PIN */
13439                 sprintf(name, "%s Playback Switch", pfx);
13440                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
13441                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
13442                 if (err < 0)
13443                         return err;
13444         }
13445         return 0;
13446 }
13447
13448 /* parse the BIOS configuration and set up the alc_spec
13449  * return 1 if successful, 0 if the proper config is not found,
13450  * or a negative error code
13451  * Based on ALC880 version - had to change it to override
13452  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
13453 static int alc861vd_parse_auto_config(struct hda_codec *codec)
13454 {
13455         struct alc_spec *spec = codec->spec;
13456         int err;
13457         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
13458
13459         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13460                                            alc861vd_ignore);
13461         if (err < 0)
13462                 return err;
13463         if (!spec->autocfg.line_outs)
13464                 return 0; /* can't find valid BIOS pin config */
13465
13466         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
13467         if (err < 0)
13468                 return err;
13469         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
13470         if (err < 0)
13471                 return err;
13472         err = alc861vd_auto_create_extra_out(spec,
13473                                              spec->autocfg.speaker_pins[0],
13474                                              "Speaker");
13475         if (err < 0)
13476                 return err;
13477         err = alc861vd_auto_create_extra_out(spec,
13478                                              spec->autocfg.hp_pins[0],
13479                                              "Headphone");
13480         if (err < 0)
13481                 return err;
13482         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
13483         if (err < 0)
13484                 return err;
13485
13486         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13487
13488         if (spec->autocfg.dig_out_pin)
13489                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
13490
13491         if (spec->kctl_alloc)
13492                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
13493
13494         spec->init_verbs[spec->num_init_verbs++]
13495                 = alc861vd_volume_init_verbs;
13496
13497         spec->num_mux_defs = 1;
13498         spec->input_mux = &spec->private_imux;
13499
13500         err = alc_auto_add_mic_boost(codec);
13501         if (err < 0)
13502                 return err;
13503
13504         return 1;
13505 }
13506
13507 /* additional initialization for auto-configuration model */
13508 static void alc861vd_auto_init(struct hda_codec *codec)
13509 {
13510         struct alc_spec *spec = codec->spec;
13511         alc861vd_auto_init_multi_out(codec);
13512         alc861vd_auto_init_hp_out(codec);
13513         alc861vd_auto_init_analog_input(codec);
13514         if (spec->unsol_event)
13515                 alc_sku_automute(codec);
13516 }
13517
13518 static int patch_alc861vd(struct hda_codec *codec)
13519 {
13520         struct alc_spec *spec;
13521         int err, board_config;
13522
13523         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13524         if (spec == NULL)
13525                 return -ENOMEM;
13526
13527         codec->spec = spec;
13528
13529         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
13530                                                   alc861vd_models,
13531                                                   alc861vd_cfg_tbl);
13532
13533         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
13534                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
13535                         "ALC861VD, trying auto-probe from BIOS...\n");
13536                 board_config = ALC861VD_AUTO;
13537         }
13538
13539         if (board_config == ALC861VD_AUTO) {
13540                 /* automatic parse from the BIOS config */
13541                 err = alc861vd_parse_auto_config(codec);
13542                 if (err < 0) {
13543                         alc_free(codec);
13544                         return err;
13545                 } else if (!err) {
13546                         printk(KERN_INFO
13547                                "hda_codec: Cannot set up configuration "
13548                                "from BIOS.  Using base mode...\n");
13549                         board_config = ALC861VD_3ST;
13550                 }
13551         }
13552
13553         if (board_config != ALC861VD_AUTO)
13554                 setup_preset(spec, &alc861vd_presets[board_config]);
13555
13556         if (codec->vendor_id == 0x10ec0660) {
13557                 spec->stream_name_analog = "ALC660-VD Analog";
13558                 spec->stream_name_digital = "ALC660-VD Digital";
13559                 /* always turn on EAPD */
13560                 spec->init_verbs[spec->num_init_verbs++] = alc660vd_eapd_verbs;
13561         } else {
13562                 spec->stream_name_analog = "ALC861VD Analog";
13563                 spec->stream_name_digital = "ALC861VD Digital";
13564         }
13565
13566         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
13567         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
13568
13569         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
13570         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
13571
13572         spec->adc_nids = alc861vd_adc_nids;
13573         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
13574         spec->capsrc_nids = alc861vd_capsrc_nids;
13575
13576         spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
13577         spec->num_mixers++;
13578
13579         spec->vmaster_nid = 0x02;
13580
13581         codec->patch_ops = alc_patch_ops;
13582
13583         if (board_config == ALC861VD_AUTO)
13584                 spec->init_hook = alc861vd_auto_init;
13585 #ifdef CONFIG_SND_HDA_POWER_SAVE
13586         if (!spec->loopback.amplist)
13587                 spec->loopback.amplist = alc861vd_loopbacks;
13588 #endif
13589
13590         return 0;
13591 }
13592
13593 /*
13594  * ALC662 support
13595  *
13596  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
13597  * configuration.  Each pin widget can choose any input DACs and a mixer.
13598  * Each ADC is connected from a mixer of all inputs.  This makes possible
13599  * 6-channel independent captures.
13600  *
13601  * In addition, an independent DAC for the multi-playback (not used in this
13602  * driver yet).
13603  */
13604 #define ALC662_DIGOUT_NID       0x06
13605 #define ALC662_DIGIN_NID        0x0a
13606
13607 static hda_nid_t alc662_dac_nids[4] = {
13608         /* front, rear, clfe, rear_surr */
13609         0x02, 0x03, 0x04
13610 };
13611
13612 static hda_nid_t alc662_adc_nids[1] = {
13613         /* ADC1-2 */
13614         0x09,
13615 };
13616
13617 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
13618
13619 /* input MUX */
13620 /* FIXME: should be a matrix-type input source selection */
13621 static struct hda_input_mux alc662_capture_source = {
13622         .num_items = 4,
13623         .items = {
13624                 { "Mic", 0x0 },
13625                 { "Front Mic", 0x1 },
13626                 { "Line", 0x2 },
13627                 { "CD", 0x4 },
13628         },
13629 };
13630
13631 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
13632         .num_items = 2,
13633         .items = {
13634                 { "Mic", 0x1 },
13635                 { "Line", 0x2 },
13636         },
13637 };
13638
13639 static struct hda_input_mux alc662_eeepc_capture_source = {
13640         .num_items = 2,
13641         .items = {
13642                 { "i-Mic", 0x1 },
13643                 { "e-Mic", 0x0 },
13644         },
13645 };
13646
13647 static struct hda_input_mux alc663_capture_source = {
13648         .num_items = 3,
13649         .items = {
13650                 { "Mic", 0x0 },
13651                 { "Front Mic", 0x1 },
13652                 { "Line", 0x2 },
13653         },
13654 };
13655
13656 static struct hda_input_mux alc663_m51va_capture_source = {
13657         .num_items = 2,
13658         .items = {
13659                 { "Ext-Mic", 0x0 },
13660                 { "D-Mic", 0x9 },
13661         },
13662 };
13663
13664 #define alc662_mux_enum_info alc_mux_enum_info
13665 #define alc662_mux_enum_get alc_mux_enum_get
13666 #define alc662_mux_enum_put alc882_mux_enum_put
13667
13668 /*
13669  * 2ch mode
13670  */
13671 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
13672         { 2, NULL }
13673 };
13674
13675 /*
13676  * 2ch mode
13677  */
13678 static struct hda_verb alc662_3ST_ch2_init[] = {
13679         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
13680         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
13681         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
13682         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
13683         { } /* end */
13684 };
13685
13686 /*
13687  * 6ch mode
13688  */
13689 static struct hda_verb alc662_3ST_ch6_init[] = {
13690         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13691         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
13692         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
13693         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13694         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
13695         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
13696         { } /* end */
13697 };
13698
13699 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
13700         { 2, alc662_3ST_ch2_init },
13701         { 6, alc662_3ST_ch6_init },
13702 };
13703
13704 /*
13705  * 2ch mode
13706  */
13707 static struct hda_verb alc662_sixstack_ch6_init[] = {
13708         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13709         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13710         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13711         { } /* end */
13712 };
13713
13714 /*
13715  * 6ch mode
13716  */
13717 static struct hda_verb alc662_sixstack_ch8_init[] = {
13718         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13719         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13720         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13721         { } /* end */
13722 };
13723
13724 static struct hda_channel_mode alc662_5stack_modes[2] = {
13725         { 2, alc662_sixstack_ch6_init },
13726         { 6, alc662_sixstack_ch8_init },
13727 };
13728
13729 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
13730  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
13731  */
13732
13733 static struct snd_kcontrol_new alc662_base_mixer[] = {
13734         /* output mixer control */
13735         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
13736         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
13737         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
13738         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
13739         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13740         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13741         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
13742         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
13743         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13744
13745         /*Input mixer control */
13746         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
13747         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
13748         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
13749         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
13750         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
13751         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
13752         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
13753         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
13754         { } /* end */
13755 };
13756
13757 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
13758         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13759         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
13760         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13761         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13762         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13763         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13764         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13765         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13766         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13767         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13768         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13769         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13770         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13771         { } /* end */
13772 };
13773
13774 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
13775         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13776         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
13777         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13778         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
13779         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13780         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13781         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
13782         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
13783         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13784         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13785         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13786         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13787         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13788         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13789         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13790         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13791         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13792         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13793         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13794         { } /* end */
13795 };
13796
13797 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
13798         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13799         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
13800         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13801         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
13802         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13803         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13804         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13805         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13806         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13807         { } /* end */
13808 };
13809
13810 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
13811         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13812
13813         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13814         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13815
13816         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
13817         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13818         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13819
13820         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
13821         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13822         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13823         { } /* end */
13824 };
13825
13826 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
13827         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13828         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13829         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13830         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
13831         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13832         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13833         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
13834         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
13835         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13836         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
13837         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13838         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13839         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13840         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13841         { } /* end */
13842 };
13843
13844 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
13845         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13846         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13847         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
13848         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13849         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13850         HDA_CODEC_MUTE("DMic Playback Switch", 0x23, 0x9, HDA_INPUT),
13851         { } /* end */
13852 };
13853
13854 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
13855         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13856         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13857         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13858         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13859         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
13860
13861         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13862         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13863         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13864         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13865         { } /* end */
13866 };
13867
13868 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
13869         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13870         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13871         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
13872
13873         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13874         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13875         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13876         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13877         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13878         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13879         { } /* end */
13880 };
13881
13882 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
13883         {
13884                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13885                 .name = "Channel Mode",
13886                 .info = alc_ch_mode_info,
13887                 .get = alc_ch_mode_get,
13888                 .put = alc_ch_mode_put,
13889         },
13890         { } /* end */
13891 };
13892
13893 static struct hda_verb alc662_init_verbs[] = {
13894         /* ADC: mute amp left and right */
13895         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13896         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
13897         /* Front mixer: unmute input/output amp left and right (volume = 0) */
13898
13899         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13900         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13901         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13902         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13903         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13904
13905         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13906         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13907         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13908         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13909         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13910         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13911
13912         /* Front Pin: output 0 (0x0c) */
13913         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13914         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13915
13916         /* Rear Pin: output 1 (0x0d) */
13917         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13918         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13919
13920         /* CLFE Pin: output 2 (0x0e) */
13921         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13922         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13923
13924         /* Mic (rear) pin: input vref at 80% */
13925         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13926         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13927         /* Front Mic pin: input vref at 80% */
13928         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13929         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13930         /* Line In pin: input */
13931         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13932         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13933         /* Line-2 In: Headphone output (output 0 - 0x0c) */
13934         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13935         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13936         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13937         /* CD pin widget for input */
13938         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13939
13940         /* FIXME: use matrix-type input source selection */
13941         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
13942         /* Input mixer */
13943         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13944         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13945         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13946         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
13947
13948         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13949         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13950         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13951         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
13952
13953         /* always trun on EAPD */
13954         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13955         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
13956
13957         { }
13958 };
13959
13960 static struct hda_verb alc662_sue_init_verbs[] = {
13961         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
13962         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
13963         {}
13964 };
13965
13966 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
13967         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13968         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13969         {}
13970 };
13971
13972 /* Set Unsolicited Event*/
13973 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
13974         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13975         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13976         {}
13977 };
13978
13979 /*
13980  * generic initialization of ADC, input mixers and output mixers
13981  */
13982 static struct hda_verb alc662_auto_init_verbs[] = {
13983         /*
13984          * Unmute ADC and set the default input to mic-in
13985          */
13986         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
13987         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13988
13989         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
13990          * mixer widget
13991          * Note: PASD motherboards uses the Line In 2 as the input for front
13992          * panel mic (mic 2)
13993          */
13994         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
13995         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13996         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13997         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13998         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13999         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14000
14001         /*
14002          * Set up output mixers (0x0c - 0x0f)
14003          */
14004         /* set vol=0 to output mixers */
14005         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14006         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14007         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14008
14009         /* set up input amps for analog loopback */
14010         /* Amp Indices: DAC = 0, mixer = 1 */
14011         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14012         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14013         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14014         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14015         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14016         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14017
14018
14019         /* FIXME: use matrix-type input source selection */
14020         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
14021         /* Input mixer */
14022         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14023         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14024         { }
14025 };
14026
14027 static struct hda_verb alc663_m51va_init_verbs[] = {
14028         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14029         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14030         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
14031
14032         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
14033
14034         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14035         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14036         {}
14037 };
14038
14039 static struct hda_verb alc663_g71v_init_verbs[] = {
14040         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14041         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
14042         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
14043
14044         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14045         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14046         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
14047
14048         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
14049         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
14050         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
14051         {}
14052 };
14053
14054 static struct hda_verb alc663_g50v_init_verbs[] = {
14055         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14056         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14057         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
14058
14059         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14060         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14061         {}
14062 };
14063
14064 /* capture mixer elements */
14065 static struct snd_kcontrol_new alc662_capture_mixer[] = {
14066         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
14067         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
14068         {
14069                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14070                 /* The multiple "Capture Source" controls confuse alsamixer
14071                  * So call somewhat different..
14072                  */
14073                 /* .name = "Capture Source", */
14074                 .name = "Input Source",
14075                 .count = 1,
14076                 .info = alc662_mux_enum_info,
14077                 .get = alc662_mux_enum_get,
14078                 .put = alc662_mux_enum_put,
14079         },
14080         { } /* end */
14081 };
14082
14083 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
14084 {
14085         unsigned int present;
14086         unsigned char bits;
14087
14088         present = snd_hda_codec_read(codec, 0x14, 0,
14089                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14090         bits = present ? HDA_AMP_MUTE : 0;
14091         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
14092                                  HDA_AMP_MUTE, bits);
14093 }
14094
14095 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
14096 {
14097         unsigned int present;
14098         unsigned char bits;
14099
14100         present = snd_hda_codec_read(codec, 0x1b, 0,
14101                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14102         bits = present ? HDA_AMP_MUTE : 0;
14103         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
14104                                  HDA_AMP_MUTE, bits);
14105         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14106                                  HDA_AMP_MUTE, bits);
14107 }
14108
14109 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
14110                                            unsigned int res)
14111 {
14112         if ((res >> 26) == ALC880_HP_EVENT)
14113                 alc662_lenovo_101e_all_automute(codec);
14114         if ((res >> 26) == ALC880_FRONT_EVENT)
14115                 alc662_lenovo_101e_ispeaker_automute(codec);
14116 }
14117
14118 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
14119 {
14120         unsigned int present;
14121
14122         present = snd_hda_codec_read(codec, 0x18, 0,
14123                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14124         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14125                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14126         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14127                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14128         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14129                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
14130         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14131                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
14132 }
14133
14134 /* unsolicited event for HP jack sensing */
14135 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
14136                                      unsigned int res)
14137 {
14138         if ((res >> 26) == ALC880_HP_EVENT)
14139                 alc262_hippo1_automute( codec );
14140
14141         if ((res >> 26) == ALC880_MIC_EVENT)
14142                 alc662_eeepc_mic_automute(codec);
14143 }
14144
14145 static void alc662_eeepc_inithook(struct hda_codec *codec)
14146 {
14147         alc262_hippo1_automute( codec );
14148         alc662_eeepc_mic_automute(codec);
14149 }
14150
14151 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
14152 {
14153         unsigned int mute;
14154         unsigned int present;
14155
14156         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
14157         present = snd_hda_codec_read(codec, 0x14, 0,
14158                                      AC_VERB_GET_PIN_SENSE, 0);
14159         present = (present & 0x80000000) != 0;
14160         if (present) {
14161                 /* mute internal speaker */
14162                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
14163                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
14164         } else {
14165                 /* unmute internal speaker if necessary */
14166                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
14167                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
14168                                          HDA_AMP_MUTE, mute);
14169         }
14170 }
14171
14172 /* unsolicited event for HP jack sensing */
14173 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
14174                                           unsigned int res)
14175 {
14176         if ((res >> 26) == ALC880_HP_EVENT)
14177                 alc662_eeepc_ep20_automute(codec);
14178 }
14179
14180 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
14181 {
14182         alc662_eeepc_ep20_automute(codec);
14183 }
14184
14185 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
14186 {
14187         unsigned int present;
14188         unsigned char bits;
14189
14190         present = snd_hda_codec_read(codec, 0x21, 0,
14191                                      AC_VERB_GET_PIN_SENSE, 0)
14192                 & AC_PINSENSE_PRESENCE;
14193         bits = present ? HDA_AMP_MUTE : 0;
14194         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14195                                  HDA_AMP_MUTE, bits);
14196 }
14197
14198 static void alc663_m51va_mic_automute(struct hda_codec *codec)
14199 {
14200         unsigned int present;
14201
14202         present = snd_hda_codec_read(codec, 0x18, 0,
14203                                      AC_VERB_GET_PIN_SENSE, 0)
14204                 & AC_PINSENSE_PRESENCE;
14205         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14206                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14207         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14208                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14209         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14210                             0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
14211         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14212                             0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
14213 }
14214
14215 static void alc663_m51va_unsol_event(struct hda_codec *codec,
14216                                            unsigned int res)
14217 {
14218         switch (res >> 26) {
14219         case ALC880_HP_EVENT:
14220                 alc663_m51va_speaker_automute(codec);
14221                 break;
14222         case ALC880_MIC_EVENT:
14223                 alc663_m51va_mic_automute(codec);
14224                 break;
14225         }
14226 }
14227
14228 static void alc663_m51va_inithook(struct hda_codec *codec)
14229 {
14230         alc663_m51va_speaker_automute(codec);
14231         alc663_m51va_mic_automute(codec);
14232 }
14233
14234 static void alc663_g71v_hp_automute(struct hda_codec *codec)
14235 {
14236         unsigned int present;
14237         unsigned char bits;
14238
14239         present = snd_hda_codec_read(codec, 0x21, 0,
14240                                      AC_VERB_GET_PIN_SENSE, 0)
14241                 & AC_PINSENSE_PRESENCE;
14242         bits = present ? HDA_AMP_MUTE : 0;
14243         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
14244                                  HDA_AMP_MUTE, bits);
14245         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14246                                  HDA_AMP_MUTE, bits);
14247 }
14248
14249 static void alc663_g71v_front_automute(struct hda_codec *codec)
14250 {
14251         unsigned int present;
14252         unsigned char bits;
14253
14254         present = snd_hda_codec_read(codec, 0x15, 0,
14255                                      AC_VERB_GET_PIN_SENSE, 0)
14256                 & AC_PINSENSE_PRESENCE;
14257         bits = present ? HDA_AMP_MUTE : 0;
14258         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14259                                  HDA_AMP_MUTE, bits);
14260 }
14261
14262 static void alc663_g71v_unsol_event(struct hda_codec *codec,
14263                                            unsigned int res)
14264 {
14265         switch (res >> 26) {
14266         case ALC880_HP_EVENT:
14267                 alc663_g71v_hp_automute(codec);
14268                 break;
14269         case ALC880_FRONT_EVENT:
14270                 alc663_g71v_front_automute(codec);
14271                 break;
14272         case ALC880_MIC_EVENT:
14273                 alc662_eeepc_mic_automute(codec);
14274                 break;
14275         }
14276 }
14277
14278 static void alc663_g71v_inithook(struct hda_codec *codec)
14279 {
14280         alc663_g71v_front_automute(codec);
14281         alc663_g71v_hp_automute(codec);
14282         alc662_eeepc_mic_automute(codec);
14283 }
14284
14285 static void alc663_g50v_unsol_event(struct hda_codec *codec,
14286                                            unsigned int res)
14287 {
14288         switch (res >> 26) {
14289         case ALC880_HP_EVENT:
14290                 alc663_m51va_speaker_automute(codec);
14291                 break;
14292         case ALC880_MIC_EVENT:
14293                 alc662_eeepc_mic_automute(codec);
14294                 break;
14295         }
14296 }
14297
14298 static void alc663_g50v_inithook(struct hda_codec *codec)
14299 {
14300         alc663_m51va_speaker_automute(codec);
14301         alc662_eeepc_mic_automute(codec);
14302 }
14303
14304 #ifdef CONFIG_SND_HDA_POWER_SAVE
14305 #define alc662_loopbacks        alc880_loopbacks
14306 #endif
14307
14308
14309 /* pcm configuration: identiacal with ALC880 */
14310 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
14311 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
14312 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
14313 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
14314
14315 /*
14316  * configuration and preset
14317  */
14318 static const char *alc662_models[ALC662_MODEL_LAST] = {
14319         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
14320         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
14321         [ALC662_3ST_6ch]        = "3stack-6ch",
14322         [ALC662_5ST_DIG]        = "6stack-dig",
14323         [ALC662_LENOVO_101E]    = "lenovo-101e",
14324         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
14325         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
14326         [ALC663_ASUS_M51VA] = "m51va",
14327         [ALC663_ASUS_G71V] = "g71v",
14328         [ALC663_ASUS_H13] = "h13",
14329         [ALC663_ASUS_G50V] = "g50v",
14330         [ALC662_AUTO]           = "auto",
14331 };
14332
14333 static struct snd_pci_quirk alc662_cfg_tbl[] = {
14334         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS G71V", ALC663_ASUS_G71V),
14335         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
14336         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS M51VA", ALC663_ASUS_G50V),
14337         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
14338         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
14339         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
14340         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
14341         SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13),
14342         SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13),
14343         SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13),
14344         {}
14345 };
14346
14347 static struct alc_config_preset alc662_presets[] = {
14348         [ALC662_3ST_2ch_DIG] = {
14349                 .mixers = { alc662_3ST_2ch_mixer, alc662_capture_mixer },
14350                 .init_verbs = { alc662_init_verbs },
14351                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14352                 .dac_nids = alc662_dac_nids,
14353                 .dig_out_nid = ALC662_DIGOUT_NID,
14354                 .dig_in_nid = ALC662_DIGIN_NID,
14355                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14356                 .channel_mode = alc662_3ST_2ch_modes,
14357                 .input_mux = &alc662_capture_source,
14358         },
14359         [ALC662_3ST_6ch_DIG] = {
14360                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
14361                             alc662_capture_mixer },
14362                 .init_verbs = { alc662_init_verbs },
14363                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14364                 .dac_nids = alc662_dac_nids,
14365                 .dig_out_nid = ALC662_DIGOUT_NID,
14366                 .dig_in_nid = ALC662_DIGIN_NID,
14367                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
14368                 .channel_mode = alc662_3ST_6ch_modes,
14369                 .need_dac_fix = 1,
14370                 .input_mux = &alc662_capture_source,
14371         },
14372         [ALC662_3ST_6ch] = {
14373                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
14374                             alc662_capture_mixer },
14375                 .init_verbs = { alc662_init_verbs },
14376                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14377                 .dac_nids = alc662_dac_nids,
14378                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
14379                 .channel_mode = alc662_3ST_6ch_modes,
14380                 .need_dac_fix = 1,
14381                 .input_mux = &alc662_capture_source,
14382         },
14383         [ALC662_5ST_DIG] = {
14384                 .mixers = { alc662_base_mixer, alc662_chmode_mixer,
14385                             alc662_capture_mixer },
14386                 .init_verbs = { alc662_init_verbs },
14387                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14388                 .dac_nids = alc662_dac_nids,
14389                 .dig_out_nid = ALC662_DIGOUT_NID,
14390                 .dig_in_nid = ALC662_DIGIN_NID,
14391                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
14392                 .channel_mode = alc662_5stack_modes,
14393                 .input_mux = &alc662_capture_source,
14394         },
14395         [ALC662_LENOVO_101E] = {
14396                 .mixers = { alc662_lenovo_101e_mixer, alc662_capture_mixer },
14397                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
14398                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14399                 .dac_nids = alc662_dac_nids,
14400                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14401                 .channel_mode = alc662_3ST_2ch_modes,
14402                 .input_mux = &alc662_lenovo_101e_capture_source,
14403                 .unsol_event = alc662_lenovo_101e_unsol_event,
14404                 .init_hook = alc662_lenovo_101e_all_automute,
14405         },
14406         [ALC662_ASUS_EEEPC_P701] = {
14407                 .mixers = { alc662_eeepc_p701_mixer, alc662_capture_mixer },
14408                 .init_verbs = { alc662_init_verbs,
14409                                 alc662_eeepc_sue_init_verbs },
14410                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14411                 .dac_nids = alc662_dac_nids,
14412                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14413                 .channel_mode = alc662_3ST_2ch_modes,
14414                 .input_mux = &alc662_eeepc_capture_source,
14415                 .unsol_event = alc662_eeepc_unsol_event,
14416                 .init_hook = alc662_eeepc_inithook,
14417         },
14418         [ALC662_ASUS_EEEPC_EP20] = {
14419                 .mixers = { alc662_eeepc_ep20_mixer, alc662_capture_mixer,
14420                             alc662_chmode_mixer },
14421                 .init_verbs = { alc662_init_verbs,
14422                                 alc662_eeepc_ep20_sue_init_verbs },
14423                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14424                 .dac_nids = alc662_dac_nids,
14425                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
14426                 .channel_mode = alc662_3ST_6ch_modes,
14427                 .input_mux = &alc662_lenovo_101e_capture_source,
14428                 .unsol_event = alc662_eeepc_ep20_unsol_event,
14429                 .init_hook = alc662_eeepc_ep20_inithook,
14430         },
14431         [ALC663_ASUS_M51VA] = {
14432                 .mixers = { alc663_m51va_mixer, alc662_capture_mixer},
14433                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
14434                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14435                 .dac_nids = alc662_dac_nids,
14436                 .dig_out_nid = ALC662_DIGOUT_NID,
14437                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14438                 .channel_mode = alc662_3ST_2ch_modes,
14439                 .input_mux = &alc663_m51va_capture_source,
14440                 .unsol_event = alc663_m51va_unsol_event,
14441                 .init_hook = alc663_m51va_inithook,
14442         },
14443         [ALC663_ASUS_G71V] = {
14444                 .mixers = { alc663_g71v_mixer, alc662_capture_mixer},
14445                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
14446                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14447                 .dac_nids = alc662_dac_nids,
14448                 .dig_out_nid = ALC662_DIGOUT_NID,
14449                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14450                 .channel_mode = alc662_3ST_2ch_modes,
14451                 .input_mux = &alc662_eeepc_capture_source,
14452                 .unsol_event = alc663_g71v_unsol_event,
14453                 .init_hook = alc663_g71v_inithook,
14454         },
14455         [ALC663_ASUS_H13] = {
14456                 .mixers = { alc663_m51va_mixer, alc662_capture_mixer},
14457                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
14458                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14459                 .dac_nids = alc662_dac_nids,
14460                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14461                 .channel_mode = alc662_3ST_2ch_modes,
14462                 .input_mux = &alc663_m51va_capture_source,
14463                 .unsol_event = alc663_m51va_unsol_event,
14464                 .init_hook = alc663_m51va_inithook,
14465         },
14466         [ALC663_ASUS_G50V] = {
14467                 .mixers = { alc663_g50v_mixer, alc662_capture_mixer},
14468                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
14469                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14470                 .dac_nids = alc662_dac_nids,
14471                 .dig_out_nid = ALC662_DIGOUT_NID,
14472                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
14473                 .channel_mode = alc662_3ST_6ch_modes,
14474                 .input_mux = &alc663_capture_source,
14475                 .unsol_event = alc663_g50v_unsol_event,
14476                 .init_hook = alc663_g50v_inithook,
14477         },
14478 };
14479
14480
14481 /*
14482  * BIOS auto configuration
14483  */
14484
14485 /* add playback controls from the parsed DAC table */
14486 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
14487                                              const struct auto_pin_cfg *cfg)
14488 {
14489         char name[32];
14490         static const char *chname[4] = {
14491                 "Front", "Surround", NULL /*CLFE*/, "Side"
14492         };
14493         hda_nid_t nid;
14494         int i, err;
14495
14496         for (i = 0; i < cfg->line_outs; i++) {
14497                 if (!spec->multiout.dac_nids[i])
14498                         continue;
14499                 nid = alc880_idx_to_dac(i);
14500                 if (i == 2) {
14501                         /* Center/LFE */
14502                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14503                                           "Center Playback Volume",
14504                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
14505                                                               HDA_OUTPUT));
14506                         if (err < 0)
14507                                 return err;
14508                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14509                                           "LFE Playback Volume",
14510                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
14511                                                               HDA_OUTPUT));
14512                         if (err < 0)
14513                                 return err;
14514                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14515                                           "Center Playback Switch",
14516                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
14517                                                               HDA_INPUT));
14518                         if (err < 0)
14519                                 return err;
14520                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14521                                           "LFE Playback Switch",
14522                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
14523                                                               HDA_INPUT));
14524                         if (err < 0)
14525                                 return err;
14526                 } else {
14527                         sprintf(name, "%s Playback Volume", chname[i]);
14528                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14529                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
14530                                                               HDA_OUTPUT));
14531                         if (err < 0)
14532                                 return err;
14533                         sprintf(name, "%s Playback Switch", chname[i]);
14534                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14535                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
14536                                                               HDA_INPUT));
14537                         if (err < 0)
14538                                 return err;
14539                 }
14540         }
14541         return 0;
14542 }
14543
14544 /* add playback controls for speaker and HP outputs */
14545 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
14546                                         const char *pfx)
14547 {
14548         hda_nid_t nid;
14549         int err;
14550         char name[32];
14551
14552         if (!pin)
14553                 return 0;
14554
14555         if (alc880_is_fixed_pin(pin)) {
14556                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14557                 /* printk("DAC nid=%x\n",nid); */
14558                 /* specify the DAC as the extra output */
14559                 if (!spec->multiout.hp_nid)
14560                         spec->multiout.hp_nid = nid;
14561                 else
14562                         spec->multiout.extra_out_nid[0] = nid;
14563                 /* control HP volume/switch on the output mixer amp */
14564                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14565                 sprintf(name, "%s Playback Volume", pfx);
14566                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14567                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
14568                 if (err < 0)
14569                         return err;
14570                 sprintf(name, "%s Playback Switch", pfx);
14571                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14572                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
14573                 if (err < 0)
14574                         return err;
14575         } else if (alc880_is_multi_pin(pin)) {
14576                 /* set manual connection */
14577                 /* we have only a switch on HP-out PIN */
14578                 sprintf(name, "%s Playback Switch", pfx);
14579                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14580                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
14581                 if (err < 0)
14582                         return err;
14583         }
14584         return 0;
14585 }
14586
14587 /* create playback/capture controls for input pins */
14588 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
14589                                                 const struct auto_pin_cfg *cfg)
14590 {
14591         struct hda_input_mux *imux = &spec->private_imux;
14592         int i, err, idx;
14593
14594         for (i = 0; i < AUTO_PIN_LAST; i++) {
14595                 if (alc880_is_input_pin(cfg->input_pins[i])) {
14596                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
14597                         err = new_analog_input(spec, cfg->input_pins[i],
14598                                                auto_pin_cfg_labels[i],
14599                                                idx, 0x0b);
14600                         if (err < 0)
14601                                 return err;
14602                         imux->items[imux->num_items].label =
14603                                 auto_pin_cfg_labels[i];
14604                         imux->items[imux->num_items].index =
14605                                 alc880_input_pin_idx(cfg->input_pins[i]);
14606                         imux->num_items++;
14607                 }
14608         }
14609         return 0;
14610 }
14611
14612 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
14613                                               hda_nid_t nid, int pin_type,
14614                                               int dac_idx)
14615 {
14616         alc_set_pin_output(codec, nid, pin_type);
14617         /* need the manual connection? */
14618         if (alc880_is_multi_pin(nid)) {
14619                 struct alc_spec *spec = codec->spec;
14620                 int idx = alc880_multi_pin_idx(nid);
14621                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
14622                                     AC_VERB_SET_CONNECT_SEL,
14623                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
14624         }
14625 }
14626
14627 static void alc662_auto_init_multi_out(struct hda_codec *codec)
14628 {
14629         struct alc_spec *spec = codec->spec;
14630         int i;
14631
14632         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
14633         for (i = 0; i <= HDA_SIDE; i++) {
14634                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14635                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14636                 if (nid)
14637                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
14638                                                           i);
14639         }
14640 }
14641
14642 static void alc662_auto_init_hp_out(struct hda_codec *codec)
14643 {
14644         struct alc_spec *spec = codec->spec;
14645         hda_nid_t pin;
14646
14647         pin = spec->autocfg.hp_pins[0];
14648         if (pin) /* connect to front */
14649                 /* use dac 0 */
14650                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
14651         pin = spec->autocfg.speaker_pins[0];
14652         if (pin)
14653                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14654 }
14655
14656 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
14657 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
14658
14659 static void alc662_auto_init_analog_input(struct hda_codec *codec)
14660 {
14661         struct alc_spec *spec = codec->spec;
14662         int i;
14663
14664         for (i = 0; i < AUTO_PIN_LAST; i++) {
14665                 hda_nid_t nid = spec->autocfg.input_pins[i];
14666                 if (alc662_is_input_pin(nid)) {
14667                         snd_hda_codec_write(codec, nid, 0,
14668                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
14669                                             (i <= AUTO_PIN_FRONT_MIC ?
14670                                              PIN_VREF80 : PIN_IN));
14671                         if (nid != ALC662_PIN_CD_NID)
14672                                 snd_hda_codec_write(codec, nid, 0,
14673                                                     AC_VERB_SET_AMP_GAIN_MUTE,
14674                                                     AMP_OUT_MUTE);
14675                 }
14676         }
14677 }
14678
14679 static int alc662_parse_auto_config(struct hda_codec *codec)
14680 {
14681         struct alc_spec *spec = codec->spec;
14682         int err;
14683         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
14684
14685         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14686                                            alc662_ignore);
14687         if (err < 0)
14688                 return err;
14689         if (!spec->autocfg.line_outs)
14690                 return 0; /* can't find valid BIOS pin config */
14691
14692         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
14693         if (err < 0)
14694                 return err;
14695         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
14696         if (err < 0)
14697                 return err;
14698         err = alc662_auto_create_extra_out(spec,
14699                                            spec->autocfg.speaker_pins[0],
14700                                            "Speaker");
14701         if (err < 0)
14702                 return err;
14703         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
14704                                            "Headphone");
14705         if (err < 0)
14706                 return err;
14707         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
14708         if (err < 0)
14709                 return err;
14710
14711         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14712
14713         if (spec->autocfg.dig_out_pin)
14714                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
14715
14716         if (spec->kctl_alloc)
14717                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
14718
14719         spec->num_mux_defs = 1;
14720         spec->input_mux = &spec->private_imux;
14721         
14722         spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs;
14723         spec->mixers[spec->num_mixers] = alc662_capture_mixer;
14724         spec->num_mixers++;
14725         return 1;
14726 }
14727
14728 /* additional initialization for auto-configuration model */
14729 static void alc662_auto_init(struct hda_codec *codec)
14730 {
14731         struct alc_spec *spec = codec->spec;
14732         alc662_auto_init_multi_out(codec);
14733         alc662_auto_init_hp_out(codec);
14734         alc662_auto_init_analog_input(codec);
14735         if (spec->unsol_event)
14736                 alc_sku_automute(codec);
14737 }
14738
14739 static int patch_alc662(struct hda_codec *codec)
14740 {
14741         struct alc_spec *spec;
14742         int err, board_config;
14743
14744         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14745         if (!spec)
14746                 return -ENOMEM;
14747
14748         codec->spec = spec;
14749
14750         alc_fix_pll_init(codec, 0x20, 0x04, 15);
14751
14752         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
14753                                                   alc662_models,
14754                                                   alc662_cfg_tbl);
14755         if (board_config < 0) {
14756                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
14757                        "trying auto-probe from BIOS...\n");
14758                 board_config = ALC662_AUTO;
14759         }
14760
14761         if (board_config == ALC662_AUTO) {
14762                 /* automatic parse from the BIOS config */
14763                 err = alc662_parse_auto_config(codec);
14764                 if (err < 0) {
14765                         alc_free(codec);
14766                         return err;
14767                 } else if (!err) {
14768                         printk(KERN_INFO
14769                                "hda_codec: Cannot set up configuration "
14770                                "from BIOS.  Using base mode...\n");
14771                         board_config = ALC662_3ST_2ch_DIG;
14772                 }
14773         }
14774
14775         if (board_config != ALC662_AUTO)
14776                 setup_preset(spec, &alc662_presets[board_config]);
14777
14778         if (codec->vendor_id == 0x10ec0663) {
14779                 spec->stream_name_analog = "ALC663 Analog";
14780                 spec->stream_name_digital = "ALC663 Digital";
14781         } else {
14782                 spec->stream_name_analog = "ALC662 Analog";
14783                 spec->stream_name_digital = "ALC662 Digital";
14784         }
14785
14786         spec->stream_analog_playback = &alc662_pcm_analog_playback;
14787         spec->stream_analog_capture = &alc662_pcm_analog_capture;
14788
14789         spec->stream_digital_playback = &alc662_pcm_digital_playback;
14790         spec->stream_digital_capture = &alc662_pcm_digital_capture;
14791
14792         spec->adc_nids = alc662_adc_nids;
14793         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
14794         spec->capsrc_nids = alc662_capsrc_nids;
14795
14796         spec->vmaster_nid = 0x02;
14797
14798         codec->patch_ops = alc_patch_ops;
14799         if (board_config == ALC662_AUTO)
14800                 spec->init_hook = alc662_auto_init;
14801 #ifdef CONFIG_SND_HDA_POWER_SAVE
14802         if (!spec->loopback.amplist)
14803                 spec->loopback.amplist = alc662_loopbacks;
14804 #endif
14805
14806         return 0;
14807 }
14808
14809 /*
14810  * patch entries
14811  */
14812 struct hda_codec_preset snd_hda_preset_realtek[] = {
14813         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
14814         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
14815         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
14816         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
14817         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
14818         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
14819           .patch = patch_alc861 },
14820         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
14821         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
14822         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
14823         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
14824           .patch = patch_alc883 },
14825         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
14826           .patch = patch_alc662 },
14827         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
14828         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
14829         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
14830         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
14831         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
14832           .patch = patch_alc882 }, /* should be patch_alc883() in future */
14833         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
14834         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
14835         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
14836         {} /* terminator */
14837 };