]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - sound/pci/hda/patch_realtek.c
ALSA: hda - fix spaces in patch_realtek.c
[linux-2.6-omap-h63xx.git] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
33 #include "hda_patch.h"
34
35 #define ALC880_FRONT_EVENT              0x01
36 #define ALC880_DCVOL_EVENT              0x02
37 #define ALC880_HP_EVENT                 0x04
38 #define ALC880_MIC_EVENT                0x08
39
40 /* ALC880 board config type */
41 enum {
42         ALC880_3ST,
43         ALC880_3ST_DIG,
44         ALC880_5ST,
45         ALC880_5ST_DIG,
46         ALC880_W810,
47         ALC880_Z71V,
48         ALC880_6ST,
49         ALC880_6ST_DIG,
50         ALC880_F1734,
51         ALC880_ASUS,
52         ALC880_ASUS_DIG,
53         ALC880_ASUS_W1V,
54         ALC880_ASUS_DIG2,
55         ALC880_FUJITSU,
56         ALC880_UNIWILL_DIG,
57         ALC880_UNIWILL,
58         ALC880_UNIWILL_P53,
59         ALC880_CLEVO,
60         ALC880_TCL_S700,
61         ALC880_LG,
62         ALC880_LG_LW,
63         ALC880_MEDION_RIM,
64 #ifdef CONFIG_SND_DEBUG
65         ALC880_TEST,
66 #endif
67         ALC880_AUTO,
68         ALC880_MODEL_LAST /* last tag */
69 };
70
71 /* ALC260 models */
72 enum {
73         ALC260_BASIC,
74         ALC260_HP,
75         ALC260_HP_3013,
76         ALC260_FUJITSU_S702X,
77         ALC260_ACER,
78         ALC260_WILL,
79         ALC260_REPLACER_672V,
80 #ifdef CONFIG_SND_DEBUG
81         ALC260_TEST,
82 #endif
83         ALC260_AUTO,
84         ALC260_MODEL_LAST /* last tag */
85 };
86
87 /* ALC262 models */
88 enum {
89         ALC262_BASIC,
90         ALC262_HIPPO,
91         ALC262_HIPPO_1,
92         ALC262_FUJITSU,
93         ALC262_HP_BPC,
94         ALC262_HP_BPC_D7000_WL,
95         ALC262_HP_BPC_D7000_WF,
96         ALC262_HP_TC_T5735,
97         ALC262_HP_RP5700,
98         ALC262_BENQ_ED8,
99         ALC262_SONY_ASSAMD,
100         ALC262_BENQ_T31,
101         ALC262_ULTRA,
102         ALC262_LENOVO_3000,
103         ALC262_NEC,
104         ALC262_AUTO,
105         ALC262_MODEL_LAST /* last tag */
106 };
107
108 /* ALC268 models */
109 enum {
110         ALC267_QUANTA_IL1,
111         ALC268_3ST,
112         ALC268_TOSHIBA,
113         ALC268_ACER,
114         ALC268_DELL,
115         ALC268_ZEPTO,
116 #ifdef CONFIG_SND_DEBUG
117         ALC268_TEST,
118 #endif
119         ALC268_AUTO,
120         ALC268_MODEL_LAST /* last tag */
121 };
122
123 /* ALC269 models */
124 enum {
125         ALC269_BASIC,
126         ALC269_ASUS_EEEPC_P703,
127         ALC269_ASUS_EEEPC_P901,
128         ALC269_AUTO,
129         ALC269_MODEL_LAST /* last tag */
130 };
131
132 /* ALC861 models */
133 enum {
134         ALC861_3ST,
135         ALC660_3ST,
136         ALC861_3ST_DIG,
137         ALC861_6ST_DIG,
138         ALC861_UNIWILL_M31,
139         ALC861_TOSHIBA,
140         ALC861_ASUS,
141         ALC861_ASUS_LAPTOP,
142         ALC861_AUTO,
143         ALC861_MODEL_LAST,
144 };
145
146 /* ALC861-VD models */
147 enum {
148         ALC660VD_3ST,
149         ALC660VD_3ST_DIG,
150         ALC861VD_3ST,
151         ALC861VD_3ST_DIG,
152         ALC861VD_6ST_DIG,
153         ALC861VD_LENOVO,
154         ALC861VD_DALLAS,
155         ALC861VD_HP,
156         ALC861VD_AUTO,
157         ALC861VD_MODEL_LAST,
158 };
159
160 /* ALC662 models */
161 enum {
162         ALC662_3ST_2ch_DIG,
163         ALC662_3ST_6ch_DIG,
164         ALC662_3ST_6ch,
165         ALC662_5ST_DIG,
166         ALC662_LENOVO_101E,
167         ALC662_ASUS_EEEPC_P701,
168         ALC662_ASUS_EEEPC_EP20,
169         ALC663_ASUS_M51VA,
170         ALC663_ASUS_G71V,
171         ALC663_ASUS_H13,
172         ALC663_ASUS_G50V,
173         ALC662_AUTO,
174         ALC662_MODEL_LAST,
175 };
176
177 /* ALC882 models */
178 enum {
179         ALC882_3ST_DIG,
180         ALC882_6ST_DIG,
181         ALC882_ARIMA,
182         ALC882_W2JC,
183         ALC882_TARGA,
184         ALC882_ASUS_A7J,
185         ALC882_ASUS_A7M,
186         ALC885_MACPRO,
187         ALC885_MBP3,
188         ALC885_IMAC24,
189         ALC882_AUTO,
190         ALC882_MODEL_LAST,
191 };
192
193 /* ALC883 models */
194 enum {
195         ALC883_3ST_2ch_DIG,
196         ALC883_3ST_6ch_DIG,
197         ALC883_3ST_6ch,
198         ALC883_6ST_DIG,
199         ALC883_TARGA_DIG,
200         ALC883_TARGA_2ch_DIG,
201         ALC883_ACER,
202         ALC883_ACER_ASPIRE,
203         ALC883_MEDION,
204         ALC883_MEDION_MD2,
205         ALC883_LAPTOP_EAPD,
206         ALC883_LENOVO_101E_2ch,
207         ALC883_LENOVO_NB0763,
208         ALC888_LENOVO_MS7195_DIG,
209         ALC883_HAIER_W66,
210         ALC888_3ST_HP,
211         ALC888_6ST_DELL,
212         ALC883_MITAC,
213         ALC883_CLEVO_M720,
214         ALC883_FUJITSU_PI2515,
215         ALC883_3ST_6ch_INTEL,
216         ALC883_AUTO,
217         ALC883_MODEL_LAST,
218 };
219
220 /* for GPIO Poll */
221 #define GPIO_MASK       0x03
222
223 struct alc_spec {
224         /* codec parameterization */
225         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
226         unsigned int num_mixers;
227
228         const struct hda_verb *init_verbs[5];   /* initialization verbs
229                                                  * don't forget NULL
230                                                  * termination!
231                                                  */
232         unsigned int num_init_verbs;
233
234         char *stream_name_analog;       /* analog PCM stream */
235         struct hda_pcm_stream *stream_analog_playback;
236         struct hda_pcm_stream *stream_analog_capture;
237         struct hda_pcm_stream *stream_analog_alt_playback;
238         struct hda_pcm_stream *stream_analog_alt_capture;
239
240         char *stream_name_digital;      /* digital PCM stream */
241         struct hda_pcm_stream *stream_digital_playback;
242         struct hda_pcm_stream *stream_digital_capture;
243
244         /* playback */
245         struct hda_multi_out multiout;  /* playback set-up
246                                          * max_channels, dacs must be set
247                                          * dig_out_nid and hp_nid are optional
248                                          */
249         hda_nid_t alt_dac_nid;
250
251         /* capture */
252         unsigned int num_adc_nids;
253         hda_nid_t *adc_nids;
254         hda_nid_t *capsrc_nids;
255         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
256
257         /* capture source */
258         unsigned int num_mux_defs;
259         const struct hda_input_mux *input_mux;
260         unsigned int cur_mux[3];
261
262         /* channel model */
263         const struct hda_channel_mode *channel_mode;
264         int num_channel_mode;
265         int need_dac_fix;
266
267         /* PCM information */
268         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
269
270         /* dynamic controls, init_verbs and input_mux */
271         struct auto_pin_cfg autocfg;
272         unsigned int num_kctl_alloc, num_kctl_used;
273         struct snd_kcontrol_new *kctl_alloc;
274         struct hda_input_mux private_imux;
275         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
276
277         /* hooks */
278         void (*init_hook)(struct hda_codec *codec);
279         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
280
281         /* for pin sensing */
282         unsigned int sense_updated: 1;
283         unsigned int jack_present: 1;
284         unsigned int master_sw: 1;
285
286         /* for virtual master */
287         hda_nid_t vmaster_nid;
288 #ifdef CONFIG_SND_HDA_POWER_SAVE
289         struct hda_loopback_check loopback;
290 #endif
291
292         /* for PLL fix */
293         hda_nid_t pll_nid;
294         unsigned int pll_coef_idx, pll_coef_bit;
295 };
296
297 /*
298  * configuration template - to be copied to the spec instance
299  */
300 struct alc_config_preset {
301         struct snd_kcontrol_new *mixers[5]; /* should be identical size
302                                              * with spec
303                                              */
304         const struct hda_verb *init_verbs[5];
305         unsigned int num_dacs;
306         hda_nid_t *dac_nids;
307         hda_nid_t dig_out_nid;          /* optional */
308         hda_nid_t hp_nid;               /* optional */
309         unsigned int num_adc_nids;
310         hda_nid_t *adc_nids;
311         hda_nid_t *capsrc_nids;
312         hda_nid_t dig_in_nid;
313         unsigned int num_channel_mode;
314         const struct hda_channel_mode *channel_mode;
315         int need_dac_fix;
316         unsigned int num_mux_defs;
317         const struct hda_input_mux *input_mux;
318         void (*unsol_event)(struct hda_codec *, unsigned int);
319         void (*init_hook)(struct hda_codec *);
320 #ifdef CONFIG_SND_HDA_POWER_SAVE
321         struct hda_amp_list *loopbacks;
322 #endif
323 };
324
325
326 /*
327  * input MUX handling
328  */
329 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
330                              struct snd_ctl_elem_info *uinfo)
331 {
332         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
333         struct alc_spec *spec = codec->spec;
334         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
335         if (mux_idx >= spec->num_mux_defs)
336                 mux_idx = 0;
337         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
338 }
339
340 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
341                             struct snd_ctl_elem_value *ucontrol)
342 {
343         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
344         struct alc_spec *spec = codec->spec;
345         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
346
347         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
348         return 0;
349 }
350
351 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
352                             struct snd_ctl_elem_value *ucontrol)
353 {
354         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
355         struct alc_spec *spec = codec->spec;
356         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
357         unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
358         hda_nid_t nid = spec->capsrc_nids ?
359                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
360         return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
361                                      nid, &spec->cur_mux[adc_idx]);
362 }
363
364
365 /*
366  * channel mode setting
367  */
368 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
369                             struct snd_ctl_elem_info *uinfo)
370 {
371         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
372         struct alc_spec *spec = codec->spec;
373         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
374                                     spec->num_channel_mode);
375 }
376
377 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
378                            struct snd_ctl_elem_value *ucontrol)
379 {
380         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
381         struct alc_spec *spec = codec->spec;
382         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
383                                    spec->num_channel_mode,
384                                    spec->multiout.max_channels);
385 }
386
387 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
388                            struct snd_ctl_elem_value *ucontrol)
389 {
390         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
391         struct alc_spec *spec = codec->spec;
392         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
393                                       spec->num_channel_mode,
394                                       &spec->multiout.max_channels);
395         if (err >= 0 && spec->need_dac_fix)
396                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
397         return err;
398 }
399
400 /*
401  * Control the mode of pin widget settings via the mixer.  "pc" is used
402  * instead of "%" to avoid consequences of accidently treating the % as
403  * being part of a format specifier.  Maximum allowed length of a value is
404  * 63 characters plus NULL terminator.
405  *
406  * Note: some retasking pin complexes seem to ignore requests for input
407  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
408  * are requested.  Therefore order this list so that this behaviour will not
409  * cause problems when mixer clients move through the enum sequentially.
410  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
411  * March 2006.
412  */
413 static char *alc_pin_mode_names[] = {
414         "Mic 50pc bias", "Mic 80pc bias",
415         "Line in", "Line out", "Headphone out",
416 };
417 static unsigned char alc_pin_mode_values[] = {
418         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
419 };
420 /* The control can present all 5 options, or it can limit the options based
421  * in the pin being assumed to be exclusively an input or an output pin.  In
422  * addition, "input" pins may or may not process the mic bias option
423  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
424  * accept requests for bias as of chip versions up to March 2006) and/or
425  * wiring in the computer.
426  */
427 #define ALC_PIN_DIR_IN              0x00
428 #define ALC_PIN_DIR_OUT             0x01
429 #define ALC_PIN_DIR_INOUT           0x02
430 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
431 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
432
433 /* Info about the pin modes supported by the different pin direction modes.
434  * For each direction the minimum and maximum values are given.
435  */
436 static signed char alc_pin_mode_dir_info[5][2] = {
437         { 0, 2 },    /* ALC_PIN_DIR_IN */
438         { 3, 4 },    /* ALC_PIN_DIR_OUT */
439         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
440         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
441         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
442 };
443 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
444 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
445 #define alc_pin_mode_n_items(_dir) \
446         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
447
448 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
449                              struct snd_ctl_elem_info *uinfo)
450 {
451         unsigned int item_num = uinfo->value.enumerated.item;
452         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
453
454         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
455         uinfo->count = 1;
456         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
457
458         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
459                 item_num = alc_pin_mode_min(dir);
460         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
461         return 0;
462 }
463
464 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
465                             struct snd_ctl_elem_value *ucontrol)
466 {
467         unsigned int i;
468         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
469         hda_nid_t nid = kcontrol->private_value & 0xffff;
470         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
471         long *valp = ucontrol->value.integer.value;
472         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
473                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
474                                                  0x00);
475
476         /* Find enumerated value for current pinctl setting */
477         i = alc_pin_mode_min(dir);
478         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
479                 i++;
480         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
481         return 0;
482 }
483
484 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
485                             struct snd_ctl_elem_value *ucontrol)
486 {
487         signed int change;
488         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
489         hda_nid_t nid = kcontrol->private_value & 0xffff;
490         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
491         long val = *ucontrol->value.integer.value;
492         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
493                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
494                                                  0x00);
495
496         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
497                 val = alc_pin_mode_min(dir);
498
499         change = pinctl != alc_pin_mode_values[val];
500         if (change) {
501                 /* Set pin mode to that requested */
502                 snd_hda_codec_write_cache(codec, nid, 0,
503                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
504                                           alc_pin_mode_values[val]);
505
506                 /* Also enable the retasking pin's input/output as required
507                  * for the requested pin mode.  Enum values of 2 or less are
508                  * input modes.
509                  *
510                  * Dynamically switching the input/output buffers probably
511                  * reduces noise slightly (particularly on input) so we'll
512                  * do it.  However, having both input and output buffers
513                  * enabled simultaneously doesn't seem to be problematic if
514                  * this turns out to be necessary in the future.
515                  */
516                 if (val <= 2) {
517                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
518                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
519                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
520                                                  HDA_AMP_MUTE, 0);
521                 } else {
522                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
523                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
524                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
525                                                  HDA_AMP_MUTE, 0);
526                 }
527         }
528         return change;
529 }
530
531 #define ALC_PIN_MODE(xname, nid, dir) \
532         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
533           .info = alc_pin_mode_info, \
534           .get = alc_pin_mode_get, \
535           .put = alc_pin_mode_put, \
536           .private_value = nid | (dir<<16) }
537
538 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
539  * together using a mask with more than one bit set.  This control is
540  * currently used only by the ALC260 test model.  At this stage they are not
541  * needed for any "production" models.
542  */
543 #ifdef CONFIG_SND_DEBUG
544 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
545
546 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
547                              struct snd_ctl_elem_value *ucontrol)
548 {
549         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
550         hda_nid_t nid = kcontrol->private_value & 0xffff;
551         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
552         long *valp = ucontrol->value.integer.value;
553         unsigned int val = snd_hda_codec_read(codec, nid, 0,
554                                               AC_VERB_GET_GPIO_DATA, 0x00);
555
556         *valp = (val & mask) != 0;
557         return 0;
558 }
559 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
560                              struct snd_ctl_elem_value *ucontrol)
561 {
562         signed int change;
563         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
564         hda_nid_t nid = kcontrol->private_value & 0xffff;
565         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
566         long val = *ucontrol->value.integer.value;
567         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
568                                                     AC_VERB_GET_GPIO_DATA,
569                                                     0x00);
570
571         /* Set/unset the masked GPIO bit(s) as needed */
572         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
573         if (val == 0)
574                 gpio_data &= ~mask;
575         else
576                 gpio_data |= mask;
577         snd_hda_codec_write_cache(codec, nid, 0,
578                                   AC_VERB_SET_GPIO_DATA, gpio_data);
579
580         return change;
581 }
582 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
583         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
584           .info = alc_gpio_data_info, \
585           .get = alc_gpio_data_get, \
586           .put = alc_gpio_data_put, \
587           .private_value = nid | (mask<<16) }
588 #endif   /* CONFIG_SND_DEBUG */
589
590 /* A switch control to allow the enabling of the digital IO pins on the
591  * ALC260.  This is incredibly simplistic; the intention of this control is
592  * to provide something in the test model allowing digital outputs to be
593  * identified if present.  If models are found which can utilise these
594  * outputs a more complete mixer control can be devised for those models if
595  * necessary.
596  */
597 #ifdef CONFIG_SND_DEBUG
598 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
599
600 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
601                               struct snd_ctl_elem_value *ucontrol)
602 {
603         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
604         hda_nid_t nid = kcontrol->private_value & 0xffff;
605         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
606         long *valp = ucontrol->value.integer.value;
607         unsigned int val = snd_hda_codec_read(codec, nid, 0,
608                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
609
610         *valp = (val & mask) != 0;
611         return 0;
612 }
613 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
614                               struct snd_ctl_elem_value *ucontrol)
615 {
616         signed int change;
617         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
618         hda_nid_t nid = kcontrol->private_value & 0xffff;
619         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
620         long val = *ucontrol->value.integer.value;
621         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
622                                                     AC_VERB_GET_DIGI_CONVERT_1,
623                                                     0x00);
624
625         /* Set/unset the masked control bit(s) as needed */
626         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
627         if (val==0)
628                 ctrl_data &= ~mask;
629         else
630                 ctrl_data |= mask;
631         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
632                                   ctrl_data);
633
634         return change;
635 }
636 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
637         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
638           .info = alc_spdif_ctrl_info, \
639           .get = alc_spdif_ctrl_get, \
640           .put = alc_spdif_ctrl_put, \
641           .private_value = nid | (mask<<16) }
642 #endif   /* CONFIG_SND_DEBUG */
643
644 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
645  * Again, this is only used in the ALC26x test models to help identify when
646  * the EAPD line must be asserted for features to work.
647  */
648 #ifdef CONFIG_SND_DEBUG
649 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
650
651 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
652                               struct snd_ctl_elem_value *ucontrol)
653 {
654         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
655         hda_nid_t nid = kcontrol->private_value & 0xffff;
656         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
657         long *valp = ucontrol->value.integer.value;
658         unsigned int val = snd_hda_codec_read(codec, nid, 0,
659                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
660
661         *valp = (val & mask) != 0;
662         return 0;
663 }
664
665 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
666                               struct snd_ctl_elem_value *ucontrol)
667 {
668         int change;
669         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
670         hda_nid_t nid = kcontrol->private_value & 0xffff;
671         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
672         long val = *ucontrol->value.integer.value;
673         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
674                                                     AC_VERB_GET_EAPD_BTLENABLE,
675                                                     0x00);
676
677         /* Set/unset the masked control bit(s) as needed */
678         change = (!val ? 0 : mask) != (ctrl_data & mask);
679         if (!val)
680                 ctrl_data &= ~mask;
681         else
682                 ctrl_data |= mask;
683         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
684                                   ctrl_data);
685
686         return change;
687 }
688
689 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
690         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
691           .info = alc_eapd_ctrl_info, \
692           .get = alc_eapd_ctrl_get, \
693           .put = alc_eapd_ctrl_put, \
694           .private_value = nid | (mask<<16) }
695 #endif   /* CONFIG_SND_DEBUG */
696
697 /*
698  * set up from the preset table
699  */
700 static void setup_preset(struct alc_spec *spec,
701                          const struct alc_config_preset *preset)
702 {
703         int i;
704
705         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
706                 spec->mixers[spec->num_mixers++] = preset->mixers[i];
707         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
708              i++)
709                 spec->init_verbs[spec->num_init_verbs++] =
710                         preset->init_verbs[i];
711
712         spec->channel_mode = preset->channel_mode;
713         spec->num_channel_mode = preset->num_channel_mode;
714         spec->need_dac_fix = preset->need_dac_fix;
715
716         spec->multiout.max_channels = spec->channel_mode[0].channels;
717
718         spec->multiout.num_dacs = preset->num_dacs;
719         spec->multiout.dac_nids = preset->dac_nids;
720         spec->multiout.dig_out_nid = preset->dig_out_nid;
721         spec->multiout.hp_nid = preset->hp_nid;
722
723         spec->num_mux_defs = preset->num_mux_defs;
724         if (!spec->num_mux_defs)
725                 spec->num_mux_defs = 1;
726         spec->input_mux = preset->input_mux;
727
728         spec->num_adc_nids = preset->num_adc_nids;
729         spec->adc_nids = preset->adc_nids;
730         spec->capsrc_nids = preset->capsrc_nids;
731         spec->dig_in_nid = preset->dig_in_nid;
732
733         spec->unsol_event = preset->unsol_event;
734         spec->init_hook = preset->init_hook;
735 #ifdef CONFIG_SND_HDA_POWER_SAVE
736         spec->loopback.amplist = preset->loopbacks;
737 #endif
738 }
739
740 /* Enable GPIO mask and set output */
741 static struct hda_verb alc_gpio1_init_verbs[] = {
742         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
743         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
744         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
745         { }
746 };
747
748 static struct hda_verb alc_gpio2_init_verbs[] = {
749         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
750         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
751         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
752         { }
753 };
754
755 static struct hda_verb alc_gpio3_init_verbs[] = {
756         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
757         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
758         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
759         { }
760 };
761
762 /*
763  * Fix hardware PLL issue
764  * On some codecs, the analog PLL gating control must be off while
765  * the default value is 1.
766  */
767 static void alc_fix_pll(struct hda_codec *codec)
768 {
769         struct alc_spec *spec = codec->spec;
770         unsigned int val;
771
772         if (!spec->pll_nid)
773                 return;
774         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
775                             spec->pll_coef_idx);
776         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
777                                  AC_VERB_GET_PROC_COEF, 0);
778         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
779                             spec->pll_coef_idx);
780         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
781                             val & ~(1 << spec->pll_coef_bit));
782 }
783
784 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
785                              unsigned int coef_idx, unsigned int coef_bit)
786 {
787         struct alc_spec *spec = codec->spec;
788         spec->pll_nid = nid;
789         spec->pll_coef_idx = coef_idx;
790         spec->pll_coef_bit = coef_bit;
791         alc_fix_pll(codec);
792 }
793
794 static void alc_sku_automute(struct hda_codec *codec)
795 {
796         struct alc_spec *spec = codec->spec;
797         unsigned int present;
798         unsigned int hp_nid = spec->autocfg.hp_pins[0];
799         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
800
801         /* need to execute and sync at first */
802         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
803         present = snd_hda_codec_read(codec, hp_nid, 0,
804                                      AC_VERB_GET_PIN_SENSE, 0);
805         spec->jack_present = (present & 0x80000000) != 0;
806         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
807                             spec->jack_present ? 0 : PIN_OUT);
808 }
809
810 /* unsolicited event for HP jack sensing */
811 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
812 {
813         if (codec->vendor_id == 0x10ec0880)
814                 res >>= 28;
815         else
816                 res >>= 26;
817         if (res != ALC880_HP_EVENT)
818                 return;
819
820         alc_sku_automute(codec);
821 }
822
823 /* additional initialization for ALC888 variants */
824 static void alc888_coef_init(struct hda_codec *codec)
825 {
826         unsigned int tmp;
827
828         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
829         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
830         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
831         if ((tmp & 0xf0) == 2)
832                 /* alc888S-VC */
833                 snd_hda_codec_read(codec, 0x20, 0,
834                                    AC_VERB_SET_PROC_COEF, 0x830);
835          else
836                  /* alc888-VB */
837                  snd_hda_codec_read(codec, 0x20, 0,
838                                     AC_VERB_SET_PROC_COEF, 0x3030);
839 }
840
841 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
842  *      31 ~ 16 :       Manufacture ID
843  *      15 ~ 8  :       SKU ID
844  *      7  ~ 0  :       Assembly ID
845  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
846  */
847 static void alc_subsystem_id(struct hda_codec *codec,
848                              unsigned int porta, unsigned int porte,
849                              unsigned int portd)
850 {
851         unsigned int ass, tmp, i;
852         unsigned nid;
853         struct alc_spec *spec = codec->spec;
854
855         ass = codec->subsystem_id & 0xffff;
856         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
857                 goto do_sku;
858
859         /*
860          * 31~30        : port conetcivity
861          * 29~21        : reserve
862          * 20           : PCBEEP input
863          * 19~16        : Check sum (15:1)
864          * 15~1         : Custom
865          * 0            : override
866         */
867         nid = 0x1d;
868         if (codec->vendor_id == 0x10ec0260)
869                 nid = 0x17;
870         ass = snd_hda_codec_read(codec, nid, 0,
871                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
872         if (!(ass & 1) && !(ass & 0x100000))
873                 return;
874         if ((ass >> 30) != 1)   /* no physical connection */
875                 return;
876
877         /* check sum */
878         tmp = 0;
879         for (i = 1; i < 16; i++) {
880                 if ((ass >> i) & 1)
881                         tmp++;
882         }
883         if (((ass >> 16) & 0xf) != tmp)
884                 return;
885 do_sku:
886         /*
887          * 0 : override
888          * 1 :  Swap Jack
889          * 2 : 0 --> Desktop, 1 --> Laptop
890          * 3~5 : External Amplifier control
891          * 7~6 : Reserved
892         */
893         tmp = (ass & 0x38) >> 3;        /* external Amp control */
894         switch (tmp) {
895         case 1:
896                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
897                 break;
898         case 3:
899                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
900                 break;
901         case 7:
902                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
903                 break;
904         case 5: /* set EAPD output high */
905                 switch (codec->vendor_id) {
906                 case 0x10ec0260:
907                         snd_hda_codec_write(codec, 0x0f, 0,
908                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
909                         snd_hda_codec_write(codec, 0x10, 0,
910                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
911                         break;
912                 case 0x10ec0262:
913                 case 0x10ec0267:
914                 case 0x10ec0268:
915                 case 0x10ec0269:
916                 case 0x10ec0660:
917                 case 0x10ec0662:
918                 case 0x10ec0663:
919                 case 0x10ec0862:
920                 case 0x10ec0889:
921                         snd_hda_codec_write(codec, 0x14, 0,
922                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
923                         snd_hda_codec_write(codec, 0x15, 0,
924                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
925                         break;
926                 }
927                 switch (codec->vendor_id) {
928                 case 0x10ec0260:
929                         snd_hda_codec_write(codec, 0x1a, 0,
930                                             AC_VERB_SET_COEF_INDEX, 7);
931                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
932                                                  AC_VERB_GET_PROC_COEF, 0);
933                         snd_hda_codec_write(codec, 0x1a, 0,
934                                             AC_VERB_SET_COEF_INDEX, 7);
935                         snd_hda_codec_write(codec, 0x1a, 0,
936                                             AC_VERB_SET_PROC_COEF,
937                                             tmp | 0x2010);
938                         break;
939                 case 0x10ec0262:
940                 case 0x10ec0880:
941                 case 0x10ec0882:
942                 case 0x10ec0883:
943                 case 0x10ec0885:
944                 case 0x10ec0889:
945                         snd_hda_codec_write(codec, 0x20, 0,
946                                             AC_VERB_SET_COEF_INDEX, 7);
947                         tmp = snd_hda_codec_read(codec, 0x20, 0,
948                                                  AC_VERB_GET_PROC_COEF, 0);
949                         snd_hda_codec_write(codec, 0x20, 0,
950                                             AC_VERB_SET_COEF_INDEX, 7);
951                         snd_hda_codec_write(codec, 0x20, 0,
952                                             AC_VERB_SET_PROC_COEF,
953                                             tmp | 0x2010);
954                         break;
955                 case 0x10ec0888:
956                         /*alc888_coef_init(codec);*/ /* called in alc_init() */
957                         break;
958                 case 0x10ec0267:
959                 case 0x10ec0268:
960                         snd_hda_codec_write(codec, 0x20, 0,
961                                             AC_VERB_SET_COEF_INDEX, 7);
962                         tmp = snd_hda_codec_read(codec, 0x20, 0,
963                                                  AC_VERB_GET_PROC_COEF, 0);
964                         snd_hda_codec_write(codec, 0x20, 0,
965                                             AC_VERB_SET_COEF_INDEX, 7);
966                         snd_hda_codec_write(codec, 0x20, 0,
967                                             AC_VERB_SET_PROC_COEF,
968                                             tmp | 0x3000);
969                         break;
970                 }
971         default:
972                 break;
973         }
974
975         /* is laptop or Desktop and enable the function "Mute internal speaker
976          * when the external headphone out jack is plugged"
977          */
978         if (!(ass & 0x8000))
979                 return;
980         /*
981          * 10~8 : Jack location
982          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
983          * 14~13: Resvered
984          * 15   : 1 --> enable the function "Mute internal speaker
985          *              when the external headphone out jack is plugged"
986          */
987         if (!spec->autocfg.speaker_pins[0]) {
988                 if (spec->autocfg.line_out_pins[0])
989                         spec->autocfg.speaker_pins[0] =
990                                 spec->autocfg.line_out_pins[0];
991                 else
992                         return;
993         }
994
995         if (!spec->autocfg.hp_pins[0]) {
996                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
997                 if (tmp == 0)
998                         spec->autocfg.hp_pins[0] = porta;
999                 else if (tmp == 1)
1000                         spec->autocfg.hp_pins[0] = porte;
1001                 else if (tmp == 2)
1002                         spec->autocfg.hp_pins[0] = portd;
1003                 else
1004                         return;
1005         }
1006
1007         snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1008                             AC_VERB_SET_UNSOLICITED_ENABLE,
1009                             AC_USRSP_EN | ALC880_HP_EVENT);
1010
1011         spec->unsol_event = alc_sku_unsol_event;
1012 }
1013
1014 /*
1015  * Fix-up pin default configurations
1016  */
1017
1018 struct alc_pincfg {
1019         hda_nid_t nid;
1020         u32 val;
1021 };
1022
1023 static void alc_fix_pincfg(struct hda_codec *codec,
1024                            const struct snd_pci_quirk *quirk,
1025                            const struct alc_pincfg **pinfix)
1026 {
1027         const struct alc_pincfg *cfg;
1028
1029         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1030         if (!quirk)
1031                 return;
1032
1033         cfg = pinfix[quirk->value];
1034         for (; cfg->nid; cfg++) {
1035                 int i;
1036                 u32 val = cfg->val;
1037                 for (i = 0; i < 4; i++) {
1038                         snd_hda_codec_write(codec, cfg->nid, 0,
1039                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
1040                                     val & 0xff);
1041                         val >>= 8;
1042                 }
1043         }
1044 }
1045
1046 /*
1047  * ALC880 3-stack model
1048  *
1049  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1050  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1051  *                 F-Mic = 0x1b, HP = 0x19
1052  */
1053
1054 static hda_nid_t alc880_dac_nids[4] = {
1055         /* front, rear, clfe, rear_surr */
1056         0x02, 0x05, 0x04, 0x03
1057 };
1058
1059 static hda_nid_t alc880_adc_nids[3] = {
1060         /* ADC0-2 */
1061         0x07, 0x08, 0x09,
1062 };
1063
1064 /* The datasheet says the node 0x07 is connected from inputs,
1065  * but it shows zero connection in the real implementation on some devices.
1066  * Note: this is a 915GAV bug, fixed on 915GLV
1067  */
1068 static hda_nid_t alc880_adc_nids_alt[2] = {
1069         /* ADC1-2 */
1070         0x08, 0x09,
1071 };
1072
1073 #define ALC880_DIGOUT_NID       0x06
1074 #define ALC880_DIGIN_NID        0x0a
1075
1076 static struct hda_input_mux alc880_capture_source = {
1077         .num_items = 4,
1078         .items = {
1079                 { "Mic", 0x0 },
1080                 { "Front Mic", 0x3 },
1081                 { "Line", 0x2 },
1082                 { "CD", 0x4 },
1083         },
1084 };
1085
1086 /* channel source setting (2/6 channel selection for 3-stack) */
1087 /* 2ch mode */
1088 static struct hda_verb alc880_threestack_ch2_init[] = {
1089         /* set line-in to input, mute it */
1090         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1091         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1092         /* set mic-in to input vref 80%, mute it */
1093         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1094         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1095         { } /* end */
1096 };
1097
1098 /* 6ch mode */
1099 static struct hda_verb alc880_threestack_ch6_init[] = {
1100         /* set line-in to output, unmute it */
1101         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1102         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1103         /* set mic-in to output, unmute it */
1104         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1105         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1106         { } /* end */
1107 };
1108
1109 static struct hda_channel_mode alc880_threestack_modes[2] = {
1110         { 2, alc880_threestack_ch2_init },
1111         { 6, alc880_threestack_ch6_init },
1112 };
1113
1114 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1115         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1116         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1117         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1118         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1119         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1120         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1121         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1122         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1123         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1124         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1125         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1126         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1127         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1128         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1129         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1130         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1131         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1132         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1133         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1134         {
1135                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1136                 .name = "Channel Mode",
1137                 .info = alc_ch_mode_info,
1138                 .get = alc_ch_mode_get,
1139                 .put = alc_ch_mode_put,
1140         },
1141         { } /* end */
1142 };
1143
1144 /* capture mixer elements */
1145 static struct snd_kcontrol_new alc880_capture_mixer[] = {
1146         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
1147         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
1148         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
1149         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
1150         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
1151         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
1152         {
1153                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1154                 /* The multiple "Capture Source" controls confuse alsamixer
1155                  * So call somewhat different..
1156                  */
1157                 /* .name = "Capture Source", */
1158                 .name = "Input Source",
1159                 .count = 3,
1160                 .info = alc_mux_enum_info,
1161                 .get = alc_mux_enum_get,
1162                 .put = alc_mux_enum_put,
1163         },
1164         { } /* end */
1165 };
1166
1167 /* capture mixer elements (in case NID 0x07 not available) */
1168 static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
1169         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1170         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1171         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
1172         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
1173         {
1174                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1175                 /* The multiple "Capture Source" controls confuse alsamixer
1176                  * So call somewhat different..
1177                  */
1178                 /* .name = "Capture Source", */
1179                 .name = "Input Source",
1180                 .count = 2,
1181                 .info = alc_mux_enum_info,
1182                 .get = alc_mux_enum_get,
1183                 .put = alc_mux_enum_put,
1184         },
1185         { } /* end */
1186 };
1187
1188
1189
1190 /*
1191  * ALC880 5-stack model
1192  *
1193  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1194  *      Side = 0x02 (0xd)
1195  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1196  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1197  */
1198
1199 /* additional mixers to alc880_three_stack_mixer */
1200 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1201         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1202         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1203         { } /* end */
1204 };
1205
1206 /* channel source setting (6/8 channel selection for 5-stack) */
1207 /* 6ch mode */
1208 static struct hda_verb alc880_fivestack_ch6_init[] = {
1209         /* set line-in to input, mute it */
1210         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1211         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1212         { } /* end */
1213 };
1214
1215 /* 8ch mode */
1216 static struct hda_verb alc880_fivestack_ch8_init[] = {
1217         /* set line-in to output, unmute it */
1218         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1219         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1220         { } /* end */
1221 };
1222
1223 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1224         { 6, alc880_fivestack_ch6_init },
1225         { 8, alc880_fivestack_ch8_init },
1226 };
1227
1228
1229 /*
1230  * ALC880 6-stack model
1231  *
1232  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1233  *      Side = 0x05 (0x0f)
1234  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1235  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1236  */
1237
1238 static hda_nid_t alc880_6st_dac_nids[4] = {
1239         /* front, rear, clfe, rear_surr */
1240         0x02, 0x03, 0x04, 0x05
1241 };
1242
1243 static struct hda_input_mux alc880_6stack_capture_source = {
1244         .num_items = 4,
1245         .items = {
1246                 { "Mic", 0x0 },
1247                 { "Front Mic", 0x1 },
1248                 { "Line", 0x2 },
1249                 { "CD", 0x4 },
1250         },
1251 };
1252
1253 /* fixed 8-channels */
1254 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1255         { 8, NULL },
1256 };
1257
1258 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1259         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1260         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1261         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1262         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1263         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1264         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1265         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1266         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1267         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1268         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1269         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1270         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1271         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1272         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1273         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1274         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1275         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1276         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1277         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1278         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1279         {
1280                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1281                 .name = "Channel Mode",
1282                 .info = alc_ch_mode_info,
1283                 .get = alc_ch_mode_get,
1284                 .put = alc_ch_mode_put,
1285         },
1286         { } /* end */
1287 };
1288
1289
1290 /*
1291  * ALC880 W810 model
1292  *
1293  * W810 has rear IO for:
1294  * Front (DAC 02)
1295  * Surround (DAC 03)
1296  * Center/LFE (DAC 04)
1297  * Digital out (06)
1298  *
1299  * The system also has a pair of internal speakers, and a headphone jack.
1300  * These are both connected to Line2 on the codec, hence to DAC 02.
1301  *
1302  * There is a variable resistor to control the speaker or headphone
1303  * volume. This is a hardware-only device without a software API.
1304  *
1305  * Plugging headphones in will disable the internal speakers. This is
1306  * implemented in hardware, not via the driver using jack sense. In
1307  * a similar fashion, plugging into the rear socket marked "front" will
1308  * disable both the speakers and headphones.
1309  *
1310  * For input, there's a microphone jack, and an "audio in" jack.
1311  * These may not do anything useful with this driver yet, because I
1312  * haven't setup any initialization verbs for these yet...
1313  */
1314
1315 static hda_nid_t alc880_w810_dac_nids[3] = {
1316         /* front, rear/surround, clfe */
1317         0x02, 0x03, 0x04
1318 };
1319
1320 /* fixed 6 channels */
1321 static struct hda_channel_mode alc880_w810_modes[1] = {
1322         { 6, NULL }
1323 };
1324
1325 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1326 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1327         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1328         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1329         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1330         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1331         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1332         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1333         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1334         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1335         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1336         { } /* end */
1337 };
1338
1339
1340 /*
1341  * Z710V model
1342  *
1343  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1344  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1345  *                 Line = 0x1a
1346  */
1347
1348 static hda_nid_t alc880_z71v_dac_nids[1] = {
1349         0x02
1350 };
1351 #define ALC880_Z71V_HP_DAC      0x03
1352
1353 /* fixed 2 channels */
1354 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1355         { 2, NULL }
1356 };
1357
1358 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1359         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1360         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1361         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1362         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1363         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1364         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1365         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1366         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1367         { } /* end */
1368 };
1369
1370
1371 /*
1372  * ALC880 F1734 model
1373  *
1374  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1375  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1376  */
1377
1378 static hda_nid_t alc880_f1734_dac_nids[1] = {
1379         0x03
1380 };
1381 #define ALC880_F1734_HP_DAC     0x02
1382
1383 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1384         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1385         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1386         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1387         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1388         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1389         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1390         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1391         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1392         { } /* end */
1393 };
1394
1395 static struct hda_input_mux alc880_f1734_capture_source = {
1396         .num_items = 2,
1397         .items = {
1398                 { "Mic", 0x1 },
1399                 { "CD", 0x4 },
1400         },
1401 };
1402
1403
1404 /*
1405  * ALC880 ASUS model
1406  *
1407  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1408  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1409  *  Mic = 0x18, Line = 0x1a
1410  */
1411
1412 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1413 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1414
1415 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1416         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1417         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1418         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1419         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1420         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1421         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1422         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1423         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1424         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1425         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1426         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1427         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1428         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1429         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1430         {
1431                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1432                 .name = "Channel Mode",
1433                 .info = alc_ch_mode_info,
1434                 .get = alc_ch_mode_get,
1435                 .put = alc_ch_mode_put,
1436         },
1437         { } /* end */
1438 };
1439
1440 /*
1441  * ALC880 ASUS W1V model
1442  *
1443  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1444  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1445  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1446  */
1447
1448 /* additional mixers to alc880_asus_mixer */
1449 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1450         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1451         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1452         { } /* end */
1453 };
1454
1455 /* additional mixers to alc880_asus_mixer */
1456 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1457         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1458         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1459         { } /* end */
1460 };
1461
1462 /* TCL S700 */
1463 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1464         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1465         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1466         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1467         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1468         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1469         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1470         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1471         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1472         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1473         {
1474                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1475                 /* The multiple "Capture Source" controls confuse alsamixer
1476                  * So call somewhat different..
1477                  */
1478                 /* .name = "Capture Source", */
1479                 .name = "Input Source",
1480                 .count = 1,
1481                 .info = alc_mux_enum_info,
1482                 .get = alc_mux_enum_get,
1483                 .put = alc_mux_enum_put,
1484         },
1485         { } /* end */
1486 };
1487
1488 /* Uniwill */
1489 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1490         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1491         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1492         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1493         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1494         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1495         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1496         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1497         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1498         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1499         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1500         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1501         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1502         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1503         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1504         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1505         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1506         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1507         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1508         {
1509                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1510                 .name = "Channel Mode",
1511                 .info = alc_ch_mode_info,
1512                 .get = alc_ch_mode_get,
1513                 .put = alc_ch_mode_put,
1514         },
1515         { } /* end */
1516 };
1517
1518 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1519         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1520         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1521         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1522         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1523         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1524         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1525         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1526         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1527         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1528         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1529         { } /* end */
1530 };
1531
1532 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1533         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1534         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1535         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1536         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1537         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1538         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1539         { } /* end */
1540 };
1541
1542 /*
1543  * virtual master controls
1544  */
1545
1546 /*
1547  * slave controls for virtual master
1548  */
1549 static const char *alc_slave_vols[] = {
1550         "Front Playback Volume",
1551         "Surround Playback Volume",
1552         "Center Playback Volume",
1553         "LFE Playback Volume",
1554         "Side Playback Volume",
1555         "Headphone Playback Volume",
1556         "Speaker Playback Volume",
1557         "Mono Playback Volume",
1558         "Line-Out Playback Volume",
1559         NULL,
1560 };
1561
1562 static const char *alc_slave_sws[] = {
1563         "Front Playback Switch",
1564         "Surround Playback Switch",
1565         "Center Playback Switch",
1566         "LFE Playback Switch",
1567         "Side Playback Switch",
1568         "Headphone Playback Switch",
1569         "Speaker Playback Switch",
1570         "Mono Playback Switch",
1571         "IEC958 Playback Switch",
1572         NULL,
1573 };
1574
1575 /*
1576  * build control elements
1577  */
1578 static int alc_build_controls(struct hda_codec *codec)
1579 {
1580         struct alc_spec *spec = codec->spec;
1581         int err;
1582         int i;
1583
1584         for (i = 0; i < spec->num_mixers; i++) {
1585                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1586                 if (err < 0)
1587                         return err;
1588         }
1589
1590         if (spec->multiout.dig_out_nid) {
1591                 err = snd_hda_create_spdif_out_ctls(codec,
1592                                                     spec->multiout.dig_out_nid);
1593                 if (err < 0)
1594                         return err;
1595                 err = snd_hda_create_spdif_share_sw(codec,
1596                                                     &spec->multiout);
1597                 if (err < 0)
1598                         return err;
1599                 spec->multiout.share_spdif = 1;
1600         }
1601         if (spec->dig_in_nid) {
1602                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1603                 if (err < 0)
1604                         return err;
1605         }
1606
1607         /* if we have no master control, let's create it */
1608         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1609                 unsigned int vmaster_tlv[4];
1610                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1611                                         HDA_OUTPUT, vmaster_tlv);
1612                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1613                                           vmaster_tlv, alc_slave_vols);
1614                 if (err < 0)
1615                         return err;
1616         }
1617         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1618                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1619                                           NULL, alc_slave_sws);
1620                 if (err < 0)
1621                         return err;
1622         }
1623
1624         return 0;
1625 }
1626
1627
1628 /*
1629  * initialize the codec volumes, etc
1630  */
1631
1632 /*
1633  * generic initialization of ADC, input mixers and output mixers
1634  */
1635 static struct hda_verb alc880_volume_init_verbs[] = {
1636         /*
1637          * Unmute ADC0-2 and set the default input to mic-in
1638          */
1639         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
1640         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1641         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
1642         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1643         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1644         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1645
1646         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1647          * mixer widget
1648          * Note: PASD motherboards uses the Line In 2 as the input for front
1649          * panel mic (mic 2)
1650          */
1651         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
1652         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1653         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1654         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1655         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1656         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1657         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1658         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1659
1660         /*
1661          * Set up output mixers (0x0c - 0x0f)
1662          */
1663         /* set vol=0 to output mixers */
1664         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1665         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1666         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1667         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1668         /* set up input amps for analog loopback */
1669         /* Amp Indices: DAC = 0, mixer = 1 */
1670         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1671         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1672         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1673         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1674         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1675         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1676         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1677         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1678
1679         { }
1680 };
1681
1682 /*
1683  * 3-stack pin configuration:
1684  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
1685  */
1686 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
1687         /*
1688          * preset connection lists of input pins
1689          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1690          */
1691         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1692         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1693         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1694
1695         /*
1696          * Set pin mode and muting
1697          */
1698         /* set front pin widgets 0x14 for output */
1699         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1700         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1701         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1702         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1703         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1704         /* Mic2 (as headphone out) for HP output */
1705         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1706         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1707         /* Line In pin widget for input */
1708         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1709         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1710         /* Line2 (as front mic) pin widget for input and vref at 80% */
1711         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1712         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1713         /* CD pin widget for input */
1714         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1715
1716         { }
1717 };
1718
1719 /*
1720  * 5-stack pin configuration:
1721  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
1722  * line-in/side = 0x1a, f-mic = 0x1b
1723  */
1724 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
1725         /*
1726          * preset connection lists of input pins
1727          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1728          */
1729         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1730         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1731
1732         /*
1733          * Set pin mode and muting
1734          */
1735         /* set pin widgets 0x14-0x17 for output */
1736         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1737         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1738         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1739         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1740         /* unmute pins for output (no gain on this amp) */
1741         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1742         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1743         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1744         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1745
1746         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1747         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1748         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1749         /* Mic2 (as headphone out) for HP output */
1750         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1751         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1752         /* Line In pin widget for input */
1753         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1754         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1755         /* Line2 (as front mic) pin widget for input and vref at 80% */
1756         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1757         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1758         /* CD pin widget for input */
1759         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1760
1761         { }
1762 };
1763
1764 /*
1765  * W810 pin configuration:
1766  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
1767  */
1768 static struct hda_verb alc880_pin_w810_init_verbs[] = {
1769         /* hphone/speaker input selector: front DAC */
1770         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1771
1772         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1773         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1774         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1775         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1776         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1777         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1778
1779         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1780         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1781
1782         { }
1783 };
1784
1785 /*
1786  * Z71V pin configuration:
1787  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
1788  */
1789 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
1790         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1791         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1792         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1793         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1794
1795         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1796         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1797         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1798         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1799
1800         { }
1801 };
1802
1803 /*
1804  * 6-stack pin configuration:
1805  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
1806  * f-mic = 0x19, line = 0x1a, HP = 0x1b
1807  */
1808 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1809         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1810
1811         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1812         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1813         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1814         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1815         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1816         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1817         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1818         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1819
1820         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1821         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1822         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1823         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1824         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1825         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1826         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1827         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1828         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1829
1830         { }
1831 };
1832
1833 /*
1834  * Uniwill pin configuration:
1835  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
1836  * line = 0x1a
1837  */
1838 static struct hda_verb alc880_uniwill_init_verbs[] = {
1839         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1840
1841         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1842         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1843         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1844         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1845         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1846         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1847         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1848         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1849         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1850         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1851         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1852         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1853         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1854         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1855
1856         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1857         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1858         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1859         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1860         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1861         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1862         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
1863         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
1864         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1865
1866         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1867         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
1868
1869         { }
1870 };
1871
1872 /*
1873 * Uniwill P53
1874 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
1875  */
1876 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
1877         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1878
1879         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1880         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1881         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1882         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1883         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1884         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1885         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1886         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1887         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1888         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1889         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1890         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1891
1892         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1893         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1894         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1895         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1896         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1897         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1898
1899         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1900         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
1901
1902         { }
1903 };
1904
1905 static struct hda_verb alc880_beep_init_verbs[] = {
1906         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
1907         { }
1908 };
1909
1910 /* toggle speaker-output according to the hp-jack state */
1911 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
1912 {
1913         unsigned int present;
1914         unsigned char bits;
1915
1916         present = snd_hda_codec_read(codec, 0x14, 0,
1917                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1918         bits = present ? HDA_AMP_MUTE : 0;
1919         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1920                                  HDA_AMP_MUTE, bits);
1921         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
1922                                  HDA_AMP_MUTE, bits);
1923 }
1924
1925 /* auto-toggle front mic */
1926 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
1927 {
1928         unsigned int present;
1929         unsigned char bits;
1930
1931         present = snd_hda_codec_read(codec, 0x18, 0,
1932                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1933         bits = present ? HDA_AMP_MUTE : 0;
1934         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
1935 }
1936
1937 static void alc880_uniwill_automute(struct hda_codec *codec)
1938 {
1939         alc880_uniwill_hp_automute(codec);
1940         alc880_uniwill_mic_automute(codec);
1941 }
1942
1943 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
1944                                        unsigned int res)
1945 {
1946         /* Looks like the unsol event is incompatible with the standard
1947          * definition.  4bit tag is placed at 28 bit!
1948          */
1949         switch (res >> 28) {
1950         case ALC880_HP_EVENT:
1951                 alc880_uniwill_hp_automute(codec);
1952                 break;
1953         case ALC880_MIC_EVENT:
1954                 alc880_uniwill_mic_automute(codec);
1955                 break;
1956         }
1957 }
1958
1959 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
1960 {
1961         unsigned int present;
1962         unsigned char bits;
1963
1964         present = snd_hda_codec_read(codec, 0x14, 0,
1965                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1966         bits = present ? HDA_AMP_MUTE : 0;
1967         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
1968 }
1969
1970 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
1971 {
1972         unsigned int present;
1973
1974         present = snd_hda_codec_read(codec, 0x21, 0,
1975                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
1976         present &= HDA_AMP_VOLMASK;
1977         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
1978                                  HDA_AMP_VOLMASK, present);
1979         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
1980                                  HDA_AMP_VOLMASK, present);
1981 }
1982
1983 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
1984                                            unsigned int res)
1985 {
1986         /* Looks like the unsol event is incompatible with the standard
1987          * definition.  4bit tag is placed at 28 bit!
1988          */
1989         if ((res >> 28) == ALC880_HP_EVENT)
1990                 alc880_uniwill_p53_hp_automute(codec);
1991         if ((res >> 28) == ALC880_DCVOL_EVENT)
1992                 alc880_uniwill_p53_dcvol_automute(codec);
1993 }
1994
1995 /*
1996  * F1734 pin configuration:
1997  * HP = 0x14, speaker-out = 0x15, mic = 0x18
1998  */
1999 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2000         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2001         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2002         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2003         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2004         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2005
2006         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2007         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2008         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2009         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2010
2011         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2012         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2013         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2014         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2015         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2016         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2017         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2018         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2019         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2020
2021         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2022         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2023
2024         { }
2025 };
2026
2027 /*
2028  * ASUS pin configuration:
2029  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2030  */
2031 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2032         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2033         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2034         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2035         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2036
2037         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2038         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2039         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2040         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2041         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2042         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2043         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2044         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2045
2046         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2047         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2048         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2049         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2050         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2051         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2052         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2053         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2054         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2055
2056         { }
2057 };
2058
2059 /* Enable GPIO mask and set output */
2060 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2061 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2062
2063 /* Clevo m520g init */
2064 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2065         /* headphone output */
2066         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2067         /* line-out */
2068         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2069         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2070         /* Line-in */
2071         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2072         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2073         /* CD */
2074         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2075         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2076         /* Mic1 (rear panel) */
2077         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2078         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2079         /* Mic2 (front panel) */
2080         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2081         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2082         /* headphone */
2083         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2084         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2085         /* change to EAPD mode */
2086         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2087         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2088
2089         { }
2090 };
2091
2092 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2093         /* change to EAPD mode */
2094         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2095         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2096
2097         /* Headphone output */
2098         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2099         /* Front output*/
2100         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2101         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2102
2103         /* Line In pin widget for input */
2104         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2105         /* CD pin widget for input */
2106         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2107         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2108         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2109
2110         /* change to EAPD mode */
2111         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2112         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2113
2114         { }
2115 };
2116
2117 /*
2118  * LG m1 express dual
2119  *
2120  * Pin assignment:
2121  *   Rear Line-In/Out (blue): 0x14
2122  *   Build-in Mic-In: 0x15
2123  *   Speaker-out: 0x17
2124  *   HP-Out (green): 0x1b
2125  *   Mic-In/Out (red): 0x19
2126  *   SPDIF-Out: 0x1e
2127  */
2128
2129 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2130 static hda_nid_t alc880_lg_dac_nids[3] = {
2131         0x05, 0x02, 0x03
2132 };
2133
2134 /* seems analog CD is not working */
2135 static struct hda_input_mux alc880_lg_capture_source = {
2136         .num_items = 3,
2137         .items = {
2138                 { "Mic", 0x1 },
2139                 { "Line", 0x5 },
2140                 { "Internal Mic", 0x6 },
2141         },
2142 };
2143
2144 /* 2,4,6 channel modes */
2145 static struct hda_verb alc880_lg_ch2_init[] = {
2146         /* set line-in and mic-in to input */
2147         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2148         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2149         { }
2150 };
2151
2152 static struct hda_verb alc880_lg_ch4_init[] = {
2153         /* set line-in to out and mic-in to input */
2154         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2155         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2156         { }
2157 };
2158
2159 static struct hda_verb alc880_lg_ch6_init[] = {
2160         /* set line-in and mic-in to output */
2161         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2162         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2163         { }
2164 };
2165
2166 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2167         { 2, alc880_lg_ch2_init },
2168         { 4, alc880_lg_ch4_init },
2169         { 6, alc880_lg_ch6_init },
2170 };
2171
2172 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2173         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2174         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2175         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2176         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2177         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2178         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2179         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2180         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2181         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2182         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2183         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2184         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2185         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2186         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2187         {
2188                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2189                 .name = "Channel Mode",
2190                 .info = alc_ch_mode_info,
2191                 .get = alc_ch_mode_get,
2192                 .put = alc_ch_mode_put,
2193         },
2194         { } /* end */
2195 };
2196
2197 static struct hda_verb alc880_lg_init_verbs[] = {
2198         /* set capture source to mic-in */
2199         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2200         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2201         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2202         /* mute all amp mixer inputs */
2203         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2204         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2205         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2206         /* line-in to input */
2207         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2208         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2209         /* built-in mic */
2210         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2211         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2212         /* speaker-out */
2213         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2214         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2215         /* mic-in to input */
2216         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2217         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2218         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2219         /* HP-out */
2220         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2221         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2222         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2223         /* jack sense */
2224         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2225         { }
2226 };
2227
2228 /* toggle speaker-output according to the hp-jack state */
2229 static void alc880_lg_automute(struct hda_codec *codec)
2230 {
2231         unsigned int present;
2232         unsigned char bits;
2233
2234         present = snd_hda_codec_read(codec, 0x1b, 0,
2235                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2236         bits = present ? HDA_AMP_MUTE : 0;
2237         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2238                                  HDA_AMP_MUTE, bits);
2239 }
2240
2241 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2242 {
2243         /* Looks like the unsol event is incompatible with the standard
2244          * definition.  4bit tag is placed at 28 bit!
2245          */
2246         if ((res >> 28) == 0x01)
2247                 alc880_lg_automute(codec);
2248 }
2249
2250 /*
2251  * LG LW20
2252  *
2253  * Pin assignment:
2254  *   Speaker-out: 0x14
2255  *   Mic-In: 0x18
2256  *   Built-in Mic-In: 0x19
2257  *   Line-In: 0x1b
2258  *   HP-Out: 0x1a
2259  *   SPDIF-Out: 0x1e
2260  */
2261
2262 static struct hda_input_mux alc880_lg_lw_capture_source = {
2263         .num_items = 3,
2264         .items = {
2265                 { "Mic", 0x0 },
2266                 { "Internal Mic", 0x1 },
2267                 { "Line In", 0x2 },
2268         },
2269 };
2270
2271 #define alc880_lg_lw_modes alc880_threestack_modes
2272
2273 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2274         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2275         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2276         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2277         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2278         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2279         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2280         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2281         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2282         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2283         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2284         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2285         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2286         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2287         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2288         {
2289                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2290                 .name = "Channel Mode",
2291                 .info = alc_ch_mode_info,
2292                 .get = alc_ch_mode_get,
2293                 .put = alc_ch_mode_put,
2294         },
2295         { } /* end */
2296 };
2297
2298 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2299         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2300         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2301         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2302
2303         /* set capture source to mic-in */
2304         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2305         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2306         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2307         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2308         /* speaker-out */
2309         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2310         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2311         /* HP-out */
2312         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2313         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2314         /* mic-in to input */
2315         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2316         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2317         /* built-in mic */
2318         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2319         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2320         /* jack sense */
2321         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2322         { }
2323 };
2324
2325 /* toggle speaker-output according to the hp-jack state */
2326 static void alc880_lg_lw_automute(struct hda_codec *codec)
2327 {
2328         unsigned int present;
2329         unsigned char bits;
2330
2331         present = snd_hda_codec_read(codec, 0x1b, 0,
2332                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2333         bits = present ? HDA_AMP_MUTE : 0;
2334         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2335                                  HDA_AMP_MUTE, bits);
2336 }
2337
2338 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2339 {
2340         /* Looks like the unsol event is incompatible with the standard
2341          * definition.  4bit tag is placed at 28 bit!
2342          */
2343         if ((res >> 28) == 0x01)
2344                 alc880_lg_lw_automute(codec);
2345 }
2346
2347 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2348         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2349         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2350         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2351         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2352         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2353         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2354         { } /* end */
2355 };
2356
2357 static struct hda_input_mux alc880_medion_rim_capture_source = {
2358         .num_items = 2,
2359         .items = {
2360                 { "Mic", 0x0 },
2361                 { "Internal Mic", 0x1 },
2362         },
2363 };
2364
2365 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2366         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2367
2368         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2369         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2370
2371         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2372         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2373         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2374         /* Mic2 (as headphone out) for HP output */
2375         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2376         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2377         /* Internal Speaker */
2378         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2379         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2380
2381         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2382         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2383
2384         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2385         { }
2386 };
2387
2388 /* toggle speaker-output according to the hp-jack state */
2389 static void alc880_medion_rim_automute(struct hda_codec *codec)
2390 {
2391         unsigned int present;
2392         unsigned char bits;
2393
2394         present = snd_hda_codec_read(codec, 0x14, 0,
2395                                      AC_VERB_GET_PIN_SENSE, 0)
2396                 & AC_PINSENSE_PRESENCE;
2397         bits = present ? HDA_AMP_MUTE : 0;
2398         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2399                                  HDA_AMP_MUTE, bits);
2400         if (present)
2401                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2402         else
2403                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2404 }
2405
2406 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2407                                           unsigned int res)
2408 {
2409         /* Looks like the unsol event is incompatible with the standard
2410          * definition.  4bit tag is placed at 28 bit!
2411          */
2412         if ((res >> 28) == ALC880_HP_EVENT)
2413                 alc880_medion_rim_automute(codec);
2414 }
2415
2416 #ifdef CONFIG_SND_HDA_POWER_SAVE
2417 static struct hda_amp_list alc880_loopbacks[] = {
2418         { 0x0b, HDA_INPUT, 0 },
2419         { 0x0b, HDA_INPUT, 1 },
2420         { 0x0b, HDA_INPUT, 2 },
2421         { 0x0b, HDA_INPUT, 3 },
2422         { 0x0b, HDA_INPUT, 4 },
2423         { } /* end */
2424 };
2425
2426 static struct hda_amp_list alc880_lg_loopbacks[] = {
2427         { 0x0b, HDA_INPUT, 1 },
2428         { 0x0b, HDA_INPUT, 6 },
2429         { 0x0b, HDA_INPUT, 7 },
2430         { } /* end */
2431 };
2432 #endif
2433
2434 /*
2435  * Common callbacks
2436  */
2437
2438 static int alc_init(struct hda_codec *codec)
2439 {
2440         struct alc_spec *spec = codec->spec;
2441         unsigned int i;
2442
2443         alc_fix_pll(codec);
2444         if (codec->vendor_id == 0x10ec0888)
2445                 alc888_coef_init(codec);
2446
2447         for (i = 0; i < spec->num_init_verbs; i++)
2448                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2449
2450         if (spec->init_hook)
2451                 spec->init_hook(codec);
2452
2453         return 0;
2454 }
2455
2456 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2457 {
2458         struct alc_spec *spec = codec->spec;
2459
2460         if (spec->unsol_event)
2461                 spec->unsol_event(codec, res);
2462 }
2463
2464 #ifdef CONFIG_SND_HDA_POWER_SAVE
2465 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2466 {
2467         struct alc_spec *spec = codec->spec;
2468         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2469 }
2470 #endif
2471
2472 /*
2473  * Analog playback callbacks
2474  */
2475 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2476                                     struct hda_codec *codec,
2477                                     struct snd_pcm_substream *substream)
2478 {
2479         struct alc_spec *spec = codec->spec;
2480         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2481                                              hinfo);
2482 }
2483
2484 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2485                                        struct hda_codec *codec,
2486                                        unsigned int stream_tag,
2487                                        unsigned int format,
2488                                        struct snd_pcm_substream *substream)
2489 {
2490         struct alc_spec *spec = codec->spec;
2491         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2492                                                 stream_tag, format, substream);
2493 }
2494
2495 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2496                                        struct hda_codec *codec,
2497                                        struct snd_pcm_substream *substream)
2498 {
2499         struct alc_spec *spec = codec->spec;
2500         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2501 }
2502
2503 /*
2504  * Digital out
2505  */
2506 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2507                                         struct hda_codec *codec,
2508                                         struct snd_pcm_substream *substream)
2509 {
2510         struct alc_spec *spec = codec->spec;
2511         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2512 }
2513
2514 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2515                                            struct hda_codec *codec,
2516                                            unsigned int stream_tag,
2517                                            unsigned int format,
2518                                            struct snd_pcm_substream *substream)
2519 {
2520         struct alc_spec *spec = codec->spec;
2521         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2522                                              stream_tag, format, substream);
2523 }
2524
2525 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2526                                          struct hda_codec *codec,
2527                                          struct snd_pcm_substream *substream)
2528 {
2529         struct alc_spec *spec = codec->spec;
2530         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2531 }
2532
2533 /*
2534  * Analog capture
2535  */
2536 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2537                                       struct hda_codec *codec,
2538                                       unsigned int stream_tag,
2539                                       unsigned int format,
2540                                       struct snd_pcm_substream *substream)
2541 {
2542         struct alc_spec *spec = codec->spec;
2543
2544         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2545                                    stream_tag, 0, format);
2546         return 0;
2547 }
2548
2549 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2550                                       struct hda_codec *codec,
2551                                       struct snd_pcm_substream *substream)
2552 {
2553         struct alc_spec *spec = codec->spec;
2554
2555         snd_hda_codec_cleanup_stream(codec,
2556                                      spec->adc_nids[substream->number + 1]);
2557         return 0;
2558 }
2559
2560
2561 /*
2562  */
2563 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2564         .substreams = 1,
2565         .channels_min = 2,
2566         .channels_max = 8,
2567         /* NID is set in alc_build_pcms */
2568         .ops = {
2569                 .open = alc880_playback_pcm_open,
2570                 .prepare = alc880_playback_pcm_prepare,
2571                 .cleanup = alc880_playback_pcm_cleanup
2572         },
2573 };
2574
2575 static struct hda_pcm_stream alc880_pcm_analog_capture = {
2576         .substreams = 1,
2577         .channels_min = 2,
2578         .channels_max = 2,
2579         /* NID is set in alc_build_pcms */
2580 };
2581
2582 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
2583         .substreams = 1,
2584         .channels_min = 2,
2585         .channels_max = 2,
2586         /* NID is set in alc_build_pcms */
2587 };
2588
2589 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
2590         .substreams = 2, /* can be overridden */
2591         .channels_min = 2,
2592         .channels_max = 2,
2593         /* NID is set in alc_build_pcms */
2594         .ops = {
2595                 .prepare = alc880_alt_capture_pcm_prepare,
2596                 .cleanup = alc880_alt_capture_pcm_cleanup
2597         },
2598 };
2599
2600 static struct hda_pcm_stream alc880_pcm_digital_playback = {
2601         .substreams = 1,
2602         .channels_min = 2,
2603         .channels_max = 2,
2604         /* NID is set in alc_build_pcms */
2605         .ops = {
2606                 .open = alc880_dig_playback_pcm_open,
2607                 .close = alc880_dig_playback_pcm_close,
2608                 .prepare = alc880_dig_playback_pcm_prepare
2609         },
2610 };
2611
2612 static struct hda_pcm_stream alc880_pcm_digital_capture = {
2613         .substreams = 1,
2614         .channels_min = 2,
2615         .channels_max = 2,
2616         /* NID is set in alc_build_pcms */
2617 };
2618
2619 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2620 static struct hda_pcm_stream alc_pcm_null_stream = {
2621         .substreams = 0,
2622         .channels_min = 0,
2623         .channels_max = 0,
2624 };
2625
2626 static int alc_build_pcms(struct hda_codec *codec)
2627 {
2628         struct alc_spec *spec = codec->spec;
2629         struct hda_pcm *info = spec->pcm_rec;
2630         int i;
2631
2632         codec->num_pcms = 1;
2633         codec->pcm_info = info;
2634
2635         info->name = spec->stream_name_analog;
2636         if (spec->stream_analog_playback) {
2637                 if (snd_BUG_ON(!spec->multiout.dac_nids))
2638                         return -EINVAL;
2639                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
2640                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2641         }
2642         if (spec->stream_analog_capture) {
2643                 if (snd_BUG_ON(!spec->adc_nids))
2644                         return -EINVAL;
2645                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2646                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2647         }
2648
2649         if (spec->channel_mode) {
2650                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2651                 for (i = 0; i < spec->num_channel_mode; i++) {
2652                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2653                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2654                         }
2655                 }
2656         }
2657
2658         /* SPDIF for stream index #1 */
2659         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2660                 codec->num_pcms = 2;
2661                 info = spec->pcm_rec + 1;
2662                 info->name = spec->stream_name_digital;
2663                 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2664                 if (spec->multiout.dig_out_nid &&
2665                     spec->stream_digital_playback) {
2666                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
2667                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2668                 }
2669                 if (spec->dig_in_nid &&
2670                     spec->stream_digital_capture) {
2671                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
2672                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2673                 }
2674                 /* FIXME: do we need this for all Realtek codec models? */
2675                 codec->spdif_status_reset = 1;
2676         }
2677
2678         /* If the use of more than one ADC is requested for the current
2679          * model, configure a second analog capture-only PCM.
2680          */
2681         /* Additional Analaog capture for index #2 */
2682         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
2683             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
2684                 codec->num_pcms = 3;
2685                 info = spec->pcm_rec + 2;
2686                 info->name = spec->stream_name_analog;
2687                 if (spec->alt_dac_nid) {
2688                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2689                                 *spec->stream_analog_alt_playback;
2690                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2691                                 spec->alt_dac_nid;
2692                 } else {
2693                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2694                                 alc_pcm_null_stream;
2695                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2696                 }
2697                 if (spec->num_adc_nids > 1) {
2698                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2699                                 *spec->stream_analog_alt_capture;
2700                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2701                                 spec->adc_nids[1];
2702                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2703                                 spec->num_adc_nids - 1;
2704                 } else {
2705                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2706                                 alc_pcm_null_stream;
2707                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2708                 }
2709         }
2710
2711         return 0;
2712 }
2713
2714 static void alc_free(struct hda_codec *codec)
2715 {
2716         struct alc_spec *spec = codec->spec;
2717         unsigned int i;
2718
2719         if (!spec)
2720                 return;
2721
2722         if (spec->kctl_alloc) {
2723                 for (i = 0; i < spec->num_kctl_used; i++)
2724                         kfree(spec->kctl_alloc[i].name);
2725                 kfree(spec->kctl_alloc);
2726         }
2727         kfree(spec);
2728         codec->spec = NULL; /* to be sure */
2729 }
2730
2731 /*
2732  */
2733 static struct hda_codec_ops alc_patch_ops = {
2734         .build_controls = alc_build_controls,
2735         .build_pcms = alc_build_pcms,
2736         .init = alc_init,
2737         .free = alc_free,
2738         .unsol_event = alc_unsol_event,
2739 #ifdef CONFIG_SND_HDA_POWER_SAVE
2740         .check_power_status = alc_check_power_status,
2741 #endif
2742 };
2743
2744
2745 /*
2746  * Test configuration for debugging
2747  *
2748  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
2749  * enum controls.
2750  */
2751 #ifdef CONFIG_SND_DEBUG
2752 static hda_nid_t alc880_test_dac_nids[4] = {
2753         0x02, 0x03, 0x04, 0x05
2754 };
2755
2756 static struct hda_input_mux alc880_test_capture_source = {
2757         .num_items = 7,
2758         .items = {
2759                 { "In-1", 0x0 },
2760                 { "In-2", 0x1 },
2761                 { "In-3", 0x2 },
2762                 { "In-4", 0x3 },
2763                 { "CD", 0x4 },
2764                 { "Front", 0x5 },
2765                 { "Surround", 0x6 },
2766         },
2767 };
2768
2769 static struct hda_channel_mode alc880_test_modes[4] = {
2770         { 2, NULL },
2771         { 4, NULL },
2772         { 6, NULL },
2773         { 8, NULL },
2774 };
2775
2776 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
2777                                  struct snd_ctl_elem_info *uinfo)
2778 {
2779         static char *texts[] = {
2780                 "N/A", "Line Out", "HP Out",
2781                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
2782         };
2783         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2784         uinfo->count = 1;
2785         uinfo->value.enumerated.items = 8;
2786         if (uinfo->value.enumerated.item >= 8)
2787                 uinfo->value.enumerated.item = 7;
2788         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2789         return 0;
2790 }
2791
2792 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
2793                                 struct snd_ctl_elem_value *ucontrol)
2794 {
2795         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2796         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2797         unsigned int pin_ctl, item = 0;
2798
2799         pin_ctl = snd_hda_codec_read(codec, nid, 0,
2800                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2801         if (pin_ctl & AC_PINCTL_OUT_EN) {
2802                 if (pin_ctl & AC_PINCTL_HP_EN)
2803                         item = 2;
2804                 else
2805                         item = 1;
2806         } else if (pin_ctl & AC_PINCTL_IN_EN) {
2807                 switch (pin_ctl & AC_PINCTL_VREFEN) {
2808                 case AC_PINCTL_VREF_HIZ: item = 3; break;
2809                 case AC_PINCTL_VREF_50:  item = 4; break;
2810                 case AC_PINCTL_VREF_GRD: item = 5; break;
2811                 case AC_PINCTL_VREF_80:  item = 6; break;
2812                 case AC_PINCTL_VREF_100: item = 7; break;
2813                 }
2814         }
2815         ucontrol->value.enumerated.item[0] = item;
2816         return 0;
2817 }
2818
2819 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
2820                                 struct snd_ctl_elem_value *ucontrol)
2821 {
2822         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2823         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2824         static unsigned int ctls[] = {
2825                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
2826                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
2827                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
2828                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
2829                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
2830                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
2831         };
2832         unsigned int old_ctl, new_ctl;
2833
2834         old_ctl = snd_hda_codec_read(codec, nid, 0,
2835                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2836         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
2837         if (old_ctl != new_ctl) {
2838                 int val;
2839                 snd_hda_codec_write_cache(codec, nid, 0,
2840                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
2841                                           new_ctl);
2842                 val = ucontrol->value.enumerated.item[0] >= 3 ?
2843                         HDA_AMP_MUTE : 0;
2844                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
2845                                          HDA_AMP_MUTE, val);
2846                 return 1;
2847         }
2848         return 0;
2849 }
2850
2851 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
2852                                  struct snd_ctl_elem_info *uinfo)
2853 {
2854         static char *texts[] = {
2855                 "Front", "Surround", "CLFE", "Side"
2856         };
2857         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2858         uinfo->count = 1;
2859         uinfo->value.enumerated.items = 4;
2860         if (uinfo->value.enumerated.item >= 4)
2861                 uinfo->value.enumerated.item = 3;
2862         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2863         return 0;
2864 }
2865
2866 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
2867                                 struct snd_ctl_elem_value *ucontrol)
2868 {
2869         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2870         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2871         unsigned int sel;
2872
2873         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
2874         ucontrol->value.enumerated.item[0] = sel & 3;
2875         return 0;
2876 }
2877
2878 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
2879                                 struct snd_ctl_elem_value *ucontrol)
2880 {
2881         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2882         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2883         unsigned int sel;
2884
2885         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
2886         if (ucontrol->value.enumerated.item[0] != sel) {
2887                 sel = ucontrol->value.enumerated.item[0] & 3;
2888                 snd_hda_codec_write_cache(codec, nid, 0,
2889                                           AC_VERB_SET_CONNECT_SEL, sel);
2890                 return 1;
2891         }
2892         return 0;
2893 }
2894
2895 #define PIN_CTL_TEST(xname,nid) {                       \
2896                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2897                         .name = xname,                 \
2898                         .info = alc_test_pin_ctl_info, \
2899                         .get = alc_test_pin_ctl_get,   \
2900                         .put = alc_test_pin_ctl_put,   \
2901                         .private_value = nid           \
2902                         }
2903
2904 #define PIN_SRC_TEST(xname,nid) {                       \
2905                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2906                         .name = xname,                 \
2907                         .info = alc_test_pin_src_info, \
2908                         .get = alc_test_pin_src_get,   \
2909                         .put = alc_test_pin_src_put,   \
2910                         .private_value = nid           \
2911                         }
2912
2913 static struct snd_kcontrol_new alc880_test_mixer[] = {
2914         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2915         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2916         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
2917         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2918         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2919         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2920         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
2921         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2922         PIN_CTL_TEST("Front Pin Mode", 0x14),
2923         PIN_CTL_TEST("Surround Pin Mode", 0x15),
2924         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
2925         PIN_CTL_TEST("Side Pin Mode", 0x17),
2926         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
2927         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
2928         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
2929         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
2930         PIN_SRC_TEST("In-1 Pin Source", 0x18),
2931         PIN_SRC_TEST("In-2 Pin Source", 0x19),
2932         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
2933         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
2934         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
2935         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
2936         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
2937         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
2938         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
2939         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
2940         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
2941         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
2942         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
2943         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
2944         {
2945                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2946                 .name = "Channel Mode",
2947                 .info = alc_ch_mode_info,
2948                 .get = alc_ch_mode_get,
2949                 .put = alc_ch_mode_put,
2950         },
2951         { } /* end */
2952 };
2953
2954 static struct hda_verb alc880_test_init_verbs[] = {
2955         /* Unmute inputs of 0x0c - 0x0f */
2956         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2957         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2958         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2959         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2960         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2961         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2962         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2963         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2964         /* Vol output for 0x0c-0x0f */
2965         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2966         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2967         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2968         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2969         /* Set output pins 0x14-0x17 */
2970         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2971         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2972         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2973         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2974         /* Unmute output pins 0x14-0x17 */
2975         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2976         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2977         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2978         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2979         /* Set input pins 0x18-0x1c */
2980         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2981         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2982         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2983         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2984         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2985         /* Mute input pins 0x18-0x1b */
2986         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2987         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2988         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2989         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2990         /* ADC set up */
2991         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2992         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2993         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2994         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2995         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2996         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2997         /* Analog input/passthru */
2998         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2999         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3000         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3001         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3002         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3003         { }
3004 };
3005 #endif
3006
3007 /*
3008  */
3009
3010 static const char *alc880_models[ALC880_MODEL_LAST] = {
3011         [ALC880_3ST]            = "3stack",
3012         [ALC880_TCL_S700]       = "tcl",
3013         [ALC880_3ST_DIG]        = "3stack-digout",
3014         [ALC880_CLEVO]          = "clevo",
3015         [ALC880_5ST]            = "5stack",
3016         [ALC880_5ST_DIG]        = "5stack-digout",
3017         [ALC880_W810]           = "w810",
3018         [ALC880_Z71V]           = "z71v",
3019         [ALC880_6ST]            = "6stack",
3020         [ALC880_6ST_DIG]        = "6stack-digout",
3021         [ALC880_ASUS]           = "asus",
3022         [ALC880_ASUS_W1V]       = "asus-w1v",
3023         [ALC880_ASUS_DIG]       = "asus-dig",
3024         [ALC880_ASUS_DIG2]      = "asus-dig2",
3025         [ALC880_UNIWILL_DIG]    = "uniwill",
3026         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3027         [ALC880_FUJITSU]        = "fujitsu",
3028         [ALC880_F1734]          = "F1734",
3029         [ALC880_LG]             = "lg",
3030         [ALC880_LG_LW]          = "lg-lw",
3031         [ALC880_MEDION_RIM]     = "medion",
3032 #ifdef CONFIG_SND_DEBUG
3033         [ALC880_TEST]           = "test",
3034 #endif
3035         [ALC880_AUTO]           = "auto",
3036 };
3037
3038 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3039         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3040         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3041         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3042         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3043         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3044         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3045         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3046         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3047         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3048         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3049         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3050         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3051         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3052         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3053         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3054         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3055         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3056         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3057         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3058         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3059         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3060         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3061         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3062         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3063         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3064         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
3065         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3066         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3067         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3068         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3069         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3070         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3071         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3072         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3073         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3074         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3075         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3076         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3077         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3078         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3079         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3080         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3081         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3082         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3083         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3084         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3085         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3086         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3087         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3088         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3089         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3090         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3091         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3092         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3093         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3094         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3095         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3096         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3097         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3098         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3099         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3100         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3101         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3102         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3103         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3104         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3105         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3106         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3107         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
3108         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3109         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3110         {}
3111 };
3112
3113 /*
3114  * ALC880 codec presets
3115  */
3116 static struct alc_config_preset alc880_presets[] = {
3117         [ALC880_3ST] = {
3118                 .mixers = { alc880_three_stack_mixer },
3119                 .init_verbs = { alc880_volume_init_verbs,
3120                                 alc880_pin_3stack_init_verbs },
3121                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3122                 .dac_nids = alc880_dac_nids,
3123                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3124                 .channel_mode = alc880_threestack_modes,
3125                 .need_dac_fix = 1,
3126                 .input_mux = &alc880_capture_source,
3127         },
3128         [ALC880_3ST_DIG] = {
3129                 .mixers = { alc880_three_stack_mixer },
3130                 .init_verbs = { alc880_volume_init_verbs,
3131                                 alc880_pin_3stack_init_verbs },
3132                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3133                 .dac_nids = alc880_dac_nids,
3134                 .dig_out_nid = ALC880_DIGOUT_NID,
3135                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3136                 .channel_mode = alc880_threestack_modes,
3137                 .need_dac_fix = 1,
3138                 .input_mux = &alc880_capture_source,
3139         },
3140         [ALC880_TCL_S700] = {
3141                 .mixers = { alc880_tcl_s700_mixer },
3142                 .init_verbs = { alc880_volume_init_verbs,
3143                                 alc880_pin_tcl_S700_init_verbs,
3144                                 alc880_gpio2_init_verbs },
3145                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3146                 .dac_nids = alc880_dac_nids,
3147                 .hp_nid = 0x03,
3148                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3149                 .channel_mode = alc880_2_jack_modes,
3150                 .input_mux = &alc880_capture_source,
3151         },
3152         [ALC880_5ST] = {
3153                 .mixers = { alc880_three_stack_mixer,
3154                             alc880_five_stack_mixer},
3155                 .init_verbs = { alc880_volume_init_verbs,
3156                                 alc880_pin_5stack_init_verbs },
3157                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3158                 .dac_nids = alc880_dac_nids,
3159                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3160                 .channel_mode = alc880_fivestack_modes,
3161                 .input_mux = &alc880_capture_source,
3162         },
3163         [ALC880_5ST_DIG] = {
3164                 .mixers = { alc880_three_stack_mixer,
3165                             alc880_five_stack_mixer },
3166                 .init_verbs = { alc880_volume_init_verbs,
3167                                 alc880_pin_5stack_init_verbs },
3168                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3169                 .dac_nids = alc880_dac_nids,
3170                 .dig_out_nid = ALC880_DIGOUT_NID,
3171                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3172                 .channel_mode = alc880_fivestack_modes,
3173                 .input_mux = &alc880_capture_source,
3174         },
3175         [ALC880_6ST] = {
3176                 .mixers = { alc880_six_stack_mixer },
3177                 .init_verbs = { alc880_volume_init_verbs,
3178                                 alc880_pin_6stack_init_verbs },
3179                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3180                 .dac_nids = alc880_6st_dac_nids,
3181                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3182                 .channel_mode = alc880_sixstack_modes,
3183                 .input_mux = &alc880_6stack_capture_source,
3184         },
3185         [ALC880_6ST_DIG] = {
3186                 .mixers = { alc880_six_stack_mixer },
3187                 .init_verbs = { alc880_volume_init_verbs,
3188                                 alc880_pin_6stack_init_verbs },
3189                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3190                 .dac_nids = alc880_6st_dac_nids,
3191                 .dig_out_nid = ALC880_DIGOUT_NID,
3192                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3193                 .channel_mode = alc880_sixstack_modes,
3194                 .input_mux = &alc880_6stack_capture_source,
3195         },
3196         [ALC880_W810] = {
3197                 .mixers = { alc880_w810_base_mixer },
3198                 .init_verbs = { alc880_volume_init_verbs,
3199                                 alc880_pin_w810_init_verbs,
3200                                 alc880_gpio2_init_verbs },
3201                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3202                 .dac_nids = alc880_w810_dac_nids,
3203                 .dig_out_nid = ALC880_DIGOUT_NID,
3204                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3205                 .channel_mode = alc880_w810_modes,
3206                 .input_mux = &alc880_capture_source,
3207         },
3208         [ALC880_Z71V] = {
3209                 .mixers = { alc880_z71v_mixer },
3210                 .init_verbs = { alc880_volume_init_verbs,
3211                                 alc880_pin_z71v_init_verbs },
3212                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3213                 .dac_nids = alc880_z71v_dac_nids,
3214                 .dig_out_nid = ALC880_DIGOUT_NID,
3215                 .hp_nid = 0x03,
3216                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3217                 .channel_mode = alc880_2_jack_modes,
3218                 .input_mux = &alc880_capture_source,
3219         },
3220         [ALC880_F1734] = {
3221                 .mixers = { alc880_f1734_mixer },
3222                 .init_verbs = { alc880_volume_init_verbs,
3223                                 alc880_pin_f1734_init_verbs },
3224                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3225                 .dac_nids = alc880_f1734_dac_nids,
3226                 .hp_nid = 0x02,
3227                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3228                 .channel_mode = alc880_2_jack_modes,
3229                 .input_mux = &alc880_f1734_capture_source,
3230                 .unsol_event = alc880_uniwill_p53_unsol_event,
3231                 .init_hook = alc880_uniwill_p53_hp_automute,
3232         },
3233         [ALC880_ASUS] = {
3234                 .mixers = { alc880_asus_mixer },
3235                 .init_verbs = { alc880_volume_init_verbs,
3236                                 alc880_pin_asus_init_verbs,
3237                                 alc880_gpio1_init_verbs },
3238                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3239                 .dac_nids = alc880_asus_dac_nids,
3240                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3241                 .channel_mode = alc880_asus_modes,
3242                 .need_dac_fix = 1,
3243                 .input_mux = &alc880_capture_source,
3244         },
3245         [ALC880_ASUS_DIG] = {
3246                 .mixers = { alc880_asus_mixer },
3247                 .init_verbs = { alc880_volume_init_verbs,
3248                                 alc880_pin_asus_init_verbs,
3249                                 alc880_gpio1_init_verbs },
3250                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3251                 .dac_nids = alc880_asus_dac_nids,
3252                 .dig_out_nid = ALC880_DIGOUT_NID,
3253                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3254                 .channel_mode = alc880_asus_modes,
3255                 .need_dac_fix = 1,
3256                 .input_mux = &alc880_capture_source,
3257         },
3258         [ALC880_ASUS_DIG2] = {
3259                 .mixers = { alc880_asus_mixer },
3260                 .init_verbs = { alc880_volume_init_verbs,
3261                                 alc880_pin_asus_init_verbs,
3262                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3263                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3264                 .dac_nids = alc880_asus_dac_nids,
3265                 .dig_out_nid = ALC880_DIGOUT_NID,
3266                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3267                 .channel_mode = alc880_asus_modes,
3268                 .need_dac_fix = 1,
3269                 .input_mux = &alc880_capture_source,
3270         },
3271         [ALC880_ASUS_W1V] = {
3272                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3273                 .init_verbs = { alc880_volume_init_verbs,
3274                                 alc880_pin_asus_init_verbs,
3275                                 alc880_gpio1_init_verbs },
3276                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3277                 .dac_nids = alc880_asus_dac_nids,
3278                 .dig_out_nid = ALC880_DIGOUT_NID,
3279                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3280                 .channel_mode = alc880_asus_modes,
3281                 .need_dac_fix = 1,
3282                 .input_mux = &alc880_capture_source,
3283         },
3284         [ALC880_UNIWILL_DIG] = {
3285                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3286                 .init_verbs = { alc880_volume_init_verbs,
3287                                 alc880_pin_asus_init_verbs },
3288                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3289                 .dac_nids = alc880_asus_dac_nids,
3290                 .dig_out_nid = ALC880_DIGOUT_NID,
3291                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3292                 .channel_mode = alc880_asus_modes,
3293                 .need_dac_fix = 1,
3294                 .input_mux = &alc880_capture_source,
3295         },
3296         [ALC880_UNIWILL] = {
3297                 .mixers = { alc880_uniwill_mixer },
3298                 .init_verbs = { alc880_volume_init_verbs,
3299                                 alc880_uniwill_init_verbs },
3300                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3301                 .dac_nids = alc880_asus_dac_nids,
3302                 .dig_out_nid = ALC880_DIGOUT_NID,
3303                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3304                 .channel_mode = alc880_threestack_modes,
3305                 .need_dac_fix = 1,
3306                 .input_mux = &alc880_capture_source,
3307                 .unsol_event = alc880_uniwill_unsol_event,
3308                 .init_hook = alc880_uniwill_automute,
3309         },
3310         [ALC880_UNIWILL_P53] = {
3311                 .mixers = { alc880_uniwill_p53_mixer },
3312                 .init_verbs = { alc880_volume_init_verbs,
3313                                 alc880_uniwill_p53_init_verbs },
3314                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3315                 .dac_nids = alc880_asus_dac_nids,
3316                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3317                 .channel_mode = alc880_threestack_modes,
3318                 .input_mux = &alc880_capture_source,
3319                 .unsol_event = alc880_uniwill_p53_unsol_event,
3320                 .init_hook = alc880_uniwill_p53_hp_automute,
3321         },
3322         [ALC880_FUJITSU] = {
3323                 .mixers = { alc880_fujitsu_mixer,
3324                             alc880_pcbeep_mixer, },
3325                 .init_verbs = { alc880_volume_init_verbs,
3326                                 alc880_uniwill_p53_init_verbs,
3327                                 alc880_beep_init_verbs },
3328                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3329                 .dac_nids = alc880_dac_nids,
3330                 .dig_out_nid = ALC880_DIGOUT_NID,
3331                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3332                 .channel_mode = alc880_2_jack_modes,
3333                 .input_mux = &alc880_capture_source,
3334                 .unsol_event = alc880_uniwill_p53_unsol_event,
3335                 .init_hook = alc880_uniwill_p53_hp_automute,
3336         },
3337         [ALC880_CLEVO] = {
3338                 .mixers = { alc880_three_stack_mixer },
3339                 .init_verbs = { alc880_volume_init_verbs,
3340                                 alc880_pin_clevo_init_verbs },
3341                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3342                 .dac_nids = alc880_dac_nids,
3343                 .hp_nid = 0x03,
3344                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3345                 .channel_mode = alc880_threestack_modes,
3346                 .need_dac_fix = 1,
3347                 .input_mux = &alc880_capture_source,
3348         },
3349         [ALC880_LG] = {
3350                 .mixers = { alc880_lg_mixer },
3351                 .init_verbs = { alc880_volume_init_verbs,
3352                                 alc880_lg_init_verbs },
3353                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3354                 .dac_nids = alc880_lg_dac_nids,
3355                 .dig_out_nid = ALC880_DIGOUT_NID,
3356                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3357                 .channel_mode = alc880_lg_ch_modes,
3358                 .need_dac_fix = 1,
3359                 .input_mux = &alc880_lg_capture_source,
3360                 .unsol_event = alc880_lg_unsol_event,
3361                 .init_hook = alc880_lg_automute,
3362 #ifdef CONFIG_SND_HDA_POWER_SAVE
3363                 .loopbacks = alc880_lg_loopbacks,
3364 #endif
3365         },
3366         [ALC880_LG_LW] = {
3367                 .mixers = { alc880_lg_lw_mixer },
3368                 .init_verbs = { alc880_volume_init_verbs,
3369                                 alc880_lg_lw_init_verbs },
3370                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3371                 .dac_nids = alc880_dac_nids,
3372                 .dig_out_nid = ALC880_DIGOUT_NID,
3373                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3374                 .channel_mode = alc880_lg_lw_modes,
3375                 .input_mux = &alc880_lg_lw_capture_source,
3376                 .unsol_event = alc880_lg_lw_unsol_event,
3377                 .init_hook = alc880_lg_lw_automute,
3378         },
3379         [ALC880_MEDION_RIM] = {
3380                 .mixers = { alc880_medion_rim_mixer },
3381                 .init_verbs = { alc880_volume_init_verbs,
3382                                 alc880_medion_rim_init_verbs,
3383                                 alc_gpio2_init_verbs },
3384                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3385                 .dac_nids = alc880_dac_nids,
3386                 .dig_out_nid = ALC880_DIGOUT_NID,
3387                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3388                 .channel_mode = alc880_2_jack_modes,
3389                 .input_mux = &alc880_medion_rim_capture_source,
3390                 .unsol_event = alc880_medion_rim_unsol_event,
3391                 .init_hook = alc880_medion_rim_automute,
3392         },
3393 #ifdef CONFIG_SND_DEBUG
3394         [ALC880_TEST] = {
3395                 .mixers = { alc880_test_mixer },
3396                 .init_verbs = { alc880_test_init_verbs },
3397                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3398                 .dac_nids = alc880_test_dac_nids,
3399                 .dig_out_nid = ALC880_DIGOUT_NID,
3400                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3401                 .channel_mode = alc880_test_modes,
3402                 .input_mux = &alc880_test_capture_source,
3403         },
3404 #endif
3405 };
3406
3407 /*
3408  * Automatic parse of I/O pins from the BIOS configuration
3409  */
3410
3411 #define NUM_CONTROL_ALLOC       32
3412 #define NUM_VERB_ALLOC          32
3413
3414 enum {
3415         ALC_CTL_WIDGET_VOL,
3416         ALC_CTL_WIDGET_MUTE,
3417         ALC_CTL_BIND_MUTE,
3418 };
3419 static struct snd_kcontrol_new alc880_control_templates[] = {
3420         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3421         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3422         HDA_BIND_MUTE(NULL, 0, 0, 0),
3423 };
3424
3425 /* add dynamic controls */
3426 static int add_control(struct alc_spec *spec, int type, const char *name,
3427                        unsigned long val)
3428 {
3429         struct snd_kcontrol_new *knew;
3430
3431         if (spec->num_kctl_used >= spec->num_kctl_alloc) {
3432                 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
3433
3434                 /* array + terminator */
3435                 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
3436                 if (!knew)
3437                         return -ENOMEM;
3438                 if (spec->kctl_alloc) {
3439                         memcpy(knew, spec->kctl_alloc,
3440                                sizeof(*knew) * spec->num_kctl_alloc);
3441                         kfree(spec->kctl_alloc);
3442                 }
3443                 spec->kctl_alloc = knew;
3444                 spec->num_kctl_alloc = num;
3445         }
3446
3447         knew = &spec->kctl_alloc[spec->num_kctl_used];
3448         *knew = alc880_control_templates[type];
3449         knew->name = kstrdup(name, GFP_KERNEL);
3450         if (!knew->name)
3451                 return -ENOMEM;
3452         knew->private_value = val;
3453         spec->num_kctl_used++;
3454         return 0;
3455 }
3456
3457 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3458 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3459 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3460 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3461 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3462 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3463 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3464 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3465 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3466 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3467 #define ALC880_PIN_CD_NID               0x1c
3468
3469 /* fill in the dac_nids table from the parsed pin configuration */
3470 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3471                                      const struct auto_pin_cfg *cfg)
3472 {
3473         hda_nid_t nid;
3474         int assigned[4];
3475         int i, j;
3476
3477         memset(assigned, 0, sizeof(assigned));
3478         spec->multiout.dac_nids = spec->private_dac_nids;
3479
3480         /* check the pins hardwired to audio widget */
3481         for (i = 0; i < cfg->line_outs; i++) {
3482                 nid = cfg->line_out_pins[i];
3483                 if (alc880_is_fixed_pin(nid)) {
3484                         int idx = alc880_fixed_pin_idx(nid);
3485                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3486                         assigned[idx] = 1;
3487                 }
3488         }
3489         /* left pins can be connect to any audio widget */
3490         for (i = 0; i < cfg->line_outs; i++) {
3491                 nid = cfg->line_out_pins[i];
3492                 if (alc880_is_fixed_pin(nid))
3493                         continue;
3494                 /* search for an empty channel */
3495                 for (j = 0; j < cfg->line_outs; j++) {
3496                         if (!assigned[j]) {
3497                                 spec->multiout.dac_nids[i] =
3498                                         alc880_idx_to_dac(j);
3499                                 assigned[j] = 1;
3500                                 break;
3501                         }
3502                 }
3503         }
3504         spec->multiout.num_dacs = cfg->line_outs;
3505         return 0;
3506 }
3507
3508 /* add playback controls from the parsed DAC table */
3509 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3510                                              const struct auto_pin_cfg *cfg)
3511 {
3512         char name[32];
3513         static const char *chname[4] = {
3514                 "Front", "Surround", NULL /*CLFE*/, "Side"
3515         };
3516         hda_nid_t nid;
3517         int i, err;
3518
3519         for (i = 0; i < cfg->line_outs; i++) {
3520                 if (!spec->multiout.dac_nids[i])
3521                         continue;
3522                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3523                 if (i == 2) {
3524                         /* Center/LFE */
3525                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3526                                           "Center Playback Volume",
3527                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3528                                                               HDA_OUTPUT));
3529                         if (err < 0)
3530                                 return err;
3531                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3532                                           "LFE Playback Volume",
3533                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3534                                                               HDA_OUTPUT));
3535                         if (err < 0)
3536                                 return err;
3537                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3538                                           "Center Playback Switch",
3539                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
3540                                                               HDA_INPUT));
3541                         if (err < 0)
3542                                 return err;
3543                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3544                                           "LFE Playback Switch",
3545                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
3546                                                               HDA_INPUT));
3547                         if (err < 0)
3548                                 return err;
3549                 } else {
3550                         sprintf(name, "%s Playback Volume", chname[i]);
3551                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3552                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3553                                                               HDA_OUTPUT));
3554                         if (err < 0)
3555                                 return err;
3556                         sprintf(name, "%s Playback Switch", chname[i]);
3557                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3558                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
3559                                                               HDA_INPUT));
3560                         if (err < 0)
3561                                 return err;
3562                 }
3563         }
3564         return 0;
3565 }
3566
3567 /* add playback controls for speaker and HP outputs */
3568 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
3569                                         const char *pfx)
3570 {
3571         hda_nid_t nid;
3572         int err;
3573         char name[32];
3574
3575         if (!pin)
3576                 return 0;
3577
3578         if (alc880_is_fixed_pin(pin)) {
3579                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
3580                 /* specify the DAC as the extra output */
3581                 if (!spec->multiout.hp_nid)
3582                         spec->multiout.hp_nid = nid;
3583                 else
3584                         spec->multiout.extra_out_nid[0] = nid;
3585                 /* control HP volume/switch on the output mixer amp */
3586                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
3587                 sprintf(name, "%s Playback Volume", pfx);
3588                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3589                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3590                 if (err < 0)
3591                         return err;
3592                 sprintf(name, "%s Playback Switch", pfx);
3593                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3594                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
3595                 if (err < 0)
3596                         return err;
3597         } else if (alc880_is_multi_pin(pin)) {
3598                 /* set manual connection */
3599                 /* we have only a switch on HP-out PIN */
3600                 sprintf(name, "%s Playback Switch", pfx);
3601                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3602                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3603                 if (err < 0)
3604                         return err;
3605         }
3606         return 0;
3607 }
3608
3609 /* create input playback/capture controls for the given pin */
3610 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
3611                             const char *ctlname,
3612                             int idx, hda_nid_t mix_nid)
3613 {
3614         char name[32];
3615         int err;
3616
3617         sprintf(name, "%s Playback Volume", ctlname);
3618         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3619                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3620         if (err < 0)
3621                 return err;
3622         sprintf(name, "%s Playback Switch", ctlname);
3623         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3624                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3625         if (err < 0)
3626                 return err;
3627         return 0;
3628 }
3629
3630 /* create playback/capture controls for input pins */
3631 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3632                                                 const struct auto_pin_cfg *cfg)
3633 {
3634         struct hda_input_mux *imux = &spec->private_imux;
3635         int i, err, idx;
3636
3637         for (i = 0; i < AUTO_PIN_LAST; i++) {
3638                 if (alc880_is_input_pin(cfg->input_pins[i])) {
3639                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
3640                         err = new_analog_input(spec, cfg->input_pins[i],
3641                                                auto_pin_cfg_labels[i],
3642                                                idx, 0x0b);
3643                         if (err < 0)
3644                                 return err;
3645                         imux->items[imux->num_items].label =
3646                                 auto_pin_cfg_labels[i];
3647                         imux->items[imux->num_items].index =
3648                                 alc880_input_pin_idx(cfg->input_pins[i]);
3649                         imux->num_items++;
3650                 }
3651         }
3652         return 0;
3653 }
3654
3655 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
3656                                unsigned int pin_type)
3657 {
3658         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3659                             pin_type);
3660         /* unmute pin */
3661         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3662                             AMP_OUT_UNMUTE);
3663 }
3664
3665 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3666                                               hda_nid_t nid, int pin_type,
3667                                               int dac_idx)
3668 {
3669         alc_set_pin_output(codec, nid, pin_type);
3670         /* need the manual connection? */
3671         if (alc880_is_multi_pin(nid)) {
3672                 struct alc_spec *spec = codec->spec;
3673                 int idx = alc880_multi_pin_idx(nid);
3674                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
3675                                     AC_VERB_SET_CONNECT_SEL,
3676                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
3677         }
3678 }
3679
3680 static int get_pin_type(int line_out_type)
3681 {
3682         if (line_out_type == AUTO_PIN_HP_OUT)
3683                 return PIN_HP;
3684         else
3685                 return PIN_OUT;
3686 }
3687
3688 static void alc880_auto_init_multi_out(struct hda_codec *codec)
3689 {
3690         struct alc_spec *spec = codec->spec;
3691         int i;
3692
3693         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
3694         for (i = 0; i < spec->autocfg.line_outs; i++) {
3695                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3696                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3697                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
3698         }
3699 }
3700
3701 static void alc880_auto_init_extra_out(struct hda_codec *codec)
3702 {
3703         struct alc_spec *spec = codec->spec;
3704         hda_nid_t pin;
3705
3706         pin = spec->autocfg.speaker_pins[0];
3707         if (pin) /* connect to front */
3708                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
3709         pin = spec->autocfg.hp_pins[0];
3710         if (pin) /* connect to front */
3711                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3712 }
3713
3714 static void alc880_auto_init_analog_input(struct hda_codec *codec)
3715 {
3716         struct alc_spec *spec = codec->spec;
3717         int i;
3718
3719         for (i = 0; i < AUTO_PIN_LAST; i++) {
3720                 hda_nid_t nid = spec->autocfg.input_pins[i];
3721                 if (alc880_is_input_pin(nid)) {
3722                         snd_hda_codec_write(codec, nid, 0,
3723                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
3724                                             i <= AUTO_PIN_FRONT_MIC ?
3725                                             PIN_VREF80 : PIN_IN);
3726                         if (nid != ALC880_PIN_CD_NID)
3727                                 snd_hda_codec_write(codec, nid, 0,
3728                                                     AC_VERB_SET_AMP_GAIN_MUTE,
3729                                                     AMP_OUT_MUTE);
3730                 }
3731         }
3732 }
3733
3734 /* parse the BIOS configuration and set up the alc_spec */
3735 /* return 1 if successful, 0 if the proper config is not found,
3736  * or a negative error code
3737  */
3738 static int alc880_parse_auto_config(struct hda_codec *codec)
3739 {
3740         struct alc_spec *spec = codec->spec;
3741         int err;
3742         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3743
3744         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3745                                            alc880_ignore);
3746         if (err < 0)
3747                 return err;
3748         if (!spec->autocfg.line_outs)
3749                 return 0; /* can't find valid BIOS pin config */
3750
3751         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
3752         if (err < 0)
3753                 return err;
3754         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
3755         if (err < 0)
3756                 return err;
3757         err = alc880_auto_create_extra_out(spec,
3758                                            spec->autocfg.speaker_pins[0],
3759                                            "Speaker");
3760         if (err < 0)
3761                 return err;
3762         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
3763                                            "Headphone");
3764         if (err < 0)
3765                 return err;
3766         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
3767         if (err < 0)
3768                 return err;
3769
3770         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3771
3772         if (spec->autocfg.dig_out_pin)
3773                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
3774         if (spec->autocfg.dig_in_pin)
3775                 spec->dig_in_nid = ALC880_DIGIN_NID;
3776
3777         if (spec->kctl_alloc)
3778                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3779
3780         spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
3781
3782         spec->num_mux_defs = 1;
3783         spec->input_mux = &spec->private_imux;
3784
3785         return 1;
3786 }
3787
3788 /* additional initialization for auto-configuration model */
3789 static void alc880_auto_init(struct hda_codec *codec)
3790 {
3791         struct alc_spec *spec = codec->spec;
3792         alc880_auto_init_multi_out(codec);
3793         alc880_auto_init_extra_out(codec);
3794         alc880_auto_init_analog_input(codec);
3795         if (spec->unsol_event)
3796                 alc_sku_automute(codec);
3797 }
3798
3799 /*
3800  * OK, here we have finally the patch for ALC880
3801  */
3802
3803 static int patch_alc880(struct hda_codec *codec)
3804 {
3805         struct alc_spec *spec;
3806         int board_config;
3807         int err;
3808
3809         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3810         if (spec == NULL)
3811                 return -ENOMEM;
3812
3813         codec->spec = spec;
3814
3815         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
3816                                                   alc880_models,
3817                                                   alc880_cfg_tbl);
3818         if (board_config < 0) {
3819                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
3820                        "trying auto-probe from BIOS...\n");
3821                 board_config = ALC880_AUTO;
3822         }
3823
3824         if (board_config == ALC880_AUTO) {
3825                 /* automatic parse from the BIOS config */
3826                 err = alc880_parse_auto_config(codec);
3827                 if (err < 0) {
3828                         alc_free(codec);
3829                         return err;
3830                 } else if (!err) {
3831                         printk(KERN_INFO
3832                                "hda_codec: Cannot set up configuration "
3833                                "from BIOS.  Using 3-stack mode...\n");
3834                         board_config = ALC880_3ST;
3835                 }
3836         }
3837
3838         if (board_config != ALC880_AUTO)
3839                 setup_preset(spec, &alc880_presets[board_config]);
3840
3841         spec->stream_name_analog = "ALC880 Analog";
3842         spec->stream_analog_playback = &alc880_pcm_analog_playback;
3843         spec->stream_analog_capture = &alc880_pcm_analog_capture;
3844         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
3845
3846         spec->stream_name_digital = "ALC880 Digital";
3847         spec->stream_digital_playback = &alc880_pcm_digital_playback;
3848         spec->stream_digital_capture = &alc880_pcm_digital_capture;
3849
3850         if (!spec->adc_nids && spec->input_mux) {
3851                 /* check whether NID 0x07 is valid */
3852                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
3853                 /* get type */
3854                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3855                 if (wcap != AC_WID_AUD_IN) {
3856                         spec->adc_nids = alc880_adc_nids_alt;
3857                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
3858                         spec->mixers[spec->num_mixers] =
3859                                 alc880_capture_alt_mixer;
3860                         spec->num_mixers++;
3861                 } else {
3862                         spec->adc_nids = alc880_adc_nids;
3863                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
3864                         spec->mixers[spec->num_mixers] = alc880_capture_mixer;
3865                         spec->num_mixers++;
3866                 }
3867         }
3868
3869         spec->vmaster_nid = 0x0c;
3870
3871         codec->patch_ops = alc_patch_ops;
3872         if (board_config == ALC880_AUTO)
3873                 spec->init_hook = alc880_auto_init;
3874 #ifdef CONFIG_SND_HDA_POWER_SAVE
3875         if (!spec->loopback.amplist)
3876                 spec->loopback.amplist = alc880_loopbacks;
3877 #endif
3878
3879         return 0;
3880 }
3881
3882
3883 /*
3884  * ALC260 support
3885  */
3886
3887 static hda_nid_t alc260_dac_nids[1] = {
3888         /* front */
3889         0x02,
3890 };
3891
3892 static hda_nid_t alc260_adc_nids[1] = {
3893         /* ADC0 */
3894         0x04,
3895 };
3896
3897 static hda_nid_t alc260_adc_nids_alt[1] = {
3898         /* ADC1 */
3899         0x05,
3900 };
3901
3902 static hda_nid_t alc260_hp_adc_nids[2] = {
3903         /* ADC1, 0 */
3904         0x05, 0x04
3905 };
3906
3907 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
3908  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
3909  */
3910 static hda_nid_t alc260_dual_adc_nids[2] = {
3911         /* ADC0, ADC1 */
3912         0x04, 0x05
3913 };
3914
3915 #define ALC260_DIGOUT_NID       0x03
3916 #define ALC260_DIGIN_NID        0x06
3917
3918 static struct hda_input_mux alc260_capture_source = {
3919         .num_items = 4,
3920         .items = {
3921                 { "Mic", 0x0 },
3922                 { "Front Mic", 0x1 },
3923                 { "Line", 0x2 },
3924                 { "CD", 0x4 },
3925         },
3926 };
3927
3928 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
3929  * headphone jack and the internal CD lines since these are the only pins at
3930  * which audio can appear.  For flexibility, also allow the option of
3931  * recording the mixer output on the second ADC (ADC0 doesn't have a
3932  * connection to the mixer output).
3933  */
3934 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
3935         {
3936                 .num_items = 3,
3937                 .items = {
3938                         { "Mic/Line", 0x0 },
3939                         { "CD", 0x4 },
3940                         { "Headphone", 0x2 },
3941                 },
3942         },
3943         {
3944                 .num_items = 4,
3945                 .items = {
3946                         { "Mic/Line", 0x0 },
3947                         { "CD", 0x4 },
3948                         { "Headphone", 0x2 },
3949                         { "Mixer", 0x5 },
3950                 },
3951         },
3952
3953 };
3954
3955 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
3956  * the Fujitsu S702x, but jacks are marked differently.
3957  */
3958 static struct hda_input_mux alc260_acer_capture_sources[2] = {
3959         {
3960                 .num_items = 4,
3961                 .items = {
3962                         { "Mic", 0x0 },
3963                         { "Line", 0x2 },
3964                         { "CD", 0x4 },
3965                         { "Headphone", 0x5 },
3966                 },
3967         },
3968         {
3969                 .num_items = 5,
3970                 .items = {
3971                         { "Mic", 0x0 },
3972                         { "Line", 0x2 },
3973                         { "CD", 0x4 },
3974                         { "Headphone", 0x6 },
3975                         { "Mixer", 0x5 },
3976                 },
3977         },
3978 };
3979 /*
3980  * This is just place-holder, so there's something for alc_build_pcms to look
3981  * at when it calculates the maximum number of channels. ALC260 has no mixer
3982  * element which allows changing the channel mode, so the verb list is
3983  * never used.
3984  */
3985 static struct hda_channel_mode alc260_modes[1] = {
3986         { 2, NULL },
3987 };
3988
3989
3990 /* Mixer combinations
3991  *
3992  * basic: base_output + input + pc_beep + capture
3993  * HP: base_output + input + capture_alt
3994  * HP_3013: hp_3013 + input + capture
3995  * fujitsu: fujitsu + capture
3996  * acer: acer + capture
3997  */
3998
3999 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
4000         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4001         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4002         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4003         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4004         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4005         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4006         { } /* end */
4007 };
4008
4009 static struct snd_kcontrol_new alc260_input_mixer[] = {
4010         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4011         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4012         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4013         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4014         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4015         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4016         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4017         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4018         { } /* end */
4019 };
4020
4021 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
4022         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
4023         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
4024         { } /* end */
4025 };
4026
4027 /* update HP, line and mono out pins according to the master switch */
4028 static void alc260_hp_master_update(struct hda_codec *codec,
4029                                     hda_nid_t hp, hda_nid_t line,
4030                                     hda_nid_t mono)
4031 {
4032         struct alc_spec *spec = codec->spec;
4033         unsigned int val = spec->master_sw ? PIN_HP : 0;
4034         /* change HP and line-out pins */
4035         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4036                             val);
4037         snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4038                             val);
4039         /* mono (speaker) depending on the HP jack sense */
4040         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4041         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4042                             val);
4043 }
4044
4045 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4046                                    struct snd_ctl_elem_value *ucontrol)
4047 {
4048         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4049         struct alc_spec *spec = codec->spec;
4050         *ucontrol->value.integer.value = spec->master_sw;
4051         return 0;
4052 }
4053
4054 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4055                                    struct snd_ctl_elem_value *ucontrol)
4056 {
4057         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4058         struct alc_spec *spec = codec->spec;
4059         int val = !!*ucontrol->value.integer.value;
4060         hda_nid_t hp, line, mono;
4061
4062         if (val == spec->master_sw)
4063                 return 0;
4064         spec->master_sw = val;
4065         hp = (kcontrol->private_value >> 16) & 0xff;
4066         line = (kcontrol->private_value >> 8) & 0xff;
4067         mono = kcontrol->private_value & 0xff;
4068         alc260_hp_master_update(codec, hp, line, mono);
4069         return 1;
4070 }
4071
4072 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4073         {
4074                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4075                 .name = "Master Playback Switch",
4076                 .info = snd_ctl_boolean_mono_info,
4077                 .get = alc260_hp_master_sw_get,
4078                 .put = alc260_hp_master_sw_put,
4079                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4080         },
4081         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4082         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4083         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4084         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4085         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4086                               HDA_OUTPUT),
4087         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4088         { } /* end */
4089 };
4090
4091 static struct hda_verb alc260_hp_unsol_verbs[] = {
4092         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4093         {},
4094 };
4095
4096 static void alc260_hp_automute(struct hda_codec *codec)
4097 {
4098         struct alc_spec *spec = codec->spec;
4099         unsigned int present;
4100
4101         present = snd_hda_codec_read(codec, 0x10, 0,
4102                                      AC_VERB_GET_PIN_SENSE, 0);
4103         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4104         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4105 }
4106
4107 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4108 {
4109         if ((res >> 26) == ALC880_HP_EVENT)
4110                 alc260_hp_automute(codec);
4111 }
4112
4113 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4114         {
4115                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4116                 .name = "Master Playback Switch",
4117                 .info = snd_ctl_boolean_mono_info,
4118                 .get = alc260_hp_master_sw_get,
4119                 .put = alc260_hp_master_sw_put,
4120                 .private_value = (0x10 << 16) | (0x15 << 8) | 0x11
4121         },
4122         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4123         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4124         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4125         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4126         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4127         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4128         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4129         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4130         { } /* end */
4131 };
4132
4133 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4134         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4135         {},
4136 };
4137
4138 static void alc260_hp_3013_automute(struct hda_codec *codec)
4139 {
4140         struct alc_spec *spec = codec->spec;
4141         unsigned int present;
4142
4143         present = snd_hda_codec_read(codec, 0x15, 0,
4144                                      AC_VERB_GET_PIN_SENSE, 0);
4145         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4146         alc260_hp_master_update(codec, 0x10, 0x15, 0x11);
4147 }
4148
4149 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4150                                        unsigned int res)
4151 {
4152         if ((res >> 26) == ALC880_HP_EVENT)
4153                 alc260_hp_3013_automute(codec);
4154 }
4155
4156 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12, 
4157  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4158  */
4159 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4160         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4161         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4162         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4163         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4164         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4165         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4166         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4167         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4168         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4169         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4170         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4171         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4172         { } /* end */
4173 };
4174
4175 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4176  * versions of the ALC260 don't act on requests to enable mic bias from NID
4177  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4178  * datasheet doesn't mention this restriction.  At this stage it's not clear
4179  * whether this behaviour is intentional or is a hardware bug in chip
4180  * revisions available in early 2006.  Therefore for now allow the
4181  * "Headphone Jack Mode" control to span all choices, but if it turns out
4182  * that the lack of mic bias for this NID is intentional we could change the
4183  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4184  *
4185  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4186  * don't appear to make the mic bias available from the "line" jack, even
4187  * though the NID used for this jack (0x14) can supply it.  The theory is
4188  * that perhaps Acer have included blocking capacitors between the ALC260
4189  * and the output jack.  If this turns out to be the case for all such
4190  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4191  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4192  *
4193  * The C20x Tablet series have a mono internal speaker which is controlled
4194  * via the chip's Mono sum widget and pin complex, so include the necessary
4195  * controls for such models.  On models without a "mono speaker" the control
4196  * won't do anything.
4197  */
4198 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4199         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4200         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4201         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4202         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4203                               HDA_OUTPUT),
4204         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4205                            HDA_INPUT),
4206         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4207         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4208         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4209         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4210         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4211         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4212         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4213         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4214         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4215         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4216         { } /* end */
4217 };
4218
4219 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4220  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4221  */
4222 static struct snd_kcontrol_new alc260_will_mixer[] = {
4223         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4224         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4225         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4226         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4227         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4228         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4229         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4230         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4231         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4232         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4233         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4234         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4235         { } /* end */
4236 };
4237
4238 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4239  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4240  */
4241 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4242         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4243         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4244         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4245         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4246         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4247         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4248         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4249         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4250         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4251         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4252         { } /* end */
4253 };
4254
4255 /* capture mixer elements */
4256 static struct snd_kcontrol_new alc260_capture_mixer[] = {
4257         HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
4258         HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
4259         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
4260         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),
4261         {
4262                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4263                 /* The multiple "Capture Source" controls confuse alsamixer
4264                  * So call somewhat different..
4265                  */
4266                 /* .name = "Capture Source", */
4267                 .name = "Input Source",
4268                 .count = 2,
4269                 .info = alc_mux_enum_info,
4270                 .get = alc_mux_enum_get,
4271                 .put = alc_mux_enum_put,
4272         },
4273         { } /* end */
4274 };
4275
4276 static struct snd_kcontrol_new alc260_capture_alt_mixer[] = {
4277         HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
4278         HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
4279         {
4280                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4281                 /* The multiple "Capture Source" controls confuse alsamixer
4282                  * So call somewhat different..
4283                  */
4284                 /* .name = "Capture Source", */
4285                 .name = "Input Source",
4286                 .count = 1,
4287                 .info = alc_mux_enum_info,
4288                 .get = alc_mux_enum_get,
4289                 .put = alc_mux_enum_put,
4290         },
4291         { } /* end */
4292 };
4293
4294 /*
4295  * initialization verbs
4296  */
4297 static struct hda_verb alc260_init_verbs[] = {
4298         /* Line In pin widget for input */
4299         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4300         /* CD pin widget for input */
4301         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4302         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4303         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4304         /* Mic2 (front panel) pin widget for input and vref at 80% */
4305         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4306         /* LINE-2 is used for line-out in rear */
4307         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4308         /* select line-out */
4309         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4310         /* LINE-OUT pin */
4311         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4312         /* enable HP */
4313         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4314         /* enable Mono */
4315         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4316         /* mute capture amp left and right */
4317         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4318         /* set connection select to line in (default select for this ADC) */
4319         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4320         /* mute capture amp left and right */
4321         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4322         /* set connection select to line in (default select for this ADC) */
4323         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4324         /* set vol=0 Line-Out mixer amp left and right */
4325         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4326         /* unmute pin widget amp left and right (no gain on this amp) */
4327         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4328         /* set vol=0 HP mixer amp left and right */
4329         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4330         /* unmute pin widget amp left and right (no gain on this amp) */
4331         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4332         /* set vol=0 Mono mixer amp left and right */
4333         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4334         /* unmute pin widget amp left and right (no gain on this amp) */
4335         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4336         /* unmute LINE-2 out pin */
4337         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4338         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4339          * Line In 2 = 0x03
4340          */
4341         /* mute analog inputs */
4342         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4343         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4344         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4345         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4346         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4347         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4348         /* mute Front out path */
4349         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4350         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4351         /* mute Headphone out path */
4352         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4353         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4354         /* mute Mono out path */
4355         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4356         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4357         { }
4358 };
4359
4360 #if 0 /* should be identical with alc260_init_verbs? */
4361 static struct hda_verb alc260_hp_init_verbs[] = {
4362         /* Headphone and output */
4363         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4364         /* mono output */
4365         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4366         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4367         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4368         /* Mic2 (front panel) pin widget for input and vref at 80% */
4369         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4370         /* Line In pin widget for input */
4371         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4372         /* Line-2 pin widget for output */
4373         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4374         /* CD pin widget for input */
4375         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4376         /* unmute amp left and right */
4377         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4378         /* set connection select to line in (default select for this ADC) */
4379         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4380         /* unmute Line-Out mixer amp left and right (volume = 0) */
4381         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4382         /* mute pin widget amp left and right (no gain on this amp) */
4383         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4384         /* unmute HP mixer amp left and right (volume = 0) */
4385         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4386         /* mute pin widget amp left and right (no gain on this amp) */
4387         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4388         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4389          * Line In 2 = 0x03
4390          */
4391         /* mute analog inputs */
4392         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4393         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4394         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4395         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4396         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4397         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4398         /* Unmute Front out path */
4399         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4400         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4401         /* Unmute Headphone out path */
4402         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4403         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4404         /* Unmute Mono out path */
4405         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4406         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4407         { }
4408 };
4409 #endif
4410
4411 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4412         /* Line out and output */
4413         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4414         /* mono output */
4415         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4416         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4417         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4418         /* Mic2 (front panel) pin widget for input and vref at 80% */
4419         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4420         /* Line In pin widget for input */
4421         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4422         /* Headphone pin widget for output */
4423         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4424         /* CD pin widget for input */
4425         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4426         /* unmute amp left and right */
4427         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4428         /* set connection select to line in (default select for this ADC) */
4429         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4430         /* unmute Line-Out mixer amp left and right (volume = 0) */
4431         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4432         /* mute pin widget amp left and right (no gain on this amp) */
4433         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4434         /* unmute HP mixer amp left and right (volume = 0) */
4435         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4436         /* mute pin widget amp left and right (no gain on this amp) */
4437         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4438         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4439          * Line In 2 = 0x03
4440          */
4441         /* mute analog inputs */
4442         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4443         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4444         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4445         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4446         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4447         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4448         /* Unmute Front out path */
4449         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4450         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4451         /* Unmute Headphone out path */
4452         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4453         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4454         /* Unmute Mono out path */
4455         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4456         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4457         { }
4458 };
4459
4460 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4461  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4462  * audio = 0x16, internal speaker = 0x10.
4463  */
4464 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4465         /* Disable all GPIOs */
4466         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4467         /* Internal speaker is connected to headphone pin */
4468         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4469         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4470         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4471         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4472         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4473         /* Ensure all other unused pins are disabled and muted. */
4474         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4475         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4476         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4477         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4478         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4479         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4480         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4481         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4482
4483         /* Disable digital (SPDIF) pins */
4484         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4485         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4486
4487         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
4488          * when acting as an output.
4489          */
4490         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4491
4492         /* Start with output sum widgets muted and their output gains at min */
4493         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4494         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4495         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4496         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4497         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4498         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4499         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4500         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4501         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4502
4503         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
4504         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4505         /* Unmute Line1 pin widget output buffer since it starts as an output.
4506          * If the pin mode is changed by the user the pin mode control will
4507          * take care of enabling the pin's input/output buffers as needed.
4508          * Therefore there's no need to enable the input buffer at this
4509          * stage.
4510          */
4511         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4512         /* Unmute input buffer of pin widget used for Line-in (no equiv
4513          * mixer ctrl)
4514          */
4515         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4516
4517         /* Mute capture amp left and right */
4518         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4519         /* Set ADC connection select to match default mixer setting - line
4520          * in (on mic1 pin)
4521          */
4522         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4523
4524         /* Do the same for the second ADC: mute capture input amp and
4525          * set ADC connection to line in (on mic1 pin)
4526          */
4527         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4528         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4529
4530         /* Mute all inputs to mixer widget (even unconnected ones) */
4531         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4532         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4533         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4534         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4535         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4536         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4537         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4538         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4539
4540         { }
4541 };
4542
4543 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
4544  * similar laptops (adapted from Fujitsu init verbs).
4545  */
4546 static struct hda_verb alc260_acer_init_verbs[] = {
4547         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
4548          * the headphone jack.  Turn this on and rely on the standard mute
4549          * methods whenever the user wants to turn these outputs off.
4550          */
4551         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4552         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4553         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
4554         /* Internal speaker/Headphone jack is connected to Line-out pin */
4555         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4556         /* Internal microphone/Mic jack is connected to Mic1 pin */
4557         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
4558         /* Line In jack is connected to Line1 pin */
4559         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4560         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
4561         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4562         /* Ensure all other unused pins are disabled and muted. */
4563         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4564         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4565         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4566         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4567         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4568         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4569         /* Disable digital (SPDIF) pins */
4570         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4571         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4572
4573         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
4574          * bus when acting as outputs.
4575          */
4576         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4577         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4578
4579         /* Start with output sum widgets muted and their output gains at min */
4580         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4581         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4582         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4583         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4584         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4585         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4586         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4587         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4588         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4589
4590         /* Unmute Line-out pin widget amp left and right
4591          * (no equiv mixer ctrl)
4592          */
4593         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4594         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
4595         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4596         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
4597          * inputs. If the pin mode is changed by the user the pin mode control
4598          * will take care of enabling the pin's input/output buffers as needed.
4599          * Therefore there's no need to enable the input buffer at this
4600          * stage.
4601          */
4602         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4603         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4604
4605         /* Mute capture amp left and right */
4606         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4607         /* Set ADC connection select to match default mixer setting - mic
4608          * (on mic1 pin)
4609          */
4610         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4611
4612         /* Do similar with the second ADC: mute capture input amp and
4613          * set ADC connection to mic to match ALSA's default state.
4614          */
4615         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4616         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4617
4618         /* Mute all inputs to mixer widget (even unconnected ones) */
4619         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4620         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4621         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4622         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4623         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4624         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4625         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4626         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4627
4628         { }
4629 };
4630
4631 static struct hda_verb alc260_will_verbs[] = {
4632         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4633         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
4634         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
4635         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4636         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4637         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
4638         {}
4639 };
4640
4641 static struct hda_verb alc260_replacer_672v_verbs[] = {
4642         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4643         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4644         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
4645
4646         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4647         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4648         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4649
4650         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4651         {}
4652 };
4653
4654 /* toggle speaker-output according to the hp-jack state */
4655 static void alc260_replacer_672v_automute(struct hda_codec *codec)
4656 {
4657         unsigned int present;
4658
4659         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
4660         present = snd_hda_codec_read(codec, 0x0f, 0,
4661                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
4662         if (present) {
4663                 snd_hda_codec_write_cache(codec, 0x01, 0,
4664                                           AC_VERB_SET_GPIO_DATA, 1);
4665                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4666                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4667                                           PIN_HP);
4668         } else {
4669                 snd_hda_codec_write_cache(codec, 0x01, 0,
4670                                           AC_VERB_SET_GPIO_DATA, 0);
4671                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4672                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4673                                           PIN_OUT);
4674         }
4675 }
4676
4677 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
4678                                        unsigned int res)
4679 {
4680         if ((res >> 26) == ALC880_HP_EVENT)
4681                 alc260_replacer_672v_automute(codec);
4682 }
4683
4684 /* Test configuration for debugging, modelled after the ALC880 test
4685  * configuration.
4686  */
4687 #ifdef CONFIG_SND_DEBUG
4688 static hda_nid_t alc260_test_dac_nids[1] = {
4689         0x02,
4690 };
4691 static hda_nid_t alc260_test_adc_nids[2] = {
4692         0x04, 0x05,
4693 };
4694 /* For testing the ALC260, each input MUX needs its own definition since
4695  * the signal assignments are different.  This assumes that the first ADC
4696  * is NID 0x04.
4697  */
4698 static struct hda_input_mux alc260_test_capture_sources[2] = {
4699         {
4700                 .num_items = 7,
4701                 .items = {
4702                         { "MIC1 pin", 0x0 },
4703                         { "MIC2 pin", 0x1 },
4704                         { "LINE1 pin", 0x2 },
4705                         { "LINE2 pin", 0x3 },
4706                         { "CD pin", 0x4 },
4707                         { "LINE-OUT pin", 0x5 },
4708                         { "HP-OUT pin", 0x6 },
4709                 },
4710         },
4711         {
4712                 .num_items = 8,
4713                 .items = {
4714                         { "MIC1 pin", 0x0 },
4715                         { "MIC2 pin", 0x1 },
4716                         { "LINE1 pin", 0x2 },
4717                         { "LINE2 pin", 0x3 },
4718                         { "CD pin", 0x4 },
4719                         { "Mixer", 0x5 },
4720                         { "LINE-OUT pin", 0x6 },
4721                         { "HP-OUT pin", 0x7 },
4722                 },
4723         },
4724 };
4725 static struct snd_kcontrol_new alc260_test_mixer[] = {
4726         /* Output driver widgets */
4727         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4728         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4729         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4730         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
4731         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4732         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
4733
4734         /* Modes for retasking pin widgets
4735          * Note: the ALC260 doesn't seem to act on requests to enable mic
4736          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
4737          * mention this restriction.  At this stage it's not clear whether
4738          * this behaviour is intentional or is a hardware bug in chip
4739          * revisions available at least up until early 2006.  Therefore for
4740          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
4741          * choices, but if it turns out that the lack of mic bias for these
4742          * NIDs is intentional we could change their modes from
4743          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4744          */
4745         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
4746         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
4747         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
4748         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
4749         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
4750         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
4751
4752         /* Loopback mixer controls */
4753         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
4754         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
4755         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
4756         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
4757         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
4758         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
4759         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
4760         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
4761         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4762         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4763         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4764         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4765         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
4766         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
4767         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
4768         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
4769
4770         /* Controls for GPIO pins, assuming they are configured as outputs */
4771         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
4772         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
4773         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
4774         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
4775
4776         /* Switches to allow the digital IO pins to be enabled.  The datasheet
4777          * is ambigious as to which NID is which; testing on laptops which
4778          * make this output available should provide clarification.
4779          */
4780         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
4781         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
4782
4783         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
4784          * this output to turn on an external amplifier.
4785          */
4786         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
4787         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
4788
4789         { } /* end */
4790 };
4791 static struct hda_verb alc260_test_init_verbs[] = {
4792         /* Enable all GPIOs as outputs with an initial value of 0 */
4793         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
4794         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4795         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
4796
4797         /* Enable retasking pins as output, initially without power amp */
4798         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4799         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4800         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4801         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4802         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4803         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4804
4805         /* Disable digital (SPDIF) pins initially, but users can enable
4806          * them via a mixer switch.  In the case of SPDIF-out, this initverb
4807          * payload also sets the generation to 0, output to be in "consumer"
4808          * PCM format, copyright asserted, no pre-emphasis and no validity
4809          * control.
4810          */
4811         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4812         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4813
4814         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
4815          * OUT1 sum bus when acting as an output.
4816          */
4817         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4818         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
4819         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4820         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
4821
4822         /* Start with output sum widgets muted and their output gains at min */
4823         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4824         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4825         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4826         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4827         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4828         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4829         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4830         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4831         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4832
4833         /* Unmute retasking pin widget output buffers since the default
4834          * state appears to be output.  As the pin mode is changed by the
4835          * user the pin mode control will take care of enabling the pin's
4836          * input/output buffers as needed.
4837          */
4838         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4839         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4840         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4841         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4842         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4843         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4844         /* Also unmute the mono-out pin widget */
4845         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4846
4847         /* Mute capture amp left and right */
4848         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4849         /* Set ADC connection select to match default mixer setting (mic1
4850          * pin)
4851          */
4852         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4853
4854         /* Do the same for the second ADC: mute capture input amp and
4855          * set ADC connection to mic1 pin
4856          */
4857         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4858         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4859
4860         /* Mute all inputs to mixer widget (even unconnected ones) */
4861         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4862         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4863         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4864         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4865         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4866         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4867         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4868         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4869
4870         { }
4871 };
4872 #endif
4873
4874 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
4875 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
4876
4877 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
4878 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
4879
4880 /*
4881  * for BIOS auto-configuration
4882  */
4883
4884 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
4885                                         const char *pfx)
4886 {
4887         hda_nid_t nid_vol;
4888         unsigned long vol_val, sw_val;
4889         char name[32];
4890         int err;
4891
4892         if (nid >= 0x0f && nid < 0x11) {
4893                 nid_vol = nid - 0x7;
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 if (nid == 0x11) {
4897                 nid_vol = nid - 0x7;
4898                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
4899                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
4900         } else if (nid >= 0x12 && nid <= 0x15) {
4901                 nid_vol = 0x08;
4902                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4903                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4904         } else
4905                 return 0; /* N/A */
4906
4907         snprintf(name, sizeof(name), "%s Playback Volume", pfx);
4908         err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
4909         if (err < 0)
4910                 return err;
4911         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
4912         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
4913         if (err < 0)
4914                 return err;
4915         return 1;
4916 }
4917
4918 /* add playback controls from the parsed DAC table */
4919 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
4920                                              const struct auto_pin_cfg *cfg)
4921 {
4922         hda_nid_t nid;
4923         int err;
4924
4925         spec->multiout.num_dacs = 1;
4926         spec->multiout.dac_nids = spec->private_dac_nids;
4927         spec->multiout.dac_nids[0] = 0x02;
4928
4929         nid = cfg->line_out_pins[0];
4930         if (nid) {
4931                 err = alc260_add_playback_controls(spec, nid, "Front");
4932                 if (err < 0)
4933                         return err;
4934         }
4935
4936         nid = cfg->speaker_pins[0];
4937         if (nid) {
4938                 err = alc260_add_playback_controls(spec, nid, "Speaker");
4939                 if (err < 0)
4940                         return err;
4941         }
4942
4943         nid = cfg->hp_pins[0];
4944         if (nid) {
4945                 err = alc260_add_playback_controls(spec, nid, "Headphone");
4946                 if (err < 0)
4947                         return err;
4948         }
4949         return 0;
4950 }
4951
4952 /* create playback/capture controls for input pins */
4953 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
4954                                                 const struct auto_pin_cfg *cfg)
4955 {
4956         struct hda_input_mux *imux = &spec->private_imux;
4957         int i, err, idx;
4958
4959         for (i = 0; i < AUTO_PIN_LAST; i++) {
4960                 if (cfg->input_pins[i] >= 0x12) {
4961                         idx = cfg->input_pins[i] - 0x12;
4962                         err = new_analog_input(spec, cfg->input_pins[i],
4963                                                auto_pin_cfg_labels[i], idx,
4964                                                0x07);
4965                         if (err < 0)
4966                                 return err;
4967                         imux->items[imux->num_items].label =
4968                                 auto_pin_cfg_labels[i];
4969                         imux->items[imux->num_items].index = idx;
4970                         imux->num_items++;
4971                 }
4972                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
4973                         idx = cfg->input_pins[i] - 0x09;
4974                         err = new_analog_input(spec, cfg->input_pins[i],
4975                                                auto_pin_cfg_labels[i], idx,
4976                                                0x07);
4977                         if (err < 0)
4978                                 return err;
4979                         imux->items[imux->num_items].label =
4980                                 auto_pin_cfg_labels[i];
4981                         imux->items[imux->num_items].index = idx;
4982                         imux->num_items++;
4983                 }
4984         }
4985         return 0;
4986 }
4987
4988 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
4989                                               hda_nid_t nid, int pin_type,
4990                                               int sel_idx)
4991 {
4992         alc_set_pin_output(codec, nid, pin_type);
4993         /* need the manual connection? */
4994         if (nid >= 0x12) {
4995                 int idx = nid - 0x12;
4996                 snd_hda_codec_write(codec, idx + 0x0b, 0,
4997                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
4998         }
4999 }
5000
5001 static void alc260_auto_init_multi_out(struct hda_codec *codec)
5002 {
5003         struct alc_spec *spec = codec->spec;
5004         hda_nid_t nid;
5005
5006         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
5007         nid = spec->autocfg.line_out_pins[0];
5008         if (nid) {
5009                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5010                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5011         }
5012
5013         nid = spec->autocfg.speaker_pins[0];
5014         if (nid)
5015                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5016
5017         nid = spec->autocfg.hp_pins[0];
5018         if (nid)
5019                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5020 }
5021
5022 #define ALC260_PIN_CD_NID               0x16
5023 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5024 {
5025         struct alc_spec *spec = codec->spec;
5026         int i;
5027
5028         for (i = 0; i < AUTO_PIN_LAST; i++) {
5029                 hda_nid_t nid = spec->autocfg.input_pins[i];
5030                 if (nid >= 0x12) {
5031                         snd_hda_codec_write(codec, nid, 0,
5032                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5033                                             i <= AUTO_PIN_FRONT_MIC ?
5034                                             PIN_VREF80 : PIN_IN);
5035                         if (nid != ALC260_PIN_CD_NID)
5036                                 snd_hda_codec_write(codec, nid, 0,
5037                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5038                                                     AMP_OUT_MUTE);
5039                 }
5040         }
5041 }
5042
5043 /*
5044  * generic initialization of ADC, input mixers and output mixers
5045  */
5046 static struct hda_verb alc260_volume_init_verbs[] = {
5047         /*
5048          * Unmute ADC0-1 and set the default input to mic-in
5049          */
5050         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5051         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5052         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5053         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5054
5055         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5056          * mixer widget
5057          * Note: PASD motherboards uses the Line In 2 as the input for
5058          * front panel mic (mic 2)
5059          */
5060         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5061         /* mute analog inputs */
5062         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5063         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5064         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5065         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5066         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5067
5068         /*
5069          * Set up output mixers (0x08 - 0x0a)
5070          */
5071         /* set vol=0 to output mixers */
5072         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5073         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5074         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5075         /* set up input amps for analog loopback */
5076         /* Amp Indices: DAC = 0, mixer = 1 */
5077         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5078         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5079         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5080         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5081         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5082         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5083
5084         { }
5085 };
5086
5087 static int alc260_parse_auto_config(struct hda_codec *codec)
5088 {
5089         struct alc_spec *spec = codec->spec;
5090         unsigned int wcap;
5091         int err;
5092         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5093
5094         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5095                                            alc260_ignore);
5096         if (err < 0)
5097                 return err;
5098         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5099         if (err < 0)
5100                 return err;
5101         if (!spec->kctl_alloc)
5102                 return 0; /* can't find valid BIOS pin config */
5103         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5104         if (err < 0)
5105                 return err;
5106
5107         spec->multiout.max_channels = 2;
5108
5109         if (spec->autocfg.dig_out_pin)
5110                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5111         if (spec->kctl_alloc)
5112                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
5113
5114         spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs;
5115
5116         spec->num_mux_defs = 1;
5117         spec->input_mux = &spec->private_imux;
5118
5119         /* check whether NID 0x04 is valid */
5120         wcap = get_wcaps(codec, 0x04);
5121         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
5122         if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
5123                 spec->adc_nids = alc260_adc_nids_alt;
5124                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
5125                 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
5126         } else {
5127                 spec->adc_nids = alc260_adc_nids;
5128                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
5129                 spec->mixers[spec->num_mixers] = alc260_capture_mixer;
5130         }
5131         spec->num_mixers++;
5132
5133         return 1;
5134 }
5135
5136 /* additional initialization for auto-configuration model */
5137 static void alc260_auto_init(struct hda_codec *codec)
5138 {
5139         struct alc_spec *spec = codec->spec;
5140         alc260_auto_init_multi_out(codec);
5141         alc260_auto_init_analog_input(codec);
5142         if (spec->unsol_event)
5143                 alc_sku_automute(codec);
5144 }
5145
5146 #ifdef CONFIG_SND_HDA_POWER_SAVE
5147 static struct hda_amp_list alc260_loopbacks[] = {
5148         { 0x07, HDA_INPUT, 0 },
5149         { 0x07, HDA_INPUT, 1 },
5150         { 0x07, HDA_INPUT, 2 },
5151         { 0x07, HDA_INPUT, 3 },
5152         { 0x07, HDA_INPUT, 4 },
5153         { } /* end */
5154 };
5155 #endif
5156
5157 /*
5158  * ALC260 configurations
5159  */
5160 static const char *alc260_models[ALC260_MODEL_LAST] = {
5161         [ALC260_BASIC]          = "basic",
5162         [ALC260_HP]             = "hp",
5163         [ALC260_HP_3013]        = "hp-3013",
5164         [ALC260_FUJITSU_S702X]  = "fujitsu",
5165         [ALC260_ACER]           = "acer",
5166         [ALC260_WILL]           = "will",
5167         [ALC260_REPLACER_672V]  = "replacer",
5168 #ifdef CONFIG_SND_DEBUG
5169         [ALC260_TEST]           = "test",
5170 #endif
5171         [ALC260_AUTO]           = "auto",
5172 };
5173
5174 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5175         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5176         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5177         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5178         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5179         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5180         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
5181         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_3013),
5182         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5183         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5184         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5185         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5186         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5187         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5188         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5189         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5190         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5191         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5192         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5193         {}
5194 };
5195
5196 static struct alc_config_preset alc260_presets[] = {
5197         [ALC260_BASIC] = {
5198                 .mixers = { alc260_base_output_mixer,
5199                             alc260_input_mixer,
5200                             alc260_pc_beep_mixer,
5201                             alc260_capture_mixer },
5202                 .init_verbs = { alc260_init_verbs },
5203                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5204                 .dac_nids = alc260_dac_nids,
5205                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5206                 .adc_nids = alc260_adc_nids,
5207                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5208                 .channel_mode = alc260_modes,
5209                 .input_mux = &alc260_capture_source,
5210         },
5211         [ALC260_HP] = {
5212                 .mixers = { alc260_hp_output_mixer,
5213                             alc260_input_mixer,
5214                             alc260_capture_alt_mixer },
5215                 .init_verbs = { alc260_init_verbs,
5216                                 alc260_hp_unsol_verbs },
5217                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5218                 .dac_nids = alc260_dac_nids,
5219                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5220                 .adc_nids = alc260_hp_adc_nids,
5221                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5222                 .channel_mode = alc260_modes,
5223                 .input_mux = &alc260_capture_source,
5224                 .unsol_event = alc260_hp_unsol_event,
5225                 .init_hook = alc260_hp_automute,
5226         },
5227         [ALC260_HP_3013] = {
5228                 .mixers = { alc260_hp_3013_mixer,
5229                             alc260_input_mixer,
5230                             alc260_capture_alt_mixer },
5231                 .init_verbs = { alc260_hp_3013_init_verbs,
5232                                 alc260_hp_3013_unsol_verbs },
5233                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5234                 .dac_nids = alc260_dac_nids,
5235                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5236                 .adc_nids = alc260_hp_adc_nids,
5237                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5238                 .channel_mode = alc260_modes,
5239                 .input_mux = &alc260_capture_source,
5240                 .unsol_event = alc260_hp_3013_unsol_event,
5241                 .init_hook = alc260_hp_3013_automute,
5242         },
5243         [ALC260_FUJITSU_S702X] = {
5244                 .mixers = { alc260_fujitsu_mixer,
5245                             alc260_capture_mixer },
5246                 .init_verbs = { alc260_fujitsu_init_verbs },
5247                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5248                 .dac_nids = alc260_dac_nids,
5249                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5250                 .adc_nids = alc260_dual_adc_nids,
5251                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5252                 .channel_mode = alc260_modes,
5253                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5254                 .input_mux = alc260_fujitsu_capture_sources,
5255         },
5256         [ALC260_ACER] = {
5257                 .mixers = { alc260_acer_mixer,
5258                             alc260_capture_mixer },
5259                 .init_verbs = { alc260_acer_init_verbs },
5260                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5261                 .dac_nids = alc260_dac_nids,
5262                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5263                 .adc_nids = alc260_dual_adc_nids,
5264                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5265                 .channel_mode = alc260_modes,
5266                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5267                 .input_mux = alc260_acer_capture_sources,
5268         },
5269         [ALC260_WILL] = {
5270                 .mixers = { alc260_will_mixer,
5271                             alc260_capture_mixer },
5272                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5273                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5274                 .dac_nids = alc260_dac_nids,
5275                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5276                 .adc_nids = alc260_adc_nids,
5277                 .dig_out_nid = ALC260_DIGOUT_NID,
5278                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5279                 .channel_mode = alc260_modes,
5280                 .input_mux = &alc260_capture_source,
5281         },
5282         [ALC260_REPLACER_672V] = {
5283                 .mixers = { alc260_replacer_672v_mixer,
5284                             alc260_capture_mixer },
5285                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5286                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5287                 .dac_nids = alc260_dac_nids,
5288                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5289                 .adc_nids = alc260_adc_nids,
5290                 .dig_out_nid = ALC260_DIGOUT_NID,
5291                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5292                 .channel_mode = alc260_modes,
5293                 .input_mux = &alc260_capture_source,
5294                 .unsol_event = alc260_replacer_672v_unsol_event,
5295                 .init_hook = alc260_replacer_672v_automute,
5296         },
5297 #ifdef CONFIG_SND_DEBUG
5298         [ALC260_TEST] = {
5299                 .mixers = { alc260_test_mixer,
5300                             alc260_capture_mixer },
5301                 .init_verbs = { alc260_test_init_verbs },
5302                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5303                 .dac_nids = alc260_test_dac_nids,
5304                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5305                 .adc_nids = alc260_test_adc_nids,
5306                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5307                 .channel_mode = alc260_modes,
5308                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5309                 .input_mux = alc260_test_capture_sources,
5310         },
5311 #endif
5312 };
5313
5314 static int patch_alc260(struct hda_codec *codec)
5315 {
5316         struct alc_spec *spec;
5317         int err, board_config;
5318
5319         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5320         if (spec == NULL)
5321                 return -ENOMEM;
5322
5323         codec->spec = spec;
5324
5325         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
5326                                                   alc260_models,
5327                                                   alc260_cfg_tbl);
5328         if (board_config < 0) {
5329                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
5330                            "trying auto-probe from BIOS...\n");
5331                 board_config = ALC260_AUTO;
5332         }
5333
5334         if (board_config == ALC260_AUTO) {
5335                 /* automatic parse from the BIOS config */
5336                 err = alc260_parse_auto_config(codec);
5337                 if (err < 0) {
5338                         alc_free(codec);
5339                         return err;
5340                 } else if (!err) {
5341                         printk(KERN_INFO
5342                                "hda_codec: Cannot set up configuration "
5343                                "from BIOS.  Using base mode...\n");
5344                         board_config = ALC260_BASIC;
5345                 }
5346         }
5347
5348         if (board_config != ALC260_AUTO)
5349                 setup_preset(spec, &alc260_presets[board_config]);
5350
5351         spec->stream_name_analog = "ALC260 Analog";
5352         spec->stream_analog_playback = &alc260_pcm_analog_playback;
5353         spec->stream_analog_capture = &alc260_pcm_analog_capture;
5354
5355         spec->stream_name_digital = "ALC260 Digital";
5356         spec->stream_digital_playback = &alc260_pcm_digital_playback;
5357         spec->stream_digital_capture = &alc260_pcm_digital_capture;
5358
5359         spec->vmaster_nid = 0x08;
5360
5361         codec->patch_ops = alc_patch_ops;
5362         if (board_config == ALC260_AUTO)
5363                 spec->init_hook = alc260_auto_init;
5364 #ifdef CONFIG_SND_HDA_POWER_SAVE
5365         if (!spec->loopback.amplist)
5366                 spec->loopback.amplist = alc260_loopbacks;
5367 #endif
5368
5369         return 0;
5370 }
5371
5372
5373 /*
5374  * ALC882 support
5375  *
5376  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5377  * configuration.  Each pin widget can choose any input DACs and a mixer.
5378  * Each ADC is connected from a mixer of all inputs.  This makes possible
5379  * 6-channel independent captures.
5380  *
5381  * In addition, an independent DAC for the multi-playback (not used in this
5382  * driver yet).
5383  */
5384 #define ALC882_DIGOUT_NID       0x06
5385 #define ALC882_DIGIN_NID        0x0a
5386
5387 static struct hda_channel_mode alc882_ch_modes[1] = {
5388         { 8, NULL }
5389 };
5390
5391 static hda_nid_t alc882_dac_nids[4] = {
5392         /* front, rear, clfe, rear_surr */
5393         0x02, 0x03, 0x04, 0x05
5394 };
5395
5396 /* identical with ALC880 */
5397 #define alc882_adc_nids         alc880_adc_nids
5398 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5399
5400 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5401 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5402
5403 /* input MUX */
5404 /* FIXME: should be a matrix-type input source selection */
5405
5406 static struct hda_input_mux alc882_capture_source = {
5407         .num_items = 4,
5408         .items = {
5409                 { "Mic", 0x0 },
5410                 { "Front Mic", 0x1 },
5411                 { "Line", 0x2 },
5412                 { "CD", 0x4 },
5413         },
5414 };
5415 #define alc882_mux_enum_info alc_mux_enum_info
5416 #define alc882_mux_enum_get alc_mux_enum_get
5417
5418 static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol,
5419                                struct snd_ctl_elem_value *ucontrol)
5420 {
5421         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5422         struct alc_spec *spec = codec->spec;
5423         const struct hda_input_mux *imux = spec->input_mux;
5424         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
5425         hda_nid_t nid = spec->capsrc_nids ?
5426                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
5427         unsigned int *cur_val = &spec->cur_mux[adc_idx];
5428         unsigned int i, idx;
5429
5430         idx = ucontrol->value.enumerated.item[0];
5431         if (idx >= imux->num_items)
5432                 idx = imux->num_items - 1;
5433         if (*cur_val == idx)
5434                 return 0;
5435         for (i = 0; i < imux->num_items; i++) {
5436                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
5437                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
5438                                          imux->items[i].index,
5439                                          HDA_AMP_MUTE, v);
5440         }
5441         *cur_val = idx;
5442         return 1;
5443 }
5444
5445 /*
5446  * 2ch mode
5447  */
5448 static struct hda_verb alc882_3ST_ch2_init[] = {
5449         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5450         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5451         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5452         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5453         { } /* end */
5454 };
5455
5456 /*
5457  * 6ch mode
5458  */
5459 static struct hda_verb alc882_3ST_ch6_init[] = {
5460         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5461         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5462         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5463         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5464         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5465         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5466         { } /* end */
5467 };
5468
5469 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5470         { 2, alc882_3ST_ch2_init },
5471         { 6, alc882_3ST_ch6_init },
5472 };
5473
5474 /*
5475  * 6ch mode
5476  */
5477 static struct hda_verb alc882_sixstack_ch6_init[] = {
5478         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5479         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5480         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5481         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5482         { } /* end */
5483 };
5484
5485 /*
5486  * 8ch mode
5487  */
5488 static struct hda_verb alc882_sixstack_ch8_init[] = {
5489         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5490         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5491         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5492         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5493         { } /* end */
5494 };
5495
5496 static struct hda_channel_mode alc882_sixstack_modes[2] = {
5497         { 6, alc882_sixstack_ch6_init },
5498         { 8, alc882_sixstack_ch8_init },
5499 };
5500
5501 /*
5502  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
5503  */
5504
5505 /*
5506  * 2ch mode
5507  */
5508 static struct hda_verb alc885_mbp_ch2_init[] = {
5509         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5510         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5511         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5512         { } /* end */
5513 };
5514
5515 /*
5516  * 6ch mode
5517  */
5518 static struct hda_verb alc885_mbp_ch6_init[] = {
5519         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5520         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5521         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5522         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5523         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5524         { } /* end */
5525 };
5526
5527 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
5528         { 2, alc885_mbp_ch2_init },
5529         { 6, alc885_mbp_ch6_init },
5530 };
5531
5532
5533 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
5534  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
5535  */
5536 static struct snd_kcontrol_new alc882_base_mixer[] = {
5537         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5538         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5539         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5540         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5541         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5542         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5543         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5544         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5545         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
5546         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
5547         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5548         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5549         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5550         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5551         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5552         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5553         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5554         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5555         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5556         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5557         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5558         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5559         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5560         { } /* end */
5561 };
5562
5563 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
5564         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5565         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
5566         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
5567         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
5568         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5569         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5570         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
5571         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
5572         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
5573         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
5574         { } /* end */
5575 };
5576 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
5577         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5578         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5579         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5580         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5581         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5582         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5583         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5584         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5585         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5586         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5587         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5588         { } /* end */
5589 };
5590
5591 static struct snd_kcontrol_new alc882_targa_mixer[] = {
5592         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5593         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5594         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5595         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5596         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5597         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5598         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5599         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5600         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5601         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5602         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5603         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5604         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5605         { } /* end */
5606 };
5607
5608 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
5609  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
5610  */
5611 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
5612         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5613         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5614         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5615         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
5616         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5617         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5618         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5619         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5620         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
5621         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
5622         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5623         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5624         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5625         { } /* end */
5626 };
5627
5628 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
5629         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5630         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5631         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5632         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5633         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5634         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5635         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5636         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5637         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5638         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5639         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5640         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5641         { } /* end */
5642 };
5643
5644 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
5645         {
5646                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5647                 .name = "Channel Mode",
5648                 .info = alc_ch_mode_info,
5649                 .get = alc_ch_mode_get,
5650                 .put = alc_ch_mode_put,
5651         },
5652         { } /* end */
5653 };
5654
5655 static struct hda_verb alc882_init_verbs[] = {
5656         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5657         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5658         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5659         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5660         /* Rear mixer */
5661         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5662         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5663         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5664         /* CLFE mixer */
5665         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5666         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5667         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5668         /* Side mixer */
5669         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5670         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5671         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5672
5673         /* Front Pin: output 0 (0x0c) */
5674         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5675         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5676         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5677         /* Rear Pin: output 1 (0x0d) */
5678         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5679         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5680         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5681         /* CLFE Pin: output 2 (0x0e) */
5682         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5683         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5684         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
5685         /* Side Pin: output 3 (0x0f) */
5686         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5687         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5688         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
5689         /* Mic (rear) pin: input vref at 80% */
5690         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5691         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5692         /* Front Mic pin: input vref at 80% */
5693         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5694         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5695         /* Line In pin: input */
5696         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5697         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5698         /* Line-2 In: Headphone output (output 0 - 0x0c) */
5699         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5700         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5701         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
5702         /* CD pin widget for input */
5703         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5704
5705         /* FIXME: use matrix-type input source selection */
5706         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5707         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5708         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5709         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5710         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5711         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5712         /* Input mixer2 */
5713         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5714         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5715         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5716         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5717         /* Input mixer3 */
5718         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5719         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5720         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5721         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5722         /* ADC1: mute amp left and right */
5723         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5724         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5725         /* ADC2: mute amp left and right */
5726         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5727         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5728         /* ADC3: mute amp left and right */
5729         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5730         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5731
5732         { }
5733 };
5734
5735 static struct hda_verb alc882_eapd_verbs[] = {
5736         /* change to EAPD mode */
5737         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5738         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
5739         { }
5740 };
5741
5742 /* Mac Pro test */
5743 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
5744         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5745         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5746         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
5747         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
5748         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
5749         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
5750         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
5751         { } /* end */
5752 };
5753
5754 static struct hda_verb alc882_macpro_init_verbs[] = {
5755         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5756         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5757         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5758         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5759         /* Front Pin: output 0 (0x0c) */
5760         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5761         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5762         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5763         /* Front Mic pin: input vref at 80% */
5764         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5765         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5766         /* Speaker:  output */
5767         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5768         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5769         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
5770         /* Headphone output (output 0 - 0x0c) */
5771         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5772         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5773         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5774
5775         /* FIXME: use matrix-type input source selection */
5776         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5777         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5778         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5779         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5780         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5781         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5782         /* Input mixer2 */
5783         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5784         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5785         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5786         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5787         /* Input mixer3 */
5788         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5789         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5790         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5791         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5792         /* ADC1: mute amp left and right */
5793         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5794         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5795         /* ADC2: mute amp left and right */
5796         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5797         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5798         /* ADC3: mute amp left and right */
5799         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5800         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5801
5802         { }
5803 };
5804
5805 /* Macbook Pro rev3 */
5806 static struct hda_verb alc885_mbp3_init_verbs[] = {
5807         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5808         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5809         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5810         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5811         /* Rear mixer */
5812         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5813         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5814         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5815         /* Front Pin: output 0 (0x0c) */
5816         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5817         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5818         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5819         /* HP Pin: output 0 (0x0d) */
5820         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
5821         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5822         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5823         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5824         /* Mic (rear) pin: input vref at 80% */
5825         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5826         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5827         /* Front Mic pin: input vref at 80% */
5828         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5829         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5830         /* Line In pin: use output 1 when in LineOut mode */
5831         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5832         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5833         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
5834
5835         /* FIXME: use matrix-type input source selection */
5836         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5837         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5838         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5839         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5840         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5841         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5842         /* Input mixer2 */
5843         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5844         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5845         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5846         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5847         /* Input mixer3 */
5848         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5849         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5850         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5851         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5852         /* ADC1: mute amp left and right */
5853         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5854         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5855         /* ADC2: mute amp left and right */
5856         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5857         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5858         /* ADC3: mute amp left and right */
5859         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5860         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5861
5862         { }
5863 };
5864
5865 /* iMac 24 mixer. */
5866 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
5867         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5868         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
5869         { } /* end */
5870 };
5871
5872 /* iMac 24 init verbs. */
5873 static struct hda_verb alc885_imac24_init_verbs[] = {
5874         /* Internal speakers: output 0 (0x0c) */
5875         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5876         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5877         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5878         /* Internal speakers: output 0 (0x0c) */
5879         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5880         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5881         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
5882         /* Headphone: output 0 (0x0c) */
5883         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5884         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5885         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5886         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5887         /* Front Mic: input vref at 80% */
5888         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5889         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5890         { }
5891 };
5892
5893 /* Toggle speaker-output according to the hp-jack state */
5894 static void alc885_imac24_automute(struct hda_codec *codec)
5895 {
5896         unsigned int present;
5897
5898         present = snd_hda_codec_read(codec, 0x14, 0,
5899                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5900         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
5901                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5902         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
5903                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5904 }
5905
5906 /* Processes unsolicited events. */
5907 static void alc885_imac24_unsol_event(struct hda_codec *codec,
5908                                       unsigned int res)
5909 {
5910         /* Headphone insertion or removal. */
5911         if ((res >> 26) == ALC880_HP_EVENT)
5912                 alc885_imac24_automute(codec);
5913 }
5914
5915 static void alc885_mbp3_automute(struct hda_codec *codec)
5916 {
5917         unsigned int present;
5918
5919         present = snd_hda_codec_read(codec, 0x15, 0,
5920                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5921         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
5922                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5923         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
5924                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
5925
5926 }
5927 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
5928                                     unsigned int res)
5929 {
5930         /* Headphone insertion or removal. */
5931         if ((res >> 26) == ALC880_HP_EVENT)
5932                 alc885_mbp3_automute(codec);
5933 }
5934
5935
5936 static struct hda_verb alc882_targa_verbs[] = {
5937         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5938         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5939
5940         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5941         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5942
5943         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5944         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5945         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5946
5947         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5948         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5949         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
5950         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
5951         { } /* end */
5952 };
5953
5954 /* toggle speaker-output according to the hp-jack state */
5955 static void alc882_targa_automute(struct hda_codec *codec)
5956 {
5957         unsigned int present;
5958
5959         present = snd_hda_codec_read(codec, 0x14, 0,
5960                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5961         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
5962                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5963         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
5964                                   present ? 1 : 3);
5965 }
5966
5967 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
5968 {
5969         /* Looks like the unsol event is incompatible with the standard
5970          * definition.  4bit tag is placed at 26 bit!
5971          */
5972         if (((res >> 26) == ALC880_HP_EVENT)) {
5973                 alc882_targa_automute(codec);
5974         }
5975 }
5976
5977 static struct hda_verb alc882_asus_a7j_verbs[] = {
5978         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5979         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5980
5981         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5982         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5983         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5984
5985         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5986         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5987         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5988
5989         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5990         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5991         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5992         { } /* end */
5993 };
5994
5995 static struct hda_verb alc882_asus_a7m_verbs[] = {
5996         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5997         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5998
5999         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6000         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6001         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6002
6003         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6004         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6005         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6006
6007         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6008         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6009         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6010         { } /* end */
6011 };
6012
6013 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6014 {
6015         unsigned int gpiostate, gpiomask, gpiodir;
6016
6017         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6018                                        AC_VERB_GET_GPIO_DATA, 0);
6019
6020         if (!muted)
6021                 gpiostate |= (1 << pin);
6022         else
6023                 gpiostate &= ~(1 << pin);
6024
6025         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
6026                                       AC_VERB_GET_GPIO_MASK, 0);
6027         gpiomask |= (1 << pin);
6028
6029         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
6030                                      AC_VERB_GET_GPIO_DIRECTION, 0);
6031         gpiodir |= (1 << pin);
6032
6033
6034         snd_hda_codec_write(codec, codec->afg, 0,
6035                             AC_VERB_SET_GPIO_MASK, gpiomask);
6036         snd_hda_codec_write(codec, codec->afg, 0,
6037                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
6038
6039         msleep(1);
6040
6041         snd_hda_codec_write(codec, codec->afg, 0,
6042                             AC_VERB_SET_GPIO_DATA, gpiostate);
6043 }
6044
6045 /* set up GPIO at initialization */
6046 static void alc885_macpro_init_hook(struct hda_codec *codec)
6047 {
6048         alc882_gpio_mute(codec, 0, 0);
6049         alc882_gpio_mute(codec, 1, 0);
6050 }
6051
6052 /* set up GPIO and update auto-muting at initialization */
6053 static void alc885_imac24_init_hook(struct hda_codec *codec)
6054 {
6055         alc885_macpro_init_hook(codec);
6056         alc885_imac24_automute(codec);
6057 }
6058
6059 /*
6060  * generic initialization of ADC, input mixers and output mixers
6061  */
6062 static struct hda_verb alc882_auto_init_verbs[] = {
6063         /*
6064          * Unmute ADC0-2 and set the default input to mic-in
6065          */
6066         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6067         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6068         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6069         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6070         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6071         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6072
6073         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6074          * mixer widget
6075          * Note: PASD motherboards uses the Line In 2 as the input for
6076          * front panel mic (mic 2)
6077          */
6078         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6079         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6080         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6081         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6082         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6083         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6084
6085         /*
6086          * Set up output mixers (0x0c - 0x0f)
6087          */
6088         /* set vol=0 to output mixers */
6089         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6090         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6091         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6092         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6093         /* set up input amps for analog loopback */
6094         /* Amp Indices: DAC = 0, mixer = 1 */
6095         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6096         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6097         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6098         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6099         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6100         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6101         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6102         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6103         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6104         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6105
6106         /* FIXME: use matrix-type input source selection */
6107         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6108         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6109         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6110         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6111         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6112         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6113         /* Input mixer2 */
6114         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6115         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6116         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6117         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6118         /* Input mixer3 */
6119         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6120         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6121         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6122         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6123
6124         { }
6125 };
6126
6127 /* capture mixer elements */
6128 static struct snd_kcontrol_new alc882_capture_alt_mixer[] = {
6129         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6130         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6131         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6132         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6133         {
6134                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6135                 /* The multiple "Capture Source" controls confuse alsamixer
6136                  * So call somewhat different..
6137                  */
6138                 /* .name = "Capture Source", */
6139                 .name = "Input Source",
6140                 .count = 2,
6141                 .info = alc882_mux_enum_info,
6142                 .get = alc882_mux_enum_get,
6143                 .put = alc882_mux_enum_put,
6144         },
6145         { } /* end */
6146 };
6147
6148 static struct snd_kcontrol_new alc882_capture_mixer[] = {
6149         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
6150         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
6151         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
6152         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
6153         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
6154         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
6155         {
6156                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6157                 /* The multiple "Capture Source" controls confuse alsamixer
6158                  * So call somewhat different..
6159                  */
6160                 /* .name = "Capture Source", */
6161                 .name = "Input Source",
6162                 .count = 3,
6163                 .info = alc882_mux_enum_info,
6164                 .get = alc882_mux_enum_get,
6165                 .put = alc882_mux_enum_put,
6166         },
6167         { } /* end */
6168 };
6169
6170 #ifdef CONFIG_SND_HDA_POWER_SAVE
6171 #define alc882_loopbacks        alc880_loopbacks
6172 #endif
6173
6174 /* pcm configuration: identiacal with ALC880 */
6175 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6176 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6177 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6178 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6179
6180 /*
6181  * configuration and preset
6182  */
6183 static const char *alc882_models[ALC882_MODEL_LAST] = {
6184         [ALC882_3ST_DIG]        = "3stack-dig",
6185         [ALC882_6ST_DIG]        = "6stack-dig",
6186         [ALC882_ARIMA]          = "arima",
6187         [ALC882_W2JC]           = "w2jc",
6188         [ALC882_TARGA]          = "targa",
6189         [ALC882_ASUS_A7J]       = "asus-a7j",
6190         [ALC882_ASUS_A7M]       = "asus-a7m",
6191         [ALC885_MACPRO]         = "macpro",
6192         [ALC885_MBP3]           = "mbp3",
6193         [ALC885_IMAC24]         = "imac24",
6194         [ALC882_AUTO]           = "auto",
6195 };
6196
6197 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6198         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6199         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6200         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6201         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6202         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6203         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6204         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6205         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6206         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6207         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6208         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6209         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6210         {}
6211 };
6212
6213 static struct alc_config_preset alc882_presets[] = {
6214         [ALC882_3ST_DIG] = {
6215                 .mixers = { alc882_base_mixer },
6216                 .init_verbs = { alc882_init_verbs },
6217                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6218                 .dac_nids = alc882_dac_nids,
6219                 .dig_out_nid = ALC882_DIGOUT_NID,
6220                 .dig_in_nid = ALC882_DIGIN_NID,
6221                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6222                 .channel_mode = alc882_ch_modes,
6223                 .need_dac_fix = 1,
6224                 .input_mux = &alc882_capture_source,
6225         },
6226         [ALC882_6ST_DIG] = {
6227                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6228                 .init_verbs = { alc882_init_verbs },
6229                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6230                 .dac_nids = alc882_dac_nids,
6231                 .dig_out_nid = ALC882_DIGOUT_NID,
6232                 .dig_in_nid = ALC882_DIGIN_NID,
6233                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6234                 .channel_mode = alc882_sixstack_modes,
6235                 .input_mux = &alc882_capture_source,
6236         },
6237         [ALC882_ARIMA] = {
6238                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6239                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6240                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6241                 .dac_nids = alc882_dac_nids,
6242                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6243                 .channel_mode = alc882_sixstack_modes,
6244                 .input_mux = &alc882_capture_source,
6245         },
6246         [ALC882_W2JC] = {
6247                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6248                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6249                                 alc880_gpio1_init_verbs },
6250                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6251                 .dac_nids = alc882_dac_nids,
6252                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6253                 .channel_mode = alc880_threestack_modes,
6254                 .need_dac_fix = 1,
6255                 .input_mux = &alc882_capture_source,
6256                 .dig_out_nid = ALC882_DIGOUT_NID,
6257         },
6258         [ALC885_MBP3] = {
6259                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6260                 .init_verbs = { alc885_mbp3_init_verbs,
6261                                 alc880_gpio1_init_verbs },
6262                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6263                 .dac_nids = alc882_dac_nids,
6264                 .channel_mode = alc885_mbp_6ch_modes,
6265                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
6266                 .input_mux = &alc882_capture_source,
6267                 .dig_out_nid = ALC882_DIGOUT_NID,
6268                 .dig_in_nid = ALC882_DIGIN_NID,
6269                 .unsol_event = alc885_mbp3_unsol_event,
6270                 .init_hook = alc885_mbp3_automute,
6271         },
6272         [ALC885_MACPRO] = {
6273                 .mixers = { alc882_macpro_mixer },
6274                 .init_verbs = { alc882_macpro_init_verbs },
6275                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6276                 .dac_nids = alc882_dac_nids,
6277                 .dig_out_nid = ALC882_DIGOUT_NID,
6278                 .dig_in_nid = ALC882_DIGIN_NID,
6279                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6280                 .channel_mode = alc882_ch_modes,
6281                 .input_mux = &alc882_capture_source,
6282                 .init_hook = alc885_macpro_init_hook,
6283         },
6284         [ALC885_IMAC24] = {
6285                 .mixers = { alc885_imac24_mixer },
6286                 .init_verbs = { alc885_imac24_init_verbs },
6287                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6288                 .dac_nids = alc882_dac_nids,
6289                 .dig_out_nid = ALC882_DIGOUT_NID,
6290                 .dig_in_nid = ALC882_DIGIN_NID,
6291                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6292                 .channel_mode = alc882_ch_modes,
6293                 .input_mux = &alc882_capture_source,
6294                 .unsol_event = alc885_imac24_unsol_event,
6295                 .init_hook = alc885_imac24_init_hook,
6296         },
6297         [ALC882_TARGA] = {
6298                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer,
6299                             alc882_capture_mixer },
6300                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6301                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6302                 .dac_nids = alc882_dac_nids,
6303                 .dig_out_nid = ALC882_DIGOUT_NID,
6304                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6305                 .adc_nids = alc882_adc_nids,
6306                 .capsrc_nids = alc882_capsrc_nids,
6307                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6308                 .channel_mode = alc882_3ST_6ch_modes,
6309                 .need_dac_fix = 1,
6310                 .input_mux = &alc882_capture_source,
6311                 .unsol_event = alc882_targa_unsol_event,
6312                 .init_hook = alc882_targa_automute,
6313         },
6314         [ALC882_ASUS_A7J] = {
6315                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer,
6316                             alc882_capture_mixer },
6317                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6318                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6319                 .dac_nids = alc882_dac_nids,
6320                 .dig_out_nid = ALC882_DIGOUT_NID,
6321                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6322                 .adc_nids = alc882_adc_nids,
6323                 .capsrc_nids = alc882_capsrc_nids,
6324                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6325                 .channel_mode = alc882_3ST_6ch_modes,
6326                 .need_dac_fix = 1,
6327                 .input_mux = &alc882_capture_source,
6328         },
6329         [ALC882_ASUS_A7M] = {
6330                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6331                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6332                                 alc880_gpio1_init_verbs,
6333                                 alc882_asus_a7m_verbs },
6334                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6335                 .dac_nids = alc882_dac_nids,
6336                 .dig_out_nid = ALC882_DIGOUT_NID,
6337                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6338                 .channel_mode = alc880_threestack_modes,
6339                 .need_dac_fix = 1,
6340                 .input_mux = &alc882_capture_source,
6341         },
6342 };
6343
6344
6345 /*
6346  * Pin config fixes
6347  */
6348 enum {
6349         PINFIX_ABIT_AW9D_MAX
6350 };
6351
6352 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6353         { 0x15, 0x01080104 }, /* side */
6354         { 0x16, 0x01011012 }, /* rear */
6355         { 0x17, 0x01016011 }, /* clfe */
6356         { }
6357 };
6358
6359 static const struct alc_pincfg *alc882_pin_fixes[] = {
6360         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6361 };
6362
6363 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6364         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6365         {}
6366 };
6367
6368 /*
6369  * BIOS auto configuration
6370  */
6371 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6372                                               hda_nid_t nid, int pin_type,
6373                                               int dac_idx)
6374 {
6375         /* set as output */
6376         struct alc_spec *spec = codec->spec;
6377         int idx;
6378
6379         alc_set_pin_output(codec, nid, pin_type);
6380         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6381                 idx = 4;
6382         else
6383                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6384         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6385
6386 }
6387
6388 static void alc882_auto_init_multi_out(struct hda_codec *codec)
6389 {
6390         struct alc_spec *spec = codec->spec;
6391         int i;
6392
6393         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6394         for (i = 0; i <= HDA_SIDE; i++) {
6395                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6396                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6397                 if (nid)
6398                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6399                                                           i);
6400         }
6401 }
6402
6403 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6404 {
6405         struct alc_spec *spec = codec->spec;
6406         hda_nid_t pin;
6407
6408         pin = spec->autocfg.hp_pins[0];
6409         if (pin) /* connect to front */
6410                 /* use dac 0 */
6411                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6412         pin = spec->autocfg.speaker_pins[0];
6413         if (pin)
6414                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6415 }
6416
6417 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6418 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6419
6420 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6421 {
6422         struct alc_spec *spec = codec->spec;
6423         int i;
6424
6425         for (i = 0; i < AUTO_PIN_LAST; i++) {
6426                 hda_nid_t nid = spec->autocfg.input_pins[i];
6427                 unsigned int vref;
6428                 if (!nid)
6429                         continue;
6430                 vref = PIN_IN;
6431                 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6432                         unsigned int pincap;
6433                         pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
6434                         if ((pincap >> AC_PINCAP_VREF_SHIFT) &
6435                             AC_PINCAP_VREF_80)
6436                                 vref = PIN_VREF80;
6437                 }
6438                 snd_hda_codec_write(codec, nid, 0,
6439                                     AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6440                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6441                         snd_hda_codec_write(codec, nid, 0,
6442                                             AC_VERB_SET_AMP_GAIN_MUTE,
6443                                             AMP_OUT_MUTE);
6444         }
6445 }
6446
6447 static void alc882_auto_init_input_src(struct hda_codec *codec)
6448 {
6449         struct alc_spec *spec = codec->spec;
6450         const struct hda_input_mux *imux = spec->input_mux;
6451         int c;
6452
6453         for (c = 0; c < spec->num_adc_nids; c++) {
6454                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
6455                 hda_nid_t nid = spec->capsrc_nids[c];
6456                 int conns, mute, idx, item;
6457
6458                 conns = snd_hda_get_connections(codec, nid, conn_list,
6459                                                 ARRAY_SIZE(conn_list));
6460                 if (conns < 0)
6461                         continue;
6462                 for (idx = 0; idx < conns; idx++) {
6463                         /* if the current connection is the selected one,
6464                          * unmute it as default - otherwise mute it
6465                          */
6466                         mute = AMP_IN_MUTE(idx);
6467                         for (item = 0; item < imux->num_items; item++) {
6468                                 if (imux->items[item].index == idx) {
6469                                         if (spec->cur_mux[c] == item)
6470                                                 mute = AMP_IN_UNMUTE(idx);
6471                                         break;
6472                                 }
6473                         }
6474                         snd_hda_codec_write(codec, nid, 0,
6475                                             AC_VERB_SET_AMP_GAIN_MUTE, mute);
6476                 }
6477         }
6478 }
6479
6480 /* add mic boosts if needed */
6481 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6482 {
6483         struct alc_spec *spec = codec->spec;
6484         int err;
6485         hda_nid_t nid;
6486
6487         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6488         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6489                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6490                                   "Mic Boost",
6491                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6492                 if (err < 0)
6493                         return err;
6494         }
6495         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6496         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6497                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6498                                   "Front Mic Boost",
6499                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6500                 if (err < 0)
6501                         return err;
6502         }
6503         return 0;
6504 }
6505
6506 /* almost identical with ALC880 parser... */
6507 static int alc882_parse_auto_config(struct hda_codec *codec)
6508 {
6509         struct alc_spec *spec = codec->spec;
6510         int err = alc880_parse_auto_config(codec);
6511
6512         if (err < 0)
6513                 return err;
6514         else if (!err)
6515                 return 0; /* no config found */
6516
6517         err = alc_auto_add_mic_boost(codec);
6518         if (err < 0)
6519                 return err;
6520
6521         /* hack - override the init verbs */
6522         spec->init_verbs[0] = alc882_auto_init_verbs;
6523
6524         return 1; /* config found */
6525 }
6526
6527 /* additional initialization for auto-configuration model */
6528 static void alc882_auto_init(struct hda_codec *codec)
6529 {
6530         struct alc_spec *spec = codec->spec;
6531         alc882_auto_init_multi_out(codec);
6532         alc882_auto_init_hp_out(codec);
6533         alc882_auto_init_analog_input(codec);
6534         alc882_auto_init_input_src(codec);
6535         if (spec->unsol_event)
6536                 alc_sku_automute(codec);
6537 }
6538
6539 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
6540
6541 static int patch_alc882(struct hda_codec *codec)
6542 {
6543         struct alc_spec *spec;
6544         int err, board_config;
6545
6546         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6547         if (spec == NULL)
6548                 return -ENOMEM;
6549
6550         codec->spec = spec;
6551
6552         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
6553                                                   alc882_models,
6554                                                   alc882_cfg_tbl);
6555
6556         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
6557                 /* Pick up systems that don't supply PCI SSID */
6558                 switch (codec->subsystem_id) {
6559                 case 0x106b0c00: /* Mac Pro */
6560                         board_config = ALC885_MACPRO;
6561                         break;
6562                 case 0x106b1000: /* iMac 24 */
6563                         board_config = ALC885_IMAC24;
6564                         break;
6565                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
6566                 case 0x106b2c00: /* Macbook Pro rev3 */
6567                 case 0x106b3600: /* Macbook 3.1 */
6568                         board_config = ALC885_MBP3;
6569                         break;
6570                 default:
6571                         /* ALC889A is handled better as ALC888-compatible */
6572                         if (codec->revision_id == 0x100103) {
6573                                 alc_free(codec);
6574                                 return patch_alc883(codec);
6575                         }
6576                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
6577                                          "trying auto-probe from BIOS...\n");
6578                         board_config = ALC882_AUTO;
6579                 }
6580         }
6581
6582         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
6583
6584         if (board_config == ALC882_AUTO) {
6585                 /* automatic parse from the BIOS config */
6586                 err = alc882_parse_auto_config(codec);
6587                 if (err < 0) {
6588                         alc_free(codec);
6589                         return err;
6590                 } else if (!err) {
6591                         printk(KERN_INFO
6592                                "hda_codec: Cannot set up configuration "
6593                                "from BIOS.  Using base mode...\n");
6594                         board_config = ALC882_3ST_DIG;
6595                 }
6596         }
6597
6598         if (board_config != ALC882_AUTO)
6599                 setup_preset(spec, &alc882_presets[board_config]);
6600
6601         if (codec->vendor_id == 0x10ec0885) {
6602                 spec->stream_name_analog = "ALC885 Analog";
6603                 spec->stream_name_digital = "ALC885 Digital";
6604         } else {
6605                 spec->stream_name_analog = "ALC882 Analog";
6606                 spec->stream_name_digital = "ALC882 Digital";
6607         }
6608
6609         spec->stream_analog_playback = &alc882_pcm_analog_playback;
6610         spec->stream_analog_capture = &alc882_pcm_analog_capture;
6611         /* FIXME: setup DAC5 */
6612         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
6613         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
6614
6615         spec->stream_digital_playback = &alc882_pcm_digital_playback;
6616         spec->stream_digital_capture = &alc882_pcm_digital_capture;
6617
6618         if (!spec->adc_nids && spec->input_mux) {
6619                 /* check whether NID 0x07 is valid */
6620                 unsigned int wcap = get_wcaps(codec, 0x07);
6621                 /* get type */
6622                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
6623                 if (wcap != AC_WID_AUD_IN) {
6624                         spec->adc_nids = alc882_adc_nids_alt;
6625                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
6626                         spec->capsrc_nids = alc882_capsrc_nids_alt;
6627                         spec->mixers[spec->num_mixers] =
6628                                 alc882_capture_alt_mixer;
6629                         spec->num_mixers++;
6630                 } else {
6631                         spec->adc_nids = alc882_adc_nids;
6632                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
6633                         spec->capsrc_nids = alc882_capsrc_nids;
6634                         spec->mixers[spec->num_mixers] = alc882_capture_mixer;
6635                         spec->num_mixers++;
6636                 }
6637         }
6638
6639         spec->vmaster_nid = 0x0c;
6640
6641         codec->patch_ops = alc_patch_ops;
6642         if (board_config == ALC882_AUTO)
6643                 spec->init_hook = alc882_auto_init;
6644 #ifdef CONFIG_SND_HDA_POWER_SAVE
6645         if (!spec->loopback.amplist)
6646                 spec->loopback.amplist = alc882_loopbacks;
6647 #endif
6648
6649         return 0;
6650 }
6651
6652 /*
6653  * ALC883 support
6654  *
6655  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
6656  * configuration.  Each pin widget can choose any input DACs and a mixer.
6657  * Each ADC is connected from a mixer of all inputs.  This makes possible
6658  * 6-channel independent captures.
6659  *
6660  * In addition, an independent DAC for the multi-playback (not used in this
6661  * driver yet).
6662  */
6663 #define ALC883_DIGOUT_NID       0x06
6664 #define ALC883_DIGIN_NID        0x0a
6665
6666 static hda_nid_t alc883_dac_nids[4] = {
6667         /* front, rear, clfe, rear_surr */
6668         0x02, 0x03, 0x04, 0x05
6669 };
6670
6671 static hda_nid_t alc883_adc_nids[2] = {
6672         /* ADC1-2 */
6673         0x08, 0x09,
6674 };
6675
6676 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
6677
6678 /* input MUX */
6679 /* FIXME: should be a matrix-type input source selection */
6680
6681 static struct hda_input_mux alc883_capture_source = {
6682         .num_items = 4,
6683         .items = {
6684                 { "Mic", 0x0 },
6685                 { "Front Mic", 0x1 },
6686                 { "Line", 0x2 },
6687                 { "CD", 0x4 },
6688         },
6689 };
6690
6691 static struct hda_input_mux alc883_3stack_6ch_intel = {
6692         .num_items = 4,
6693         .items = {
6694                 { "Mic", 0x1 },
6695                 { "Front Mic", 0x0 },
6696                 { "Line", 0x2 },
6697                 { "CD", 0x4 },
6698         },
6699 };
6700
6701 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6702         .num_items = 2,
6703         .items = {
6704                 { "Mic", 0x1 },
6705                 { "Line", 0x2 },
6706         },
6707 };
6708
6709 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6710         .num_items = 4,
6711         .items = {
6712                 { "Mic", 0x0 },
6713                 { "iMic", 0x1 },
6714                 { "Line", 0x2 },
6715                 { "CD", 0x4 },
6716         },
6717 };
6718
6719 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6720         .num_items = 2,
6721         .items = {
6722                 { "Mic", 0x0 },
6723                 { "Int Mic", 0x1 },
6724         },
6725 };
6726
6727 #define alc883_mux_enum_info alc_mux_enum_info
6728 #define alc883_mux_enum_get alc_mux_enum_get
6729 /* ALC883 has the ALC882-type input selection */
6730 #define alc883_mux_enum_put alc882_mux_enum_put
6731
6732 /*
6733  * 2ch mode
6734  */
6735 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6736         { 2, NULL }
6737 };
6738
6739 /*
6740  * 2ch mode
6741  */
6742 static struct hda_verb alc883_3ST_ch2_init[] = {
6743         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6744         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6745         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6746         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6747         { } /* end */
6748 };
6749
6750 /*
6751  * 4ch mode
6752  */
6753 static struct hda_verb alc883_3ST_ch4_init[] = {
6754         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6755         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6756         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6757         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6758         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6759         { } /* end */
6760 };
6761
6762 /*
6763  * 6ch mode
6764  */
6765 static struct hda_verb alc883_3ST_ch6_init[] = {
6766         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6767         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6768         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6769         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6770         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6771         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6772         { } /* end */
6773 };
6774
6775 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
6776         { 2, alc883_3ST_ch2_init },
6777         { 4, alc883_3ST_ch4_init },
6778         { 6, alc883_3ST_ch6_init },
6779 };
6780
6781 /*
6782  * 2ch mode
6783  */
6784 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
6785         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6786         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6787         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6788         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6789         { } /* end */
6790 };
6791
6792 /*
6793  * 4ch mode
6794  */
6795 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
6796         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6797         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6798         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6799         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6800         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6801         { } /* end */
6802 };
6803
6804 /*
6805  * 6ch mode
6806  */
6807 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
6808         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6809         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6810         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
6811         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6812         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6813         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6814         { } /* end */
6815 };
6816
6817 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
6818         { 2, alc883_3ST_ch2_intel_init },
6819         { 4, alc883_3ST_ch4_intel_init },
6820         { 6, alc883_3ST_ch6_intel_init },
6821 };
6822
6823 /*
6824  * 6ch mode
6825  */
6826 static struct hda_verb alc883_sixstack_ch6_init[] = {
6827         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6828         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6829         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6830         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6831         { } /* end */
6832 };
6833
6834 /*
6835  * 8ch mode
6836  */
6837 static struct hda_verb alc883_sixstack_ch8_init[] = {
6838         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6839         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6840         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6841         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6842         { } /* end */
6843 };
6844
6845 static struct hda_channel_mode alc883_sixstack_modes[2] = {
6846         { 6, alc883_sixstack_ch6_init },
6847         { 8, alc883_sixstack_ch8_init },
6848 };
6849
6850 static struct hda_verb alc883_medion_eapd_verbs[] = {
6851         /* eanable EAPD on medion laptop */
6852         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6853         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
6854         { }
6855 };
6856
6857 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6858  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6859  */
6860
6861 static struct snd_kcontrol_new alc883_base_mixer[] = {
6862         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6863         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6864         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6865         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6866         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6867         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6868         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6869         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6870         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6871         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6872         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6873         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6874         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6875         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6876         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6877         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6878         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6879         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6880         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6881         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6882         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6883         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6884         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6885         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6886         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6887         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6888         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6889         {
6890                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6891                 /* .name = "Capture Source", */
6892                 .name = "Input Source",
6893                 .count = 2,
6894                 .info = alc883_mux_enum_info,
6895                 .get = alc883_mux_enum_get,
6896                 .put = alc883_mux_enum_put,
6897         },
6898         { } /* end */
6899 };
6900
6901 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
6902         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6903         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6904         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6905         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6906         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6907         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6908         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6909         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6910         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6911         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6912         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6913         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6914         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6915         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6916         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6917         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6918         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6919         {
6920                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6921                 /* .name = "Capture Source", */
6922                 .name = "Input Source",
6923                 .count = 2,
6924                 .info = alc883_mux_enum_info,
6925                 .get = alc883_mux_enum_get,
6926                 .put = alc883_mux_enum_put,
6927         },
6928         { } /* end */
6929 };
6930
6931 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
6932         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6933         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
6934         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6935         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6936         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6937         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6938         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6939         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6940         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6941         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6942         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6943         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6944         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6945         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6946         {
6947                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6948                 /* .name = "Capture Source", */
6949                 .name = "Input Source",
6950                 .count = 2,
6951                 .info = alc883_mux_enum_info,
6952                 .get = alc883_mux_enum_get,
6953                 .put = alc883_mux_enum_put,
6954         },
6955         { } /* end */
6956 };
6957
6958 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
6959         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6960         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
6961         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6962         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6963         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6964         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6965         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6966         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6967         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6968         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6969         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6970         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6971         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6972         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6973         {
6974                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6975                 /* .name = "Capture Source", */
6976                 .name = "Input Source",
6977                 .count = 2,
6978                 .info = alc883_mux_enum_info,
6979                 .get = alc883_mux_enum_get,
6980                 .put = alc883_mux_enum_put,
6981         },
6982         { } /* end */
6983 };
6984
6985 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
6986         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6987         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6988         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6989         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6990         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6991         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6992         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6993         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6994         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6995         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6996         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6997         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6998         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6999         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7000         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7001         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7002         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7003         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7004         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7005         {
7006                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7007                 /* .name = "Capture Source", */
7008                 .name = "Input Source",
7009                 .count = 2,
7010                 .info = alc883_mux_enum_info,
7011                 .get = alc883_mux_enum_get,
7012                 .put = alc883_mux_enum_put,
7013         },
7014         { } /* end */
7015 };
7016
7017 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7018         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7019         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7020         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7021         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7022         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7023         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7024         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7025         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7026         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7027         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7028         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7029         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7030         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7031         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7032         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7033         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7034         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7035         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7036         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7037         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7038         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7039         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7040         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7041         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7042         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7043         {
7044                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7045                 /* .name = "Capture Source", */
7046                 .name = "Input Source",
7047                 .count = 2,
7048                 .info = alc883_mux_enum_info,
7049                 .get = alc883_mux_enum_get,
7050                 .put = alc883_mux_enum_put,
7051         },
7052         { } /* end */
7053 };
7054
7055 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7056         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7057         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7058         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7059         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7060         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7061                               HDA_OUTPUT),
7062         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7063         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7064         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7065         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7066         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7067         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7068         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7069         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7070         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7071         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7072         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7073         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7074         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7075         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7076         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7077         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7078         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7079         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7080         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7081         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7082         {
7083                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7084                 /* .name = "Capture Source", */
7085                 .name = "Input Source",
7086                 .count = 2,
7087                 .info = alc883_mux_enum_info,
7088                 .get = alc883_mux_enum_get,
7089                 .put = alc883_mux_enum_put,
7090         },
7091         { } /* end */
7092 };
7093
7094 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7095         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7096         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7097         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7098         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7099         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7100         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7101         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7102         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7103         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7104         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7105         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7106         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7107         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7108         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7109         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7110         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7111         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7112         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7113         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7114         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7115         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7116         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7117         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7118
7119         {
7120                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7121                 /* .name = "Capture Source", */
7122                 .name = "Input Source",
7123                 .count = 1,
7124                 .info = alc883_mux_enum_info,
7125                 .get = alc883_mux_enum_get,
7126                 .put = alc883_mux_enum_put,
7127         },
7128         { } /* end */
7129 };
7130
7131 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
7132         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7133         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7134         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7135         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7136         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7137         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7138         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7139         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7140         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7141         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7142         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7143         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7144         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7145         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7146         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7147         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7148         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7149         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7150         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7151         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7152         {
7153                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7154                 /* .name = "Capture Source", */
7155                 .name = "Input Source",
7156                 .count = 2,
7157                 .info = alc883_mux_enum_info,
7158                 .get = alc883_mux_enum_get,
7159                 .put = alc883_mux_enum_put,
7160         },
7161         { } /* end */
7162 };
7163
7164 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
7165         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7166         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7167         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7168         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7169         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7170         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7171         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7172         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7173         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7174         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7175         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7176         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7177         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7178         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7179         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7180         {
7181                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7182                 /* .name = "Capture Source", */
7183                 .name = "Input Source",
7184                 .count = 2,
7185                 .info = alc883_mux_enum_info,
7186                 .get = alc883_mux_enum_get,
7187                 .put = alc883_mux_enum_put,
7188         },
7189         { } /* end */
7190 };
7191
7192 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7193         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7194         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7195         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7196         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7197         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7198         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7199         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7200         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7201         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7202         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7203         {
7204                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7205                 /* .name = "Capture Source", */
7206                 .name = "Input Source",
7207                 .count = 1,
7208                 .info = alc883_mux_enum_info,
7209                 .get = alc883_mux_enum_get,
7210                 .put = alc883_mux_enum_put,
7211         },
7212         { } /* end */
7213 };
7214
7215 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7216         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7217         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7218         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7219         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7220         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7221         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7222         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7223         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7224         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7225         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7226         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7227         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7228         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7229         {
7230                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7231                 /* .name = "Capture Source", */
7232                 .name = "Input Source",
7233                 .count = 2,
7234                 .info = alc883_mux_enum_info,
7235                 .get = alc883_mux_enum_get,
7236                 .put = alc883_mux_enum_put,
7237         },
7238         { } /* end */
7239 };
7240
7241 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7242         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7243         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7244         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7245         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7246         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7247         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7248         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7249         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7250         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7251         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7252         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7253         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7254         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7255         {
7256                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7257                 /* .name = "Capture Source", */
7258                 .name = "Input Source",
7259                 .count = 2,
7260                 .info = alc883_mux_enum_info,
7261                 .get = alc883_mux_enum_get,
7262                 .put = alc883_mux_enum_put,
7263         },
7264         { } /* end */
7265 };
7266
7267 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7268         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7269         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7270         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7271         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7272         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7273         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7274         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7275         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7276         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7277         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7278         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7279         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7280         {
7281                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7282                 /* .name = "Capture Source", */
7283                 .name = "Input Source",
7284                 .count = 2,
7285                 .info = alc883_mux_enum_info,
7286                 .get = alc883_mux_enum_get,
7287                 .put = alc883_mux_enum_put,
7288         },
7289         { } /* end */
7290 };
7291
7292 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7293         {
7294                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7295                 .name = "Channel Mode",
7296                 .info = alc_ch_mode_info,
7297                 .get = alc_ch_mode_get,
7298                 .put = alc_ch_mode_put,
7299         },
7300         { } /* end */
7301 };
7302
7303 static struct hda_verb alc883_init_verbs[] = {
7304         /* ADC1: mute amp left and right */
7305         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7306         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7307         /* ADC2: mute amp left and right */
7308         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7309         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7310         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7311         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7312         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7313         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7314         /* Rear mixer */
7315         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7316         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7317         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7318         /* CLFE mixer */
7319         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7320         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7321         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7322         /* Side mixer */
7323         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7324         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7325         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7326
7327         /* mute analog input loopbacks */
7328         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7329         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7330         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7331         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7332         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7333
7334         /* Front Pin: output 0 (0x0c) */
7335         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7336         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7337         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7338         /* Rear Pin: output 1 (0x0d) */
7339         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7340         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7341         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7342         /* CLFE Pin: output 2 (0x0e) */
7343         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7344         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7345         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7346         /* Side Pin: output 3 (0x0f) */
7347         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7348         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7349         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7350         /* Mic (rear) pin: input vref at 80% */
7351         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7352         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7353         /* Front Mic pin: input vref at 80% */
7354         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7355         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7356         /* Line In pin: input */
7357         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7358         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7359         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7360         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7361         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7362         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7363         /* CD pin widget for input */
7364         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7365
7366         /* FIXME: use matrix-type input source selection */
7367         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7368         /* Input mixer2 */
7369         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7370         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7371         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7372         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7373         /* Input mixer3 */
7374         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7375         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7376         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7377         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7378         { }
7379 };
7380
7381 /* toggle speaker-output according to the hp-jack state */
7382 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7383 {
7384         unsigned int present;
7385
7386         present = snd_hda_codec_read(codec, 0x15, 0,
7387                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7388         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7389                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7390         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7391                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7392 }
7393
7394 /* auto-toggle front mic */
7395 /*
7396 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7397 {
7398         unsigned int present;
7399         unsigned char bits;
7400
7401         present = snd_hda_codec_read(codec, 0x18, 0,
7402                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7403         bits = present ? HDA_AMP_MUTE : 0;
7404         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7405 }
7406 */
7407
7408 static void alc883_mitac_automute(struct hda_codec *codec)
7409 {
7410         alc883_mitac_hp_automute(codec);
7411         /* alc883_mitac_mic_automute(codec); */
7412 }
7413
7414 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7415                                            unsigned int res)
7416 {
7417         switch (res >> 26) {
7418         case ALC880_HP_EVENT:
7419                 alc883_mitac_hp_automute(codec);
7420                 break;
7421         case ALC880_MIC_EVENT:
7422                 /* alc883_mitac_mic_automute(codec); */
7423                 break;
7424         }
7425 }
7426
7427 static struct hda_verb alc883_mitac_verbs[] = {
7428         /* HP */
7429         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7430         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7431         /* Subwoofer */
7432         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7433         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7434
7435         /* enable unsolicited event */
7436         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7437         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7438
7439         { } /* end */
7440 };
7441
7442 static struct hda_verb alc883_clevo_m720_verbs[] = {
7443         /* HP */
7444         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7445         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7446         /* Int speaker */
7447         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7448         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7449
7450         /* enable unsolicited event */
7451         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7452         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7453
7454         { } /* end */
7455 };
7456
7457 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7458         /* HP */
7459         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7460         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7461         /* Subwoofer */
7462         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7463         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7464
7465         /* enable unsolicited event */
7466         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7467
7468         { } /* end */
7469 };
7470
7471 static struct hda_verb alc883_tagra_verbs[] = {
7472         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7473         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7474
7475         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7476         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7477
7478         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7479         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7480         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7481
7482         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7483         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7484         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7485         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7486
7487         { } /* end */
7488 };
7489
7490 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7491         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7492         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7493         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7494         { } /* end */
7495 };
7496
7497 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7498         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7499         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7500         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7501         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7502         { } /* end */
7503 };
7504
7505 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7506         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7507         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7508         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7509         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7510         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7511         { } /* end */
7512 };
7513
7514 static struct hda_verb alc883_haier_w66_verbs[] = {
7515         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7516         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7517
7518         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7519
7520         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7521         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7522         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7523         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7524         { } /* end */
7525 };
7526
7527 static struct hda_verb alc888_3st_hp_verbs[] = {
7528         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7529         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7530         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7531         { }
7532 };
7533
7534 static struct hda_verb alc888_6st_dell_verbs[] = {
7535         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7536         { }
7537 };
7538
7539 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7540         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7541         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7542         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7543         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7544         { }
7545 };
7546
7547 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7548         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7549         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7550         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7551         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7552         { }
7553 };
7554
7555 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7556         { 2, alc888_3st_hp_2ch_init },
7557         { 6, alc888_3st_hp_6ch_init },
7558 };
7559
7560 /* toggle front-jack and RCA according to the hp-jack state */
7561 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7562 {
7563         unsigned int present;
7564
7565         present = snd_hda_codec_read(codec, 0x1b, 0,
7566                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7567         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7568                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7569         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7570                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7571 }
7572
7573 /* toggle RCA according to the front-jack state */
7574 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7575 {
7576         unsigned int present;
7577
7578         present = snd_hda_codec_read(codec, 0x14, 0,
7579                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7580         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7581                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7582 }
7583
7584 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7585                                              unsigned int res)
7586 {
7587         if ((res >> 26) == ALC880_HP_EVENT)
7588                 alc888_lenovo_ms7195_front_automute(codec);
7589         if ((res >> 26) == ALC880_FRONT_EVENT)
7590                 alc888_lenovo_ms7195_rca_automute(codec);
7591 }
7592
7593 static struct hda_verb alc883_medion_md2_verbs[] = {
7594         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7595         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7596
7597         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7598
7599         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7600         { } /* end */
7601 };
7602
7603 /* toggle speaker-output according to the hp-jack state */
7604 static void alc883_medion_md2_automute(struct hda_codec *codec)
7605 {
7606         unsigned int present;
7607
7608         present = snd_hda_codec_read(codec, 0x14, 0,
7609                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7610         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7611                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7612 }
7613
7614 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
7615                                           unsigned int res)
7616 {
7617         if ((res >> 26) == ALC880_HP_EVENT)
7618                 alc883_medion_md2_automute(codec);
7619 }
7620
7621 /* toggle speaker-output according to the hp-jack state */
7622 static void alc883_tagra_automute(struct hda_codec *codec)
7623 {
7624         unsigned int present;
7625         unsigned char bits;
7626
7627         present = snd_hda_codec_read(codec, 0x14, 0,
7628                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7629         bits = present ? HDA_AMP_MUTE : 0;
7630         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
7631                                  HDA_AMP_MUTE, bits);
7632         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7633                                   present ? 1 : 3);
7634 }
7635
7636 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
7637 {
7638         if ((res >> 26) == ALC880_HP_EVENT)
7639                 alc883_tagra_automute(codec);
7640 }
7641
7642 /* toggle speaker-output according to the hp-jack state */
7643 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
7644 {
7645         unsigned int present;
7646         unsigned char bits;
7647
7648         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
7649                 & AC_PINSENSE_PRESENCE;
7650         bits = present ? HDA_AMP_MUTE : 0;
7651         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7652                                  HDA_AMP_MUTE, bits);
7653 }
7654
7655 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
7656 {
7657         unsigned int present;
7658
7659         present = snd_hda_codec_read(codec, 0x18, 0,
7660                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7661         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
7662                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7663 }
7664
7665 static void alc883_clevo_m720_automute(struct hda_codec *codec)
7666 {
7667         alc883_clevo_m720_hp_automute(codec);
7668         alc883_clevo_m720_mic_automute(codec);
7669 }
7670
7671 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
7672                                            unsigned int res)
7673 {
7674         switch (res >> 26) {
7675         case ALC880_HP_EVENT:
7676                 alc883_clevo_m720_hp_automute(codec);
7677                 break;
7678         case ALC880_MIC_EVENT:
7679                 alc883_clevo_m720_mic_automute(codec);
7680                 break;
7681         }
7682 }
7683
7684 /* toggle speaker-output according to the hp-jack state */
7685 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
7686 {
7687         unsigned int present;
7688         unsigned char bits;
7689
7690         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
7691                 & AC_PINSENSE_PRESENCE;
7692         bits = present ? HDA_AMP_MUTE : 0;
7693         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7694                                  HDA_AMP_MUTE, bits);
7695 }
7696
7697 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
7698                                                   unsigned int res)
7699 {
7700         if ((res >> 26) == ALC880_HP_EVENT)
7701                 alc883_2ch_fujitsu_pi2515_automute(codec);
7702 }
7703
7704 static void alc883_haier_w66_automute(struct hda_codec *codec)
7705 {
7706         unsigned int present;
7707         unsigned char bits;
7708
7709         present = snd_hda_codec_read(codec, 0x1b, 0,
7710                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7711         bits = present ? 0x80 : 0;
7712         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7713                                  0x80, bits);
7714 }
7715
7716 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
7717                                          unsigned int res)
7718 {
7719         if ((res >> 26) == ALC880_HP_EVENT)
7720                 alc883_haier_w66_automute(codec);
7721 }
7722
7723 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
7724 {
7725         unsigned int present;
7726         unsigned char bits;
7727
7728         present = snd_hda_codec_read(codec, 0x14, 0,
7729                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7730         bits = present ? HDA_AMP_MUTE : 0;
7731         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7732                                  HDA_AMP_MUTE, bits);
7733 }
7734
7735 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
7736 {
7737         unsigned int present;
7738         unsigned char bits;
7739
7740         present = snd_hda_codec_read(codec, 0x1b, 0,
7741                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7742         bits = present ? HDA_AMP_MUTE : 0;
7743         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7744                                  HDA_AMP_MUTE, bits);
7745         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7746                                  HDA_AMP_MUTE, bits);
7747 }
7748
7749 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
7750                                            unsigned int res)
7751 {
7752         if ((res >> 26) == ALC880_HP_EVENT)
7753                 alc883_lenovo_101e_all_automute(codec);
7754         if ((res >> 26) == ALC880_FRONT_EVENT)
7755                 alc883_lenovo_101e_ispeaker_automute(codec);
7756 }
7757
7758 /* toggle speaker-output according to the hp-jack state */
7759 static void alc883_acer_aspire_automute(struct hda_codec *codec)
7760 {
7761         unsigned int present;
7762
7763         present = snd_hda_codec_read(codec, 0x14, 0,
7764                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7765         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7766                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7767         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7768                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7769 }
7770
7771 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
7772                                            unsigned int res)
7773 {
7774         if ((res >> 26) == ALC880_HP_EVENT)
7775                 alc883_acer_aspire_automute(codec);
7776 }
7777
7778 static struct hda_verb alc883_acer_eapd_verbs[] = {
7779         /* HP Pin: output 0 (0x0c) */
7780         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7781         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7782         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7783         /* Front Pin: output 0 (0x0c) */
7784         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7785         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7786         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7787         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
7788         /* eanable EAPD on medion laptop */
7789         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7790         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
7791         /* enable unsolicited event */
7792         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7793         { }
7794 };
7795
7796 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
7797 {
7798         unsigned int present;
7799
7800         present = snd_hda_codec_read(codec, 0x1b, 0,
7801                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7802         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7803                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7804         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7805                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7806         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7807                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7808         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7809                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7810 }
7811
7812 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
7813                                              unsigned int res)
7814 {
7815         switch (res >> 26) {
7816         case ALC880_HP_EVENT:
7817                 printk("hp_event\n");
7818                 alc888_6st_dell_front_automute(codec);
7819                 break;
7820         }
7821 }
7822
7823 /*
7824  * generic initialization of ADC, input mixers and output mixers
7825  */
7826 static struct hda_verb alc883_auto_init_verbs[] = {
7827         /*
7828          * Unmute ADC0-2 and set the default input to mic-in
7829          */
7830         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7831         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7832         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7833         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7834
7835         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7836          * mixer widget
7837          * Note: PASD motherboards uses the Line In 2 as the input for
7838          * front panel mic (mic 2)
7839          */
7840         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7841         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7842         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7843         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7844         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7845         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7846
7847         /*
7848          * Set up output mixers (0x0c - 0x0f)
7849          */
7850         /* set vol=0 to output mixers */
7851         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7852         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7853         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7854         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7855         /* set up input amps for analog loopback */
7856         /* Amp Indices: DAC = 0, mixer = 1 */
7857         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7858         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7859         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7860         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7861         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7862         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7863         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7864         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7865         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7866         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7867
7868         /* FIXME: use matrix-type input source selection */
7869         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7870         /* Input mixer1 */
7871         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7872         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7873         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7874         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
7875         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7876         /* Input mixer2 */
7877         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7878         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7879         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7880         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
7881         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7882
7883         { }
7884 };
7885
7886 /* capture mixer elements */
7887 static struct snd_kcontrol_new alc883_capture_mixer[] = {
7888         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7889         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7890         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7891         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7892         {
7893                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7894                 /* The multiple "Capture Source" controls confuse alsamixer
7895                  * So call somewhat different..
7896                  */
7897                 /* .name = "Capture Source", */
7898                 .name = "Input Source",
7899                 .count = 2,
7900                 .info = alc882_mux_enum_info,
7901                 .get = alc882_mux_enum_get,
7902                 .put = alc882_mux_enum_put,
7903         },
7904         { } /* end */
7905 };
7906
7907 #ifdef CONFIG_SND_HDA_POWER_SAVE
7908 #define alc883_loopbacks        alc880_loopbacks
7909 #endif
7910
7911 /* pcm configuration: identiacal with ALC880 */
7912 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
7913 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
7914 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
7915 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
7916 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
7917
7918 /*
7919  * configuration and preset
7920  */
7921 static const char *alc883_models[ALC883_MODEL_LAST] = {
7922         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
7923         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
7924         [ALC883_3ST_6ch]        = "3stack-6ch",
7925         [ALC883_6ST_DIG]        = "6stack-dig",
7926         [ALC883_TARGA_DIG]      = "targa-dig",
7927         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
7928         [ALC883_ACER]           = "acer",
7929         [ALC883_ACER_ASPIRE]    = "acer-aspire",
7930         [ALC883_MEDION]         = "medion",
7931         [ALC883_MEDION_MD2]     = "medion-md2",
7932         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
7933         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
7934         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
7935         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
7936         [ALC883_HAIER_W66]      = "haier-w66",
7937         [ALC888_3ST_HP]         = "3stack-hp",
7938         [ALC888_6ST_DELL]       = "6stack-dell",
7939         [ALC883_MITAC]          = "mitac",
7940         [ALC883_CLEVO_M720]     = "clevo-m720",
7941         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
7942         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
7943         [ALC883_AUTO]           = "auto",
7944 };
7945
7946 static struct snd_pci_quirk alc883_cfg_tbl[] = {
7947         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
7948         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
7949         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
7950         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
7951         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
7952         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
7953         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
7954         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
7955         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
7956         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
7957         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
7958         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
7959         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
7960         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
7961         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
7962         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
7963         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
7964         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
7965         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
7966         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
7967         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
7968         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
7969         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
7970         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
7971         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
7972         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
7973         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
7974         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
7975         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
7976         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
7977         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
7978         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
7979         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
7980         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
7981         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
7982         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
7983         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
7984         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
7985         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
7986         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
7987         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
7988         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
7989         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
7990         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
7991         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
7992         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
7993         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
7994         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
7995         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7996         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7997         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7998         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
7999         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8000         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8001         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8002         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8003         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8004         {}
8005 };
8006
8007 static struct alc_config_preset alc883_presets[] = {
8008         [ALC883_3ST_2ch_DIG] = {
8009                 .mixers = { alc883_3ST_2ch_mixer },
8010                 .init_verbs = { alc883_init_verbs },
8011                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8012                 .dac_nids = alc883_dac_nids,
8013                 .dig_out_nid = ALC883_DIGOUT_NID,
8014                 .dig_in_nid = ALC883_DIGIN_NID,
8015                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8016                 .channel_mode = alc883_3ST_2ch_modes,
8017                 .input_mux = &alc883_capture_source,
8018         },
8019         [ALC883_3ST_6ch_DIG] = {
8020                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8021                 .init_verbs = { alc883_init_verbs },
8022                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8023                 .dac_nids = alc883_dac_nids,
8024                 .dig_out_nid = ALC883_DIGOUT_NID,
8025                 .dig_in_nid = ALC883_DIGIN_NID,
8026                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8027                 .channel_mode = alc883_3ST_6ch_modes,
8028                 .need_dac_fix = 1,
8029                 .input_mux = &alc883_capture_source,
8030         },
8031         [ALC883_3ST_6ch] = {
8032                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8033                 .init_verbs = { alc883_init_verbs },
8034                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8035                 .dac_nids = alc883_dac_nids,
8036                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8037                 .channel_mode = alc883_3ST_6ch_modes,
8038                 .need_dac_fix = 1,
8039                 .input_mux = &alc883_capture_source,
8040         },
8041         [ALC883_3ST_6ch_INTEL] = {
8042                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
8043                 .init_verbs = { alc883_init_verbs },
8044                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8045                 .dac_nids = alc883_dac_nids,
8046                 .dig_out_nid = ALC883_DIGOUT_NID,
8047                 .dig_in_nid = ALC883_DIGIN_NID,
8048                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
8049                 .channel_mode = alc883_3ST_6ch_intel_modes,
8050                 .need_dac_fix = 1,
8051                 .input_mux = &alc883_3stack_6ch_intel,
8052         },
8053         [ALC883_6ST_DIG] = {
8054                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8055                 .init_verbs = { alc883_init_verbs },
8056                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8057                 .dac_nids = alc883_dac_nids,
8058                 .dig_out_nid = ALC883_DIGOUT_NID,
8059                 .dig_in_nid = ALC883_DIGIN_NID,
8060                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8061                 .channel_mode = alc883_sixstack_modes,
8062                 .input_mux = &alc883_capture_source,
8063         },
8064         [ALC883_TARGA_DIG] = {
8065                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
8066                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8067                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8068                 .dac_nids = alc883_dac_nids,
8069                 .dig_out_nid = ALC883_DIGOUT_NID,
8070                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8071                 .channel_mode = alc883_3ST_6ch_modes,
8072                 .need_dac_fix = 1,
8073                 .input_mux = &alc883_capture_source,
8074                 .unsol_event = alc883_tagra_unsol_event,
8075                 .init_hook = alc883_tagra_automute,
8076         },
8077         [ALC883_TARGA_2ch_DIG] = {
8078                 .mixers = { alc883_tagra_2ch_mixer},
8079                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8080                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8081                 .dac_nids = alc883_dac_nids,
8082                 .dig_out_nid = ALC883_DIGOUT_NID,
8083                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8084                 .channel_mode = alc883_3ST_2ch_modes,
8085                 .input_mux = &alc883_capture_source,
8086                 .unsol_event = alc883_tagra_unsol_event,
8087                 .init_hook = alc883_tagra_automute,
8088         },
8089         [ALC883_ACER] = {
8090                 .mixers = { alc883_base_mixer },
8091                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
8092                  * and the headphone jack.  Turn this on and rely on the
8093                  * standard mute methods whenever the user wants to turn
8094                  * these outputs off.
8095                  */
8096                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
8097                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8098                 .dac_nids = alc883_dac_nids,
8099                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8100                 .channel_mode = alc883_3ST_2ch_modes,
8101                 .input_mux = &alc883_capture_source,
8102         },
8103         [ALC883_ACER_ASPIRE] = {
8104                 .mixers = { alc883_acer_aspire_mixer },
8105                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
8106                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8107                 .dac_nids = alc883_dac_nids,
8108                 .dig_out_nid = ALC883_DIGOUT_NID,
8109                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8110                 .channel_mode = alc883_3ST_2ch_modes,
8111                 .input_mux = &alc883_capture_source,
8112                 .unsol_event = alc883_acer_aspire_unsol_event,
8113                 .init_hook = alc883_acer_aspire_automute,
8114         },
8115         [ALC883_MEDION] = {
8116                 .mixers = { alc883_fivestack_mixer,
8117                             alc883_chmode_mixer },
8118                 .init_verbs = { alc883_init_verbs,
8119                                 alc883_medion_eapd_verbs },
8120                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8121                 .dac_nids = alc883_dac_nids,
8122                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8123                 .channel_mode = alc883_sixstack_modes,
8124                 .input_mux = &alc883_capture_source,
8125         },
8126         [ALC883_MEDION_MD2] = {
8127                 .mixers = { alc883_medion_md2_mixer},
8128                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
8129                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8130                 .dac_nids = alc883_dac_nids,
8131                 .dig_out_nid = ALC883_DIGOUT_NID,
8132                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8133                 .channel_mode = alc883_3ST_2ch_modes,
8134                 .input_mux = &alc883_capture_source,
8135                 .unsol_event = alc883_medion_md2_unsol_event,
8136                 .init_hook = alc883_medion_md2_automute,
8137         },
8138         [ALC883_LAPTOP_EAPD] = {
8139                 .mixers = { alc883_base_mixer },
8140                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
8141                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8142                 .dac_nids = alc883_dac_nids,
8143                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8144                 .channel_mode = alc883_3ST_2ch_modes,
8145                 .input_mux = &alc883_capture_source,
8146         },
8147         [ALC883_CLEVO_M720] = {
8148                 .mixers = { alc883_clevo_m720_mixer },
8149                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
8150                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8151                 .dac_nids = alc883_dac_nids,
8152                 .dig_out_nid = ALC883_DIGOUT_NID,
8153                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8154                 .channel_mode = alc883_3ST_2ch_modes,
8155                 .input_mux = &alc883_capture_source,
8156                 .unsol_event = alc883_clevo_m720_unsol_event,
8157                 .init_hook = alc883_clevo_m720_automute,
8158         },
8159         [ALC883_LENOVO_101E_2ch] = {
8160                 .mixers = { alc883_lenovo_101e_2ch_mixer},
8161                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
8162                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8163                 .dac_nids = alc883_dac_nids,
8164                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8165                 .channel_mode = alc883_3ST_2ch_modes,
8166                 .input_mux = &alc883_lenovo_101e_capture_source,
8167                 .unsol_event = alc883_lenovo_101e_unsol_event,
8168                 .init_hook = alc883_lenovo_101e_all_automute,
8169         },
8170         [ALC883_LENOVO_NB0763] = {
8171                 .mixers = { alc883_lenovo_nb0763_mixer },
8172                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
8173                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8174                 .dac_nids = alc883_dac_nids,
8175                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8176                 .channel_mode = alc883_3ST_2ch_modes,
8177                 .need_dac_fix = 1,
8178                 .input_mux = &alc883_lenovo_nb0763_capture_source,
8179                 .unsol_event = alc883_medion_md2_unsol_event,
8180                 .init_hook = alc883_medion_md2_automute,
8181         },
8182         [ALC888_LENOVO_MS7195_DIG] = {
8183                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8184                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
8185                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8186                 .dac_nids = alc883_dac_nids,
8187                 .dig_out_nid = ALC883_DIGOUT_NID,
8188                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8189                 .channel_mode = alc883_3ST_6ch_modes,
8190                 .need_dac_fix = 1,
8191                 .input_mux = &alc883_capture_source,
8192                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
8193                 .init_hook = alc888_lenovo_ms7195_front_automute,
8194         },
8195         [ALC883_HAIER_W66] = {
8196                 .mixers = { alc883_tagra_2ch_mixer},
8197                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
8198                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8199                 .dac_nids = alc883_dac_nids,
8200                 .dig_out_nid = ALC883_DIGOUT_NID,
8201                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8202                 .channel_mode = alc883_3ST_2ch_modes,
8203                 .input_mux = &alc883_capture_source,
8204                 .unsol_event = alc883_haier_w66_unsol_event,
8205                 .init_hook = alc883_haier_w66_automute,
8206         },
8207         [ALC888_3ST_HP] = {
8208                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8209                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
8210                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8211                 .dac_nids = alc883_dac_nids,
8212                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
8213                 .channel_mode = alc888_3st_hp_modes,
8214                 .need_dac_fix = 1,
8215                 .input_mux = &alc883_capture_source,
8216         },
8217         [ALC888_6ST_DELL] = {
8218                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8219                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
8220                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8221                 .dac_nids = alc883_dac_nids,
8222                 .dig_out_nid = ALC883_DIGOUT_NID,
8223                 .dig_in_nid = ALC883_DIGIN_NID,
8224                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8225                 .channel_mode = alc883_sixstack_modes,
8226                 .input_mux = &alc883_capture_source,
8227                 .unsol_event = alc888_6st_dell_unsol_event,
8228                 .init_hook = alc888_6st_dell_front_automute,
8229         },
8230         [ALC883_MITAC] = {
8231                 .mixers = { alc883_mitac_mixer },
8232                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
8233                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8234                 .dac_nids = alc883_dac_nids,
8235                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8236                 .channel_mode = alc883_3ST_2ch_modes,
8237                 .input_mux = &alc883_capture_source,
8238                 .unsol_event = alc883_mitac_unsol_event,
8239                 .init_hook = alc883_mitac_automute,
8240         },
8241         [ALC883_FUJITSU_PI2515] = {
8242                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
8243                 .init_verbs = { alc883_init_verbs,
8244                                 alc883_2ch_fujitsu_pi2515_verbs},
8245                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8246                 .dac_nids = alc883_dac_nids,
8247                 .dig_out_nid = ALC883_DIGOUT_NID,
8248                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8249                 .channel_mode = alc883_3ST_2ch_modes,
8250                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8251                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8252                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8253         },
8254 };
8255
8256
8257 /*
8258  * BIOS auto configuration
8259  */
8260 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
8261                                               hda_nid_t nid, int pin_type,
8262                                               int dac_idx)
8263 {
8264         /* set as output */
8265         struct alc_spec *spec = codec->spec;
8266         int idx;
8267
8268         alc_set_pin_output(codec, nid, pin_type);
8269         if (spec->multiout.dac_nids[dac_idx] == 0x25)
8270                 idx = 4;
8271         else
8272                 idx = spec->multiout.dac_nids[dac_idx] - 2;
8273         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
8274
8275 }
8276
8277 static void alc883_auto_init_multi_out(struct hda_codec *codec)
8278 {
8279         struct alc_spec *spec = codec->spec;
8280         int i;
8281
8282         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
8283         for (i = 0; i <= HDA_SIDE; i++) {
8284                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
8285                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
8286                 if (nid)
8287                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
8288                                                           i);
8289         }
8290 }
8291
8292 static void alc883_auto_init_hp_out(struct hda_codec *codec)
8293 {
8294         struct alc_spec *spec = codec->spec;
8295         hda_nid_t pin;
8296
8297         pin = spec->autocfg.hp_pins[0];
8298         if (pin) /* connect to front */
8299                 /* use dac 0 */
8300                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8301         pin = spec->autocfg.speaker_pins[0];
8302         if (pin)
8303                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
8304 }
8305
8306 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
8307 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
8308
8309 static void alc883_auto_init_analog_input(struct hda_codec *codec)
8310 {
8311         struct alc_spec *spec = codec->spec;
8312         int i;
8313
8314         for (i = 0; i < AUTO_PIN_LAST; i++) {
8315                 hda_nid_t nid = spec->autocfg.input_pins[i];
8316                 if (alc883_is_input_pin(nid)) {
8317                         snd_hda_codec_write(codec, nid, 0,
8318                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
8319                                             (i <= AUTO_PIN_FRONT_MIC ?
8320                                              PIN_VREF80 : PIN_IN));
8321                         if (nid != ALC883_PIN_CD_NID)
8322                                 snd_hda_codec_write(codec, nid, 0,
8323                                                     AC_VERB_SET_AMP_GAIN_MUTE,
8324                                                     AMP_OUT_MUTE);
8325                 }
8326         }
8327 }
8328
8329 #define alc883_auto_init_input_src      alc882_auto_init_input_src
8330
8331 /* almost identical with ALC880 parser... */
8332 static int alc883_parse_auto_config(struct hda_codec *codec)
8333 {
8334         struct alc_spec *spec = codec->spec;
8335         int err = alc880_parse_auto_config(codec);
8336
8337         if (err < 0)
8338                 return err;
8339         else if (!err)
8340                 return 0; /* no config found */
8341
8342         err = alc_auto_add_mic_boost(codec);
8343         if (err < 0)
8344                 return err;
8345
8346         /* hack - override the init verbs */
8347         spec->init_verbs[0] = alc883_auto_init_verbs;
8348         spec->mixers[spec->num_mixers] = alc883_capture_mixer;
8349         spec->num_mixers++;
8350
8351         return 1; /* config found */
8352 }
8353
8354 /* additional initialization for auto-configuration model */
8355 static void alc883_auto_init(struct hda_codec *codec)
8356 {
8357         struct alc_spec *spec = codec->spec;
8358         alc883_auto_init_multi_out(codec);
8359         alc883_auto_init_hp_out(codec);
8360         alc883_auto_init_analog_input(codec);
8361         alc883_auto_init_input_src(codec);
8362         if (spec->unsol_event)
8363                 alc_sku_automute(codec);
8364 }
8365
8366 static int patch_alc883(struct hda_codec *codec)
8367 {
8368         struct alc_spec *spec;
8369         int err, board_config;
8370
8371         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8372         if (spec == NULL)
8373                 return -ENOMEM;
8374
8375         codec->spec = spec;
8376
8377         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
8378
8379         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
8380                                                   alc883_models,
8381                                                   alc883_cfg_tbl);
8382         if (board_config < 0) {
8383                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
8384                        "trying auto-probe from BIOS...\n");
8385                 board_config = ALC883_AUTO;
8386         }
8387
8388         if (board_config == ALC883_AUTO) {
8389                 /* automatic parse from the BIOS config */
8390                 err = alc883_parse_auto_config(codec);
8391                 if (err < 0) {
8392                         alc_free(codec);
8393                         return err;
8394                 } else if (!err) {
8395                         printk(KERN_INFO
8396                                "hda_codec: Cannot set up configuration "
8397                                "from BIOS.  Using base mode...\n");
8398                         board_config = ALC883_3ST_2ch_DIG;
8399                 }
8400         }
8401
8402         if (board_config != ALC883_AUTO)
8403                 setup_preset(spec, &alc883_presets[board_config]);
8404
8405         switch (codec->vendor_id) {
8406         case 0x10ec0888:
8407                 spec->stream_name_analog = "ALC888 Analog";
8408                 spec->stream_name_digital = "ALC888 Digital";
8409                 break;
8410         case 0x10ec0889:
8411                 spec->stream_name_analog = "ALC889 Analog";
8412                 spec->stream_name_digital = "ALC889 Digital";
8413                 break;
8414         default:
8415                 spec->stream_name_analog = "ALC883 Analog";
8416                 spec->stream_name_digital = "ALC883 Digital";
8417                 break;
8418         }
8419
8420         spec->stream_analog_playback = &alc883_pcm_analog_playback;
8421         spec->stream_analog_capture = &alc883_pcm_analog_capture;
8422         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
8423
8424         spec->stream_digital_playback = &alc883_pcm_digital_playback;
8425         spec->stream_digital_capture = &alc883_pcm_digital_capture;
8426
8427         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
8428         spec->adc_nids = alc883_adc_nids;
8429         spec->capsrc_nids = alc883_capsrc_nids;
8430
8431         spec->vmaster_nid = 0x0c;
8432
8433         codec->patch_ops = alc_patch_ops;
8434         if (board_config == ALC883_AUTO)
8435                 spec->init_hook = alc883_auto_init;
8436
8437 #ifdef CONFIG_SND_HDA_POWER_SAVE
8438         if (!spec->loopback.amplist)
8439                 spec->loopback.amplist = alc883_loopbacks;
8440 #endif
8441
8442         return 0;
8443 }
8444
8445 /*
8446  * ALC262 support
8447  */
8448
8449 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
8450 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
8451
8452 #define alc262_dac_nids         alc260_dac_nids
8453 #define alc262_adc_nids         alc882_adc_nids
8454 #define alc262_adc_nids_alt     alc882_adc_nids_alt
8455 #define alc262_capsrc_nids      alc882_capsrc_nids
8456 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
8457
8458 #define alc262_modes            alc260_modes
8459 #define alc262_capture_source   alc882_capture_source
8460
8461 static struct snd_kcontrol_new alc262_base_mixer[] = {
8462         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8463         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8464         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8465         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8466         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8467         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8468         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8469         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8470         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8471         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8472         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8473         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8474         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8475            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8476         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
8477         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8478         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8479         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
8480         { } /* end */
8481 };
8482
8483 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
8484         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8485         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8486         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8487         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8488         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8489         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8490         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8491         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8492         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8493         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8494         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8495         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8496         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8497            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8498         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
8499         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8500         { } /* end */
8501 };
8502
8503 /* update HP, line and mono-out pins according to the master switch */
8504 static void alc262_hp_master_update(struct hda_codec *codec)
8505 {
8506         struct alc_spec *spec = codec->spec;
8507         int val = spec->master_sw;
8508
8509         /* HP & line-out */
8510         snd_hda_codec_write_cache(codec, 0x1b, 0,
8511                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8512                                   val ? PIN_HP : 0);
8513         snd_hda_codec_write_cache(codec, 0x15, 0,
8514                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8515                                   val ? PIN_HP : 0);
8516         /* mono (speaker) depending on the HP jack sense */
8517         val = val && !spec->jack_present;
8518         snd_hda_codec_write_cache(codec, 0x16, 0,
8519                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8520                                   val ? PIN_OUT : 0);
8521 }
8522
8523 static void alc262_hp_bpc_automute(struct hda_codec *codec)
8524 {
8525         struct alc_spec *spec = codec->spec;
8526         unsigned int presence;
8527         presence = snd_hda_codec_read(codec, 0x1b, 0,
8528                                       AC_VERB_GET_PIN_SENSE, 0);
8529         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8530         alc262_hp_master_update(codec);
8531 }
8532
8533 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
8534 {
8535         if ((res >> 26) != ALC880_HP_EVENT)
8536                 return;
8537         alc262_hp_bpc_automute(codec);
8538 }
8539
8540 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
8541 {
8542         struct alc_spec *spec = codec->spec;
8543         unsigned int presence;
8544         presence = snd_hda_codec_read(codec, 0x15, 0,
8545                                       AC_VERB_GET_PIN_SENSE, 0);
8546         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8547         alc262_hp_master_update(codec);
8548 }
8549
8550 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
8551                                            unsigned int res)
8552 {
8553         if ((res >> 26) != ALC880_HP_EVENT)
8554                 return;
8555         alc262_hp_wildwest_automute(codec);
8556 }
8557
8558 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
8559                                    struct snd_ctl_elem_value *ucontrol)
8560 {
8561         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8562         struct alc_spec *spec = codec->spec;
8563         *ucontrol->value.integer.value = spec->master_sw;
8564         return 0;
8565 }
8566
8567 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
8568                                    struct snd_ctl_elem_value *ucontrol)
8569 {
8570         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8571         struct alc_spec *spec = codec->spec;
8572         int val = !!*ucontrol->value.integer.value;
8573
8574         if (val == spec->master_sw)
8575                 return 0;
8576         spec->master_sw = val;
8577         alc262_hp_master_update(codec);
8578         return 1;
8579 }
8580
8581 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
8582         {
8583                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8584                 .name = "Master Playback Switch",
8585                 .info = snd_ctl_boolean_mono_info,
8586                 .get = alc262_hp_master_sw_get,
8587                 .put = alc262_hp_master_sw_put,
8588         },
8589         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8590         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8591         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8592         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
8593                               HDA_OUTPUT),
8594         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
8595                             HDA_OUTPUT),
8596         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8597         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8598         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8599         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8600         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8601         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8602         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8603         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8604         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8605         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8606         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8607         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
8608         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
8609         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
8610         { } /* end */
8611 };
8612
8613 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
8614         {
8615                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8616                 .name = "Master Playback Switch",
8617                 .info = snd_ctl_boolean_mono_info,
8618                 .get = alc262_hp_master_sw_get,
8619                 .put = alc262_hp_master_sw_put,
8620         },
8621         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8622         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8623         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8624         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8625         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
8626                               HDA_OUTPUT),
8627         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
8628                             HDA_OUTPUT),
8629         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
8630         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
8631         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
8632         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8633         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8634         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8635         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8636         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8637         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
8638         { } /* end */
8639 };
8640
8641 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
8642         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8643         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8644         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
8645         { } /* end */
8646 };
8647
8648 /* mute/unmute internal speaker according to the hp jack and mute state */
8649 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
8650 {
8651         struct alc_spec *spec = codec->spec;
8652
8653         if (force || !spec->sense_updated) {
8654                 unsigned int present;
8655                 present = snd_hda_codec_read(codec, 0x15, 0,
8656                                              AC_VERB_GET_PIN_SENSE, 0);
8657                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
8658                 spec->sense_updated = 1;
8659         }
8660         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
8661                                  spec->jack_present ? HDA_AMP_MUTE : 0);
8662 }
8663
8664 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
8665                                         unsigned int res)
8666 {
8667         if ((res >> 26) != ALC880_HP_EVENT)
8668                 return;
8669         alc262_hp_t5735_automute(codec, 1);
8670 }
8671
8672 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
8673 {
8674         alc262_hp_t5735_automute(codec, 1);
8675 }
8676
8677 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
8678         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8679         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8680         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8681         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8682         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8683         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8684         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8685         { } /* end */
8686 };
8687
8688 static struct hda_verb alc262_hp_t5735_verbs[] = {
8689         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8690         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8691
8692         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8693         { }
8694 };
8695
8696 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
8697         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8698         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8699         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
8700         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
8701         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8702         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8703         { } /* end */
8704 };
8705
8706 static struct hda_verb alc262_hp_rp5700_verbs[] = {
8707         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8708         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8709         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8710         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8711         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8712         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8713         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8714         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8715         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
8716         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
8717         {}
8718 };
8719
8720 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
8721         .num_items = 1,
8722         .items = {
8723                 { "Line", 0x1 },
8724         },
8725 };
8726
8727 /* bind hp and internal speaker mute (with plug check) */
8728 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
8729                                      struct snd_ctl_elem_value *ucontrol)
8730 {
8731         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8732         long *valp = ucontrol->value.integer.value;
8733         int change;
8734
8735         /* change hp mute */
8736         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
8737                                           HDA_AMP_MUTE,
8738                                           valp[0] ? 0 : HDA_AMP_MUTE);
8739         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
8740                                            HDA_AMP_MUTE,
8741                                            valp[1] ? 0 : HDA_AMP_MUTE);
8742         if (change) {
8743                 /* change speaker according to HP jack state */
8744                 struct alc_spec *spec = codec->spec;
8745                 unsigned int mute;
8746                 if (spec->jack_present)
8747                         mute = HDA_AMP_MUTE;
8748                 else
8749                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
8750                                                       HDA_OUTPUT, 0);
8751                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8752                                          HDA_AMP_MUTE, mute);
8753         }
8754         return change;
8755 }
8756
8757 static struct snd_kcontrol_new alc262_sony_mixer[] = {
8758         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8759         {
8760                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8761                 .name = "Master Playback Switch",
8762                 .info = snd_hda_mixer_amp_switch_info,
8763                 .get = snd_hda_mixer_amp_switch_get,
8764                 .put = alc262_sony_master_sw_put,
8765                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
8766         },
8767         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8768         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8769         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8770         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8771         { } /* end */
8772 };
8773
8774 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
8775         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8776         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8777         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8778         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8779         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8780         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8781         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8782         { } /* end */
8783 };
8784
8785 #define alc262_capture_mixer            alc882_capture_mixer
8786 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
8787
8788 /*
8789  * generic initialization of ADC, input mixers and output mixers
8790  */
8791 static struct hda_verb alc262_init_verbs[] = {
8792         /*
8793          * Unmute ADC0-2 and set the default input to mic-in
8794          */
8795         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8796         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8797         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8798         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8799         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8800         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8801
8802         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8803          * mixer widget
8804          * Note: PASD motherboards uses the Line In 2 as the input for
8805          * front panel mic (mic 2)
8806          */
8807         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8808         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8809         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8810         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8811         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8812         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8813
8814         /*
8815          * Set up output mixers (0x0c - 0x0e)
8816          */
8817         /* set vol=0 to output mixers */
8818         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8819         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8820         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8821         /* set up input amps for analog loopback */
8822         /* Amp Indices: DAC = 0, mixer = 1 */
8823         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8824         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8825         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8826         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8827         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8828         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8829
8830         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8831         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8832         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8833         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8834         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8835         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8836
8837         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8838         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8839         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8840         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8841         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8842
8843         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8844         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8845
8846         /* FIXME: use matrix-type input source selection */
8847         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8848         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8849         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8850         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8851         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8852         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8853         /* Input mixer2 */
8854         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8855         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8856         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8857         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8858         /* Input mixer3 */
8859         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8860         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8861         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8862         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8863
8864         { }
8865 };
8866
8867 static struct hda_verb alc262_hippo_unsol_verbs[] = {
8868         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8869         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8870         {}
8871 };
8872
8873 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
8874         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8875         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8876         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8877
8878         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8879         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8880         {}
8881 };
8882
8883 static struct hda_verb alc262_sony_unsol_verbs[] = {
8884         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8885         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8886         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
8887
8888         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8889         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8890         {}
8891 };
8892
8893 /* mute/unmute internal speaker according to the hp jack and mute state */
8894 static void alc262_hippo_automute(struct hda_codec *codec)
8895 {
8896         struct alc_spec *spec = codec->spec;
8897         unsigned int mute;
8898         unsigned int present;
8899
8900         /* need to execute and sync at first */
8901         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
8902         present = snd_hda_codec_read(codec, 0x15, 0,
8903                                      AC_VERB_GET_PIN_SENSE, 0);
8904         spec->jack_present = (present & 0x80000000) != 0;
8905         if (spec->jack_present) {
8906                 /* mute internal speaker */
8907                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8908                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8909         } else {
8910                 /* unmute internal speaker if necessary */
8911                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
8912                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8913                                          HDA_AMP_MUTE, mute);
8914         }
8915 }
8916
8917 /* unsolicited event for HP jack sensing */
8918 static void alc262_hippo_unsol_event(struct hda_codec *codec,
8919                                        unsigned int res)
8920 {
8921         if ((res >> 26) != ALC880_HP_EVENT)
8922                 return;
8923         alc262_hippo_automute(codec);
8924 }
8925
8926 static void alc262_hippo1_automute(struct hda_codec *codec)
8927 {
8928         unsigned int mute;
8929         unsigned int present;
8930
8931         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8932         present = snd_hda_codec_read(codec, 0x1b, 0,
8933                                      AC_VERB_GET_PIN_SENSE, 0);
8934         present = (present & 0x80000000) != 0;
8935         if (present) {
8936                 /* mute internal speaker */
8937                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8938                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8939         } else {
8940                 /* unmute internal speaker if necessary */
8941                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8942                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8943                                          HDA_AMP_MUTE, mute);
8944         }
8945 }
8946
8947 /* unsolicited event for HP jack sensing */
8948 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
8949                                        unsigned int res)
8950 {
8951         if ((res >> 26) != ALC880_HP_EVENT)
8952                 return;
8953         alc262_hippo1_automute(codec);
8954 }
8955
8956 /*
8957  * nec model
8958  *  0x15 = headphone
8959  *  0x16 = internal speaker
8960  *  0x18 = external mic
8961  */
8962
8963 static struct snd_kcontrol_new alc262_nec_mixer[] = {
8964         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
8965         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
8966
8967         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8968         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8969         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8970
8971         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8972         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8973         { } /* end */
8974 };
8975
8976 static struct hda_verb alc262_nec_verbs[] = {
8977         /* Unmute Speaker */
8978         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8979
8980         /* Headphone */
8981         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8982         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8983
8984         /* External mic to headphone */
8985         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8986         /* External mic to speaker */
8987         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8988         {}
8989 };
8990
8991 /*
8992  * fujitsu model
8993  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
8994  *  0x1b = port replicator headphone out
8995  */
8996
8997 #define ALC_HP_EVENT    0x37
8998
8999 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
9000         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9001         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9002         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9003         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9004         {}
9005 };
9006
9007 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
9008         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9009         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9010         {}
9011 };
9012
9013 static struct hda_input_mux alc262_fujitsu_capture_source = {
9014         .num_items = 3,
9015         .items = {
9016                 { "Mic", 0x0 },
9017                 { "Int Mic", 0x1 },
9018                 { "CD", 0x4 },
9019         },
9020 };
9021
9022 static struct hda_input_mux alc262_HP_capture_source = {
9023         .num_items = 5,
9024         .items = {
9025                 { "Mic", 0x0 },
9026                 { "Front Mic", 0x1 },
9027                 { "Line", 0x2 },
9028                 { "CD", 0x4 },
9029                 { "AUX IN", 0x6 },
9030         },
9031 };
9032
9033 static struct hda_input_mux alc262_HP_D7000_capture_source = {
9034         .num_items = 4,
9035         .items = {
9036                 { "Mic", 0x0 },
9037                 { "Front Mic", 0x2 },
9038                 { "Line", 0x1 },
9039                 { "CD", 0x4 },
9040         },
9041 };
9042
9043 /* mute/unmute internal speaker according to the hp jacks and mute state */
9044 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
9045 {
9046         struct alc_spec *spec = codec->spec;
9047         unsigned int mute;
9048
9049         if (force || !spec->sense_updated) {
9050                 unsigned int present;
9051                 /* need to execute and sync at first */
9052                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
9053                 /* check laptop HP jack */
9054                 present = snd_hda_codec_read(codec, 0x14, 0,
9055                                              AC_VERB_GET_PIN_SENSE, 0);
9056                 /* need to execute and sync at first */
9057                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9058                 /* check docking HP jack */
9059                 present |= snd_hda_codec_read(codec, 0x1b, 0,
9060                                               AC_VERB_GET_PIN_SENSE, 0);
9061                 if (present & AC_PINSENSE_PRESENCE)
9062                         spec->jack_present = 1;
9063                 else
9064                         spec->jack_present = 0;
9065                 spec->sense_updated = 1;
9066         }
9067         /* unmute internal speaker only if both HPs are unplugged and
9068          * master switch is on
9069          */
9070         if (spec->jack_present)
9071                 mute = HDA_AMP_MUTE;
9072         else
9073                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9074         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9075                                  HDA_AMP_MUTE, mute);
9076 }
9077
9078 /* unsolicited event for HP jack sensing */
9079 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
9080                                        unsigned int res)
9081 {
9082         if ((res >> 26) != ALC_HP_EVENT)
9083                 return;
9084         alc262_fujitsu_automute(codec, 1);
9085 }
9086
9087 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
9088 {
9089         alc262_fujitsu_automute(codec, 1);
9090 }
9091
9092 /* bind volumes of both NID 0x0c and 0x0d */
9093 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
9094         .ops = &snd_hda_bind_vol,
9095         .values = {
9096                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
9097                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
9098                 0
9099         },
9100 };
9101
9102 /* mute/unmute internal speaker according to the hp jack and mute state */
9103 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
9104 {
9105         struct alc_spec *spec = codec->spec;
9106         unsigned int mute;
9107
9108         if (force || !spec->sense_updated) {
9109                 unsigned int present_int_hp;
9110                 /* need to execute and sync at first */
9111                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9112                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
9113                                         AC_VERB_GET_PIN_SENSE, 0);
9114                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
9115                 spec->sense_updated = 1;
9116         }
9117         if (spec->jack_present) {
9118                 /* mute internal speaker */
9119                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9120                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9121                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9122                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9123         } else {
9124                 /* unmute internal speaker if necessary */
9125                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9126                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9127                                          HDA_AMP_MUTE, mute);
9128                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9129                                          HDA_AMP_MUTE, mute);
9130         }
9131 }
9132
9133 /* unsolicited event for HP jack sensing */
9134 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
9135                                        unsigned int res)
9136 {
9137         if ((res >> 26) != ALC_HP_EVENT)
9138                 return;
9139         alc262_lenovo_3000_automute(codec, 1);
9140 }
9141
9142 /* bind hp and internal speaker mute (with plug check) */
9143 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
9144                                          struct snd_ctl_elem_value *ucontrol)
9145 {
9146         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9147         long *valp = ucontrol->value.integer.value;
9148         int change;
9149
9150         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9151                                                  HDA_AMP_MUTE,
9152                                                  valp ? 0 : HDA_AMP_MUTE);
9153         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9154                                                  HDA_AMP_MUTE,
9155                                                  valp ? 0 : HDA_AMP_MUTE);
9156
9157         if (change)
9158                 alc262_fujitsu_automute(codec, 0);
9159         return change;
9160 }
9161
9162 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
9163         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9164         {
9165                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9166                 .name = "Master Playback Switch",
9167                 .info = snd_hda_mixer_amp_switch_info,
9168                 .get = snd_hda_mixer_amp_switch_get,
9169                 .put = alc262_fujitsu_master_sw_put,
9170                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9171         },
9172         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9173         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9174         HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
9175         HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
9176         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9177         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9178         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9179         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9180         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9181         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9182         { } /* end */
9183 };
9184
9185 /* bind hp and internal speaker mute (with plug check) */
9186 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
9187                                          struct snd_ctl_elem_value *ucontrol)
9188 {
9189         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9190         long *valp = ucontrol->value.integer.value;
9191         int change;
9192
9193         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9194                                                  HDA_AMP_MUTE,
9195                                                  valp ? 0 : HDA_AMP_MUTE);
9196
9197         if (change)
9198                 alc262_lenovo_3000_automute(codec, 0);
9199         return change;
9200 }
9201
9202 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
9203         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9204         {
9205                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9206                 .name = "Master Playback Switch",
9207                 .info = snd_hda_mixer_amp_switch_info,
9208                 .get = snd_hda_mixer_amp_switch_get,
9209                 .put = alc262_lenovo_3000_master_sw_put,
9210                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
9211         },
9212         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9213         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9214         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9215         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9216         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9217         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9218         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9219         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9220         { } /* end */
9221 };
9222
9223 /* additional init verbs for Benq laptops */
9224 static struct hda_verb alc262_EAPD_verbs[] = {
9225         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9226         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
9227         {}
9228 };
9229
9230 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
9231         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9232         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9233
9234         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9235         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
9236         {}
9237 };
9238
9239 /* Samsung Q1 Ultra Vista model setup */
9240 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
9241         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9242         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
9243         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9244         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9245         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
9246         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
9247         { } /* end */
9248 };
9249
9250 static struct hda_verb alc262_ultra_verbs[] = {
9251         /* output mixer */
9252         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9253         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9254         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9255         /* speaker */
9256         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9257         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9258         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9259         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9260         /* HP */
9261         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9262         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9263         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9264         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9265         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9266         /* internal mic */
9267         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9268         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9269         /* ADC, choose mic */
9270         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9271         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9272         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9273         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9274         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9275         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9276         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9277         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9278         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
9279         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
9280         {}
9281 };
9282
9283 /* mute/unmute internal speaker according to the hp jack and mute state */
9284 static void alc262_ultra_automute(struct hda_codec *codec)
9285 {
9286         struct alc_spec *spec = codec->spec;
9287         unsigned int mute;
9288
9289         mute = 0;
9290         /* auto-mute only when HP is used as HP */
9291         if (!spec->cur_mux[0]) {
9292                 unsigned int present;
9293                 /* need to execute and sync at first */
9294                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9295                 present = snd_hda_codec_read(codec, 0x15, 0,
9296                                              AC_VERB_GET_PIN_SENSE, 0);
9297                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9298                 if (spec->jack_present)
9299                         mute = HDA_AMP_MUTE;
9300         }
9301         /* mute/unmute internal speaker */
9302         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9303                                  HDA_AMP_MUTE, mute);
9304         /* mute/unmute HP */
9305         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9306                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
9307 }
9308
9309 /* unsolicited event for HP jack sensing */
9310 static void alc262_ultra_unsol_event(struct hda_codec *codec,
9311                                        unsigned int res)
9312 {
9313         if ((res >> 26) != ALC880_HP_EVENT)
9314                 return;
9315         alc262_ultra_automute(codec);
9316 }
9317
9318 static struct hda_input_mux alc262_ultra_capture_source = {
9319         .num_items = 2,
9320         .items = {
9321                 { "Mic", 0x1 },
9322                 { "Headphone", 0x7 },
9323         },
9324 };
9325
9326 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
9327                                      struct snd_ctl_elem_value *ucontrol)
9328 {
9329         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9330         struct alc_spec *spec = codec->spec;
9331         int ret;
9332
9333         ret = alc882_mux_enum_put(kcontrol, ucontrol);
9334         if (!ret)
9335                 return 0;
9336         /* reprogram the HP pin as mic or HP according to the input source */
9337         snd_hda_codec_write_cache(codec, 0x15, 0,
9338                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9339                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
9340         alc262_ultra_automute(codec); /* mute/unmute HP */
9341         return ret;
9342 }
9343
9344 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
9345         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
9346         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
9347         {
9348                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9349                 .name = "Capture Source",
9350                 .info = alc882_mux_enum_info,
9351                 .get = alc882_mux_enum_get,
9352                 .put = alc262_ultra_mux_enum_put,
9353         },
9354         { } /* end */
9355 };
9356
9357 /* add playback controls from the parsed DAC table */
9358 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
9359                                              const struct auto_pin_cfg *cfg)
9360 {
9361         hda_nid_t nid;
9362         int err;
9363
9364         spec->multiout.num_dacs = 1;    /* only use one dac */
9365         spec->multiout.dac_nids = spec->private_dac_nids;
9366         spec->multiout.dac_nids[0] = 2;
9367
9368         nid = cfg->line_out_pins[0];
9369         if (nid) {
9370                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9371                                   "Front Playback Volume",
9372                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
9373                 if (err < 0)
9374                         return err;
9375                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9376                                   "Front Playback Switch",
9377                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
9378                 if (err < 0)
9379                         return err;
9380         }
9381
9382         nid = cfg->speaker_pins[0];
9383         if (nid) {
9384                 if (nid == 0x16) {
9385                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9386                                           "Speaker Playback Volume",
9387                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9388                                                               HDA_OUTPUT));
9389                         if (err < 0)
9390                                 return err;
9391                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9392                                           "Speaker Playback Switch",
9393                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9394                                                               HDA_OUTPUT));
9395                         if (err < 0)
9396                                 return err;
9397                 } else {
9398                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9399                                           "Speaker Playback Switch",
9400                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9401                                                               HDA_OUTPUT));
9402                         if (err < 0)
9403                                 return err;
9404                 }
9405         }
9406         nid = cfg->hp_pins[0];
9407         if (nid) {
9408                 /* spec->multiout.hp_nid = 2; */
9409                 if (nid == 0x16) {
9410                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9411                                           "Headphone Playback Volume",
9412                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9413                                                               HDA_OUTPUT));
9414                         if (err < 0)
9415                                 return err;
9416                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9417                                           "Headphone Playback Switch",
9418                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9419                                                               HDA_OUTPUT));
9420                         if (err < 0)
9421                                 return err;
9422                 } else {
9423                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9424                                           "Headphone Playback Switch",
9425                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9426                                                               HDA_OUTPUT));
9427                         if (err < 0)
9428                                 return err;
9429                 }
9430         }
9431         return 0;
9432 }
9433
9434 /* identical with ALC880 */
9435 #define alc262_auto_create_analog_input_ctls \
9436         alc880_auto_create_analog_input_ctls
9437
9438 /*
9439  * generic initialization of ADC, input mixers and output mixers
9440  */
9441 static struct hda_verb alc262_volume_init_verbs[] = {
9442         /*
9443          * Unmute ADC0-2 and set the default input to mic-in
9444          */
9445         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9446         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9447         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9448         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9449         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9450         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9451
9452         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9453          * mixer widget
9454          * Note: PASD motherboards uses the Line In 2 as the input for
9455          * front panel mic (mic 2)
9456          */
9457         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9458         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9459         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9460         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9461         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9462         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9463
9464         /*
9465          * Set up output mixers (0x0c - 0x0f)
9466          */
9467         /* set vol=0 to output mixers */
9468         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9469         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9470         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9471
9472         /* set up input amps for analog loopback */
9473         /* Amp Indices: DAC = 0, mixer = 1 */
9474         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9475         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9476         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9477         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9478         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9479         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9480
9481         /* FIXME: use matrix-type input source selection */
9482         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9483         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9484         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9485         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9486         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9487         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9488         /* Input mixer2 */
9489         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9490         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9491         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9492         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9493         /* Input mixer3 */
9494         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9495         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9496         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9497         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9498
9499         { }
9500 };
9501
9502 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
9503         /*
9504          * Unmute ADC0-2 and set the default input to mic-in
9505          */
9506         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9507         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9508         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9509         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9510         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9511         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9512
9513         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9514          * mixer widget
9515          * Note: PASD motherboards uses the Line In 2 as the input for
9516          * front panel mic (mic 2)
9517          */
9518         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9519         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9520         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9521         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9522         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9523         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9524         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9525         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9526
9527         /*
9528          * Set up output mixers (0x0c - 0x0e)
9529          */
9530         /* set vol=0 to output mixers */
9531         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9532         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9533         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9534
9535         /* set up input amps for analog loopback */
9536         /* Amp Indices: DAC = 0, mixer = 1 */
9537         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9538         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9539         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9540         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9541         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9542         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9543
9544         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9545         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9546         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9547
9548         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9549         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9550
9551         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9552         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9553
9554         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9555         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9556         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9557         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9558         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9559
9560         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9561         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9562         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9563         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9564         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9565         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9566
9567
9568         /* FIXME: use matrix-type input source selection */
9569         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9570         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9571         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9572         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9573         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9574         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9575         /* Input mixer2 */
9576         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9577         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9578         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9579         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9580         /* Input mixer3 */
9581         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9582         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9583         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9584         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9585
9586         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9587
9588         { }
9589 };
9590
9591 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
9592         /*
9593          * Unmute ADC0-2 and set the default input to mic-in
9594          */
9595         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9596         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9597         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9598         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9599         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9600         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9601
9602         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9603          * mixer widget
9604          * Note: PASD motherboards uses the Line In 2 as the input for front
9605          * panel mic (mic 2)
9606          */
9607         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9608         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9609         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9610         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9611         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9612         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9613         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9614         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9615         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
9616         /*
9617          * Set up output mixers (0x0c - 0x0e)
9618          */
9619         /* set vol=0 to output mixers */
9620         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9621         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9622         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9623
9624         /* set up input amps for analog loopback */
9625         /* Amp Indices: DAC = 0, mixer = 1 */
9626         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9627         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9628         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9629         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9630         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9631         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9632
9633
9634         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
9635         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
9636         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
9637         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
9638         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
9639         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
9640         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
9641
9642         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9643         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9644
9645         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9646         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9647
9648         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
9649         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9650         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9651         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9652         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9653         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9654
9655         /* FIXME: use matrix-type input source selection */
9656         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9657         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9658         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
9659         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
9660         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
9661         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
9662         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
9663         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
9664         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
9665         /* Input mixer2 */
9666         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9667         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9668         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9669         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9670         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9671         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
9672         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
9673         /* Input mixer3 */
9674         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9675         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9676         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9677         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9678         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9679         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
9680         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
9681
9682         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9683
9684         { }
9685 };
9686
9687 #ifdef CONFIG_SND_HDA_POWER_SAVE
9688 #define alc262_loopbacks        alc880_loopbacks
9689 #endif
9690
9691 /* pcm configuration: identiacal with ALC880 */
9692 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
9693 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
9694 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
9695 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
9696
9697 /*
9698  * BIOS auto configuration
9699  */
9700 static int alc262_parse_auto_config(struct hda_codec *codec)
9701 {
9702         struct alc_spec *spec = codec->spec;
9703         int err;
9704         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
9705
9706         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9707                                            alc262_ignore);
9708         if (err < 0)
9709                 return err;
9710         if (!spec->autocfg.line_outs)
9711                 return 0; /* can't find valid BIOS pin config */
9712         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
9713         if (err < 0)
9714                 return err;
9715         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
9716         if (err < 0)
9717                 return err;
9718
9719         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
9720
9721         if (spec->autocfg.dig_out_pin)
9722                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
9723         if (spec->autocfg.dig_in_pin)
9724                 spec->dig_in_nid = ALC262_DIGIN_NID;
9725
9726         if (spec->kctl_alloc)
9727                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
9728
9729         spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs;
9730         spec->num_mux_defs = 1;
9731         spec->input_mux = &spec->private_imux;
9732
9733         err = alc_auto_add_mic_boost(codec);
9734         if (err < 0)
9735                 return err;
9736
9737         return 1;
9738 }
9739
9740 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
9741 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
9742 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
9743 #define alc262_auto_init_input_src      alc882_auto_init_input_src
9744
9745
9746 /* init callback for auto-configuration model -- overriding the default init */
9747 static void alc262_auto_init(struct hda_codec *codec)
9748 {
9749         struct alc_spec *spec = codec->spec;
9750         alc262_auto_init_multi_out(codec);
9751         alc262_auto_init_hp_out(codec);
9752         alc262_auto_init_analog_input(codec);
9753         alc262_auto_init_input_src(codec);
9754         if (spec->unsol_event)
9755                 alc_sku_automute(codec);
9756 }
9757
9758 /*
9759  * configuration and preset
9760  */
9761 static const char *alc262_models[ALC262_MODEL_LAST] = {
9762         [ALC262_BASIC]          = "basic",
9763         [ALC262_HIPPO]          = "hippo",
9764         [ALC262_HIPPO_1]        = "hippo_1",
9765         [ALC262_FUJITSU]        = "fujitsu",
9766         [ALC262_HP_BPC]         = "hp-bpc",
9767         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
9768         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
9769         [ALC262_HP_RP5700]      = "hp-rp5700",
9770         [ALC262_BENQ_ED8]       = "benq",
9771         [ALC262_BENQ_T31]       = "benq-t31",
9772         [ALC262_SONY_ASSAMD]    = "sony-assamd",
9773         [ALC262_ULTRA]          = "ultra",
9774         [ALC262_LENOVO_3000]    = "lenovo-3000",
9775         [ALC262_NEC]            = "nec",
9776         [ALC262_AUTO]           = "auto",
9777 };
9778
9779 static struct snd_pci_quirk alc262_cfg_tbl[] = {
9780         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
9781         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
9782         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
9783         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
9784         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
9785         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
9786         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
9787         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
9788         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
9789         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
9790         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
9791         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
9792         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
9793         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
9794         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
9795         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
9796         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
9797         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
9798         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
9799         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
9800         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
9801         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
9802                       ALC262_HP_TC_T5735),
9803         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
9804         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9805         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
9806         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9807         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9808         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
9809         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
9810                       ALC262_SONY_ASSAMD),
9811         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
9812         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
9813         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
9814         SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
9815         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
9816         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
9817         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
9818         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
9819         {}
9820 };
9821
9822 static struct alc_config_preset alc262_presets[] = {
9823         [ALC262_BASIC] = {
9824                 .mixers = { alc262_base_mixer },
9825                 .init_verbs = { alc262_init_verbs },
9826                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9827                 .dac_nids = alc262_dac_nids,
9828                 .hp_nid = 0x03,
9829                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9830                 .channel_mode = alc262_modes,
9831                 .input_mux = &alc262_capture_source,
9832         },
9833         [ALC262_HIPPO] = {
9834                 .mixers = { alc262_base_mixer },
9835                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
9836                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9837                 .dac_nids = alc262_dac_nids,
9838                 .hp_nid = 0x03,
9839                 .dig_out_nid = ALC262_DIGOUT_NID,
9840                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9841                 .channel_mode = alc262_modes,
9842                 .input_mux = &alc262_capture_source,
9843                 .unsol_event = alc262_hippo_unsol_event,
9844                 .init_hook = alc262_hippo_automute,
9845         },
9846         [ALC262_HIPPO_1] = {
9847                 .mixers = { alc262_hippo1_mixer },
9848                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
9849                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9850                 .dac_nids = alc262_dac_nids,
9851                 .hp_nid = 0x02,
9852                 .dig_out_nid = ALC262_DIGOUT_NID,
9853                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9854                 .channel_mode = alc262_modes,
9855                 .input_mux = &alc262_capture_source,
9856                 .unsol_event = alc262_hippo1_unsol_event,
9857                 .init_hook = alc262_hippo1_automute,
9858         },
9859         [ALC262_FUJITSU] = {
9860                 .mixers = { alc262_fujitsu_mixer },
9861                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
9862                                 alc262_fujitsu_unsol_verbs },
9863                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9864                 .dac_nids = alc262_dac_nids,
9865                 .hp_nid = 0x03,
9866                 .dig_out_nid = ALC262_DIGOUT_NID,
9867                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9868                 .channel_mode = alc262_modes,
9869                 .input_mux = &alc262_fujitsu_capture_source,
9870                 .unsol_event = alc262_fujitsu_unsol_event,
9871                 .init_hook = alc262_fujitsu_init_hook,
9872         },
9873         [ALC262_HP_BPC] = {
9874                 .mixers = { alc262_HP_BPC_mixer },
9875                 .init_verbs = { alc262_HP_BPC_init_verbs },
9876                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9877                 .dac_nids = alc262_dac_nids,
9878                 .hp_nid = 0x03,
9879                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9880                 .channel_mode = alc262_modes,
9881                 .input_mux = &alc262_HP_capture_source,
9882                 .unsol_event = alc262_hp_bpc_unsol_event,
9883                 .init_hook = alc262_hp_bpc_automute,
9884         },
9885         [ALC262_HP_BPC_D7000_WF] = {
9886                 .mixers = { alc262_HP_BPC_WildWest_mixer },
9887                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
9888                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9889                 .dac_nids = alc262_dac_nids,
9890                 .hp_nid = 0x03,
9891                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9892                 .channel_mode = alc262_modes,
9893                 .input_mux = &alc262_HP_D7000_capture_source,
9894                 .unsol_event = alc262_hp_wildwest_unsol_event,
9895                 .init_hook = alc262_hp_wildwest_automute,
9896         },
9897         [ALC262_HP_BPC_D7000_WL] = {
9898                 .mixers = { alc262_HP_BPC_WildWest_mixer,
9899                             alc262_HP_BPC_WildWest_option_mixer },
9900                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
9901                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9902                 .dac_nids = alc262_dac_nids,
9903                 .hp_nid = 0x03,
9904                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9905                 .channel_mode = alc262_modes,
9906                 .input_mux = &alc262_HP_D7000_capture_source,
9907                 .unsol_event = alc262_hp_wildwest_unsol_event,
9908                 .init_hook = alc262_hp_wildwest_automute,
9909         },
9910         [ALC262_HP_TC_T5735] = {
9911                 .mixers = { alc262_hp_t5735_mixer },
9912                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
9913                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9914                 .dac_nids = alc262_dac_nids,
9915                 .hp_nid = 0x03,
9916                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9917                 .channel_mode = alc262_modes,
9918                 .input_mux = &alc262_capture_source,
9919                 .unsol_event = alc262_hp_t5735_unsol_event,
9920                 .init_hook = alc262_hp_t5735_init_hook,
9921         },
9922         [ALC262_HP_RP5700] = {
9923                 .mixers = { alc262_hp_rp5700_mixer },
9924                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
9925                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9926                 .dac_nids = alc262_dac_nids,
9927                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9928                 .channel_mode = alc262_modes,
9929                 .input_mux = &alc262_hp_rp5700_capture_source,
9930         },
9931         [ALC262_BENQ_ED8] = {
9932                 .mixers = { alc262_base_mixer },
9933                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
9934                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9935                 .dac_nids = alc262_dac_nids,
9936                 .hp_nid = 0x03,
9937                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9938                 .channel_mode = alc262_modes,
9939                 .input_mux = &alc262_capture_source,
9940         },
9941         [ALC262_SONY_ASSAMD] = {
9942                 .mixers = { alc262_sony_mixer },
9943                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
9944                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9945                 .dac_nids = alc262_dac_nids,
9946                 .hp_nid = 0x02,
9947                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9948                 .channel_mode = alc262_modes,
9949                 .input_mux = &alc262_capture_source,
9950                 .unsol_event = alc262_hippo_unsol_event,
9951                 .init_hook = alc262_hippo_automute,
9952         },
9953         [ALC262_BENQ_T31] = {
9954                 .mixers = { alc262_benq_t31_mixer },
9955                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
9956                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9957                 .dac_nids = alc262_dac_nids,
9958                 .hp_nid = 0x03,
9959                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9960                 .channel_mode = alc262_modes,
9961                 .input_mux = &alc262_capture_source,
9962                 .unsol_event = alc262_hippo_unsol_event,
9963                 .init_hook = alc262_hippo_automute,
9964         },
9965         [ALC262_ULTRA] = {
9966                 .mixers = { alc262_ultra_mixer, alc262_ultra_capture_mixer },
9967                 .init_verbs = { alc262_ultra_verbs },
9968                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9969                 .dac_nids = alc262_dac_nids,
9970                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9971                 .channel_mode = alc262_modes,
9972                 .input_mux = &alc262_ultra_capture_source,
9973                 .adc_nids = alc262_adc_nids, /* ADC0 */
9974                 .capsrc_nids = alc262_capsrc_nids,
9975                 .num_adc_nids = 1, /* single ADC */
9976                 .unsol_event = alc262_ultra_unsol_event,
9977                 .init_hook = alc262_ultra_automute,
9978         },
9979         [ALC262_LENOVO_3000] = {
9980                 .mixers = { alc262_lenovo_3000_mixer },
9981                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
9982                                 alc262_lenovo_3000_unsol_verbs },
9983                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9984                 .dac_nids = alc262_dac_nids,
9985                 .hp_nid = 0x03,
9986                 .dig_out_nid = ALC262_DIGOUT_NID,
9987                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9988                 .channel_mode = alc262_modes,
9989                 .input_mux = &alc262_fujitsu_capture_source,
9990                 .unsol_event = alc262_lenovo_3000_unsol_event,
9991         },
9992         [ALC262_NEC] = {
9993                 .mixers = { alc262_nec_mixer },
9994                 .init_verbs = { alc262_nec_verbs },
9995                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9996                 .dac_nids = alc262_dac_nids,
9997                 .hp_nid = 0x03,
9998                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9999                 .channel_mode = alc262_modes,
10000                 .input_mux = &alc262_capture_source,
10001         },
10002 };
10003
10004 static int patch_alc262(struct hda_codec *codec)
10005 {
10006         struct alc_spec *spec;
10007         int board_config;
10008         int err;
10009
10010         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10011         if (spec == NULL)
10012                 return -ENOMEM;
10013
10014         codec->spec = spec;
10015 #if 0
10016         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
10017          * under-run
10018          */
10019         {
10020         int tmp;
10021         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10022         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
10023         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10024         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
10025         }
10026 #endif
10027
10028         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
10029
10030         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
10031                                                   alc262_models,
10032                                                   alc262_cfg_tbl);
10033
10034         if (board_config < 0) {
10035                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
10036                        "trying auto-probe from BIOS...\n");
10037                 board_config = ALC262_AUTO;
10038         }
10039
10040         if (board_config == ALC262_AUTO) {
10041                 /* automatic parse from the BIOS config */
10042                 err = alc262_parse_auto_config(codec);
10043                 if (err < 0) {
10044                         alc_free(codec);
10045                         return err;
10046                 } else if (!err) {
10047                         printk(KERN_INFO
10048                                "hda_codec: Cannot set up configuration "
10049                                "from BIOS.  Using base mode...\n");
10050                         board_config = ALC262_BASIC;
10051                 }
10052         }
10053
10054         if (board_config != ALC262_AUTO)
10055                 setup_preset(spec, &alc262_presets[board_config]);
10056
10057         spec->stream_name_analog = "ALC262 Analog";
10058         spec->stream_analog_playback = &alc262_pcm_analog_playback;
10059         spec->stream_analog_capture = &alc262_pcm_analog_capture;
10060
10061         spec->stream_name_digital = "ALC262 Digital";
10062         spec->stream_digital_playback = &alc262_pcm_digital_playback;
10063         spec->stream_digital_capture = &alc262_pcm_digital_capture;
10064
10065         if (!spec->adc_nids && spec->input_mux) {
10066                 /* check whether NID 0x07 is valid */
10067                 unsigned int wcap = get_wcaps(codec, 0x07);
10068
10069                 /* get type */
10070                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10071                 if (wcap != AC_WID_AUD_IN) {
10072                         spec->adc_nids = alc262_adc_nids_alt;
10073                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
10074                         spec->capsrc_nids = alc262_capsrc_nids_alt;
10075                         spec->mixers[spec->num_mixers] =
10076                                 alc262_capture_alt_mixer;
10077                         spec->num_mixers++;
10078                 } else {
10079                         spec->adc_nids = alc262_adc_nids;
10080                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
10081                         spec->capsrc_nids = alc262_capsrc_nids;
10082                         spec->mixers[spec->num_mixers] = alc262_capture_mixer;
10083                         spec->num_mixers++;
10084                 }
10085         }
10086
10087         spec->vmaster_nid = 0x0c;
10088
10089         codec->patch_ops = alc_patch_ops;
10090         if (board_config == ALC262_AUTO)
10091                 spec->init_hook = alc262_auto_init;
10092 #ifdef CONFIG_SND_HDA_POWER_SAVE
10093         if (!spec->loopback.amplist)
10094                 spec->loopback.amplist = alc262_loopbacks;
10095 #endif
10096
10097         return 0;
10098 }
10099
10100 /*
10101  *  ALC268 channel source setting (2 channel)
10102  */
10103 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
10104 #define alc268_modes            alc260_modes
10105
10106 static hda_nid_t alc268_dac_nids[2] = {
10107         /* front, hp */
10108         0x02, 0x03
10109 };
10110
10111 static hda_nid_t alc268_adc_nids[2] = {
10112         /* ADC0-1 */
10113         0x08, 0x07
10114 };
10115
10116 static hda_nid_t alc268_adc_nids_alt[1] = {
10117         /* ADC0 */
10118         0x08
10119 };
10120
10121 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
10122
10123 static struct snd_kcontrol_new alc268_base_mixer[] = {
10124         /* output mixer control */
10125         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10126         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10127         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10128         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10129         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10130         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10131         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10132         { }
10133 };
10134
10135 /* bind Beep switches of both NID 0x0f and 0x10 */
10136 static struct hda_bind_ctls alc268_bind_beep_sw = {
10137         .ops = &snd_hda_bind_sw,
10138         .values = {
10139                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
10140                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
10141                 0
10142         },
10143 };
10144
10145 static struct snd_kcontrol_new alc268_beep_mixer[] = {
10146         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
10147         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
10148         { }
10149 };
10150
10151 static struct hda_verb alc268_eapd_verbs[] = {
10152         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10153         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10154         { }
10155 };
10156
10157 /* Toshiba specific */
10158 #define alc268_toshiba_automute alc262_hippo_automute
10159
10160 static struct hda_verb alc268_toshiba_verbs[] = {
10161         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10162         { } /* end */
10163 };
10164
10165 /* Acer specific */
10166 /* bind volumes of both NID 0x02 and 0x03 */
10167 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
10168         .ops = &snd_hda_bind_vol,
10169         .values = {
10170                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
10171                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
10172                 0
10173         },
10174 };
10175
10176 /* mute/unmute internal speaker according to the hp jack and mute state */
10177 static void alc268_acer_automute(struct hda_codec *codec, int force)
10178 {
10179         struct alc_spec *spec = codec->spec;
10180         unsigned int mute;
10181
10182         if (force || !spec->sense_updated) {
10183                 unsigned int present;
10184                 present = snd_hda_codec_read(codec, 0x14, 0,
10185                                          AC_VERB_GET_PIN_SENSE, 0);
10186                 spec->jack_present = (present & 0x80000000) != 0;
10187                 spec->sense_updated = 1;
10188         }
10189         if (spec->jack_present)
10190                 mute = HDA_AMP_MUTE; /* mute internal speaker */
10191         else /* unmute internal speaker if necessary */
10192                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10193         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10194                                  HDA_AMP_MUTE, mute);
10195 }
10196
10197
10198 /* bind hp and internal speaker mute (with plug check) */
10199 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
10200                                      struct snd_ctl_elem_value *ucontrol)
10201 {
10202         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10203         long *valp = ucontrol->value.integer.value;
10204         int change;
10205
10206         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
10207                                           HDA_AMP_MUTE,
10208                                           valp[0] ? 0 : HDA_AMP_MUTE);
10209         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
10210                                            HDA_AMP_MUTE,
10211                                            valp[1] ? 0 : HDA_AMP_MUTE);
10212         if (change)
10213                 alc268_acer_automute(codec, 0);
10214         return change;
10215 }
10216
10217 static struct snd_kcontrol_new alc268_acer_mixer[] = {
10218         /* output mixer control */
10219         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
10220         {
10221                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10222                 .name = "Master Playback Switch",
10223                 .info = snd_hda_mixer_amp_switch_info,
10224                 .get = snd_hda_mixer_amp_switch_get,
10225                 .put = alc268_acer_master_sw_put,
10226                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10227         },
10228         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10229         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
10230         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10231         { }
10232 };
10233
10234 static struct hda_verb alc268_acer_verbs[] = {
10235         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
10236         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10237         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10238         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10239         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10240         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10241         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10242         { }
10243 };
10244
10245 /* unsolicited event for HP jack sensing */
10246 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
10247                                        unsigned int res)
10248 {
10249         if ((res >> 26) != ALC880_HP_EVENT)
10250                 return;
10251         alc268_toshiba_automute(codec);
10252 }
10253
10254 static void alc268_acer_unsol_event(struct hda_codec *codec,
10255                                        unsigned int res)
10256 {
10257         if ((res >> 26) != ALC880_HP_EVENT)
10258                 return;
10259         alc268_acer_automute(codec, 1);
10260 }
10261
10262 static void alc268_acer_init_hook(struct hda_codec *codec)
10263 {
10264         alc268_acer_automute(codec, 1);
10265 }
10266
10267 static struct snd_kcontrol_new alc268_dell_mixer[] = {
10268         /* output mixer control */
10269         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10270         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10271         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10272         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10273         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10274         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
10275         { }
10276 };
10277
10278 static struct hda_verb alc268_dell_verbs[] = {
10279         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10280         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10281         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10282         { }
10283 };
10284
10285 /* mute/unmute internal speaker according to the hp jack and mute state */
10286 static void alc268_dell_automute(struct hda_codec *codec)
10287 {
10288         unsigned int present;
10289         unsigned int mute;
10290
10291         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
10292         if (present & 0x80000000)
10293                 mute = HDA_AMP_MUTE;
10294         else
10295                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
10296         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10297                                  HDA_AMP_MUTE, mute);
10298 }
10299
10300 static void alc268_dell_unsol_event(struct hda_codec *codec,
10301                                     unsigned int res)
10302 {
10303         if ((res >> 26) != ALC880_HP_EVENT)
10304                 return;
10305         alc268_dell_automute(codec);
10306 }
10307
10308 #define alc268_dell_init_hook   alc268_dell_automute
10309
10310 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
10311         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10312         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10313         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10314         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10315         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10316         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
10317         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
10318         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10319         { }
10320 };
10321
10322 static struct hda_verb alc267_quanta_il1_verbs[] = {
10323         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10324         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
10325         { }
10326 };
10327
10328 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
10329 {
10330         unsigned int present;
10331
10332         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
10333                 & AC_PINSENSE_PRESENCE;
10334         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
10335                             present ? 0 : PIN_OUT);
10336 }
10337
10338 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
10339 {
10340         unsigned int present;
10341
10342         present = snd_hda_codec_read(codec, 0x18, 0,
10343                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10344         snd_hda_codec_write(codec, 0x23, 0,
10345                             AC_VERB_SET_CONNECT_SEL,
10346                             present ? 0x00 : 0x01);
10347 }
10348
10349 static void alc267_quanta_il1_automute(struct hda_codec *codec)
10350 {
10351         alc267_quanta_il1_hp_automute(codec);
10352         alc267_quanta_il1_mic_automute(codec);
10353 }
10354
10355 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
10356                                            unsigned int res)
10357 {
10358         switch (res >> 26) {
10359         case ALC880_HP_EVENT:
10360                 alc267_quanta_il1_hp_automute(codec);
10361                 break;
10362         case ALC880_MIC_EVENT:
10363                 alc267_quanta_il1_mic_automute(codec);
10364                 break;
10365         }
10366 }
10367
10368 /*
10369  * generic initialization of ADC, input mixers and output mixers
10370  */
10371 static struct hda_verb alc268_base_init_verbs[] = {
10372         /* Unmute DAC0-1 and set vol = 0 */
10373         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10374         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10375         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10376         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10377         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10378         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10379
10380         /*
10381          * Set up output mixers (0x0c - 0x0e)
10382          */
10383         /* set vol=0 to output mixers */
10384         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10385         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10386         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10387         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
10388
10389         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10390         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10391
10392         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10393         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10394         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10395         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10396         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10397         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10398         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10399         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10400
10401         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10402         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10403         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10404         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10405         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10406         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10407         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10408
10409         /* set PCBEEP vol = 0, mute connections */
10410         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10411         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10412         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10413
10414         /* Unmute Selector 23h,24h and set the default input to mic-in */
10415
10416         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
10417         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10418         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
10419         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10420
10421         { }
10422 };
10423
10424 /*
10425  * generic initialization of ADC, input mixers and output mixers
10426  */
10427 static struct hda_verb alc268_volume_init_verbs[] = {
10428         /* set output DAC */
10429         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10430         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10431         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10432         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10433
10434         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10435         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10436         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10437         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10438         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10439
10440         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10441         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10442         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10443         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10444         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10445
10446         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10447         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10448         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10449         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10450
10451         /* set PCBEEP vol = 0, mute connections */
10452         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10453         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10454         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10455
10456         { }
10457 };
10458
10459 #define alc268_mux_enum_info alc_mux_enum_info
10460 #define alc268_mux_enum_get alc_mux_enum_get
10461 #define alc268_mux_enum_put alc_mux_enum_put
10462
10463 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
10464         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10465         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
10466         {
10467                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10468                 /* The multiple "Capture Source" controls confuse alsamixer
10469                  * So call somewhat different..
10470                  */
10471                 /* .name = "Capture Source", */
10472                 .name = "Input Source",
10473                 .count = 1,
10474                 .info = alc268_mux_enum_info,
10475                 .get = alc268_mux_enum_get,
10476                 .put = alc268_mux_enum_put,
10477         },
10478         { } /* end */
10479 };
10480
10481 static struct snd_kcontrol_new alc268_capture_mixer[] = {
10482         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10483         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
10484         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
10485         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
10486         {
10487                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10488                 /* The multiple "Capture Source" controls confuse alsamixer
10489                  * So call somewhat different..
10490                  */
10491                 /* .name = "Capture Source", */
10492                 .name = "Input Source",
10493                 .count = 2,
10494                 .info = alc268_mux_enum_info,
10495                 .get = alc268_mux_enum_get,
10496                 .put = alc268_mux_enum_put,
10497         },
10498         { } /* end */
10499 };
10500
10501 static struct hda_input_mux alc268_capture_source = {
10502         .num_items = 4,
10503         .items = {
10504                 { "Mic", 0x0 },
10505                 { "Front Mic", 0x1 },
10506                 { "Line", 0x2 },
10507                 { "CD", 0x3 },
10508         },
10509 };
10510
10511 static struct hda_input_mux alc268_acer_capture_source = {
10512         .num_items = 3,
10513         .items = {
10514                 { "Mic", 0x0 },
10515                 { "Internal Mic", 0x6 },
10516                 { "Line", 0x2 },
10517         },
10518 };
10519
10520 #ifdef CONFIG_SND_DEBUG
10521 static struct snd_kcontrol_new alc268_test_mixer[] = {
10522         /* Volume widgets */
10523         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10524         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10525         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
10526         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
10527         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
10528         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
10529         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
10530         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
10531         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
10532         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
10533         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
10534         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
10535         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
10536         /* The below appears problematic on some hardwares */
10537         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
10538         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10539         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
10540         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
10541         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
10542
10543         /* Modes for retasking pin widgets */
10544         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
10545         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
10546         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
10547         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
10548
10549         /* Controls for GPIO pins, assuming they are configured as outputs */
10550         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
10551         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
10552         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
10553         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
10554
10555         /* Switches to allow the digital SPDIF output pin to be enabled.
10556          * The ALC268 does not have an SPDIF input.
10557          */
10558         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
10559
10560         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
10561          * this output to turn on an external amplifier.
10562          */
10563         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
10564         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
10565
10566         { } /* end */
10567 };
10568 #endif
10569
10570 /* create input playback/capture controls for the given pin */
10571 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
10572                                     const char *ctlname, int idx)
10573 {
10574         char name[32];
10575         int err;
10576
10577         sprintf(name, "%s Playback Volume", ctlname);
10578         if (nid == 0x14) {
10579                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
10580                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
10581                                                       HDA_OUTPUT));
10582                 if (err < 0)
10583                         return err;
10584         } else if (nid == 0x15) {
10585                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
10586                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
10587                                                       HDA_OUTPUT));
10588                 if (err < 0)
10589                         return err;
10590         } else
10591                 return -1;
10592         sprintf(name, "%s Playback Switch", ctlname);
10593         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
10594                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
10595         if (err < 0)
10596                 return err;
10597         return 0;
10598 }
10599
10600 /* add playback controls from the parsed DAC table */
10601 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
10602                                              const struct auto_pin_cfg *cfg)
10603 {
10604         hda_nid_t nid;
10605         int err;
10606
10607         spec->multiout.num_dacs = 2;    /* only use one dac */
10608         spec->multiout.dac_nids = spec->private_dac_nids;
10609         spec->multiout.dac_nids[0] = 2;
10610         spec->multiout.dac_nids[1] = 3;
10611
10612         nid = cfg->line_out_pins[0];
10613         if (nid)
10614                 alc268_new_analog_output(spec, nid, "Front", 0);
10615
10616         nid = cfg->speaker_pins[0];
10617         if (nid == 0x1d) {
10618                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10619                                   "Speaker Playback Volume",
10620                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
10621                 if (err < 0)
10622                         return err;
10623         }
10624         nid = cfg->hp_pins[0];
10625         if (nid)
10626                 alc268_new_analog_output(spec, nid, "Headphone", 0);
10627
10628         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
10629         if (nid == 0x16) {
10630                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10631                                   "Mono Playback Switch",
10632                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
10633                 if (err < 0)
10634                         return err;
10635         }
10636         return 0;
10637 }
10638
10639 /* create playback/capture controls for input pins */
10640 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
10641                                                 const struct auto_pin_cfg *cfg)
10642 {
10643         struct hda_input_mux *imux = &spec->private_imux;
10644         int i, idx1;
10645
10646         for (i = 0; i < AUTO_PIN_LAST; i++) {
10647                 switch(cfg->input_pins[i]) {
10648                 case 0x18:
10649                         idx1 = 0;       /* Mic 1 */
10650                         break;
10651                 case 0x19:
10652                         idx1 = 1;       /* Mic 2 */
10653                         break;
10654                 case 0x1a:
10655                         idx1 = 2;       /* Line In */
10656                         break;
10657                 case 0x1c:
10658                         idx1 = 3;       /* CD */
10659                         break;
10660                 case 0x12:
10661                 case 0x13:
10662                         idx1 = 6;       /* digital mics */
10663                         break;
10664                 default:
10665                         continue;
10666                 }
10667                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
10668                 imux->items[imux->num_items].index = idx1;
10669                 imux->num_items++;
10670         }
10671         return 0;
10672 }
10673
10674 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
10675 {
10676         struct alc_spec *spec = codec->spec;
10677         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
10678         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10679         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
10680         unsigned int    dac_vol1, dac_vol2;
10681
10682         if (speaker_nid) {
10683                 snd_hda_codec_write(codec, speaker_nid, 0,
10684                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
10685                 snd_hda_codec_write(codec, 0x0f, 0,
10686                                     AC_VERB_SET_AMP_GAIN_MUTE,
10687                                     AMP_IN_UNMUTE(1));
10688                 snd_hda_codec_write(codec, 0x10, 0,
10689                                     AC_VERB_SET_AMP_GAIN_MUTE,
10690                                     AMP_IN_UNMUTE(1));
10691         } else {
10692                 snd_hda_codec_write(codec, 0x0f, 0,
10693                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
10694                 snd_hda_codec_write(codec, 0x10, 0,
10695                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
10696         }
10697
10698         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
10699         if (line_nid == 0x14)
10700                 dac_vol2 = AMP_OUT_ZERO;
10701         else if (line_nid == 0x15)
10702                 dac_vol1 = AMP_OUT_ZERO;
10703         if (hp_nid == 0x14)
10704                 dac_vol2 = AMP_OUT_ZERO;
10705         else if (hp_nid == 0x15)
10706                 dac_vol1 = AMP_OUT_ZERO;
10707         if (line_nid != 0x16 || hp_nid != 0x16 ||
10708             spec->autocfg.line_out_pins[1] != 0x16 ||
10709             spec->autocfg.line_out_pins[2] != 0x16)
10710                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
10711
10712         snd_hda_codec_write(codec, 0x02, 0,
10713                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
10714         snd_hda_codec_write(codec, 0x03, 0,
10715                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
10716 }
10717
10718 /* pcm configuration: identiacal with ALC880 */
10719 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
10720 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
10721 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
10722 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
10723
10724 /*
10725  * BIOS auto configuration
10726  */
10727 static int alc268_parse_auto_config(struct hda_codec *codec)
10728 {
10729         struct alc_spec *spec = codec->spec;
10730         int err;
10731         static hda_nid_t alc268_ignore[] = { 0 };
10732
10733         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10734                                            alc268_ignore);
10735         if (err < 0)
10736                 return err;
10737         if (!spec->autocfg.line_outs)
10738                 return 0; /* can't find valid BIOS pin config */
10739
10740         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
10741         if (err < 0)
10742                 return err;
10743         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
10744         if (err < 0)
10745                 return err;
10746
10747         spec->multiout.max_channels = 2;
10748
10749         /* digital only support output */
10750         if (spec->autocfg.dig_out_pin)
10751                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
10752
10753         if (spec->kctl_alloc)
10754                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10755
10756         if (spec->autocfg.speaker_pins[0] != 0x1d)
10757                 spec->mixers[spec->num_mixers++] = alc268_beep_mixer;
10758
10759         spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs;
10760         spec->num_mux_defs = 1;
10761         spec->input_mux = &spec->private_imux;
10762
10763         err = alc_auto_add_mic_boost(codec);
10764         if (err < 0)
10765                 return err;
10766
10767         return 1;
10768 }
10769
10770 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
10771 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
10772 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
10773
10774 /* init callback for auto-configuration model -- overriding the default init */
10775 static void alc268_auto_init(struct hda_codec *codec)
10776 {
10777         struct alc_spec *spec = codec->spec;
10778         alc268_auto_init_multi_out(codec);
10779         alc268_auto_init_hp_out(codec);
10780         alc268_auto_init_mono_speaker_out(codec);
10781         alc268_auto_init_analog_input(codec);
10782         if (spec->unsol_event)
10783                 alc_sku_automute(codec);
10784 }
10785
10786 /*
10787  * configuration and preset
10788  */
10789 static const char *alc268_models[ALC268_MODEL_LAST] = {
10790         [ALC267_QUANTA_IL1]     = "quanta-il1",
10791         [ALC268_3ST]            = "3stack",
10792         [ALC268_TOSHIBA]        = "toshiba",
10793         [ALC268_ACER]           = "acer",
10794         [ALC268_DELL]           = "dell",
10795         [ALC268_ZEPTO]          = "zepto",
10796 #ifdef CONFIG_SND_DEBUG
10797         [ALC268_TEST]           = "test",
10798 #endif
10799         [ALC268_AUTO]           = "auto",
10800 };
10801
10802 static struct snd_pci_quirk alc268_cfg_tbl[] = {
10803         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
10804         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
10805         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
10806         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
10807         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
10808         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
10809         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
10810         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
10811         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
10812         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
10813         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
10814         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
10815         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
10816         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
10817         {}
10818 };
10819
10820 static struct alc_config_preset alc268_presets[] = {
10821         [ALC267_QUANTA_IL1] = {
10822                 .mixers = { alc267_quanta_il1_mixer },
10823                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10824                                 alc267_quanta_il1_verbs },
10825                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10826                 .dac_nids = alc268_dac_nids,
10827                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10828                 .adc_nids = alc268_adc_nids_alt,
10829                 .hp_nid = 0x03,
10830                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10831                 .channel_mode = alc268_modes,
10832                 .input_mux = &alc268_capture_source,
10833                 .unsol_event = alc267_quanta_il1_unsol_event,
10834                 .init_hook = alc267_quanta_il1_automute,
10835         },
10836         [ALC268_3ST] = {
10837                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10838                             alc268_beep_mixer },
10839                 .init_verbs = { alc268_base_init_verbs },
10840                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10841                 .dac_nids = alc268_dac_nids,
10842                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10843                 .adc_nids = alc268_adc_nids_alt,
10844                 .capsrc_nids = alc268_capsrc_nids,
10845                 .hp_nid = 0x03,
10846                 .dig_out_nid = ALC268_DIGOUT_NID,
10847                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10848                 .channel_mode = alc268_modes,
10849                 .input_mux = &alc268_capture_source,
10850         },
10851         [ALC268_TOSHIBA] = {
10852                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10853                             alc268_beep_mixer },
10854                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10855                                 alc268_toshiba_verbs },
10856                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10857                 .dac_nids = alc268_dac_nids,
10858                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10859                 .adc_nids = alc268_adc_nids_alt,
10860                 .capsrc_nids = alc268_capsrc_nids,
10861                 .hp_nid = 0x03,
10862                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10863                 .channel_mode = alc268_modes,
10864                 .input_mux = &alc268_capture_source,
10865                 .unsol_event = alc268_toshiba_unsol_event,
10866                 .init_hook = alc268_toshiba_automute,
10867         },
10868         [ALC268_ACER] = {
10869                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
10870                             alc268_beep_mixer },
10871                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10872                                 alc268_acer_verbs },
10873                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10874                 .dac_nids = alc268_dac_nids,
10875                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10876                 .adc_nids = alc268_adc_nids_alt,
10877                 .capsrc_nids = alc268_capsrc_nids,
10878                 .hp_nid = 0x02,
10879                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10880                 .channel_mode = alc268_modes,
10881                 .input_mux = &alc268_acer_capture_source,
10882                 .unsol_event = alc268_acer_unsol_event,
10883                 .init_hook = alc268_acer_init_hook,
10884         },
10885         [ALC268_DELL] = {
10886                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
10887                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10888                                 alc268_dell_verbs },
10889                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10890                 .dac_nids = alc268_dac_nids,
10891                 .hp_nid = 0x02,
10892                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10893                 .channel_mode = alc268_modes,
10894                 .unsol_event = alc268_dell_unsol_event,
10895                 .init_hook = alc268_dell_init_hook,
10896                 .input_mux = &alc268_capture_source,
10897         },
10898         [ALC268_ZEPTO] = {
10899                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10900                             alc268_beep_mixer },
10901                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10902                                 alc268_toshiba_verbs },
10903                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10904                 .dac_nids = alc268_dac_nids,
10905                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10906                 .adc_nids = alc268_adc_nids_alt,
10907                 .capsrc_nids = alc268_capsrc_nids,
10908                 .hp_nid = 0x03,
10909                 .dig_out_nid = ALC268_DIGOUT_NID,
10910                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10911                 .channel_mode = alc268_modes,
10912                 .input_mux = &alc268_capture_source,
10913                 .unsol_event = alc268_toshiba_unsol_event,
10914                 .init_hook = alc268_toshiba_automute
10915         },
10916 #ifdef CONFIG_SND_DEBUG
10917         [ALC268_TEST] = {
10918                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
10919                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10920                                 alc268_volume_init_verbs },
10921                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10922                 .dac_nids = alc268_dac_nids,
10923                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10924                 .adc_nids = alc268_adc_nids_alt,
10925                 .capsrc_nids = alc268_capsrc_nids,
10926                 .hp_nid = 0x03,
10927                 .dig_out_nid = ALC268_DIGOUT_NID,
10928                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10929                 .channel_mode = alc268_modes,
10930                 .input_mux = &alc268_capture_source,
10931         },
10932 #endif
10933 };
10934
10935 static int patch_alc268(struct hda_codec *codec)
10936 {
10937         struct alc_spec *spec;
10938         int board_config;
10939         int err;
10940
10941         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
10942         if (spec == NULL)
10943                 return -ENOMEM;
10944
10945         codec->spec = spec;
10946
10947         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
10948                                                   alc268_models,
10949                                                   alc268_cfg_tbl);
10950
10951         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
10952                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
10953                        "trying auto-probe from BIOS...\n");
10954                 board_config = ALC268_AUTO;
10955         }
10956
10957         if (board_config == ALC268_AUTO) {
10958                 /* automatic parse from the BIOS config */
10959                 err = alc268_parse_auto_config(codec);
10960                 if (err < 0) {
10961                         alc_free(codec);
10962                         return err;
10963                 } else if (!err) {
10964                         printk(KERN_INFO
10965                                "hda_codec: Cannot set up configuration "
10966                                "from BIOS.  Using base mode...\n");
10967                         board_config = ALC268_3ST;
10968                 }
10969         }
10970
10971         if (board_config != ALC268_AUTO)
10972                 setup_preset(spec, &alc268_presets[board_config]);
10973
10974         if (codec->vendor_id == 0x10ec0267) {
10975                 spec->stream_name_analog = "ALC267 Analog";
10976                 spec->stream_name_digital = "ALC267 Digital";
10977         } else {
10978                 spec->stream_name_analog = "ALC268 Analog";
10979                 spec->stream_name_digital = "ALC268 Digital";
10980         }
10981
10982         spec->stream_analog_playback = &alc268_pcm_analog_playback;
10983         spec->stream_analog_capture = &alc268_pcm_analog_capture;
10984         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
10985
10986         spec->stream_digital_playback = &alc268_pcm_digital_playback;
10987
10988         if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
10989                 /* override the amp caps for beep generator */
10990                 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
10991                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
10992                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
10993                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
10994                                           (0 << AC_AMPCAP_MUTE_SHIFT));
10995
10996         if (!spec->adc_nids && spec->input_mux) {
10997                 /* check whether NID 0x07 is valid */
10998                 unsigned int wcap = get_wcaps(codec, 0x07);
10999                 int i;
11000
11001                 /* get type */
11002                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
11003                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
11004                         spec->adc_nids = alc268_adc_nids_alt;
11005                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
11006                         spec->mixers[spec->num_mixers] =
11007                                         alc268_capture_alt_mixer;
11008                         spec->num_mixers++;
11009                 } else {
11010                         spec->adc_nids = alc268_adc_nids;
11011                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
11012                         spec->mixers[spec->num_mixers] =
11013                                 alc268_capture_mixer;
11014                         spec->num_mixers++;
11015                 }
11016                 spec->capsrc_nids = alc268_capsrc_nids;
11017                 /* set default input source */
11018                 for (i = 0; i < spec->num_adc_nids; i++)
11019                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
11020                                 0, AC_VERB_SET_CONNECT_SEL,
11021                                 spec->input_mux->items[0].index);
11022         }
11023
11024         spec->vmaster_nid = 0x02;
11025
11026         codec->patch_ops = alc_patch_ops;
11027         if (board_config == ALC268_AUTO)
11028                 spec->init_hook = alc268_auto_init;
11029
11030         return 0;
11031 }
11032
11033 /*
11034  *  ALC269 channel source setting (2 channel)
11035  */
11036 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
11037
11038 #define alc269_dac_nids         alc260_dac_nids
11039
11040 static hda_nid_t alc269_adc_nids[1] = {
11041         /* ADC1 */
11042         0x08,
11043 };
11044
11045 static hda_nid_t alc269_capsrc_nids[1] = {
11046         0x23,
11047 };
11048
11049 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
11050  *       not a mux!
11051  */
11052
11053 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
11054         .num_items = 2,
11055         .items = {
11056                 { "i-Mic", 0x5 },
11057                 { "e-Mic", 0x0 },
11058         },
11059 };
11060
11061 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
11062         .num_items = 2,
11063         .items = {
11064                 { "i-Mic", 0x1 },
11065                 { "e-Mic", 0x0 },
11066         },
11067 };
11068
11069 #define alc269_modes            alc260_modes
11070 #define alc269_capture_source   alc880_lg_lw_capture_source
11071
11072 static struct snd_kcontrol_new alc269_base_mixer[] = {
11073         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11074         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11075         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11076         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11077         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11078         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11079         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
11080         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
11081         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11082         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11083         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11084         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11085         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11086         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
11087         { } /* end */
11088 };
11089
11090 /* bind volumes of both NID 0x0c and 0x0d */
11091 static struct hda_bind_ctls alc269_epc_bind_vol = {
11092         .ops = &snd_hda_bind_vol,
11093         .values = {
11094                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
11095                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
11096                 0
11097         },
11098 };
11099
11100 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
11101         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11102         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
11103         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11104         { } /* end */
11105 };
11106
11107 /* capture mixer elements */
11108 static struct snd_kcontrol_new alc269_capture_mixer[] = {
11109         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11110         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11111         {
11112                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11113                 /* The multiple "Capture Source" controls confuse alsamixer
11114                  * So call somewhat different..
11115                  */
11116                 /* .name = "Capture Source", */
11117                 .name = "Input Source",
11118                 .count = 1,
11119                 .info = alc_mux_enum_info,
11120                 .get = alc_mux_enum_get,
11121                 .put = alc_mux_enum_put,
11122         },
11123         { } /* end */
11124 };
11125
11126 /* capture mixer elements */
11127 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
11128         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11129         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11130         { } /* end */
11131 };
11132
11133 /* beep control */
11134 static struct snd_kcontrol_new alc269_beep_mixer[] = {
11135         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
11136         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
11137         { } /* end */
11138 };
11139
11140 /*
11141  * generic initialization of ADC, input mixers and output mixers
11142  */
11143 static struct hda_verb alc269_init_verbs[] = {
11144         /*
11145          * Unmute ADC0 and set the default input to mic-in
11146          */
11147         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11148
11149         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
11150          * analog-loopback mixer widget
11151          * Note: PASD motherboards uses the Line In 2 as the input for
11152          * front panel mic (mic 2)
11153          */
11154         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11155         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11156         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11157         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11158         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11159         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11160
11161         /*
11162          * Set up output mixers (0x0c - 0x0e)
11163          */
11164         /* set vol=0 to output mixers */
11165         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11166         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11167
11168         /* set up input amps for analog loopback */
11169         /* Amp Indices: DAC = 0, mixer = 1 */
11170         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11171         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11172         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11173         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11174         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11175         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11176
11177         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11178         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11179         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11180         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11181         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11182         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11183         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11184
11185         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11186         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11187         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11188         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11189         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11190         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11191         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11192
11193         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
11194         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11195
11196         /* FIXME: use matrix-type input source selection */
11197         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
11198         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11199         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11200         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11201         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11202         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11203
11204         /* set EAPD */
11205         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11206         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
11207         { }
11208 };
11209
11210 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
11211         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11212         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
11213         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
11214         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
11215         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11216         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11217         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11218         {}
11219 };
11220
11221 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
11222         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11223         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
11224         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
11225         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
11226         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11227         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11228         {}
11229 };
11230
11231 /* toggle speaker-output according to the hp-jack state */
11232 static void alc269_speaker_automute(struct hda_codec *codec)
11233 {
11234         unsigned int present;
11235         unsigned int bits;
11236
11237         present = snd_hda_codec_read(codec, 0x15, 0,
11238                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11239         bits = present ? AMP_IN_MUTE(0) : 0;
11240         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
11241                                  AMP_IN_MUTE(0), bits);
11242         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
11243                                  AMP_IN_MUTE(0), bits);
11244 }
11245
11246 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
11247 {
11248         unsigned int present;
11249
11250         present = snd_hda_codec_read(codec, 0x18, 0, AC_VERB_GET_PIN_SENSE, 0)
11251                 & AC_PINSENSE_PRESENCE;
11252         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
11253                             present ? 0 : 5);
11254 }
11255
11256 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
11257 {
11258         unsigned int present;
11259
11260         present = snd_hda_codec_read(codec, 0x18, 0, AC_VERB_GET_PIN_SENSE, 0)
11261                 & AC_PINSENSE_PRESENCE;
11262         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11263                             present ? AMP_IN_UNMUTE(0) : AMP_IN_MUTE(0));
11264         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11265                             present ? AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1));
11266 }
11267
11268 /* unsolicited event for HP jack sensing */
11269 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
11270                                           unsigned int res)
11271 {
11272         if ((res >> 26) == ALC880_HP_EVENT)
11273                 alc269_speaker_automute(codec);
11274
11275         if ((res >> 26) == ALC880_MIC_EVENT)
11276                 alc269_eeepc_dmic_automute(codec);
11277 }
11278
11279 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
11280 {
11281         alc269_speaker_automute(codec);
11282         alc269_eeepc_dmic_automute(codec);
11283 }
11284
11285 /* unsolicited event for HP jack sensing */
11286 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
11287                                      unsigned int res)
11288 {
11289         if ((res >> 26) == ALC880_HP_EVENT)
11290                 alc269_speaker_automute(codec);
11291
11292         if ((res >> 26) == ALC880_MIC_EVENT)
11293                 alc269_eeepc_amic_automute(codec);
11294 }
11295
11296 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
11297 {
11298         alc269_speaker_automute(codec);
11299         alc269_eeepc_amic_automute(codec);
11300 }
11301
11302 /* add playback controls from the parsed DAC table */
11303 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
11304                                              const struct auto_pin_cfg *cfg)
11305 {
11306         hda_nid_t nid;
11307         int err;
11308
11309         spec->multiout.num_dacs = 1;    /* only use one dac */
11310         spec->multiout.dac_nids = spec->private_dac_nids;
11311         spec->multiout.dac_nids[0] = 2;
11312
11313         nid = cfg->line_out_pins[0];
11314         if (nid) {
11315                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
11316                                   "Front Playback Volume",
11317                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
11318                 if (err < 0)
11319                         return err;
11320                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11321                                   "Front Playback Switch",
11322                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
11323                 if (err < 0)
11324                         return err;
11325         }
11326
11327         nid = cfg->speaker_pins[0];
11328         if (nid) {
11329                 if (!cfg->line_out_pins[0]) {
11330                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11331                                           "Speaker Playback Volume",
11332                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
11333                                                               HDA_OUTPUT));
11334                         if (err < 0)
11335                                 return err;
11336                 }
11337                 if (nid == 0x16) {
11338                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11339                                           "Speaker Playback Switch",
11340                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
11341                                                               HDA_OUTPUT));
11342                         if (err < 0)
11343                                 return err;
11344                 } else {
11345                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11346                                           "Speaker Playback Switch",
11347                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
11348                                                               HDA_OUTPUT));
11349                         if (err < 0)
11350                                 return err;
11351                 }
11352         }
11353         nid = cfg->hp_pins[0];
11354         if (nid) {
11355                 /* spec->multiout.hp_nid = 2; */
11356                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
11357                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11358                                           "Headphone Playback Volume",
11359                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
11360                                                               HDA_OUTPUT));
11361                         if (err < 0)
11362                                 return err;
11363                 }
11364                 if (nid == 0x16) {
11365                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11366                                           "Headphone Playback Switch",
11367                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
11368                                                               HDA_OUTPUT));
11369                         if (err < 0)
11370                                 return err;
11371                 } else {
11372                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11373                                           "Headphone Playback Switch",
11374                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
11375                                                               HDA_OUTPUT));
11376                         if (err < 0)
11377                                 return err;
11378                 }
11379         }
11380         return 0;
11381 }
11382
11383 #define alc269_auto_create_analog_input_ctls \
11384         alc880_auto_create_analog_input_ctls
11385
11386 #ifdef CONFIG_SND_HDA_POWER_SAVE
11387 #define alc269_loopbacks        alc880_loopbacks
11388 #endif
11389
11390 /* pcm configuration: identiacal with ALC880 */
11391 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
11392 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
11393 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
11394 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
11395
11396 /*
11397  * BIOS auto configuration
11398  */
11399 static int alc269_parse_auto_config(struct hda_codec *codec)
11400 {
11401         struct alc_spec *spec = codec->spec;
11402         int i, err;
11403         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
11404
11405         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11406                                            alc269_ignore);
11407         if (err < 0)
11408                 return err;
11409
11410         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
11411         if (err < 0)
11412                 return err;
11413         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
11414         if (err < 0)
11415                 return err;
11416
11417         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11418
11419         if (spec->autocfg.dig_out_pin)
11420                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
11421
11422         if (spec->kctl_alloc)
11423                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
11424
11425         /* create a beep mixer control if the pin 0x1d isn't assigned */
11426         for (i = 0; i < ARRAY_SIZE(spec->autocfg.input_pins); i++)
11427                 if (spec->autocfg.input_pins[i] == 0x1d)
11428                         break;
11429         if (i >= ARRAY_SIZE(spec->autocfg.input_pins))
11430                 spec->mixers[spec->num_mixers++] = alc269_beep_mixer;
11431
11432         spec->init_verbs[spec->num_init_verbs++] = alc269_init_verbs;
11433         spec->num_mux_defs = 1;
11434         spec->input_mux = &spec->private_imux;
11435         /* set default input source */
11436         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
11437                                   0, AC_VERB_SET_CONNECT_SEL,
11438                                   spec->input_mux->items[0].index);
11439
11440         err = alc_auto_add_mic_boost(codec);
11441         if (err < 0)
11442                 return err;
11443
11444         spec->mixers[spec->num_mixers] = alc269_capture_mixer;
11445         spec->num_mixers++;
11446
11447         return 1;
11448 }
11449
11450 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
11451 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
11452 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
11453
11454
11455 /* init callback for auto-configuration model -- overriding the default init */
11456 static void alc269_auto_init(struct hda_codec *codec)
11457 {
11458         struct alc_spec *spec = codec->spec;
11459         alc269_auto_init_multi_out(codec);
11460         alc269_auto_init_hp_out(codec);
11461         alc269_auto_init_analog_input(codec);
11462         if (spec->unsol_event)
11463                 alc_sku_automute(codec);
11464 }
11465
11466 /*
11467  * configuration and preset
11468  */
11469 static const char *alc269_models[ALC269_MODEL_LAST] = {
11470         [ALC269_BASIC]          = "basic",
11471 };
11472
11473 static struct snd_pci_quirk alc269_cfg_tbl[] = {
11474         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
11475                       ALC269_ASUS_EEEPC_P703),
11476         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
11477                       ALC269_ASUS_EEEPC_P901),
11478         {}
11479 };
11480
11481 static struct alc_config_preset alc269_presets[] = {
11482         [ALC269_BASIC] = {
11483                 .mixers = { alc269_base_mixer, alc269_capture_mixer },
11484                 .init_verbs = { alc269_init_verbs },
11485                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
11486                 .dac_nids = alc269_dac_nids,
11487                 .hp_nid = 0x03,
11488                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
11489                 .channel_mode = alc269_modes,
11490                 .input_mux = &alc269_capture_source,
11491         },
11492         [ALC269_ASUS_EEEPC_P703] = {
11493                 .mixers = { alc269_eeepc_mixer, alc269_epc_capture_mixer },
11494                 .init_verbs = { alc269_init_verbs,
11495                                 alc269_eeepc_amic_init_verbs },
11496                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
11497                 .dac_nids = alc269_dac_nids,
11498                 .hp_nid = 0x03,
11499                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
11500                 .channel_mode = alc269_modes,
11501                 .input_mux = &alc269_eeepc_amic_capture_source,
11502                 .unsol_event = alc269_eeepc_amic_unsol_event,
11503                 .init_hook = alc269_eeepc_amic_inithook,
11504         },
11505         [ALC269_ASUS_EEEPC_P901] = {
11506                 .mixers = { alc269_eeepc_mixer, alc269_epc_capture_mixer},
11507                 .init_verbs = { alc269_init_verbs,
11508                                 alc269_eeepc_dmic_init_verbs },
11509                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
11510                 .dac_nids = alc269_dac_nids,
11511                 .hp_nid = 0x03,
11512                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
11513                 .channel_mode = alc269_modes,
11514                 .input_mux = &alc269_eeepc_dmic_capture_source,
11515                 .unsol_event = alc269_eeepc_dmic_unsol_event,
11516                 .init_hook = alc269_eeepc_dmic_inithook,
11517         },
11518 };
11519
11520 static int patch_alc269(struct hda_codec *codec)
11521 {
11522         struct alc_spec *spec;
11523         int board_config;
11524         int err;
11525
11526         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11527         if (spec == NULL)
11528                 return -ENOMEM;
11529
11530         codec->spec = spec;
11531
11532         alc_fix_pll_init(codec, 0x20, 0x04, 15);
11533
11534         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
11535                                                   alc269_models,
11536                                                   alc269_cfg_tbl);
11537
11538         if (board_config < 0) {
11539                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
11540                        "trying auto-probe from BIOS...\n");
11541                 board_config = ALC269_AUTO;
11542         }
11543
11544         if (board_config == ALC269_AUTO) {
11545                 /* automatic parse from the BIOS config */
11546                 err = alc269_parse_auto_config(codec);
11547                 if (err < 0) {
11548                         alc_free(codec);
11549                         return err;
11550                 } else if (!err) {
11551                         printk(KERN_INFO
11552                                "hda_codec: Cannot set up configuration "
11553                                "from BIOS.  Using base mode...\n");
11554                         board_config = ALC269_BASIC;
11555                 }
11556         }
11557
11558         if (board_config != ALC269_AUTO)
11559                 setup_preset(spec, &alc269_presets[board_config]);
11560
11561         spec->stream_name_analog = "ALC269 Analog";
11562         spec->stream_analog_playback = &alc269_pcm_analog_playback;
11563         spec->stream_analog_capture = &alc269_pcm_analog_capture;
11564
11565         spec->stream_name_digital = "ALC269 Digital";
11566         spec->stream_digital_playback = &alc269_pcm_digital_playback;
11567         spec->stream_digital_capture = &alc269_pcm_digital_capture;
11568
11569         spec->adc_nids = alc269_adc_nids;
11570         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
11571         spec->capsrc_nids = alc269_capsrc_nids;
11572
11573         codec->patch_ops = alc_patch_ops;
11574         if (board_config == ALC269_AUTO)
11575                 spec->init_hook = alc269_auto_init;
11576 #ifdef CONFIG_SND_HDA_POWER_SAVE
11577         if (!spec->loopback.amplist)
11578                 spec->loopback.amplist = alc269_loopbacks;
11579 #endif
11580
11581         return 0;
11582 }
11583
11584 /*
11585  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
11586  */
11587
11588 /*
11589  * set the path ways for 2 channel output
11590  * need to set the codec line out and mic 1 pin widgets to inputs
11591  */
11592 static struct hda_verb alc861_threestack_ch2_init[] = {
11593         /* set pin widget 1Ah (line in) for input */
11594         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11595         /* set pin widget 18h (mic1/2) for input, for mic also enable
11596          * the vref
11597          */
11598         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11599
11600         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
11601 #if 0
11602         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
11603         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
11604 #endif
11605         { } /* end */
11606 };
11607 /*
11608  * 6ch mode
11609  * need to set the codec line out and mic 1 pin widgets to outputs
11610  */
11611 static struct hda_verb alc861_threestack_ch6_init[] = {
11612         /* set pin widget 1Ah (line in) for output (Back Surround)*/
11613         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11614         /* set pin widget 18h (mic1) for output (CLFE)*/
11615         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11616
11617         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
11618         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
11619
11620         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
11621 #if 0
11622         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
11623         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
11624 #endif
11625         { } /* end */
11626 };
11627
11628 static struct hda_channel_mode alc861_threestack_modes[2] = {
11629         { 2, alc861_threestack_ch2_init },
11630         { 6, alc861_threestack_ch6_init },
11631 };
11632 /* Set mic1 as input and unmute the mixer */
11633 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
11634         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11635         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
11636         { } /* end */
11637 };
11638 /* Set mic1 as output and mute mixer */
11639 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
11640         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11641         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
11642         { } /* end */
11643 };
11644
11645 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
11646         { 2, alc861_uniwill_m31_ch2_init },
11647         { 4, alc861_uniwill_m31_ch4_init },
11648 };
11649
11650 /* Set mic1 and line-in as input and unmute the mixer */
11651 static struct hda_verb alc861_asus_ch2_init[] = {
11652         /* set pin widget 1Ah (line in) for input */
11653         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11654         /* set pin widget 18h (mic1/2) for input, for mic also enable
11655          * the vref
11656          */
11657         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11658
11659         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
11660 #if 0
11661         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
11662         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
11663 #endif
11664         { } /* end */
11665 };
11666 /* Set mic1 nad line-in as output and mute mixer */
11667 static struct hda_verb alc861_asus_ch6_init[] = {
11668         /* set pin widget 1Ah (line in) for output (Back Surround)*/
11669         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11670         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
11671         /* set pin widget 18h (mic1) for output (CLFE)*/
11672         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11673         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
11674         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
11675         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
11676
11677         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
11678 #if 0
11679         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
11680         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
11681 #endif
11682         { } /* end */
11683 };
11684
11685 static struct hda_channel_mode alc861_asus_modes[2] = {
11686         { 2, alc861_asus_ch2_init },
11687         { 6, alc861_asus_ch6_init },
11688 };
11689
11690 /* patch-ALC861 */
11691
11692 static struct snd_kcontrol_new alc861_base_mixer[] = {
11693         /* output mixer control */
11694         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11695         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11696         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11697         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11698         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
11699
11700         /*Input mixer control */
11701         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11702            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11703         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11704         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11705         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11706         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11707         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11708         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11709         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11710         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11711
11712         /* Capture mixer control */
11713         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11714         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11715         {
11716                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11717                 .name = "Capture Source",
11718                 .count = 1,
11719                 .info = alc_mux_enum_info,
11720                 .get = alc_mux_enum_get,
11721                 .put = alc_mux_enum_put,
11722         },
11723         { } /* end */
11724 };
11725
11726 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
11727         /* output mixer control */
11728         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11729         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11730         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11731         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11732         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
11733
11734         /* Input mixer control */
11735         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11736            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11737         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11738         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11739         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11740         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11741         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11742         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11743         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11744         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11745
11746         /* Capture mixer control */
11747         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11748         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11749         {
11750                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11751                 .name = "Capture Source",
11752                 .count = 1,
11753                 .info = alc_mux_enum_info,
11754                 .get = alc_mux_enum_get,
11755                 .put = alc_mux_enum_put,
11756         },
11757         {
11758                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11759                 .name = "Channel Mode",
11760                 .info = alc_ch_mode_info,
11761                 .get = alc_ch_mode_get,
11762                 .put = alc_ch_mode_put,
11763                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
11764         },
11765         { } /* end */
11766 };
11767
11768 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
11769         /* output mixer control */
11770         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11771         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11772         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11773
11774         /*Capture mixer control */
11775         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11776         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11777         {
11778                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11779                 .name = "Capture Source",
11780                 .count = 1,
11781                 .info = alc_mux_enum_info,
11782                 .get = alc_mux_enum_get,
11783                 .put = alc_mux_enum_put,
11784         },
11785
11786         { } /* end */
11787 };
11788
11789 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
11790         /* output mixer control */
11791         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11792         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11793         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11794         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11795         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
11796
11797         /* Input mixer control */
11798         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11799            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11800         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11801         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11802         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11803         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11804         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11805         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11806         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11807         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11808
11809         /* Capture mixer control */
11810         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11811         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11812         {
11813                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11814                 .name = "Capture Source",
11815                 .count = 1,
11816                 .info = alc_mux_enum_info,
11817                 .get = alc_mux_enum_get,
11818                 .put = alc_mux_enum_put,
11819         },
11820         {
11821                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11822                 .name = "Channel Mode",
11823                 .info = alc_ch_mode_info,
11824                 .get = alc_ch_mode_get,
11825                 .put = alc_ch_mode_put,
11826                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
11827         },
11828         { } /* end */
11829 };
11830
11831 static struct snd_kcontrol_new alc861_asus_mixer[] = {
11832         /* output mixer control */
11833         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11834         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11835         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11836         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11837         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
11838
11839         /* Input mixer control */
11840         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11841         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11842         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11843         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11844         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11845         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11846         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11847         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11848         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11849         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
11850
11851         /* Capture mixer control */
11852         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11853         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11854         {
11855                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11856                 .name = "Capture Source",
11857                 .count = 1,
11858                 .info = alc_mux_enum_info,
11859                 .get = alc_mux_enum_get,
11860                 .put = alc_mux_enum_put,
11861         },
11862         {
11863                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11864                 .name = "Channel Mode",
11865                 .info = alc_ch_mode_info,
11866                 .get = alc_ch_mode_get,
11867                 .put = alc_ch_mode_put,
11868                 .private_value = ARRAY_SIZE(alc861_asus_modes),
11869         },
11870         { }
11871 };
11872
11873 /* additional mixer */
11874 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
11875         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11876         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11877         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
11878         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
11879         { }
11880 };
11881
11882 /*
11883  * generic initialization of ADC, input mixers and output mixers
11884  */
11885 static struct hda_verb alc861_base_init_verbs[] = {
11886         /*
11887          * Unmute ADC0 and set the default input to mic-in
11888          */
11889         /* port-A for surround (rear panel) */
11890         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11891         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
11892         /* port-B for mic-in (rear panel) with vref */
11893         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11894         /* port-C for line-in (rear panel) */
11895         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11896         /* port-D for Front */
11897         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11898         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11899         /* port-E for HP out (front panel) */
11900         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
11901         /* route front PCM to HP */
11902         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11903         /* port-F for mic-in (front panel) with vref */
11904         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11905         /* port-G for CLFE (rear panel) */
11906         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11907         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11908         /* port-H for side (rear panel) */
11909         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11910         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
11911         /* CD-in */
11912         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11913         /* route front mic to ADC1*/
11914         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11915         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11916
11917         /* Unmute DAC0~3 & spdif out*/
11918         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11919         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11920         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11921         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11922         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11923
11924         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11925         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11926         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11927         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11928         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11929
11930         /* Unmute Stereo Mixer 15 */
11931         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11932         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11933         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11934         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
11935
11936         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11937         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11938         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11939         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11940         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11941         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11942         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11943         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11944         /* hp used DAC 3 (Front) */
11945         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11946         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11947
11948         { }
11949 };
11950
11951 static struct hda_verb alc861_threestack_init_verbs[] = {
11952         /*
11953          * Unmute ADC0 and set the default input to mic-in
11954          */
11955         /* port-A for surround (rear panel) */
11956         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11957         /* port-B for mic-in (rear panel) with vref */
11958         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11959         /* port-C for line-in (rear panel) */
11960         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11961         /* port-D for Front */
11962         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11963         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11964         /* port-E for HP out (front panel) */
11965         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
11966         /* route front PCM to HP */
11967         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11968         /* port-F for mic-in (front panel) with vref */
11969         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11970         /* port-G for CLFE (rear panel) */
11971         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11972         /* port-H for side (rear panel) */
11973         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11974         /* CD-in */
11975         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11976         /* route front mic to ADC1*/
11977         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11978         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11979         /* Unmute DAC0~3 & spdif out*/
11980         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11981         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11982         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11983         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11984         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11985
11986         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11987         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11988         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11989         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11990         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11991
11992         /* Unmute Stereo Mixer 15 */
11993         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11994         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11995         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11996         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
11997
11998         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11999         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12000         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12001         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12002         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12003         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12004         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12005         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12006         /* hp used DAC 3 (Front) */
12007         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12008         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12009         { }
12010 };
12011
12012 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
12013         /*
12014          * Unmute ADC0 and set the default input to mic-in
12015          */
12016         /* port-A for surround (rear panel) */
12017         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12018         /* port-B for mic-in (rear panel) with vref */
12019         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12020         /* port-C for line-in (rear panel) */
12021         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12022         /* port-D for Front */
12023         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12024         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12025         /* port-E for HP out (front panel) */
12026         /* this has to be set to VREF80 */
12027         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12028         /* route front PCM to HP */
12029         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12030         /* port-F for mic-in (front panel) with vref */
12031         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12032         /* port-G for CLFE (rear panel) */
12033         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12034         /* port-H for side (rear panel) */
12035         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12036         /* CD-in */
12037         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12038         /* route front mic to ADC1*/
12039         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12040         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12041         /* Unmute DAC0~3 & spdif out*/
12042         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12043         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12044         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12045         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12046         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12047
12048         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12049         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12050         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12051         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12052         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12053
12054         /* Unmute Stereo Mixer 15 */
12055         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12056         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12057         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12058         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12059
12060         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12061         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12062         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12063         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12064         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12065         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12066         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12067         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12068         /* hp used DAC 3 (Front) */
12069         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12070         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12071         { }
12072 };
12073
12074 static struct hda_verb alc861_asus_init_verbs[] = {
12075         /*
12076          * Unmute ADC0 and set the default input to mic-in
12077          */
12078         /* port-A for surround (rear panel)
12079          * according to codec#0 this is the HP jack
12080          */
12081         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
12082         /* route front PCM to HP */
12083         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
12084         /* port-B for mic-in (rear panel) with vref */
12085         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12086         /* port-C for line-in (rear panel) */
12087         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12088         /* port-D for Front */
12089         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12090         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12091         /* port-E for HP out (front panel) */
12092         /* this has to be set to VREF80 */
12093         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12094         /* route front PCM to HP */
12095         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12096         /* port-F for mic-in (front panel) with vref */
12097         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12098         /* port-G for CLFE (rear panel) */
12099         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12100         /* port-H for side (rear panel) */
12101         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12102         /* CD-in */
12103         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12104         /* route front mic to ADC1*/
12105         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12106         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12107         /* Unmute DAC0~3 & spdif out*/
12108         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12109         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12110         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12111         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12112         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12113         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12114         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12115         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12116         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12117         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12118
12119         /* Unmute Stereo Mixer 15 */
12120         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12121         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12122         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12123         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12124
12125         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12126         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12127         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12128         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12129         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12130         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12131         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12132         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12133         /* hp used DAC 3 (Front) */
12134         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12135         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12136         { }
12137 };
12138
12139 /* additional init verbs for ASUS laptops */
12140 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
12141         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
12142         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
12143         { }
12144 };
12145
12146 /*
12147  * generic initialization of ADC, input mixers and output mixers
12148  */
12149 static struct hda_verb alc861_auto_init_verbs[] = {
12150         /*
12151          * Unmute ADC0 and set the default input to mic-in
12152          */
12153         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
12154         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12155
12156         /* Unmute DAC0~3 & spdif out*/
12157         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12158         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12159         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12160         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12161         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12162
12163         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12164         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12165         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12166         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12167         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12168
12169         /* Unmute Stereo Mixer 15 */
12170         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12171         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12172         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12173         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
12174
12175         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12176         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12177         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12178         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12179         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12180         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12181         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12182         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12183
12184         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12185         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12186         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12187         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12188         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12189         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12190         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12191         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12192
12193         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
12194
12195         { }
12196 };
12197
12198 static struct hda_verb alc861_toshiba_init_verbs[] = {
12199         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12200
12201         { }
12202 };
12203
12204 /* toggle speaker-output according to the hp-jack state */
12205 static void alc861_toshiba_automute(struct hda_codec *codec)
12206 {
12207         unsigned int present;
12208
12209         present = snd_hda_codec_read(codec, 0x0f, 0,
12210                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12211         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
12212                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
12213         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
12214                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
12215 }
12216
12217 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
12218                                        unsigned int res)
12219 {
12220         if ((res >> 26) == ALC880_HP_EVENT)
12221                 alc861_toshiba_automute(codec);
12222 }
12223
12224 /* pcm configuration: identiacal with ALC880 */
12225 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
12226 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
12227 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
12228 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
12229
12230
12231 #define ALC861_DIGOUT_NID       0x07
12232
12233 static struct hda_channel_mode alc861_8ch_modes[1] = {
12234         { 8, NULL }
12235 };
12236
12237 static hda_nid_t alc861_dac_nids[4] = {
12238         /* front, surround, clfe, side */
12239         0x03, 0x06, 0x05, 0x04
12240 };
12241
12242 static hda_nid_t alc660_dac_nids[3] = {
12243         /* front, clfe, surround */
12244         0x03, 0x05, 0x06
12245 };
12246
12247 static hda_nid_t alc861_adc_nids[1] = {
12248         /* ADC0-2 */
12249         0x08,
12250 };
12251
12252 static struct hda_input_mux alc861_capture_source = {
12253         .num_items = 5,
12254         .items = {
12255                 { "Mic", 0x0 },
12256                 { "Front Mic", 0x3 },
12257                 { "Line", 0x1 },
12258                 { "CD", 0x4 },
12259                 { "Mixer", 0x5 },
12260         },
12261 };
12262
12263 /* fill in the dac_nids table from the parsed pin configuration */
12264 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
12265                                      const struct auto_pin_cfg *cfg)
12266 {
12267         int i;
12268         hda_nid_t nid;
12269
12270         spec->multiout.dac_nids = spec->private_dac_nids;
12271         for (i = 0; i < cfg->line_outs; i++) {
12272                 nid = cfg->line_out_pins[i];
12273                 if (nid) {
12274                         if (i >= ARRAY_SIZE(alc861_dac_nids))
12275                                 continue;
12276                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
12277                 }
12278         }
12279         spec->multiout.num_dacs = cfg->line_outs;
12280         return 0;
12281 }
12282
12283 /* add playback controls from the parsed DAC table */
12284 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
12285                                              const struct auto_pin_cfg *cfg)
12286 {
12287         char name[32];
12288         static const char *chname[4] = {
12289                 "Front", "Surround", NULL /*CLFE*/, "Side"
12290         };
12291         hda_nid_t nid;
12292         int i, idx, err;
12293
12294         for (i = 0; i < cfg->line_outs; i++) {
12295                 nid = spec->multiout.dac_nids[i];
12296                 if (!nid)
12297                         continue;
12298                 if (nid == 0x05) {
12299                         /* Center/LFE */
12300                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12301                                           "Center Playback Switch",
12302                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
12303                                                               HDA_OUTPUT));
12304                         if (err < 0)
12305                                 return err;
12306                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12307                                           "LFE Playback Switch",
12308                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12309                                                               HDA_OUTPUT));
12310                         if (err < 0)
12311                                 return err;
12312                 } else {
12313                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
12314                              idx++)
12315                                 if (nid == alc861_dac_nids[idx])
12316                                         break;
12317                         sprintf(name, "%s Playback Switch", chname[idx]);
12318                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
12319                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12320                                                               HDA_OUTPUT));
12321                         if (err < 0)
12322                                 return err;
12323                 }
12324         }
12325         return 0;
12326 }
12327
12328 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
12329 {
12330         int err;
12331         hda_nid_t nid;
12332
12333         if (!pin)
12334                 return 0;
12335
12336         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
12337                 nid = 0x03;
12338                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12339                                   "Headphone Playback Switch",
12340                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12341                 if (err < 0)
12342                         return err;
12343                 spec->multiout.hp_nid = nid;
12344         }
12345         return 0;
12346 }
12347
12348 /* create playback/capture controls for input pins */
12349 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
12350                                                 const struct auto_pin_cfg *cfg)
12351 {
12352         struct hda_input_mux *imux = &spec->private_imux;
12353         int i, err, idx, idx1;
12354
12355         for (i = 0; i < AUTO_PIN_LAST; i++) {
12356                 switch (cfg->input_pins[i]) {
12357                 case 0x0c:
12358                         idx1 = 1;
12359                         idx = 2;        /* Line In */
12360                         break;
12361                 case 0x0f:
12362                         idx1 = 2;
12363                         idx = 2;        /* Line In */
12364                         break;
12365                 case 0x0d:
12366                         idx1 = 0;
12367                         idx = 1;        /* Mic In */
12368                         break;
12369                 case 0x10:
12370                         idx1 = 3;
12371                         idx = 1;        /* Mic In */
12372                         break;
12373                 case 0x11:
12374                         idx1 = 4;
12375                         idx = 0;        /* CD */
12376                         break;
12377                 default:
12378                         continue;
12379                 }
12380
12381                 err = new_analog_input(spec, cfg->input_pins[i],
12382                                        auto_pin_cfg_labels[i], idx, 0x15);
12383                 if (err < 0)
12384                         return err;
12385
12386                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
12387                 imux->items[imux->num_items].index = idx1;
12388                 imux->num_items++;
12389         }
12390         return 0;
12391 }
12392
12393 static struct snd_kcontrol_new alc861_capture_mixer[] = {
12394         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12395         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12396
12397         {
12398                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12399                 /* The multiple "Capture Source" controls confuse alsamixer
12400                  * So call somewhat different..
12401                  */
12402                 /* .name = "Capture Source", */
12403                 .name = "Input Source",
12404                 .count = 1,
12405                 .info = alc_mux_enum_info,
12406                 .get = alc_mux_enum_get,
12407                 .put = alc_mux_enum_put,
12408         },
12409         { } /* end */
12410 };
12411
12412 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
12413                                               hda_nid_t nid,
12414                                               int pin_type, int dac_idx)
12415 {
12416         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
12417                             pin_type);
12418         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12419                             AMP_OUT_UNMUTE);
12420 }
12421
12422 static void alc861_auto_init_multi_out(struct hda_codec *codec)
12423 {
12424         struct alc_spec *spec = codec->spec;
12425         int i;
12426
12427         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
12428         for (i = 0; i < spec->autocfg.line_outs; i++) {
12429                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
12430                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
12431                 if (nid)
12432                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
12433                                                           spec->multiout.dac_nids[i]);
12434         }
12435 }
12436
12437 static void alc861_auto_init_hp_out(struct hda_codec *codec)
12438 {
12439         struct alc_spec *spec = codec->spec;
12440         hda_nid_t pin;
12441
12442         pin = spec->autocfg.hp_pins[0];
12443         if (pin) /* connect to front */
12444                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
12445                                                   spec->multiout.dac_nids[0]);
12446         pin = spec->autocfg.speaker_pins[0];
12447         if (pin)
12448                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
12449 }
12450
12451 static void alc861_auto_init_analog_input(struct hda_codec *codec)
12452 {
12453         struct alc_spec *spec = codec->spec;
12454         int i;
12455
12456         for (i = 0; i < AUTO_PIN_LAST; i++) {
12457                 hda_nid_t nid = spec->autocfg.input_pins[i];
12458                 if (nid >= 0x0c && nid <= 0x11) {
12459                         snd_hda_codec_write(codec, nid, 0,
12460                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
12461                                             i <= AUTO_PIN_FRONT_MIC ?
12462                                             PIN_VREF80 : PIN_IN);
12463                 }
12464         }
12465 }
12466
12467 /* parse the BIOS configuration and set up the alc_spec */
12468 /* return 1 if successful, 0 if the proper config is not found,
12469  * or a negative error code
12470  */
12471 static int alc861_parse_auto_config(struct hda_codec *codec)
12472 {
12473         struct alc_spec *spec = codec->spec;
12474         int err;
12475         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
12476
12477         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12478                                            alc861_ignore);
12479         if (err < 0)
12480                 return err;
12481         if (!spec->autocfg.line_outs)
12482                 return 0; /* can't find valid BIOS pin config */
12483
12484         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
12485         if (err < 0)
12486                 return err;
12487         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
12488         if (err < 0)
12489                 return err;
12490         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
12491         if (err < 0)
12492                 return err;
12493         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
12494         if (err < 0)
12495                 return err;
12496
12497         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12498
12499         if (spec->autocfg.dig_out_pin)
12500                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
12501
12502         if (spec->kctl_alloc)
12503                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
12504
12505         spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs;
12506
12507         spec->num_mux_defs = 1;
12508         spec->input_mux = &spec->private_imux;
12509
12510         spec->adc_nids = alc861_adc_nids;
12511         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
12512         spec->mixers[spec->num_mixers] = alc861_capture_mixer;
12513         spec->num_mixers++;
12514
12515         return 1;
12516 }
12517
12518 /* additional initialization for auto-configuration model */
12519 static void alc861_auto_init(struct hda_codec *codec)
12520 {
12521         struct alc_spec *spec = codec->spec;
12522         alc861_auto_init_multi_out(codec);
12523         alc861_auto_init_hp_out(codec);
12524         alc861_auto_init_analog_input(codec);
12525         if (spec->unsol_event)
12526                 alc_sku_automute(codec);
12527 }
12528
12529 #ifdef CONFIG_SND_HDA_POWER_SAVE
12530 static struct hda_amp_list alc861_loopbacks[] = {
12531         { 0x15, HDA_INPUT, 0 },
12532         { 0x15, HDA_INPUT, 1 },
12533         { 0x15, HDA_INPUT, 2 },
12534         { 0x15, HDA_INPUT, 3 },
12535         { } /* end */
12536 };
12537 #endif
12538
12539
12540 /*
12541  * configuration and preset
12542  */
12543 static const char *alc861_models[ALC861_MODEL_LAST] = {
12544         [ALC861_3ST]            = "3stack",
12545         [ALC660_3ST]            = "3stack-660",
12546         [ALC861_3ST_DIG]        = "3stack-dig",
12547         [ALC861_6ST_DIG]        = "6stack-dig",
12548         [ALC861_UNIWILL_M31]    = "uniwill-m31",
12549         [ALC861_TOSHIBA]        = "toshiba",
12550         [ALC861_ASUS]           = "asus",
12551         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
12552         [ALC861_AUTO]           = "auto",
12553 };
12554
12555 static struct snd_pci_quirk alc861_cfg_tbl[] = {
12556         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
12557         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
12558         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
12559         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
12560         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
12561         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
12562         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
12563         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
12564          *        Any other models that need this preset?
12565          */
12566         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
12567         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
12568         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
12569         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
12570         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
12571         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
12572         /* FIXME: the below seems conflict */
12573         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
12574         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
12575         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
12576         {}
12577 };
12578
12579 static struct alc_config_preset alc861_presets[] = {
12580         [ALC861_3ST] = {
12581                 .mixers = { alc861_3ST_mixer },
12582                 .init_verbs = { alc861_threestack_init_verbs },
12583                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12584                 .dac_nids = alc861_dac_nids,
12585                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
12586                 .channel_mode = alc861_threestack_modes,
12587                 .need_dac_fix = 1,
12588                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12589                 .adc_nids = alc861_adc_nids,
12590                 .input_mux = &alc861_capture_source,
12591         },
12592         [ALC861_3ST_DIG] = {
12593                 .mixers = { alc861_base_mixer },
12594                 .init_verbs = { alc861_threestack_init_verbs },
12595                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12596                 .dac_nids = alc861_dac_nids,
12597                 .dig_out_nid = ALC861_DIGOUT_NID,
12598                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
12599                 .channel_mode = alc861_threestack_modes,
12600                 .need_dac_fix = 1,
12601                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12602                 .adc_nids = alc861_adc_nids,
12603                 .input_mux = &alc861_capture_source,
12604         },
12605         [ALC861_6ST_DIG] = {
12606                 .mixers = { alc861_base_mixer },
12607                 .init_verbs = { alc861_base_init_verbs },
12608                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12609                 .dac_nids = alc861_dac_nids,
12610                 .dig_out_nid = ALC861_DIGOUT_NID,
12611                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
12612                 .channel_mode = alc861_8ch_modes,
12613                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12614                 .adc_nids = alc861_adc_nids,
12615                 .input_mux = &alc861_capture_source,
12616         },
12617         [ALC660_3ST] = {
12618                 .mixers = { alc861_3ST_mixer },
12619                 .init_verbs = { alc861_threestack_init_verbs },
12620                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
12621                 .dac_nids = alc660_dac_nids,
12622                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
12623                 .channel_mode = alc861_threestack_modes,
12624                 .need_dac_fix = 1,
12625                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12626                 .adc_nids = alc861_adc_nids,
12627                 .input_mux = &alc861_capture_source,
12628         },
12629         [ALC861_UNIWILL_M31] = {
12630                 .mixers = { alc861_uniwill_m31_mixer },
12631                 .init_verbs = { alc861_uniwill_m31_init_verbs },
12632                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12633                 .dac_nids = alc861_dac_nids,
12634                 .dig_out_nid = ALC861_DIGOUT_NID,
12635                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
12636                 .channel_mode = alc861_uniwill_m31_modes,
12637                 .need_dac_fix = 1,
12638                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12639                 .adc_nids = alc861_adc_nids,
12640                 .input_mux = &alc861_capture_source,
12641         },
12642         [ALC861_TOSHIBA] = {
12643                 .mixers = { alc861_toshiba_mixer },
12644                 .init_verbs = { alc861_base_init_verbs,
12645                                 alc861_toshiba_init_verbs },
12646                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12647                 .dac_nids = alc861_dac_nids,
12648                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
12649                 .channel_mode = alc883_3ST_2ch_modes,
12650                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12651                 .adc_nids = alc861_adc_nids,
12652                 .input_mux = &alc861_capture_source,
12653                 .unsol_event = alc861_toshiba_unsol_event,
12654                 .init_hook = alc861_toshiba_automute,
12655         },
12656         [ALC861_ASUS] = {
12657                 .mixers = { alc861_asus_mixer },
12658                 .init_verbs = { alc861_asus_init_verbs },
12659                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12660                 .dac_nids = alc861_dac_nids,
12661                 .dig_out_nid = ALC861_DIGOUT_NID,
12662                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
12663                 .channel_mode = alc861_asus_modes,
12664                 .need_dac_fix = 1,
12665                 .hp_nid = 0x06,
12666                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12667                 .adc_nids = alc861_adc_nids,
12668                 .input_mux = &alc861_capture_source,
12669         },
12670         [ALC861_ASUS_LAPTOP] = {
12671                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
12672                 .init_verbs = { alc861_asus_init_verbs,
12673                                 alc861_asus_laptop_init_verbs },
12674                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12675                 .dac_nids = alc861_dac_nids,
12676                 .dig_out_nid = ALC861_DIGOUT_NID,
12677                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
12678                 .channel_mode = alc883_3ST_2ch_modes,
12679                 .need_dac_fix = 1,
12680                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12681                 .adc_nids = alc861_adc_nids,
12682                 .input_mux = &alc861_capture_source,
12683         },
12684 };
12685
12686
12687 static int patch_alc861(struct hda_codec *codec)
12688 {
12689         struct alc_spec *spec;
12690         int board_config;
12691         int err;
12692
12693         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12694         if (spec == NULL)
12695                 return -ENOMEM;
12696
12697         codec->spec = spec;
12698
12699         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
12700                                                   alc861_models,
12701                                                   alc861_cfg_tbl);
12702
12703         if (board_config < 0) {
12704                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
12705                        "trying auto-probe from BIOS...\n");
12706                 board_config = ALC861_AUTO;
12707         }
12708
12709         if (board_config == ALC861_AUTO) {
12710                 /* automatic parse from the BIOS config */
12711                 err = alc861_parse_auto_config(codec);
12712                 if (err < 0) {
12713                         alc_free(codec);
12714                         return err;
12715                 } else if (!err) {
12716                         printk(KERN_INFO
12717                                "hda_codec: Cannot set up configuration "
12718                                "from BIOS.  Using base mode...\n");
12719                    board_config = ALC861_3ST_DIG;
12720                 }
12721         }
12722
12723         if (board_config != ALC861_AUTO)
12724                 setup_preset(spec, &alc861_presets[board_config]);
12725
12726         spec->stream_name_analog = "ALC861 Analog";
12727         spec->stream_analog_playback = &alc861_pcm_analog_playback;
12728         spec->stream_analog_capture = &alc861_pcm_analog_capture;
12729
12730         spec->stream_name_digital = "ALC861 Digital";
12731         spec->stream_digital_playback = &alc861_pcm_digital_playback;
12732         spec->stream_digital_capture = &alc861_pcm_digital_capture;
12733
12734         spec->vmaster_nid = 0x03;
12735
12736         codec->patch_ops = alc_patch_ops;
12737         if (board_config == ALC861_AUTO)
12738                 spec->init_hook = alc861_auto_init;
12739 #ifdef CONFIG_SND_HDA_POWER_SAVE
12740         if (!spec->loopback.amplist)
12741                 spec->loopback.amplist = alc861_loopbacks;
12742 #endif
12743
12744         return 0;
12745 }
12746
12747 /*
12748  * ALC861-VD support
12749  *
12750  * Based on ALC882
12751  *
12752  * In addition, an independent DAC
12753  */
12754 #define ALC861VD_DIGOUT_NID     0x06
12755
12756 static hda_nid_t alc861vd_dac_nids[4] = {
12757         /* front, surr, clfe, side surr */
12758         0x02, 0x03, 0x04, 0x05
12759 };
12760
12761 /* dac_nids for ALC660vd are in a different order - according to
12762  * Realtek's driver.
12763  * This should probably tesult in a different mixer for 6stack models
12764  * of ALC660vd codecs, but for now there is only 3stack mixer
12765  * - and it is the same as in 861vd.
12766  * adc_nids in ALC660vd are (is) the same as in 861vd
12767  */
12768 static hda_nid_t alc660vd_dac_nids[3] = {
12769         /* front, rear, clfe, rear_surr */
12770         0x02, 0x04, 0x03
12771 };
12772
12773 static hda_nid_t alc861vd_adc_nids[1] = {
12774         /* ADC0 */
12775         0x09,
12776 };
12777
12778 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
12779
12780 /* input MUX */
12781 /* FIXME: should be a matrix-type input source selection */
12782 static struct hda_input_mux alc861vd_capture_source = {
12783         .num_items = 4,
12784         .items = {
12785                 { "Mic", 0x0 },
12786                 { "Front Mic", 0x1 },
12787                 { "Line", 0x2 },
12788                 { "CD", 0x4 },
12789         },
12790 };
12791
12792 static struct hda_input_mux alc861vd_dallas_capture_source = {
12793         .num_items = 2,
12794         .items = {
12795                 { "Ext Mic", 0x0 },
12796                 { "Int Mic", 0x1 },
12797         },
12798 };
12799
12800 static struct hda_input_mux alc861vd_hp_capture_source = {
12801         .num_items = 2,
12802         .items = {
12803                 { "Front Mic", 0x0 },
12804                 { "ATAPI Mic", 0x1 },
12805         },
12806 };
12807
12808 #define alc861vd_mux_enum_info alc_mux_enum_info
12809 #define alc861vd_mux_enum_get alc_mux_enum_get
12810 /* ALC861VD has the ALC882-type input selection (but has only one ADC) */
12811 #define alc861vd_mux_enum_put alc882_mux_enum_put
12812
12813 /*
12814  * 2ch mode
12815  */
12816 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
12817         { 2, NULL }
12818 };
12819
12820 /*
12821  * 6ch mode
12822  */
12823 static struct hda_verb alc861vd_6stack_ch6_init[] = {
12824         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12825         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12826         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12827         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12828         { } /* end */
12829 };
12830
12831 /*
12832  * 8ch mode
12833  */
12834 static struct hda_verb alc861vd_6stack_ch8_init[] = {
12835         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12836         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12837         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12838         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12839         { } /* end */
12840 };
12841
12842 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
12843         { 6, alc861vd_6stack_ch6_init },
12844         { 8, alc861vd_6stack_ch8_init },
12845 };
12846
12847 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
12848         {
12849                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12850                 .name = "Channel Mode",
12851                 .info = alc_ch_mode_info,
12852                 .get = alc_ch_mode_get,
12853                 .put = alc_ch_mode_put,
12854         },
12855         { } /* end */
12856 };
12857
12858 static struct snd_kcontrol_new alc861vd_capture_mixer[] = {
12859         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
12860         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
12861
12862         {
12863                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12864                 /* The multiple "Capture Source" controls confuse alsamixer
12865                  * So call somewhat different..
12866                  */
12867                 /* .name = "Capture Source", */
12868                 .name = "Input Source",
12869                 .count = 1,
12870                 .info = alc861vd_mux_enum_info,
12871                 .get = alc861vd_mux_enum_get,
12872                 .put = alc861vd_mux_enum_put,
12873         },
12874         { } /* end */
12875 };
12876
12877 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
12878  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
12879  */
12880 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
12881         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12882         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12883
12884         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12885         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
12886
12887         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
12888                                 HDA_OUTPUT),
12889         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
12890                                 HDA_OUTPUT),
12891         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
12892         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
12893
12894         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
12895         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
12896
12897         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12898
12899         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12900         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12901         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12902
12903         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12904         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12905         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12906
12907         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12908         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12909
12910         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12911         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12912
12913         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
12914         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
12915
12916         { } /* end */
12917 };
12918
12919 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
12920         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12921         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12922
12923         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12924
12925         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12926         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12927         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12928
12929         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12930         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12931         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12932
12933         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12934         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12935
12936         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12937         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12938
12939         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
12940         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
12941
12942         { } /* end */
12943 };
12944
12945 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
12946         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12947         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
12948         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12949
12950         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12951
12952         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12953         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12954         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12955
12956         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12957         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12958         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12959
12960         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12961         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12962
12963         { } /* end */
12964 };
12965
12966 /* Pin assignment: Speaker=0x14, HP = 0x15,
12967  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
12968  */
12969 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
12970         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12971         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
12972         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12973         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
12974         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
12975         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12976         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12977         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
12978         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12979         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12980         HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
12981         HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
12982         { } /* end */
12983 };
12984
12985 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
12986  *                 Front Mic=0x18, ATAPI Mic = 0x19,
12987  */
12988 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
12989         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12990         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12991         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12992         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
12993         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12994         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12995         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12996         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12997
12998         { } /* end */
12999 };
13000
13001 /*
13002  * generic initialization of ADC, input mixers and output mixers
13003  */
13004 static struct hda_verb alc861vd_volume_init_verbs[] = {
13005         /*
13006          * Unmute ADC0 and set the default input to mic-in
13007          */
13008         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
13009         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13010
13011         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
13012          * the analog-loopback mixer widget
13013          */
13014         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
13015         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13016         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13017         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13018         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13019         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13020
13021         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
13022         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13023         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13024         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13025         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
13026
13027         /*
13028          * Set up output mixers (0x02 - 0x05)
13029          */
13030         /* set vol=0 to output mixers */
13031         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13032         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13033         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13034         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13035
13036         /* set up input amps for analog loopback */
13037         /* Amp Indices: DAC = 0, mixer = 1 */
13038         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13039         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13040         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13041         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13042         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13043         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13044         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13045         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13046
13047         { }
13048 };
13049
13050 /*
13051  * 3-stack pin configuration:
13052  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
13053  */
13054 static struct hda_verb alc861vd_3stack_init_verbs[] = {
13055         /*
13056          * Set pin mode and muting
13057          */
13058         /* set front pin widgets 0x14 for output */
13059         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13060         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13061         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13062
13063         /* Mic (rear) pin: input vref at 80% */
13064         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13065         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13066         /* Front Mic pin: input vref at 80% */
13067         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13068         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13069         /* Line In pin: input */
13070         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13071         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13072         /* Line-2 In: Headphone output (output 0 - 0x0c) */
13073         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13074         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13075         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13076         /* CD pin widget for input */
13077         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13078
13079         { }
13080 };
13081
13082 /*
13083  * 6-stack pin configuration:
13084  */
13085 static struct hda_verb alc861vd_6stack_init_verbs[] = {
13086         /*
13087          * Set pin mode and muting
13088          */
13089         /* set front pin widgets 0x14 for output */
13090         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13091         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13092         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13093
13094         /* Rear Pin: output 1 (0x0d) */
13095         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13096         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13097         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13098         /* CLFE Pin: output 2 (0x0e) */
13099         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13100         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13101         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
13102         /* Side Pin: output 3 (0x0f) */
13103         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13104         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13105         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
13106
13107         /* Mic (rear) pin: input vref at 80% */
13108         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13109         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13110         /* Front Mic pin: input vref at 80% */
13111         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13112         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13113         /* Line In pin: input */
13114         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13115         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13116         /* Line-2 In: Headphone output (output 0 - 0x0c) */
13117         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13118         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13119         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13120         /* CD pin widget for input */
13121         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13122
13123         { }
13124 };
13125
13126 static struct hda_verb alc861vd_eapd_verbs[] = {
13127         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13128         { }
13129 };
13130
13131 static struct hda_verb alc660vd_eapd_verbs[] = {
13132         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13133         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
13134         { }
13135 };
13136
13137 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
13138         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13139         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13140         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
13141         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13142         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13143         {}
13144 };
13145
13146 /* toggle speaker-output according to the hp-jack state */
13147 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
13148 {
13149         unsigned int present;
13150         unsigned char bits;
13151
13152         present = snd_hda_codec_read(codec, 0x1b, 0,
13153                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13154         bits = present ? HDA_AMP_MUTE : 0;
13155         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
13156                                  HDA_AMP_MUTE, bits);
13157 }
13158
13159 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
13160 {
13161         unsigned int present;
13162         unsigned char bits;
13163
13164         present = snd_hda_codec_read(codec, 0x18, 0,
13165                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13166         bits = present ? HDA_AMP_MUTE : 0;
13167         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
13168                                  HDA_AMP_MUTE, bits);
13169 }
13170
13171 static void alc861vd_lenovo_automute(struct hda_codec *codec)
13172 {
13173         alc861vd_lenovo_hp_automute(codec);
13174         alc861vd_lenovo_mic_automute(codec);
13175 }
13176
13177 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
13178                                         unsigned int res)
13179 {
13180         switch (res >> 26) {
13181         case ALC880_HP_EVENT:
13182                 alc861vd_lenovo_hp_automute(codec);
13183                 break;
13184         case ALC880_MIC_EVENT:
13185                 alc861vd_lenovo_mic_automute(codec);
13186                 break;
13187         }
13188 }
13189
13190 static struct hda_verb alc861vd_dallas_verbs[] = {
13191         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13192         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13193         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13194         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13195
13196         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13197         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13198         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13199         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13200         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13201         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13202         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13203         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13204
13205         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13206         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13207         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13208         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13209         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13210         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13211         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13212         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13213
13214         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
13215         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13216         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
13217         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13218         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13219         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13220         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13221         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13222
13223         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13224         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13225         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13226         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13227
13228         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13229         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
13230         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13231
13232         { } /* end */
13233 };
13234
13235 /* toggle speaker-output according to the hp-jack state */
13236 static void alc861vd_dallas_automute(struct hda_codec *codec)
13237 {
13238         unsigned int present;
13239
13240         present = snd_hda_codec_read(codec, 0x15, 0,
13241                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13242         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
13243                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
13244 }
13245
13246 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
13247 {
13248         if ((res >> 26) == ALC880_HP_EVENT)
13249                 alc861vd_dallas_automute(codec);
13250 }
13251
13252 #ifdef CONFIG_SND_HDA_POWER_SAVE
13253 #define alc861vd_loopbacks      alc880_loopbacks
13254 #endif
13255
13256 /* pcm configuration: identiacal with ALC880 */
13257 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
13258 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
13259 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
13260 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
13261
13262 /*
13263  * configuration and preset
13264  */
13265 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
13266         [ALC660VD_3ST]          = "3stack-660",
13267         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
13268         [ALC861VD_3ST]          = "3stack",
13269         [ALC861VD_3ST_DIG]      = "3stack-digout",
13270         [ALC861VD_6ST_DIG]      = "6stack-digout",
13271         [ALC861VD_LENOVO]       = "lenovo",
13272         [ALC861VD_DALLAS]       = "dallas",
13273         [ALC861VD_HP]           = "hp",
13274         [ALC861VD_AUTO]         = "auto",
13275 };
13276
13277 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
13278         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
13279         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
13280         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
13281         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
13282         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC861VD_LENOVO),
13283         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
13284         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
13285         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
13286         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
13287         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
13288         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
13289         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
13290         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
13291         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
13292         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
13293         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 N200", ALC861VD_LENOVO),
13294         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
13295         {}
13296 };
13297
13298 static struct alc_config_preset alc861vd_presets[] = {
13299         [ALC660VD_3ST] = {
13300                 .mixers = { alc861vd_3st_mixer },
13301                 .init_verbs = { alc861vd_volume_init_verbs,
13302                                  alc861vd_3stack_init_verbs },
13303                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
13304                 .dac_nids = alc660vd_dac_nids,
13305                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13306                 .channel_mode = alc861vd_3stack_2ch_modes,
13307                 .input_mux = &alc861vd_capture_source,
13308         },
13309         [ALC660VD_3ST_DIG] = {
13310                 .mixers = { alc861vd_3st_mixer },
13311                 .init_verbs = { alc861vd_volume_init_verbs,
13312                                  alc861vd_3stack_init_verbs },
13313                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
13314                 .dac_nids = alc660vd_dac_nids,
13315                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13316                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13317                 .channel_mode = alc861vd_3stack_2ch_modes,
13318                 .input_mux = &alc861vd_capture_source,
13319         },
13320         [ALC861VD_3ST] = {
13321                 .mixers = { alc861vd_3st_mixer },
13322                 .init_verbs = { alc861vd_volume_init_verbs,
13323                                  alc861vd_3stack_init_verbs },
13324                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13325                 .dac_nids = alc861vd_dac_nids,
13326                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13327                 .channel_mode = alc861vd_3stack_2ch_modes,
13328                 .input_mux = &alc861vd_capture_source,
13329         },
13330         [ALC861VD_3ST_DIG] = {
13331                 .mixers = { alc861vd_3st_mixer },
13332                 .init_verbs = { alc861vd_volume_init_verbs,
13333                                  alc861vd_3stack_init_verbs },
13334                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13335                 .dac_nids = alc861vd_dac_nids,
13336                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13337                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13338                 .channel_mode = alc861vd_3stack_2ch_modes,
13339                 .input_mux = &alc861vd_capture_source,
13340         },
13341         [ALC861VD_6ST_DIG] = {
13342                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
13343                 .init_verbs = { alc861vd_volume_init_verbs,
13344                                 alc861vd_6stack_init_verbs },
13345                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13346                 .dac_nids = alc861vd_dac_nids,
13347                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13348                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
13349                 .channel_mode = alc861vd_6stack_modes,
13350                 .input_mux = &alc861vd_capture_source,
13351         },
13352         [ALC861VD_LENOVO] = {
13353                 .mixers = { alc861vd_lenovo_mixer },
13354                 .init_verbs = { alc861vd_volume_init_verbs,
13355                                 alc861vd_3stack_init_verbs,
13356                                 alc861vd_eapd_verbs,
13357                                 alc861vd_lenovo_unsol_verbs },
13358                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
13359                 .dac_nids = alc660vd_dac_nids,
13360                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13361                 .channel_mode = alc861vd_3stack_2ch_modes,
13362                 .input_mux = &alc861vd_capture_source,
13363                 .unsol_event = alc861vd_lenovo_unsol_event,
13364                 .init_hook = alc861vd_lenovo_automute,
13365         },
13366         [ALC861VD_DALLAS] = {
13367                 .mixers = { alc861vd_dallas_mixer },
13368                 .init_verbs = { alc861vd_dallas_verbs },
13369                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13370                 .dac_nids = alc861vd_dac_nids,
13371                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13372                 .channel_mode = alc861vd_3stack_2ch_modes,
13373                 .input_mux = &alc861vd_dallas_capture_source,
13374                 .unsol_event = alc861vd_dallas_unsol_event,
13375                 .init_hook = alc861vd_dallas_automute,
13376         },
13377         [ALC861VD_HP] = {
13378                 .mixers = { alc861vd_hp_mixer },
13379                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
13380                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13381                 .dac_nids = alc861vd_dac_nids,
13382                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13383                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13384                 .channel_mode = alc861vd_3stack_2ch_modes,
13385                 .input_mux = &alc861vd_hp_capture_source,
13386                 .unsol_event = alc861vd_dallas_unsol_event,
13387                 .init_hook = alc861vd_dallas_automute,
13388         },
13389 };
13390
13391 /*
13392  * BIOS auto configuration
13393  */
13394 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
13395                                 hda_nid_t nid, int pin_type, int dac_idx)
13396 {
13397         alc_set_pin_output(codec, nid, pin_type);
13398 }
13399
13400 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
13401 {
13402         struct alc_spec *spec = codec->spec;
13403         int i;
13404
13405         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
13406         for (i = 0; i <= HDA_SIDE; i++) {
13407                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13408                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13409                 if (nid)
13410                         alc861vd_auto_set_output_and_unmute(codec, nid,
13411                                                             pin_type, i);
13412         }
13413 }
13414
13415
13416 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
13417 {
13418         struct alc_spec *spec = codec->spec;
13419         hda_nid_t pin;
13420
13421         pin = spec->autocfg.hp_pins[0];
13422         if (pin) /* connect to front and  use dac 0 */
13423                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
13424         pin = spec->autocfg.speaker_pins[0];
13425         if (pin)
13426                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13427 }
13428
13429 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
13430 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
13431
13432 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
13433 {
13434         struct alc_spec *spec = codec->spec;
13435         int i;
13436
13437         for (i = 0; i < AUTO_PIN_LAST; i++) {
13438                 hda_nid_t nid = spec->autocfg.input_pins[i];
13439                 if (alc861vd_is_input_pin(nid)) {
13440                         snd_hda_codec_write(codec, nid, 0,
13441                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
13442                                         i <= AUTO_PIN_FRONT_MIC ?
13443                                                         PIN_VREF80 : PIN_IN);
13444                         if (nid != ALC861VD_PIN_CD_NID)
13445                                 snd_hda_codec_write(codec, nid, 0,
13446                                                 AC_VERB_SET_AMP_GAIN_MUTE,
13447                                                 AMP_OUT_MUTE);
13448                 }
13449         }
13450 }
13451
13452 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
13453
13454 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
13455 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
13456
13457 /* add playback controls from the parsed DAC table */
13458 /* Based on ALC880 version. But ALC861VD has separate,
13459  * different NIDs for mute/unmute switch and volume control */
13460 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
13461                                              const struct auto_pin_cfg *cfg)
13462 {
13463         char name[32];
13464         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
13465         hda_nid_t nid_v, nid_s;
13466         int i, err;
13467
13468         for (i = 0; i < cfg->line_outs; i++) {
13469                 if (!spec->multiout.dac_nids[i])
13470                         continue;
13471                 nid_v = alc861vd_idx_to_mixer_vol(
13472                                 alc880_dac_to_idx(
13473                                         spec->multiout.dac_nids[i]));
13474                 nid_s = alc861vd_idx_to_mixer_switch(
13475                                 alc880_dac_to_idx(
13476                                         spec->multiout.dac_nids[i]));
13477
13478                 if (i == 2) {
13479                         /* Center/LFE */
13480                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13481                                           "Center Playback Volume",
13482                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
13483                                                               HDA_OUTPUT));
13484                         if (err < 0)
13485                                 return err;
13486                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13487                                           "LFE Playback Volume",
13488                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
13489                                                               HDA_OUTPUT));
13490                         if (err < 0)
13491                                 return err;
13492                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13493                                           "Center Playback Switch",
13494                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
13495                                                               HDA_INPUT));
13496                         if (err < 0)
13497                                 return err;
13498                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13499                                           "LFE Playback Switch",
13500                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
13501                                                               HDA_INPUT));
13502                         if (err < 0)
13503                                 return err;
13504                 } else {
13505                         sprintf(name, "%s Playback Volume", chname[i]);
13506                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
13507                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
13508                                                               HDA_OUTPUT));
13509                         if (err < 0)
13510                                 return err;
13511                         sprintf(name, "%s Playback Switch", chname[i]);
13512                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13513                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
13514                                                               HDA_INPUT));
13515                         if (err < 0)
13516                                 return err;
13517                 }
13518         }
13519         return 0;
13520 }
13521
13522 /* add playback controls for speaker and HP outputs */
13523 /* Based on ALC880 version. But ALC861VD has separate,
13524  * different NIDs for mute/unmute switch and volume control */
13525 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
13526                                         hda_nid_t pin, const char *pfx)
13527 {
13528         hda_nid_t nid_v, nid_s;
13529         int err;
13530         char name[32];
13531
13532         if (!pin)
13533                 return 0;
13534
13535         if (alc880_is_fixed_pin(pin)) {
13536                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
13537                 /* specify the DAC as the extra output */
13538                 if (!spec->multiout.hp_nid)
13539                         spec->multiout.hp_nid = nid_v;
13540                 else
13541                         spec->multiout.extra_out_nid[0] = nid_v;
13542                 /* control HP volume/switch on the output mixer amp */
13543                 nid_v = alc861vd_idx_to_mixer_vol(
13544                                 alc880_fixed_pin_idx(pin));
13545                 nid_s = alc861vd_idx_to_mixer_switch(
13546                                 alc880_fixed_pin_idx(pin));
13547
13548                 sprintf(name, "%s Playback Volume", pfx);
13549                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
13550                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
13551                 if (err < 0)
13552                         return err;
13553                 sprintf(name, "%s Playback Switch", pfx);
13554                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13555                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
13556                 if (err < 0)
13557                         return err;
13558         } else if (alc880_is_multi_pin(pin)) {
13559                 /* set manual connection */
13560                 /* we have only a switch on HP-out PIN */
13561                 sprintf(name, "%s Playback Switch", pfx);
13562                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
13563                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
13564                 if (err < 0)
13565                         return err;
13566         }
13567         return 0;
13568 }
13569
13570 /* parse the BIOS configuration and set up the alc_spec
13571  * return 1 if successful, 0 if the proper config is not found,
13572  * or a negative error code
13573  * Based on ALC880 version - had to change it to override
13574  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
13575 static int alc861vd_parse_auto_config(struct hda_codec *codec)
13576 {
13577         struct alc_spec *spec = codec->spec;
13578         int err;
13579         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
13580
13581         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13582                                            alc861vd_ignore);
13583         if (err < 0)
13584                 return err;
13585         if (!spec->autocfg.line_outs)
13586                 return 0; /* can't find valid BIOS pin config */
13587
13588         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
13589         if (err < 0)
13590                 return err;
13591         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
13592         if (err < 0)
13593                 return err;
13594         err = alc861vd_auto_create_extra_out(spec,
13595                                              spec->autocfg.speaker_pins[0],
13596                                              "Speaker");
13597         if (err < 0)
13598                 return err;
13599         err = alc861vd_auto_create_extra_out(spec,
13600                                              spec->autocfg.hp_pins[0],
13601                                              "Headphone");
13602         if (err < 0)
13603                 return err;
13604         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
13605         if (err < 0)
13606                 return err;
13607
13608         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13609
13610         if (spec->autocfg.dig_out_pin)
13611                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
13612
13613         if (spec->kctl_alloc)
13614                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
13615
13616         spec->init_verbs[spec->num_init_verbs++]
13617                 = alc861vd_volume_init_verbs;
13618
13619         spec->num_mux_defs = 1;
13620         spec->input_mux = &spec->private_imux;
13621
13622         err = alc_auto_add_mic_boost(codec);
13623         if (err < 0)
13624                 return err;
13625
13626         return 1;
13627 }
13628
13629 /* additional initialization for auto-configuration model */
13630 static void alc861vd_auto_init(struct hda_codec *codec)
13631 {
13632         struct alc_spec *spec = codec->spec;
13633         alc861vd_auto_init_multi_out(codec);
13634         alc861vd_auto_init_hp_out(codec);
13635         alc861vd_auto_init_analog_input(codec);
13636         alc861vd_auto_init_input_src(codec);
13637         if (spec->unsol_event)
13638                 alc_sku_automute(codec);
13639 }
13640
13641 static int patch_alc861vd(struct hda_codec *codec)
13642 {
13643         struct alc_spec *spec;
13644         int err, board_config;
13645
13646         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13647         if (spec == NULL)
13648                 return -ENOMEM;
13649
13650         codec->spec = spec;
13651
13652         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
13653                                                   alc861vd_models,
13654                                                   alc861vd_cfg_tbl);
13655
13656         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
13657                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
13658                         "ALC861VD, trying auto-probe from BIOS...\n");
13659                 board_config = ALC861VD_AUTO;
13660         }
13661
13662         if (board_config == ALC861VD_AUTO) {
13663                 /* automatic parse from the BIOS config */
13664                 err = alc861vd_parse_auto_config(codec);
13665                 if (err < 0) {
13666                         alc_free(codec);
13667                         return err;
13668                 } else if (!err) {
13669                         printk(KERN_INFO
13670                                "hda_codec: Cannot set up configuration "
13671                                "from BIOS.  Using base mode...\n");
13672                         board_config = ALC861VD_3ST;
13673                 }
13674         }
13675
13676         if (board_config != ALC861VD_AUTO)
13677                 setup_preset(spec, &alc861vd_presets[board_config]);
13678
13679         if (codec->vendor_id == 0x10ec0660) {
13680                 spec->stream_name_analog = "ALC660-VD Analog";
13681                 spec->stream_name_digital = "ALC660-VD Digital";
13682                 /* always turn on EAPD */
13683                 spec->init_verbs[spec->num_init_verbs++] = alc660vd_eapd_verbs;
13684         } else {
13685                 spec->stream_name_analog = "ALC861VD Analog";
13686                 spec->stream_name_digital = "ALC861VD Digital";
13687         }
13688
13689         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
13690         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
13691
13692         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
13693         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
13694
13695         spec->adc_nids = alc861vd_adc_nids;
13696         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
13697         spec->capsrc_nids = alc861vd_capsrc_nids;
13698
13699         spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
13700         spec->num_mixers++;
13701
13702         spec->vmaster_nid = 0x02;
13703
13704         codec->patch_ops = alc_patch_ops;
13705
13706         if (board_config == ALC861VD_AUTO)
13707                 spec->init_hook = alc861vd_auto_init;
13708 #ifdef CONFIG_SND_HDA_POWER_SAVE
13709         if (!spec->loopback.amplist)
13710                 spec->loopback.amplist = alc861vd_loopbacks;
13711 #endif
13712
13713         return 0;
13714 }
13715
13716 /*
13717  * ALC662 support
13718  *
13719  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
13720  * configuration.  Each pin widget can choose any input DACs and a mixer.
13721  * Each ADC is connected from a mixer of all inputs.  This makes possible
13722  * 6-channel independent captures.
13723  *
13724  * In addition, an independent DAC for the multi-playback (not used in this
13725  * driver yet).
13726  */
13727 #define ALC662_DIGOUT_NID       0x06
13728 #define ALC662_DIGIN_NID        0x0a
13729
13730 static hda_nid_t alc662_dac_nids[4] = {
13731         /* front, rear, clfe, rear_surr */
13732         0x02, 0x03, 0x04
13733 };
13734
13735 static hda_nid_t alc662_adc_nids[1] = {
13736         /* ADC1-2 */
13737         0x09,
13738 };
13739
13740 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
13741
13742 /* input MUX */
13743 /* FIXME: should be a matrix-type input source selection */
13744 static struct hda_input_mux alc662_capture_source = {
13745         .num_items = 4,
13746         .items = {
13747                 { "Mic", 0x0 },
13748                 { "Front Mic", 0x1 },
13749                 { "Line", 0x2 },
13750                 { "CD", 0x4 },
13751         },
13752 };
13753
13754 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
13755         .num_items = 2,
13756         .items = {
13757                 { "Mic", 0x1 },
13758                 { "Line", 0x2 },
13759         },
13760 };
13761
13762 static struct hda_input_mux alc662_eeepc_capture_source = {
13763         .num_items = 2,
13764         .items = {
13765                 { "i-Mic", 0x1 },
13766                 { "e-Mic", 0x0 },
13767         },
13768 };
13769
13770 static struct hda_input_mux alc663_capture_source = {
13771         .num_items = 3,
13772         .items = {
13773                 { "Mic", 0x0 },
13774                 { "Front Mic", 0x1 },
13775                 { "Line", 0x2 },
13776         },
13777 };
13778
13779 static struct hda_input_mux alc663_m51va_capture_source = {
13780         .num_items = 2,
13781         .items = {
13782                 { "Ext-Mic", 0x0 },
13783                 { "D-Mic", 0x9 },
13784         },
13785 };
13786
13787 #define alc662_mux_enum_info alc_mux_enum_info
13788 #define alc662_mux_enum_get alc_mux_enum_get
13789 #define alc662_mux_enum_put alc882_mux_enum_put
13790
13791 /*
13792  * 2ch mode
13793  */
13794 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
13795         { 2, NULL }
13796 };
13797
13798 /*
13799  * 2ch mode
13800  */
13801 static struct hda_verb alc662_3ST_ch2_init[] = {
13802         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
13803         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
13804         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
13805         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
13806         { } /* end */
13807 };
13808
13809 /*
13810  * 6ch mode
13811  */
13812 static struct hda_verb alc662_3ST_ch6_init[] = {
13813         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13814         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
13815         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
13816         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13817         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
13818         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
13819         { } /* end */
13820 };
13821
13822 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
13823         { 2, alc662_3ST_ch2_init },
13824         { 6, alc662_3ST_ch6_init },
13825 };
13826
13827 /*
13828  * 2ch mode
13829  */
13830 static struct hda_verb alc662_sixstack_ch6_init[] = {
13831         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13832         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13833         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13834         { } /* end */
13835 };
13836
13837 /*
13838  * 6ch mode
13839  */
13840 static struct hda_verb alc662_sixstack_ch8_init[] = {
13841         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13842         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13843         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13844         { } /* end */
13845 };
13846
13847 static struct hda_channel_mode alc662_5stack_modes[2] = {
13848         { 2, alc662_sixstack_ch6_init },
13849         { 6, alc662_sixstack_ch8_init },
13850 };
13851
13852 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
13853  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
13854  */
13855
13856 static struct snd_kcontrol_new alc662_base_mixer[] = {
13857         /* output mixer control */
13858         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
13859         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
13860         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
13861         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
13862         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13863         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13864         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
13865         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
13866         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13867
13868         /*Input mixer control */
13869         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
13870         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
13871         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
13872         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
13873         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
13874         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
13875         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
13876         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
13877         { } /* end */
13878 };
13879
13880 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
13881         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13882         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
13883         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13884         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13885         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13886         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13887         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13888         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13889         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13890         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13891         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13892         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13893         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13894         { } /* end */
13895 };
13896
13897 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
13898         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13899         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
13900         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13901         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
13902         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13903         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13904         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
13905         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
13906         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13907         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13908         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13909         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13910         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13911         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13912         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13913         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13914         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13915         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13916         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13917         { } /* end */
13918 };
13919
13920 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
13921         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13922         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
13923         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13924         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
13925         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13926         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13927         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13928         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13929         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13930         { } /* end */
13931 };
13932
13933 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
13934         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13935
13936         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13937         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13938
13939         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
13940         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13941         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13942
13943         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
13944         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13945         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13946         { } /* end */
13947 };
13948
13949 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
13950         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13951         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13952         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13953         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
13954         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13955         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13956         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
13957         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
13958         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13959         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
13960         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13961         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13962         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13963         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13964         { } /* end */
13965 };
13966
13967 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
13968         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13969         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13970         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
13971         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13972         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13973         HDA_CODEC_MUTE("DMic Playback Switch", 0x23, 0x9, HDA_INPUT),
13974         { } /* end */
13975 };
13976
13977 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
13978         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13979         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13980         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13981         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13982         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
13983
13984         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13985         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13986         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13987         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13988         { } /* end */
13989 };
13990
13991 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
13992         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13993         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13994         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
13995
13996         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13997         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13998         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13999         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14000         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14001         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14002         { } /* end */
14003 };
14004
14005 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
14006         {
14007                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14008                 .name = "Channel Mode",
14009                 .info = alc_ch_mode_info,
14010                 .get = alc_ch_mode_get,
14011                 .put = alc_ch_mode_put,
14012         },
14013         { } /* end */
14014 };
14015
14016 static struct hda_verb alc662_init_verbs[] = {
14017         /* ADC: mute amp left and right */
14018         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14019         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14020         /* Front mixer: unmute input/output amp left and right (volume = 0) */
14021
14022         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14023         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14024         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14025         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14026         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14027
14028         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14029         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14030         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14031         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14032         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14033         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14034
14035         /* Front Pin: output 0 (0x0c) */
14036         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14037         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14038
14039         /* Rear Pin: output 1 (0x0d) */
14040         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14041         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14042
14043         /* CLFE Pin: output 2 (0x0e) */
14044         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14045         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14046
14047         /* Mic (rear) pin: input vref at 80% */
14048         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14049         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14050         /* Front Mic pin: input vref at 80% */
14051         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14052         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14053         /* Line In pin: input */
14054         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14055         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14056         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14057         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14058         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14059         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14060         /* CD pin widget for input */
14061         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14062
14063         /* FIXME: use matrix-type input source selection */
14064         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
14065         /* Input mixer */
14066         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14067         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14068         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14069         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14070
14071         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14072         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14073         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14074         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14075
14076         /* always trun on EAPD */
14077         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14078         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
14079
14080         { }
14081 };
14082
14083 static struct hda_verb alc662_sue_init_verbs[] = {
14084         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
14085         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
14086         {}
14087 };
14088
14089 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
14090         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14091         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14092         {}
14093 };
14094
14095 /* Set Unsolicited Event*/
14096 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
14097         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14098         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14099         {}
14100 };
14101
14102 /*
14103  * generic initialization of ADC, input mixers and output mixers
14104  */
14105 static struct hda_verb alc662_auto_init_verbs[] = {
14106         /*
14107          * Unmute ADC and set the default input to mic-in
14108          */
14109         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14110         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14111
14112         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
14113          * mixer widget
14114          * Note: PASD motherboards uses the Line In 2 as the input for front
14115          * panel mic (mic 2)
14116          */
14117         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14118         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14119         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14120         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14121         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14122         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14123
14124         /*
14125          * Set up output mixers (0x0c - 0x0f)
14126          */
14127         /* set vol=0 to output mixers */
14128         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14129         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14130         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14131
14132         /* set up input amps for analog loopback */
14133         /* Amp Indices: DAC = 0, mixer = 1 */
14134         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14135         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14136         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14137         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14138         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14139         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14140
14141
14142         /* FIXME: use matrix-type input source selection */
14143         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
14144         /* Input mixer */
14145         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14146         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14147         { }
14148 };
14149
14150 /* additional verbs for ALC663 */
14151 static struct hda_verb alc663_auto_init_verbs[] = {
14152         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14153         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14154         { }
14155 };
14156
14157 static struct hda_verb alc663_m51va_init_verbs[] = {
14158         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14159         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14160         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
14161
14162         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
14163
14164         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14165         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14166         {}
14167 };
14168
14169 static struct hda_verb alc663_g71v_init_verbs[] = {
14170         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14171         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
14172         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
14173
14174         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14175         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14176         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
14177
14178         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
14179         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
14180         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
14181         {}
14182 };
14183
14184 static struct hda_verb alc663_g50v_init_verbs[] = {
14185         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14186         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14187         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
14188
14189         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14190         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14191         {}
14192 };
14193
14194 /* capture mixer elements */
14195 static struct snd_kcontrol_new alc662_capture_mixer[] = {
14196         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
14197         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
14198         {
14199                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14200                 /* The multiple "Capture Source" controls confuse alsamixer
14201                  * So call somewhat different..
14202                  */
14203                 /* .name = "Capture Source", */
14204                 .name = "Input Source",
14205                 .count = 1,
14206                 .info = alc662_mux_enum_info,
14207                 .get = alc662_mux_enum_get,
14208                 .put = alc662_mux_enum_put,
14209         },
14210         { } /* end */
14211 };
14212
14213 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
14214 {
14215         unsigned int present;
14216         unsigned char bits;
14217
14218         present = snd_hda_codec_read(codec, 0x14, 0,
14219                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14220         bits = present ? HDA_AMP_MUTE : 0;
14221         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
14222                                  HDA_AMP_MUTE, bits);
14223 }
14224
14225 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
14226 {
14227         unsigned int present;
14228         unsigned char bits;
14229
14230         present = snd_hda_codec_read(codec, 0x1b, 0,
14231                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14232         bits = present ? HDA_AMP_MUTE : 0;
14233         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
14234                                  HDA_AMP_MUTE, bits);
14235         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14236                                  HDA_AMP_MUTE, bits);
14237 }
14238
14239 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
14240                                            unsigned int res)
14241 {
14242         if ((res >> 26) == ALC880_HP_EVENT)
14243                 alc662_lenovo_101e_all_automute(codec);
14244         if ((res >> 26) == ALC880_FRONT_EVENT)
14245                 alc662_lenovo_101e_ispeaker_automute(codec);
14246 }
14247
14248 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
14249 {
14250         unsigned int present;
14251
14252         present = snd_hda_codec_read(codec, 0x18, 0,
14253                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14254         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14255                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14256         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14257                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14258         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14259                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
14260         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14261                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
14262 }
14263
14264 /* unsolicited event for HP jack sensing */
14265 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
14266                                      unsigned int res)
14267 {
14268         if ((res >> 26) == ALC880_HP_EVENT)
14269                 alc262_hippo1_automute( codec );
14270
14271         if ((res >> 26) == ALC880_MIC_EVENT)
14272                 alc662_eeepc_mic_automute(codec);
14273 }
14274
14275 static void alc662_eeepc_inithook(struct hda_codec *codec)
14276 {
14277         alc262_hippo1_automute( codec );
14278         alc662_eeepc_mic_automute(codec);
14279 }
14280
14281 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
14282 {
14283         unsigned int mute;
14284         unsigned int present;
14285
14286         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
14287         present = snd_hda_codec_read(codec, 0x14, 0,
14288                                      AC_VERB_GET_PIN_SENSE, 0);
14289         present = (present & 0x80000000) != 0;
14290         if (present) {
14291                 /* mute internal speaker */
14292                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
14293                                         HDA_AMP_MUTE, HDA_AMP_MUTE);
14294         } else {
14295                 /* unmute internal speaker if necessary */
14296                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
14297                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
14298                                         HDA_AMP_MUTE, mute);
14299         }
14300 }
14301
14302 /* unsolicited event for HP jack sensing */
14303 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
14304                                           unsigned int res)
14305 {
14306         if ((res >> 26) == ALC880_HP_EVENT)
14307                 alc662_eeepc_ep20_automute(codec);
14308 }
14309
14310 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
14311 {
14312         alc662_eeepc_ep20_automute(codec);
14313 }
14314
14315 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
14316 {
14317         unsigned int present;
14318         unsigned char bits;
14319
14320         present = snd_hda_codec_read(codec, 0x21, 0,
14321                                      AC_VERB_GET_PIN_SENSE, 0)
14322                 & AC_PINSENSE_PRESENCE;
14323         bits = present ? HDA_AMP_MUTE : 0;
14324         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14325                                  HDA_AMP_MUTE, bits);
14326 }
14327
14328 static void alc663_m51va_mic_automute(struct hda_codec *codec)
14329 {
14330         unsigned int present;
14331
14332         present = snd_hda_codec_read(codec, 0x18, 0,
14333                         AC_VERB_GET_PIN_SENSE, 0)
14334                         & AC_PINSENSE_PRESENCE;
14335         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14336                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14337         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14338                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14339         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14340                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
14341         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14342                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
14343 }
14344
14345 static void alc663_m51va_unsol_event(struct hda_codec *codec,
14346                                            unsigned int res)
14347 {
14348         switch (res >> 26) {
14349         case ALC880_HP_EVENT:
14350                 alc663_m51va_speaker_automute(codec);
14351                 break;
14352         case ALC880_MIC_EVENT:
14353                 alc663_m51va_mic_automute(codec);
14354                 break;
14355         }
14356 }
14357
14358 static void alc663_m51va_inithook(struct hda_codec *codec)
14359 {
14360         alc663_m51va_speaker_automute(codec);
14361         alc663_m51va_mic_automute(codec);
14362 }
14363
14364 static void alc663_g71v_hp_automute(struct hda_codec *codec)
14365 {
14366         unsigned int present;
14367         unsigned char bits;
14368
14369         present = snd_hda_codec_read(codec, 0x21, 0,
14370                                      AC_VERB_GET_PIN_SENSE, 0)
14371                 & AC_PINSENSE_PRESENCE;
14372         bits = present ? HDA_AMP_MUTE : 0;
14373         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
14374                                  HDA_AMP_MUTE, bits);
14375         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14376                                  HDA_AMP_MUTE, bits);
14377 }
14378
14379 static void alc663_g71v_front_automute(struct hda_codec *codec)
14380 {
14381         unsigned int present;
14382         unsigned char bits;
14383
14384         present = snd_hda_codec_read(codec, 0x15, 0,
14385                                      AC_VERB_GET_PIN_SENSE, 0)
14386                 & AC_PINSENSE_PRESENCE;
14387         bits = present ? HDA_AMP_MUTE : 0;
14388         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14389                                  HDA_AMP_MUTE, bits);
14390 }
14391
14392 static void alc663_g71v_unsol_event(struct hda_codec *codec,
14393                                            unsigned int res)
14394 {
14395         switch (res >> 26) {
14396         case ALC880_HP_EVENT:
14397                 alc663_g71v_hp_automute(codec);
14398                 break;
14399         case ALC880_FRONT_EVENT:
14400                 alc663_g71v_front_automute(codec);
14401                 break;
14402         case ALC880_MIC_EVENT:
14403                 alc662_eeepc_mic_automute(codec);
14404                 break;
14405         }
14406 }
14407
14408 static void alc663_g71v_inithook(struct hda_codec *codec)
14409 {
14410         alc663_g71v_front_automute(codec);
14411         alc663_g71v_hp_automute(codec);
14412         alc662_eeepc_mic_automute(codec);
14413 }
14414
14415 static void alc663_g50v_unsol_event(struct hda_codec *codec,
14416                                            unsigned int res)
14417 {
14418         switch (res >> 26) {
14419         case ALC880_HP_EVENT:
14420                 alc663_m51va_speaker_automute(codec);
14421                 break;
14422         case ALC880_MIC_EVENT:
14423                 alc662_eeepc_mic_automute(codec);
14424                 break;
14425         }
14426 }
14427
14428 static void alc663_g50v_inithook(struct hda_codec *codec)
14429 {
14430         alc663_m51va_speaker_automute(codec);
14431         alc662_eeepc_mic_automute(codec);
14432 }
14433
14434 #ifdef CONFIG_SND_HDA_POWER_SAVE
14435 #define alc662_loopbacks        alc880_loopbacks
14436 #endif
14437
14438
14439 /* pcm configuration: identiacal with ALC880 */
14440 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
14441 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
14442 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
14443 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
14444
14445 /*
14446  * configuration and preset
14447  */
14448 static const char *alc662_models[ALC662_MODEL_LAST] = {
14449         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
14450         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
14451         [ALC662_3ST_6ch]        = "3stack-6ch",
14452         [ALC662_5ST_DIG]        = "6stack-dig",
14453         [ALC662_LENOVO_101E]    = "lenovo-101e",
14454         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
14455         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
14456         [ALC663_ASUS_M51VA] = "m51va",
14457         [ALC663_ASUS_G71V] = "g71v",
14458         [ALC663_ASUS_H13] = "h13",
14459         [ALC663_ASUS_G50V] = "g50v",
14460         [ALC662_AUTO]           = "auto",
14461 };
14462
14463 static struct snd_pci_quirk alc662_cfg_tbl[] = {
14464         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS G71V", ALC663_ASUS_G71V),
14465         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
14466         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS M51VA", ALC663_ASUS_G50V),
14467         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
14468         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
14469         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
14470         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
14471         SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13),
14472         SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13),
14473         SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13),
14474         {}
14475 };
14476
14477 static struct alc_config_preset alc662_presets[] = {
14478         [ALC662_3ST_2ch_DIG] = {
14479                 .mixers = { alc662_3ST_2ch_mixer, alc662_capture_mixer },
14480                 .init_verbs = { alc662_init_verbs },
14481                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14482                 .dac_nids = alc662_dac_nids,
14483                 .dig_out_nid = ALC662_DIGOUT_NID,
14484                 .dig_in_nid = ALC662_DIGIN_NID,
14485                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14486                 .channel_mode = alc662_3ST_2ch_modes,
14487                 .input_mux = &alc662_capture_source,
14488         },
14489         [ALC662_3ST_6ch_DIG] = {
14490                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
14491                             alc662_capture_mixer },
14492                 .init_verbs = { alc662_init_verbs },
14493                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14494                 .dac_nids = alc662_dac_nids,
14495                 .dig_out_nid = ALC662_DIGOUT_NID,
14496                 .dig_in_nid = ALC662_DIGIN_NID,
14497                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
14498                 .channel_mode = alc662_3ST_6ch_modes,
14499                 .need_dac_fix = 1,
14500                 .input_mux = &alc662_capture_source,
14501         },
14502         [ALC662_3ST_6ch] = {
14503                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
14504                             alc662_capture_mixer },
14505                 .init_verbs = { alc662_init_verbs },
14506                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14507                 .dac_nids = alc662_dac_nids,
14508                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
14509                 .channel_mode = alc662_3ST_6ch_modes,
14510                 .need_dac_fix = 1,
14511                 .input_mux = &alc662_capture_source,
14512         },
14513         [ALC662_5ST_DIG] = {
14514                 .mixers = { alc662_base_mixer, alc662_chmode_mixer,
14515                             alc662_capture_mixer },
14516                 .init_verbs = { alc662_init_verbs },
14517                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14518                 .dac_nids = alc662_dac_nids,
14519                 .dig_out_nid = ALC662_DIGOUT_NID,
14520                 .dig_in_nid = ALC662_DIGIN_NID,
14521                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
14522                 .channel_mode = alc662_5stack_modes,
14523                 .input_mux = &alc662_capture_source,
14524         },
14525         [ALC662_LENOVO_101E] = {
14526                 .mixers = { alc662_lenovo_101e_mixer, alc662_capture_mixer },
14527                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
14528                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14529                 .dac_nids = alc662_dac_nids,
14530                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14531                 .channel_mode = alc662_3ST_2ch_modes,
14532                 .input_mux = &alc662_lenovo_101e_capture_source,
14533                 .unsol_event = alc662_lenovo_101e_unsol_event,
14534                 .init_hook = alc662_lenovo_101e_all_automute,
14535         },
14536         [ALC662_ASUS_EEEPC_P701] = {
14537                 .mixers = { alc662_eeepc_p701_mixer, alc662_capture_mixer },
14538                 .init_verbs = { alc662_init_verbs,
14539                                 alc662_eeepc_sue_init_verbs },
14540                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14541                 .dac_nids = alc662_dac_nids,
14542                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14543                 .channel_mode = alc662_3ST_2ch_modes,
14544                 .input_mux = &alc662_eeepc_capture_source,
14545                 .unsol_event = alc662_eeepc_unsol_event,
14546                 .init_hook = alc662_eeepc_inithook,
14547         },
14548         [ALC662_ASUS_EEEPC_EP20] = {
14549                 .mixers = { alc662_eeepc_ep20_mixer, alc662_capture_mixer,
14550                             alc662_chmode_mixer },
14551                 .init_verbs = { alc662_init_verbs,
14552                                 alc662_eeepc_ep20_sue_init_verbs },
14553                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14554                 .dac_nids = alc662_dac_nids,
14555                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
14556                 .channel_mode = alc662_3ST_6ch_modes,
14557                 .input_mux = &alc662_lenovo_101e_capture_source,
14558                 .unsol_event = alc662_eeepc_ep20_unsol_event,
14559                 .init_hook = alc662_eeepc_ep20_inithook,
14560         },
14561         [ALC663_ASUS_M51VA] = {
14562                 .mixers = { alc663_m51va_mixer, alc662_capture_mixer},
14563                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
14564                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14565                 .dac_nids = alc662_dac_nids,
14566                 .dig_out_nid = ALC662_DIGOUT_NID,
14567                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14568                 .channel_mode = alc662_3ST_2ch_modes,
14569                 .input_mux = &alc663_m51va_capture_source,
14570                 .unsol_event = alc663_m51va_unsol_event,
14571                 .init_hook = alc663_m51va_inithook,
14572         },
14573         [ALC663_ASUS_G71V] = {
14574                 .mixers = { alc663_g71v_mixer, alc662_capture_mixer},
14575                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
14576                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14577                 .dac_nids = alc662_dac_nids,
14578                 .dig_out_nid = ALC662_DIGOUT_NID,
14579                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14580                 .channel_mode = alc662_3ST_2ch_modes,
14581                 .input_mux = &alc662_eeepc_capture_source,
14582                 .unsol_event = alc663_g71v_unsol_event,
14583                 .init_hook = alc663_g71v_inithook,
14584         },
14585         [ALC663_ASUS_H13] = {
14586                 .mixers = { alc663_m51va_mixer, alc662_capture_mixer},
14587                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
14588                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14589                 .dac_nids = alc662_dac_nids,
14590                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14591                 .channel_mode = alc662_3ST_2ch_modes,
14592                 .input_mux = &alc663_m51va_capture_source,
14593                 .unsol_event = alc663_m51va_unsol_event,
14594                 .init_hook = alc663_m51va_inithook,
14595         },
14596         [ALC663_ASUS_G50V] = {
14597                 .mixers = { alc663_g50v_mixer, alc662_capture_mixer},
14598                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
14599                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14600                 .dac_nids = alc662_dac_nids,
14601                 .dig_out_nid = ALC662_DIGOUT_NID,
14602                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
14603                 .channel_mode = alc662_3ST_6ch_modes,
14604                 .input_mux = &alc663_capture_source,
14605                 .unsol_event = alc663_g50v_unsol_event,
14606                 .init_hook = alc663_g50v_inithook,
14607         },
14608 };
14609
14610
14611 /*
14612  * BIOS auto configuration
14613  */
14614
14615 /* add playback controls from the parsed DAC table */
14616 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
14617                                              const struct auto_pin_cfg *cfg)
14618 {
14619         char name[32];
14620         static const char *chname[4] = {
14621                 "Front", "Surround", NULL /*CLFE*/, "Side"
14622         };
14623         hda_nid_t nid;
14624         int i, err;
14625
14626         for (i = 0; i < cfg->line_outs; i++) {
14627                 if (!spec->multiout.dac_nids[i])
14628                         continue;
14629                 nid = alc880_idx_to_dac(i);
14630                 if (i == 2) {
14631                         /* Center/LFE */
14632                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14633                                           "Center Playback Volume",
14634                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
14635                                                               HDA_OUTPUT));
14636                         if (err < 0)
14637                                 return err;
14638                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14639                                           "LFE Playback Volume",
14640                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
14641                                                               HDA_OUTPUT));
14642                         if (err < 0)
14643                                 return err;
14644                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14645                                           "Center Playback Switch",
14646                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
14647                                                               HDA_INPUT));
14648                         if (err < 0)
14649                                 return err;
14650                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14651                                           "LFE Playback Switch",
14652                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
14653                                                               HDA_INPUT));
14654                         if (err < 0)
14655                                 return err;
14656                 } else {
14657                         sprintf(name, "%s Playback Volume", chname[i]);
14658                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14659                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
14660                                                               HDA_OUTPUT));
14661                         if (err < 0)
14662                                 return err;
14663                         sprintf(name, "%s Playback Switch", chname[i]);
14664                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14665                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
14666                                                               HDA_INPUT));
14667                         if (err < 0)
14668                                 return err;
14669                 }
14670         }
14671         return 0;
14672 }
14673
14674 /* add playback controls for speaker and HP outputs */
14675 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
14676                                         const char *pfx)
14677 {
14678         hda_nid_t nid;
14679         int err;
14680         char name[32];
14681
14682         if (!pin)
14683                 return 0;
14684
14685         if (pin == 0x17) {
14686                 /* ALC663 has a mono output pin on 0x17 */
14687                 sprintf(name, "%s Playback Switch", pfx);
14688                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14689                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
14690                 return err;
14691         }
14692
14693         if (alc880_is_fixed_pin(pin)) {
14694                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14695                 /* printk("DAC nid=%x\n",nid); */
14696                 /* specify the DAC as the extra output */
14697                 if (!spec->multiout.hp_nid)
14698                         spec->multiout.hp_nid = nid;
14699                 else
14700                         spec->multiout.extra_out_nid[0] = nid;
14701                 /* control HP volume/switch on the output mixer amp */
14702                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14703                 sprintf(name, "%s Playback Volume", pfx);
14704                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14705                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
14706                 if (err < 0)
14707                         return err;
14708                 sprintf(name, "%s Playback Switch", pfx);
14709                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14710                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
14711                 if (err < 0)
14712                         return err;
14713         } else if (alc880_is_multi_pin(pin)) {
14714                 /* set manual connection */
14715                 /* we have only a switch on HP-out PIN */
14716                 sprintf(name, "%s Playback Switch", pfx);
14717                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14718                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
14719                 if (err < 0)
14720                         return err;
14721         }
14722         return 0;
14723 }
14724
14725 /* create playback/capture controls for input pins */
14726 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
14727                                                 const struct auto_pin_cfg *cfg)
14728 {
14729         struct hda_input_mux *imux = &spec->private_imux;
14730         int i, err, idx;
14731
14732         for (i = 0; i < AUTO_PIN_LAST; i++) {
14733                 if (alc880_is_input_pin(cfg->input_pins[i])) {
14734                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
14735                         err = new_analog_input(spec, cfg->input_pins[i],
14736                                                auto_pin_cfg_labels[i],
14737                                                idx, 0x0b);
14738                         if (err < 0)
14739                                 return err;
14740                         imux->items[imux->num_items].label =
14741                                 auto_pin_cfg_labels[i];
14742                         imux->items[imux->num_items].index =
14743                                 alc880_input_pin_idx(cfg->input_pins[i]);
14744                         imux->num_items++;
14745                 }
14746         }
14747         return 0;
14748 }
14749
14750 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
14751                                               hda_nid_t nid, int pin_type,
14752                                               int dac_idx)
14753 {
14754         alc_set_pin_output(codec, nid, pin_type);
14755         /* need the manual connection? */
14756         if (alc880_is_multi_pin(nid)) {
14757                 struct alc_spec *spec = codec->spec;
14758                 int idx = alc880_multi_pin_idx(nid);
14759                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
14760                                     AC_VERB_SET_CONNECT_SEL,
14761                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
14762         }
14763 }
14764
14765 static void alc662_auto_init_multi_out(struct hda_codec *codec)
14766 {
14767         struct alc_spec *spec = codec->spec;
14768         int i;
14769
14770         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
14771         for (i = 0; i <= HDA_SIDE; i++) {
14772                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14773                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14774                 if (nid)
14775                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
14776                                                           i);
14777         }
14778 }
14779
14780 static void alc662_auto_init_hp_out(struct hda_codec *codec)
14781 {
14782         struct alc_spec *spec = codec->spec;
14783         hda_nid_t pin;
14784
14785         pin = spec->autocfg.hp_pins[0];
14786         if (pin) /* connect to front */
14787                 /* use dac 0 */
14788                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
14789         pin = spec->autocfg.speaker_pins[0];
14790         if (pin)
14791                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14792 }
14793
14794 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
14795 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
14796
14797 static void alc662_auto_init_analog_input(struct hda_codec *codec)
14798 {
14799         struct alc_spec *spec = codec->spec;
14800         int i;
14801
14802         for (i = 0; i < AUTO_PIN_LAST; i++) {
14803                 hda_nid_t nid = spec->autocfg.input_pins[i];
14804                 if (alc662_is_input_pin(nid)) {
14805                         snd_hda_codec_write(codec, nid, 0,
14806                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
14807                                             (i <= AUTO_PIN_FRONT_MIC ?
14808                                              PIN_VREF80 : PIN_IN));
14809                         if (nid != ALC662_PIN_CD_NID)
14810                                 snd_hda_codec_write(codec, nid, 0,
14811                                                     AC_VERB_SET_AMP_GAIN_MUTE,
14812                                                     AMP_OUT_MUTE);
14813                 }
14814         }
14815 }
14816
14817 #define alc662_auto_init_input_src      alc882_auto_init_input_src
14818
14819 static int alc662_parse_auto_config(struct hda_codec *codec)
14820 {
14821         struct alc_spec *spec = codec->spec;
14822         int err;
14823         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
14824
14825         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14826                                            alc662_ignore);
14827         if (err < 0)
14828                 return err;
14829         if (!spec->autocfg.line_outs)
14830                 return 0; /* can't find valid BIOS pin config */
14831
14832         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
14833         if (err < 0)
14834                 return err;
14835         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
14836         if (err < 0)
14837                 return err;
14838         err = alc662_auto_create_extra_out(spec,
14839                                            spec->autocfg.speaker_pins[0],
14840                                            "Speaker");
14841         if (err < 0)
14842                 return err;
14843         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
14844                                            "Headphone");
14845         if (err < 0)
14846                 return err;
14847         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
14848         if (err < 0)
14849                 return err;
14850
14851         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14852
14853         if (spec->autocfg.dig_out_pin)
14854                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
14855
14856         if (spec->kctl_alloc)
14857                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
14858
14859         spec->num_mux_defs = 1;
14860         spec->input_mux = &spec->private_imux;
14861
14862         spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs;
14863         if (codec->vendor_id == 0x10ec0663)
14864                 spec->init_verbs[spec->num_init_verbs++] =
14865                         alc663_auto_init_verbs;
14866
14867         err = alc_auto_add_mic_boost(codec);
14868         if (err < 0)
14869                 return err;
14870
14871         spec->mixers[spec->num_mixers] = alc662_capture_mixer;
14872         spec->num_mixers++;
14873         return 1;
14874 }
14875
14876 /* additional initialization for auto-configuration model */
14877 static void alc662_auto_init(struct hda_codec *codec)
14878 {
14879         struct alc_spec *spec = codec->spec;
14880         alc662_auto_init_multi_out(codec);
14881         alc662_auto_init_hp_out(codec);
14882         alc662_auto_init_analog_input(codec);
14883         alc662_auto_init_input_src(codec);
14884         if (spec->unsol_event)
14885                 alc_sku_automute(codec);
14886 }
14887
14888 static int patch_alc662(struct hda_codec *codec)
14889 {
14890         struct alc_spec *spec;
14891         int err, board_config;
14892
14893         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14894         if (!spec)
14895                 return -ENOMEM;
14896
14897         codec->spec = spec;
14898
14899         alc_fix_pll_init(codec, 0x20, 0x04, 15);
14900
14901         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
14902                                                   alc662_models,
14903                                                   alc662_cfg_tbl);
14904         if (board_config < 0) {
14905                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
14906                        "trying auto-probe from BIOS...\n");
14907                 board_config = ALC662_AUTO;
14908         }
14909
14910         if (board_config == ALC662_AUTO) {
14911                 /* automatic parse from the BIOS config */
14912                 err = alc662_parse_auto_config(codec);
14913                 if (err < 0) {
14914                         alc_free(codec);
14915                         return err;
14916                 } else if (!err) {
14917                         printk(KERN_INFO
14918                                "hda_codec: Cannot set up configuration "
14919                                "from BIOS.  Using base mode...\n");
14920                         board_config = ALC662_3ST_2ch_DIG;
14921                 }
14922         }
14923
14924         if (board_config != ALC662_AUTO)
14925                 setup_preset(spec, &alc662_presets[board_config]);
14926
14927         if (codec->vendor_id == 0x10ec0663) {
14928                 spec->stream_name_analog = "ALC663 Analog";
14929                 spec->stream_name_digital = "ALC663 Digital";
14930         } else {
14931                 spec->stream_name_analog = "ALC662 Analog";
14932                 spec->stream_name_digital = "ALC662 Digital";
14933         }
14934
14935         spec->stream_analog_playback = &alc662_pcm_analog_playback;
14936         spec->stream_analog_capture = &alc662_pcm_analog_capture;
14937
14938         spec->stream_digital_playback = &alc662_pcm_digital_playback;
14939         spec->stream_digital_capture = &alc662_pcm_digital_capture;
14940
14941         spec->adc_nids = alc662_adc_nids;
14942         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
14943         spec->capsrc_nids = alc662_capsrc_nids;
14944
14945         spec->vmaster_nid = 0x02;
14946
14947         codec->patch_ops = alc_patch_ops;
14948         if (board_config == ALC662_AUTO)
14949                 spec->init_hook = alc662_auto_init;
14950 #ifdef CONFIG_SND_HDA_POWER_SAVE
14951         if (!spec->loopback.amplist)
14952                 spec->loopback.amplist = alc662_loopbacks;
14953 #endif
14954
14955         return 0;
14956 }
14957
14958 /*
14959  * patch entries
14960  */
14961 struct hda_codec_preset snd_hda_preset_realtek[] = {
14962         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
14963         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
14964         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
14965         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
14966         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
14967         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
14968           .patch = patch_alc861 },
14969         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
14970         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
14971         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
14972         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
14973           .patch = patch_alc883 },
14974         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
14975           .patch = patch_alc662 },
14976         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
14977         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
14978         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
14979         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
14980         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
14981           .patch = patch_alc882 }, /* should be patch_alc883() in future */
14982         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
14983         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
14984         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
14985         {} /* terminator */
14986 };