ALSA: hda: appletv support
[pandora-kernel.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         spec->unsol_event = alc_sku_unsol_event;
1011 }
1012
1013 /*
1014  * Fix-up pin default configurations
1015  */
1016
1017 struct alc_pincfg {
1018         hda_nid_t nid;
1019         u32 val;
1020 };
1021
1022 static void alc_fix_pincfg(struct hda_codec *codec,
1023                            const struct snd_pci_quirk *quirk,
1024                            const struct alc_pincfg **pinfix)
1025 {
1026         const struct alc_pincfg *cfg;
1027
1028         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1029         if (!quirk)
1030                 return;
1031
1032         cfg = pinfix[quirk->value];
1033         for (; cfg->nid; cfg++) {
1034                 int i;
1035                 u32 val = cfg->val;
1036                 for (i = 0; i < 4; i++) {
1037                         snd_hda_codec_write(codec, cfg->nid, 0,
1038                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
1039                                     val & 0xff);
1040                         val >>= 8;
1041                 }
1042         }
1043 }
1044
1045 /*
1046  * ALC880 3-stack model
1047  *
1048  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1049  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1050  *                 F-Mic = 0x1b, HP = 0x19
1051  */
1052
1053 static hda_nid_t alc880_dac_nids[4] = {
1054         /* front, rear, clfe, rear_surr */
1055         0x02, 0x05, 0x04, 0x03
1056 };
1057
1058 static hda_nid_t alc880_adc_nids[3] = {
1059         /* ADC0-2 */
1060         0x07, 0x08, 0x09,
1061 };
1062
1063 /* The datasheet says the node 0x07 is connected from inputs,
1064  * but it shows zero connection in the real implementation on some devices.
1065  * Note: this is a 915GAV bug, fixed on 915GLV
1066  */
1067 static hda_nid_t alc880_adc_nids_alt[2] = {
1068         /* ADC1-2 */
1069         0x08, 0x09,
1070 };
1071
1072 #define ALC880_DIGOUT_NID       0x06
1073 #define ALC880_DIGIN_NID        0x0a
1074
1075 static struct hda_input_mux alc880_capture_source = {
1076         .num_items = 4,
1077         .items = {
1078                 { "Mic", 0x0 },
1079                 { "Front Mic", 0x3 },
1080                 { "Line", 0x2 },
1081                 { "CD", 0x4 },
1082         },
1083 };
1084
1085 /* channel source setting (2/6 channel selection for 3-stack) */
1086 /* 2ch mode */
1087 static struct hda_verb alc880_threestack_ch2_init[] = {
1088         /* set line-in to input, mute it */
1089         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1090         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1091         /* set mic-in to input vref 80%, mute it */
1092         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1093         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1094         { } /* end */
1095 };
1096
1097 /* 6ch mode */
1098 static struct hda_verb alc880_threestack_ch6_init[] = {
1099         /* set line-in to output, unmute it */
1100         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1101         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1102         /* set mic-in to output, unmute it */
1103         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1104         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1105         { } /* end */
1106 };
1107
1108 static struct hda_channel_mode alc880_threestack_modes[2] = {
1109         { 2, alc880_threestack_ch2_init },
1110         { 6, alc880_threestack_ch6_init },
1111 };
1112
1113 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1114         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1115         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1116         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1117         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1118         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1119         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1120         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1121         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1122         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1123         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1124         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1125         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1126         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1127         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1128         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1129         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1130         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1131         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1132         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1133         {
1134                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1135                 .name = "Channel Mode",
1136                 .info = alc_ch_mode_info,
1137                 .get = alc_ch_mode_get,
1138                 .put = alc_ch_mode_put,
1139         },
1140         { } /* end */
1141 };
1142
1143 /* capture mixer elements */
1144 static struct snd_kcontrol_new alc880_capture_mixer[] = {
1145         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
1146         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
1147         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
1148         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
1149         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
1150         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
1151         {
1152                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1153                 /* The multiple "Capture Source" controls confuse alsamixer
1154                  * So call somewhat different..
1155                  */
1156                 /* .name = "Capture Source", */
1157                 .name = "Input Source",
1158                 .count = 3,
1159                 .info = alc_mux_enum_info,
1160                 .get = alc_mux_enum_get,
1161                 .put = alc_mux_enum_put,
1162         },
1163         { } /* end */
1164 };
1165
1166 /* capture mixer elements (in case NID 0x07 not available) */
1167 static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
1168         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1169         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1170         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
1171         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
1172         {
1173                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1174                 /* The multiple "Capture Source" controls confuse alsamixer
1175                  * So call somewhat different..
1176                  */
1177                 /* .name = "Capture Source", */
1178                 .name = "Input Source",
1179                 .count = 2,
1180                 .info = alc_mux_enum_info,
1181                 .get = alc_mux_enum_get,
1182                 .put = alc_mux_enum_put,
1183         },
1184         { } /* end */
1185 };
1186
1187
1188
1189 /*
1190  * ALC880 5-stack model
1191  *
1192  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1193  *      Side = 0x02 (0xd)
1194  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1195  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1196  */
1197
1198 /* additional mixers to alc880_three_stack_mixer */
1199 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1200         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1201         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1202         { } /* end */
1203 };
1204
1205 /* channel source setting (6/8 channel selection for 5-stack) */
1206 /* 6ch mode */
1207 static struct hda_verb alc880_fivestack_ch6_init[] = {
1208         /* set line-in to input, mute it */
1209         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1210         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1211         { } /* end */
1212 };
1213
1214 /* 8ch mode */
1215 static struct hda_verb alc880_fivestack_ch8_init[] = {
1216         /* set line-in to output, unmute it */
1217         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1218         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1219         { } /* end */
1220 };
1221
1222 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1223         { 6, alc880_fivestack_ch6_init },
1224         { 8, alc880_fivestack_ch8_init },
1225 };
1226
1227
1228 /*
1229  * ALC880 6-stack model
1230  *
1231  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1232  *      Side = 0x05 (0x0f)
1233  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1234  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1235  */
1236
1237 static hda_nid_t alc880_6st_dac_nids[4] = {
1238         /* front, rear, clfe, rear_surr */
1239         0x02, 0x03, 0x04, 0x05
1240 };
1241
1242 static struct hda_input_mux alc880_6stack_capture_source = {
1243         .num_items = 4,
1244         .items = {
1245                 { "Mic", 0x0 },
1246                 { "Front Mic", 0x1 },
1247                 { "Line", 0x2 },
1248                 { "CD", 0x4 },
1249         },
1250 };
1251
1252 /* fixed 8-channels */
1253 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1254         { 8, NULL },
1255 };
1256
1257 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1258         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1259         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1260         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1261         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1262         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1263         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1264         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1265         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1266         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1267         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1268         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1269         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1270         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1271         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1272         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1273         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1274         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1275         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1276         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1277         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1278         {
1279                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1280                 .name = "Channel Mode",
1281                 .info = alc_ch_mode_info,
1282                 .get = alc_ch_mode_get,
1283                 .put = alc_ch_mode_put,
1284         },
1285         { } /* end */
1286 };
1287
1288
1289 /*
1290  * ALC880 W810 model
1291  *
1292  * W810 has rear IO for:
1293  * Front (DAC 02)
1294  * Surround (DAC 03)
1295  * Center/LFE (DAC 04)
1296  * Digital out (06)
1297  *
1298  * The system also has a pair of internal speakers, and a headphone jack.
1299  * These are both connected to Line2 on the codec, hence to DAC 02.
1300  * 
1301  * There is a variable resistor to control the speaker or headphone
1302  * volume. This is a hardware-only device without a software API.
1303  *
1304  * Plugging headphones in will disable the internal speakers. This is
1305  * implemented in hardware, not via the driver using jack sense. In
1306  * a similar fashion, plugging into the rear socket marked "front" will
1307  * disable both the speakers and headphones.
1308  *
1309  * For input, there's a microphone jack, and an "audio in" jack.
1310  * These may not do anything useful with this driver yet, because I
1311  * haven't setup any initialization verbs for these yet...
1312  */
1313
1314 static hda_nid_t alc880_w810_dac_nids[3] = {
1315         /* front, rear/surround, clfe */
1316         0x02, 0x03, 0x04
1317 };
1318
1319 /* fixed 6 channels */
1320 static struct hda_channel_mode alc880_w810_modes[1] = {
1321         { 6, NULL }
1322 };
1323
1324 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1325 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1326         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1327         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1328         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1329         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1330         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1331         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1332         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1333         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1334         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1335         { } /* end */
1336 };
1337
1338
1339 /*
1340  * Z710V model
1341  *
1342  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1343  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1344  *                 Line = 0x1a
1345  */
1346
1347 static hda_nid_t alc880_z71v_dac_nids[1] = {
1348         0x02
1349 };
1350 #define ALC880_Z71V_HP_DAC      0x03
1351
1352 /* fixed 2 channels */
1353 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1354         { 2, NULL }
1355 };
1356
1357 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1358         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1359         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1360         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1361         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1362         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1363         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1364         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1365         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1366         { } /* end */
1367 };
1368
1369
1370 /*
1371  * ALC880 F1734 model
1372  *
1373  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1374  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1375  */
1376
1377 static hda_nid_t alc880_f1734_dac_nids[1] = {
1378         0x03
1379 };
1380 #define ALC880_F1734_HP_DAC     0x02
1381
1382 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1383         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1384         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1385         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1386         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1387         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1388         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1389         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1390         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1391         { } /* end */
1392 };
1393
1394 static struct hda_input_mux alc880_f1734_capture_source = {
1395         .num_items = 2,
1396         .items = {
1397                 { "Mic", 0x1 },
1398                 { "CD", 0x4 },
1399         },
1400 };
1401
1402
1403 /*
1404  * ALC880 ASUS model
1405  *
1406  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1407  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1408  *  Mic = 0x18, Line = 0x1a
1409  */
1410
1411 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1412 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1413
1414 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1415         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1416         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1417         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1418         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1419         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1420         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1421         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1422         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1423         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1424         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1425         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1426         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1427         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1428         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1429         {
1430                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1431                 .name = "Channel Mode",
1432                 .info = alc_ch_mode_info,
1433                 .get = alc_ch_mode_get,
1434                 .put = alc_ch_mode_put,
1435         },
1436         { } /* end */
1437 };
1438
1439 /*
1440  * ALC880 ASUS W1V model
1441  *
1442  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1443  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1444  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1445  */
1446
1447 /* additional mixers to alc880_asus_mixer */
1448 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1449         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1450         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1451         { } /* end */
1452 };
1453
1454 /* additional mixers to alc880_asus_mixer */
1455 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1456         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1457         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1458         { } /* end */
1459 };
1460
1461 /* TCL S700 */
1462 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1463         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1464         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1465         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1466         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1467         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1468         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1469         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1470         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1471         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1472         {
1473                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1474                 /* The multiple "Capture Source" controls confuse alsamixer
1475                  * So call somewhat different..
1476                  */
1477                 /* .name = "Capture Source", */
1478                 .name = "Input Source",
1479                 .count = 1,
1480                 .info = alc_mux_enum_info,
1481                 .get = alc_mux_enum_get,
1482                 .put = alc_mux_enum_put,
1483         },
1484         { } /* end */
1485 };
1486
1487 /* Uniwill */
1488 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1489         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1490         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1491         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1492         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1493         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1494         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1495         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1496         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1497         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1498         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1499         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1500         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1501         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1502         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1503         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1504         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1505         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1506         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1507         {
1508                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1509                 .name = "Channel Mode",
1510                 .info = alc_ch_mode_info,
1511                 .get = alc_ch_mode_get,
1512                 .put = alc_ch_mode_put,
1513         },
1514         { } /* end */
1515 };
1516
1517 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1518         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1519         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1520         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1521         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1522         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1523         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1524         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1525         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1526         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1527         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1528         { } /* end */
1529 };
1530
1531 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1532         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1533         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1534         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1535         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1536         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1537         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1538         { } /* end */
1539 };
1540
1541 /*
1542  * virtual master controls
1543  */
1544
1545 /*
1546  * slave controls for virtual master
1547  */
1548 static const char *alc_slave_vols[] = {
1549         "Front Playback Volume",
1550         "Surround Playback Volume",
1551         "Center Playback Volume",
1552         "LFE Playback Volume",
1553         "Side Playback Volume",
1554         "Headphone Playback Volume",
1555         "Speaker Playback Volume",
1556         "Mono Playback Volume",
1557         "Line-Out Playback Volume",
1558         NULL,
1559 };
1560
1561 static const char *alc_slave_sws[] = {
1562         "Front Playback Switch",
1563         "Surround Playback Switch",
1564         "Center Playback Switch",
1565         "LFE Playback Switch",
1566         "Side Playback Switch",
1567         "Headphone Playback Switch",
1568         "Speaker Playback Switch",
1569         "Mono Playback Switch",
1570         "IEC958 Playback Switch",
1571         NULL,
1572 };
1573
1574 /*
1575  * build control elements
1576  */
1577 static int alc_build_controls(struct hda_codec *codec)
1578 {
1579         struct alc_spec *spec = codec->spec;
1580         int err;
1581         int i;
1582
1583         for (i = 0; i < spec->num_mixers; i++) {
1584                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1585                 if (err < 0)
1586                         return err;
1587         }
1588
1589         if (spec->multiout.dig_out_nid) {
1590                 err = snd_hda_create_spdif_out_ctls(codec,
1591                                                     spec->multiout.dig_out_nid);
1592                 if (err < 0)
1593                         return err;
1594                 err = snd_hda_create_spdif_share_sw(codec,
1595                                                     &spec->multiout);
1596                 if (err < 0)
1597                         return err;
1598                 spec->multiout.share_spdif = 1;
1599         }
1600         if (spec->dig_in_nid) {
1601                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1602                 if (err < 0)
1603                         return err;
1604         }
1605
1606         /* if we have no master control, let's create it */
1607         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1608                 unsigned int vmaster_tlv[4];
1609                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1610                                         HDA_OUTPUT, vmaster_tlv);
1611                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1612                                           vmaster_tlv, alc_slave_vols);
1613                 if (err < 0)
1614                         return err;
1615         }
1616         if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1617                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1618                                           NULL, alc_slave_sws);
1619                 if (err < 0)
1620                         return err;
1621         }
1622
1623         return 0;
1624 }
1625
1626
1627 /*
1628  * initialize the codec volumes, etc
1629  */
1630
1631 /*
1632  * generic initialization of ADC, input mixers and output mixers
1633  */
1634 static struct hda_verb alc880_volume_init_verbs[] = {
1635         /*
1636          * Unmute ADC0-2 and set the default input to mic-in
1637          */
1638         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
1639         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1640         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
1641         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1642         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1643         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1644
1645         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1646          * mixer widget
1647          * Note: PASD motherboards uses the Line In 2 as the input for front
1648          * panel mic (mic 2)
1649          */
1650         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
1651         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1652         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1653         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1654         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1655         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1656         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1657         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1658
1659         /*
1660          * Set up output mixers (0x0c - 0x0f)
1661          */
1662         /* set vol=0 to output mixers */
1663         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1664         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1665         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1666         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1667         /* set up input amps for analog loopback */
1668         /* Amp Indices: DAC = 0, mixer = 1 */
1669         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1670         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1671         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1672         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1673         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1674         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1675         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1676         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1677
1678         { }
1679 };
1680
1681 /*
1682  * 3-stack pin configuration:
1683  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
1684  */
1685 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
1686         /*
1687          * preset connection lists of input pins
1688          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1689          */
1690         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1691         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1692         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1693
1694         /*
1695          * Set pin mode and muting
1696          */
1697         /* set front pin widgets 0x14 for output */
1698         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1699         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1700         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1701         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1702         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1703         /* Mic2 (as headphone out) for HP output */
1704         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1705         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1706         /* Line In pin widget for input */
1707         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1708         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1709         /* Line2 (as front mic) pin widget for input and vref at 80% */
1710         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1711         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1712         /* CD pin widget for input */
1713         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1714
1715         { }
1716 };
1717
1718 /*
1719  * 5-stack pin configuration:
1720  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
1721  * line-in/side = 0x1a, f-mic = 0x1b
1722  */
1723 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
1724         /*
1725          * preset connection lists of input pins
1726          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1727          */
1728         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1729         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1730
1731         /*
1732          * Set pin mode and muting
1733          */
1734         /* set pin widgets 0x14-0x17 for output */
1735         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1736         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1737         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1738         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1739         /* unmute pins for output (no gain on this amp) */
1740         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1741         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1742         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1743         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1744
1745         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1746         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1747         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1748         /* Mic2 (as headphone out) for HP output */
1749         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1750         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1751         /* Line In pin widget for input */
1752         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1753         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1754         /* Line2 (as front mic) pin widget for input and vref at 80% */
1755         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1756         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1757         /* CD pin widget for input */
1758         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1759
1760         { }
1761 };
1762
1763 /*
1764  * W810 pin configuration:
1765  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
1766  */
1767 static struct hda_verb alc880_pin_w810_init_verbs[] = {
1768         /* hphone/speaker input selector: front DAC */
1769         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1770
1771         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1772         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1773         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1774         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1775         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1776         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1777
1778         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1779         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1780
1781         { }
1782 };
1783
1784 /*
1785  * Z71V pin configuration:
1786  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
1787  */
1788 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
1789         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1790         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1791         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1792         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1793
1794         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1795         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1796         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1797         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1798
1799         { }
1800 };
1801
1802 /*
1803  * 6-stack pin configuration:
1804  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
1805  * f-mic = 0x19, line = 0x1a, HP = 0x1b
1806  */
1807 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1808         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1809
1810         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1811         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1812         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1813         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1814         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1815         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1816         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1817         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1818
1819         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1820         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1821         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1822         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1823         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1824         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1825         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1826         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1827         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1828         
1829         { }
1830 };
1831
1832 /*
1833  * Uniwill pin configuration:
1834  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
1835  * line = 0x1a
1836  */
1837 static struct hda_verb alc880_uniwill_init_verbs[] = {
1838         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1839
1840         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1841         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1842         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1843         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1844         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1845         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1846         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1847         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1848         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1849         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1850         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1851         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1852         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1853         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1854
1855         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1856         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1857         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1858         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1859         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1860         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1861         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
1862         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
1863         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1864
1865         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1866         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
1867
1868         { }
1869 };
1870
1871 /*
1872 * Uniwill P53
1873 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19, 
1874  */
1875 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
1876         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1877
1878         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1879         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1880         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1881         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1882         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1883         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1884         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1885         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1886         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1887         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1888         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1889         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1890
1891         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1892         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1893         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1894         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1895         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1896         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1897
1898         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1899         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
1900
1901         { }
1902 };
1903
1904 static struct hda_verb alc880_beep_init_verbs[] = {
1905         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
1906         { }
1907 };
1908
1909 /* toggle speaker-output according to the hp-jack state */
1910 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
1911 {
1912         unsigned int present;
1913         unsigned char bits;
1914
1915         present = snd_hda_codec_read(codec, 0x14, 0,
1916                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1917         bits = present ? HDA_AMP_MUTE : 0;
1918         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1919                                  HDA_AMP_MUTE, bits);
1920         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
1921                                  HDA_AMP_MUTE, bits);
1922 }
1923
1924 /* auto-toggle front mic */
1925 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
1926 {
1927         unsigned int present;
1928         unsigned char bits;
1929
1930         present = snd_hda_codec_read(codec, 0x18, 0,
1931                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1932         bits = present ? HDA_AMP_MUTE : 0;
1933         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
1934 }
1935
1936 static void alc880_uniwill_automute(struct hda_codec *codec)
1937 {
1938         alc880_uniwill_hp_automute(codec);
1939         alc880_uniwill_mic_automute(codec);
1940 }
1941
1942 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
1943                                        unsigned int res)
1944 {
1945         /* Looks like the unsol event is incompatible with the standard
1946          * definition.  4bit tag is placed at 28 bit!
1947          */
1948         switch (res >> 28) {
1949         case ALC880_HP_EVENT:
1950                 alc880_uniwill_hp_automute(codec);
1951                 break;
1952         case ALC880_MIC_EVENT:
1953                 alc880_uniwill_mic_automute(codec);
1954                 break;
1955         }
1956 }
1957
1958 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
1959 {
1960         unsigned int present;
1961         unsigned char bits;
1962
1963         present = snd_hda_codec_read(codec, 0x14, 0,
1964                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1965         bits = present ? HDA_AMP_MUTE : 0;
1966         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
1967 }
1968
1969 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
1970 {
1971         unsigned int present;
1972         
1973         present = snd_hda_codec_read(codec, 0x21, 0,
1974                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
1975         present &= HDA_AMP_VOLMASK;
1976         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
1977                                  HDA_AMP_VOLMASK, present);
1978         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
1979                                  HDA_AMP_VOLMASK, present);
1980 }
1981
1982 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
1983                                            unsigned int res)
1984 {
1985         /* Looks like the unsol event is incompatible with the standard
1986          * definition.  4bit tag is placed at 28 bit!
1987          */
1988         if ((res >> 28) == ALC880_HP_EVENT)
1989                 alc880_uniwill_p53_hp_automute(codec);
1990         if ((res >> 28) == ALC880_DCVOL_EVENT)
1991                 alc880_uniwill_p53_dcvol_automute(codec);
1992 }
1993
1994 /*
1995  * F1734 pin configuration:
1996  * HP = 0x14, speaker-out = 0x15, mic = 0x18
1997  */
1998 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1999         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2000         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2001         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2002         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2003         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2004
2005         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2006         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2007         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2008         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2009
2010         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2011         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2012         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2013         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2014         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2015         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2016         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2017         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2018         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2019
2020         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2021         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2022
2023         { }
2024 };
2025
2026 /*
2027  * ASUS pin configuration:
2028  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2029  */
2030 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2031         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2032         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2033         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2034         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2035
2036         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2037         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2038         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2039         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2040         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2041         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2042         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2043         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2044
2045         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2046         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2047         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2048         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2049         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2050         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2051         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2052         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2053         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2054         
2055         { }
2056 };
2057
2058 /* Enable GPIO mask and set output */
2059 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2060 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2061
2062 /* Clevo m520g init */
2063 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2064         /* headphone output */
2065         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2066         /* line-out */
2067         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2068         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2069         /* Line-in */
2070         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2071         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2072         /* CD */
2073         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2074         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2075         /* Mic1 (rear panel) */
2076         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2077         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2078         /* Mic2 (front panel) */
2079         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2080         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2081         /* headphone */
2082         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2083         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2084         /* change to EAPD mode */
2085         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2086         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2087
2088         { }
2089 };
2090
2091 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2092         /* change to EAPD mode */
2093         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2094         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2095
2096         /* Headphone output */
2097         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2098         /* Front output*/
2099         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2100         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2101
2102         /* Line In pin widget for input */
2103         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2104         /* CD pin widget for input */
2105         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2106         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2107         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2108
2109         /* change to EAPD mode */
2110         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2111         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2112
2113         { }
2114 };
2115
2116 /*
2117  * LG m1 express dual
2118  *
2119  * Pin assignment:
2120  *   Rear Line-In/Out (blue): 0x14
2121  *   Build-in Mic-In: 0x15
2122  *   Speaker-out: 0x17
2123  *   HP-Out (green): 0x1b
2124  *   Mic-In/Out (red): 0x19
2125  *   SPDIF-Out: 0x1e
2126  */
2127
2128 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2129 static hda_nid_t alc880_lg_dac_nids[3] = {
2130         0x05, 0x02, 0x03
2131 };
2132
2133 /* seems analog CD is not working */
2134 static struct hda_input_mux alc880_lg_capture_source = {
2135         .num_items = 3,
2136         .items = {
2137                 { "Mic", 0x1 },
2138                 { "Line", 0x5 },
2139                 { "Internal Mic", 0x6 },
2140         },
2141 };
2142
2143 /* 2,4,6 channel modes */
2144 static struct hda_verb alc880_lg_ch2_init[] = {
2145         /* set line-in and mic-in to input */
2146         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2147         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2148         { }
2149 };
2150
2151 static struct hda_verb alc880_lg_ch4_init[] = {
2152         /* set line-in to out and mic-in to input */
2153         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2154         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2155         { }
2156 };
2157
2158 static struct hda_verb alc880_lg_ch6_init[] = {
2159         /* set line-in and mic-in to output */
2160         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2161         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2162         { }
2163 };
2164
2165 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2166         { 2, alc880_lg_ch2_init },
2167         { 4, alc880_lg_ch4_init },
2168         { 6, alc880_lg_ch6_init },
2169 };
2170
2171 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2172         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2173         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2174         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2175         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2176         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2177         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2178         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2179         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2180         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2181         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2182         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2183         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2184         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2185         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2186         {
2187                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2188                 .name = "Channel Mode",
2189                 .info = alc_ch_mode_info,
2190                 .get = alc_ch_mode_get,
2191                 .put = alc_ch_mode_put,
2192         },
2193         { } /* end */
2194 };
2195
2196 static struct hda_verb alc880_lg_init_verbs[] = {
2197         /* set capture source to mic-in */
2198         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2199         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2200         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2201         /* mute all amp mixer inputs */
2202         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2203         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2204         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2205         /* line-in to input */
2206         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2207         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2208         /* built-in mic */
2209         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2210         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2211         /* speaker-out */
2212         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2213         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2214         /* mic-in to input */
2215         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2216         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2217         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2218         /* HP-out */
2219         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2220         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2221         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2222         /* jack sense */
2223         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2224         { }
2225 };
2226
2227 /* toggle speaker-output according to the hp-jack state */
2228 static void alc880_lg_automute(struct hda_codec *codec)
2229 {
2230         unsigned int present;
2231         unsigned char bits;
2232
2233         present = snd_hda_codec_read(codec, 0x1b, 0,
2234                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2235         bits = present ? HDA_AMP_MUTE : 0;
2236         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2237                                  HDA_AMP_MUTE, bits);
2238 }
2239
2240 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2241 {
2242         /* Looks like the unsol event is incompatible with the standard
2243          * definition.  4bit tag is placed at 28 bit!
2244          */
2245         if ((res >> 28) == 0x01)
2246                 alc880_lg_automute(codec);
2247 }
2248
2249 /*
2250  * LG LW20
2251  *
2252  * Pin assignment:
2253  *   Speaker-out: 0x14
2254  *   Mic-In: 0x18
2255  *   Built-in Mic-In: 0x19
2256  *   Line-In: 0x1b
2257  *   HP-Out: 0x1a
2258  *   SPDIF-Out: 0x1e
2259  */
2260
2261 static struct hda_input_mux alc880_lg_lw_capture_source = {
2262         .num_items = 3,
2263         .items = {
2264                 { "Mic", 0x0 },
2265                 { "Internal Mic", 0x1 },
2266                 { "Line In", 0x2 },
2267         },
2268 };
2269
2270 #define alc880_lg_lw_modes alc880_threestack_modes
2271
2272 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2273         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2274         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2275         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2276         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2277         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2278         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2279         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2280         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2281         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2282         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2283         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2284         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2285         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2286         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2287         {
2288                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2289                 .name = "Channel Mode",
2290                 .info = alc_ch_mode_info,
2291                 .get = alc_ch_mode_get,
2292                 .put = alc_ch_mode_put,
2293         },
2294         { } /* end */
2295 };
2296
2297 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2298         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2299         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2300         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2301
2302         /* set capture source to mic-in */
2303         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2304         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2305         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2306         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2307         /* speaker-out */
2308         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2309         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2310         /* HP-out */
2311         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2312         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2313         /* mic-in to input */
2314         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2315         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2316         /* built-in mic */
2317         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2318         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2319         /* jack sense */
2320         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2321         { }
2322 };
2323
2324 /* toggle speaker-output according to the hp-jack state */
2325 static void alc880_lg_lw_automute(struct hda_codec *codec)
2326 {
2327         unsigned int present;
2328         unsigned char bits;
2329
2330         present = snd_hda_codec_read(codec, 0x1b, 0,
2331                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2332         bits = present ? HDA_AMP_MUTE : 0;
2333         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2334                                  HDA_AMP_MUTE, bits);
2335 }
2336
2337 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2338 {
2339         /* Looks like the unsol event is incompatible with the standard
2340          * definition.  4bit tag is placed at 28 bit!
2341          */
2342         if ((res >> 28) == 0x01)
2343                 alc880_lg_lw_automute(codec);
2344 }
2345
2346 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2347         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2348         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2349         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2350         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2351         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2352         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2353         { } /* end */
2354 };
2355
2356 static struct hda_input_mux alc880_medion_rim_capture_source = {
2357         .num_items = 2,
2358         .items = {
2359                 { "Mic", 0x0 },
2360                 { "Internal Mic", 0x1 },
2361         },
2362 };
2363
2364 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2365         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2366
2367         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2368         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2369
2370         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2371         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2372         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2373         /* Mic2 (as headphone out) for HP output */
2374         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2375         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2376         /* Internal Speaker */
2377         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2378         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2379
2380         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2381         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2382
2383         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2384         { }
2385 };
2386
2387 /* toggle speaker-output according to the hp-jack state */
2388 static void alc880_medion_rim_automute(struct hda_codec *codec)
2389 {
2390         unsigned int present;
2391         unsigned char bits;
2392
2393         present = snd_hda_codec_read(codec, 0x14, 0,
2394                                      AC_VERB_GET_PIN_SENSE, 0)
2395                 & AC_PINSENSE_PRESENCE;
2396         bits = present ? HDA_AMP_MUTE : 0;
2397         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2398                                  HDA_AMP_MUTE, bits);
2399         if (present)
2400                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2401         else
2402                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2403 }
2404
2405 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2406                                           unsigned int res)
2407 {
2408         /* Looks like the unsol event is incompatible with the standard
2409          * definition.  4bit tag is placed at 28 bit!
2410          */
2411         if ((res >> 28) == ALC880_HP_EVENT)
2412                 alc880_medion_rim_automute(codec);
2413 }
2414
2415 #ifdef CONFIG_SND_HDA_POWER_SAVE
2416 static struct hda_amp_list alc880_loopbacks[] = {
2417         { 0x0b, HDA_INPUT, 0 },
2418         { 0x0b, HDA_INPUT, 1 },
2419         { 0x0b, HDA_INPUT, 2 },
2420         { 0x0b, HDA_INPUT, 3 },
2421         { 0x0b, HDA_INPUT, 4 },
2422         { } /* end */
2423 };
2424
2425 static struct hda_amp_list alc880_lg_loopbacks[] = {
2426         { 0x0b, HDA_INPUT, 1 },
2427         { 0x0b, HDA_INPUT, 6 },
2428         { 0x0b, HDA_INPUT, 7 },
2429         { } /* end */
2430 };
2431 #endif
2432
2433 /*
2434  * Common callbacks
2435  */
2436
2437 static int alc_init(struct hda_codec *codec)
2438 {
2439         struct alc_spec *spec = codec->spec;
2440         unsigned int i;
2441
2442         alc_fix_pll(codec);
2443         if (codec->vendor_id == 0x10ec0888)
2444                 alc888_coef_init(codec);
2445
2446         for (i = 0; i < spec->num_init_verbs; i++)
2447                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2448
2449         if (spec->init_hook)
2450                 spec->init_hook(codec);
2451
2452         return 0;
2453 }
2454
2455 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2456 {
2457         struct alc_spec *spec = codec->spec;
2458
2459         if (spec->unsol_event)
2460                 spec->unsol_event(codec, res);
2461 }
2462
2463 #ifdef CONFIG_SND_HDA_POWER_SAVE
2464 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2465 {
2466         struct alc_spec *spec = codec->spec;
2467         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2468 }
2469 #endif
2470
2471 /*
2472  * Analog playback callbacks
2473  */
2474 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2475                                     struct hda_codec *codec,
2476                                     struct snd_pcm_substream *substream)
2477 {
2478         struct alc_spec *spec = codec->spec;
2479         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2480                                              hinfo);
2481 }
2482
2483 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2484                                        struct hda_codec *codec,
2485                                        unsigned int stream_tag,
2486                                        unsigned int format,
2487                                        struct snd_pcm_substream *substream)
2488 {
2489         struct alc_spec *spec = codec->spec;
2490         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2491                                                 stream_tag, format, substream);
2492 }
2493
2494 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2495                                        struct hda_codec *codec,
2496                                        struct snd_pcm_substream *substream)
2497 {
2498         struct alc_spec *spec = codec->spec;
2499         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2500 }
2501
2502 /*
2503  * Digital out
2504  */
2505 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2506                                         struct hda_codec *codec,
2507                                         struct snd_pcm_substream *substream)
2508 {
2509         struct alc_spec *spec = codec->spec;
2510         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2511 }
2512
2513 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2514                                            struct hda_codec *codec,
2515                                            unsigned int stream_tag,
2516                                            unsigned int format,
2517                                            struct snd_pcm_substream *substream)
2518 {
2519         struct alc_spec *spec = codec->spec;
2520         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2521                                              stream_tag, format, substream);
2522 }
2523
2524 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2525                                          struct hda_codec *codec,
2526                                          struct snd_pcm_substream *substream)
2527 {
2528         struct alc_spec *spec = codec->spec;
2529         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2530 }
2531
2532 /*
2533  * Analog capture
2534  */
2535 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2536                                       struct hda_codec *codec,
2537                                       unsigned int stream_tag,
2538                                       unsigned int format,
2539                                       struct snd_pcm_substream *substream)
2540 {
2541         struct alc_spec *spec = codec->spec;
2542
2543         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2544                                    stream_tag, 0, format);
2545         return 0;
2546 }
2547
2548 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2549                                       struct hda_codec *codec,
2550                                       struct snd_pcm_substream *substream)
2551 {
2552         struct alc_spec *spec = codec->spec;
2553
2554         snd_hda_codec_cleanup_stream(codec,
2555                                      spec->adc_nids[substream->number + 1]);
2556         return 0;
2557 }
2558
2559
2560 /*
2561  */
2562 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2563         .substreams = 1,
2564         .channels_min = 2,
2565         .channels_max = 8,
2566         /* NID is set in alc_build_pcms */
2567         .ops = {
2568                 .open = alc880_playback_pcm_open,
2569                 .prepare = alc880_playback_pcm_prepare,
2570                 .cleanup = alc880_playback_pcm_cleanup
2571         },
2572 };
2573
2574 static struct hda_pcm_stream alc880_pcm_analog_capture = {
2575         .substreams = 1,
2576         .channels_min = 2,
2577         .channels_max = 2,
2578         /* NID is set in alc_build_pcms */
2579 };
2580
2581 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
2582         .substreams = 1,
2583         .channels_min = 2,
2584         .channels_max = 2,
2585         /* NID is set in alc_build_pcms */
2586 };
2587
2588 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
2589         .substreams = 2, /* can be overridden */
2590         .channels_min = 2,
2591         .channels_max = 2,
2592         /* NID is set in alc_build_pcms */
2593         .ops = {
2594                 .prepare = alc880_alt_capture_pcm_prepare,
2595                 .cleanup = alc880_alt_capture_pcm_cleanup
2596         },
2597 };
2598
2599 static struct hda_pcm_stream alc880_pcm_digital_playback = {
2600         .substreams = 1,
2601         .channels_min = 2,
2602         .channels_max = 2,
2603         /* NID is set in alc_build_pcms */
2604         .ops = {
2605                 .open = alc880_dig_playback_pcm_open,
2606                 .close = alc880_dig_playback_pcm_close,
2607                 .prepare = alc880_dig_playback_pcm_prepare
2608         },
2609 };
2610
2611 static struct hda_pcm_stream alc880_pcm_digital_capture = {
2612         .substreams = 1,
2613         .channels_min = 2,
2614         .channels_max = 2,
2615         /* NID is set in alc_build_pcms */
2616 };
2617
2618 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2619 static struct hda_pcm_stream alc_pcm_null_stream = {
2620         .substreams = 0,
2621         .channels_min = 0,
2622         .channels_max = 0,
2623 };
2624
2625 static int alc_build_pcms(struct hda_codec *codec)
2626 {
2627         struct alc_spec *spec = codec->spec;
2628         struct hda_pcm *info = spec->pcm_rec;
2629         int i;
2630
2631         codec->num_pcms = 1;
2632         codec->pcm_info = info;
2633
2634         info->name = spec->stream_name_analog;
2635         if (spec->stream_analog_playback) {
2636                 snd_assert(spec->multiout.dac_nids, return -EINVAL);
2637                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
2638                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2639         }
2640         if (spec->stream_analog_capture) {
2641                 snd_assert(spec->adc_nids, return -EINVAL);
2642                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2643                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2644         }
2645
2646         if (spec->channel_mode) {
2647                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2648                 for (i = 0; i < spec->num_channel_mode; i++) {
2649                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2650                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2651                         }
2652                 }
2653         }
2654
2655         /* SPDIF for stream index #1 */
2656         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2657                 codec->num_pcms = 2;
2658                 info = spec->pcm_rec + 1;
2659                 info->name = spec->stream_name_digital;
2660                 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2661                 if (spec->multiout.dig_out_nid &&
2662                     spec->stream_digital_playback) {
2663                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
2664                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2665                 }
2666                 if (spec->dig_in_nid &&
2667                     spec->stream_digital_capture) {
2668                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
2669                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2670                 }
2671         }
2672
2673         /* If the use of more than one ADC is requested for the current
2674          * model, configure a second analog capture-only PCM.
2675          */
2676         /* Additional Analaog capture for index #2 */
2677         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
2678             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
2679                 codec->num_pcms = 3;
2680                 info = spec->pcm_rec + 2;
2681                 info->name = spec->stream_name_analog;
2682                 if (spec->alt_dac_nid) {
2683                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2684                                 *spec->stream_analog_alt_playback;
2685                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2686                                 spec->alt_dac_nid;
2687                 } else {
2688                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2689                                 alc_pcm_null_stream;
2690                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2691                 }
2692                 if (spec->num_adc_nids > 1) {
2693                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2694                                 *spec->stream_analog_alt_capture;
2695                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2696                                 spec->adc_nids[1];
2697                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2698                                 spec->num_adc_nids - 1;
2699                 } else {
2700                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2701                                 alc_pcm_null_stream;
2702                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
2703                 }
2704         }
2705
2706         return 0;
2707 }
2708
2709 static void alc_free(struct hda_codec *codec)
2710 {
2711         struct alc_spec *spec = codec->spec;
2712         unsigned int i;
2713
2714         if (!spec)
2715                 return;
2716
2717         if (spec->kctl_alloc) {
2718                 for (i = 0; i < spec->num_kctl_used; i++)
2719                         kfree(spec->kctl_alloc[i].name);
2720                 kfree(spec->kctl_alloc);
2721         }
2722         kfree(spec);
2723         codec->spec = NULL; /* to be sure */
2724 }
2725
2726 /*
2727  */
2728 static struct hda_codec_ops alc_patch_ops = {
2729         .build_controls = alc_build_controls,
2730         .build_pcms = alc_build_pcms,
2731         .init = alc_init,
2732         .free = alc_free,
2733         .unsol_event = alc_unsol_event,
2734 #ifdef CONFIG_SND_HDA_POWER_SAVE
2735         .check_power_status = alc_check_power_status,
2736 #endif
2737 };
2738
2739
2740 /*
2741  * Test configuration for debugging
2742  *
2743  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
2744  * enum controls.
2745  */
2746 #ifdef CONFIG_SND_DEBUG
2747 static hda_nid_t alc880_test_dac_nids[4] = {
2748         0x02, 0x03, 0x04, 0x05
2749 };
2750
2751 static struct hda_input_mux alc880_test_capture_source = {
2752         .num_items = 7,
2753         .items = {
2754                 { "In-1", 0x0 },
2755                 { "In-2", 0x1 },
2756                 { "In-3", 0x2 },
2757                 { "In-4", 0x3 },
2758                 { "CD", 0x4 },
2759                 { "Front", 0x5 },
2760                 { "Surround", 0x6 },
2761         },
2762 };
2763
2764 static struct hda_channel_mode alc880_test_modes[4] = {
2765         { 2, NULL },
2766         { 4, NULL },
2767         { 6, NULL },
2768         { 8, NULL },
2769 };
2770
2771 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
2772                                  struct snd_ctl_elem_info *uinfo)
2773 {
2774         static char *texts[] = {
2775                 "N/A", "Line Out", "HP Out",
2776                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
2777         };
2778         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2779         uinfo->count = 1;
2780         uinfo->value.enumerated.items = 8;
2781         if (uinfo->value.enumerated.item >= 8)
2782                 uinfo->value.enumerated.item = 7;
2783         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2784         return 0;
2785 }
2786
2787 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
2788                                 struct snd_ctl_elem_value *ucontrol)
2789 {
2790         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2791         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2792         unsigned int pin_ctl, item = 0;
2793
2794         pin_ctl = snd_hda_codec_read(codec, nid, 0,
2795                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2796         if (pin_ctl & AC_PINCTL_OUT_EN) {
2797                 if (pin_ctl & AC_PINCTL_HP_EN)
2798                         item = 2;
2799                 else
2800                         item = 1;
2801         } else if (pin_ctl & AC_PINCTL_IN_EN) {
2802                 switch (pin_ctl & AC_PINCTL_VREFEN) {
2803                 case AC_PINCTL_VREF_HIZ: item = 3; break;
2804                 case AC_PINCTL_VREF_50:  item = 4; break;
2805                 case AC_PINCTL_VREF_GRD: item = 5; break;
2806                 case AC_PINCTL_VREF_80:  item = 6; break;
2807                 case AC_PINCTL_VREF_100: item = 7; break;
2808                 }
2809         }
2810         ucontrol->value.enumerated.item[0] = item;
2811         return 0;
2812 }
2813
2814 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
2815                                 struct snd_ctl_elem_value *ucontrol)
2816 {
2817         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2818         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2819         static unsigned int ctls[] = {
2820                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
2821                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
2822                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
2823                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
2824                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
2825                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
2826         };
2827         unsigned int old_ctl, new_ctl;
2828
2829         old_ctl = snd_hda_codec_read(codec, nid, 0,
2830                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2831         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
2832         if (old_ctl != new_ctl) {
2833                 int val;
2834                 snd_hda_codec_write_cache(codec, nid, 0,
2835                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
2836                                           new_ctl);
2837                 val = ucontrol->value.enumerated.item[0] >= 3 ?
2838                         HDA_AMP_MUTE : 0;
2839                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
2840                                          HDA_AMP_MUTE, val);
2841                 return 1;
2842         }
2843         return 0;
2844 }
2845
2846 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
2847                                  struct snd_ctl_elem_info *uinfo)
2848 {
2849         static char *texts[] = {
2850                 "Front", "Surround", "CLFE", "Side"
2851         };
2852         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2853         uinfo->count = 1;
2854         uinfo->value.enumerated.items = 4;
2855         if (uinfo->value.enumerated.item >= 4)
2856                 uinfo->value.enumerated.item = 3;
2857         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2858         return 0;
2859 }
2860
2861 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
2862                                 struct snd_ctl_elem_value *ucontrol)
2863 {
2864         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2865         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2866         unsigned int sel;
2867
2868         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
2869         ucontrol->value.enumerated.item[0] = sel & 3;
2870         return 0;
2871 }
2872
2873 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
2874                                 struct snd_ctl_elem_value *ucontrol)
2875 {
2876         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2877         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2878         unsigned int sel;
2879
2880         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
2881         if (ucontrol->value.enumerated.item[0] != sel) {
2882                 sel = ucontrol->value.enumerated.item[0] & 3;
2883                 snd_hda_codec_write_cache(codec, nid, 0,
2884                                           AC_VERB_SET_CONNECT_SEL, sel);
2885                 return 1;
2886         }
2887         return 0;
2888 }
2889
2890 #define PIN_CTL_TEST(xname,nid) {                       \
2891                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2892                         .name = xname,                 \
2893                         .info = alc_test_pin_ctl_info, \
2894                         .get = alc_test_pin_ctl_get,   \
2895                         .put = alc_test_pin_ctl_put,   \
2896                         .private_value = nid           \
2897                         }
2898
2899 #define PIN_SRC_TEST(xname,nid) {                       \
2900                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2901                         .name = xname,                 \
2902                         .info = alc_test_pin_src_info, \
2903                         .get = alc_test_pin_src_get,   \
2904                         .put = alc_test_pin_src_put,   \
2905                         .private_value = nid           \
2906                         }
2907
2908 static struct snd_kcontrol_new alc880_test_mixer[] = {
2909         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2910         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2911         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
2912         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2913         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2914         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2915         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
2916         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2917         PIN_CTL_TEST("Front Pin Mode", 0x14),
2918         PIN_CTL_TEST("Surround Pin Mode", 0x15),
2919         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
2920         PIN_CTL_TEST("Side Pin Mode", 0x17),
2921         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
2922         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
2923         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
2924         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
2925         PIN_SRC_TEST("In-1 Pin Source", 0x18),
2926         PIN_SRC_TEST("In-2 Pin Source", 0x19),
2927         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
2928         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
2929         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
2930         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
2931         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
2932         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
2933         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
2934         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
2935         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
2936         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
2937         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
2938         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
2939         {
2940                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2941                 .name = "Channel Mode",
2942                 .info = alc_ch_mode_info,
2943                 .get = alc_ch_mode_get,
2944                 .put = alc_ch_mode_put,
2945         },
2946         { } /* end */
2947 };
2948
2949 static struct hda_verb alc880_test_init_verbs[] = {
2950         /* Unmute inputs of 0x0c - 0x0f */
2951         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2952         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2953         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2954         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2955         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2956         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2957         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2958         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2959         /* Vol output for 0x0c-0x0f */
2960         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2961         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2962         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2963         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2964         /* Set output pins 0x14-0x17 */
2965         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2966         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2967         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2968         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2969         /* Unmute output pins 0x14-0x17 */
2970         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2971         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2972         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2973         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2974         /* Set input pins 0x18-0x1c */
2975         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2976         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2977         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2978         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2979         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2980         /* Mute input pins 0x18-0x1b */
2981         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2982         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2983         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2984         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2985         /* ADC set up */
2986         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2987         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2988         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2989         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2990         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2991         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2992         /* Analog input/passthru */
2993         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2994         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2995         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2996         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2997         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2998         { }
2999 };
3000 #endif
3001
3002 /*
3003  */
3004
3005 static const char *alc880_models[ALC880_MODEL_LAST] = {
3006         [ALC880_3ST]            = "3stack",
3007         [ALC880_TCL_S700]       = "tcl",
3008         [ALC880_3ST_DIG]        = "3stack-digout",
3009         [ALC880_CLEVO]          = "clevo",
3010         [ALC880_5ST]            = "5stack",
3011         [ALC880_5ST_DIG]        = "5stack-digout",
3012         [ALC880_W810]           = "w810",
3013         [ALC880_Z71V]           = "z71v",
3014         [ALC880_6ST]            = "6stack",
3015         [ALC880_6ST_DIG]        = "6stack-digout",
3016         [ALC880_ASUS]           = "asus",
3017         [ALC880_ASUS_W1V]       = "asus-w1v",
3018         [ALC880_ASUS_DIG]       = "asus-dig",
3019         [ALC880_ASUS_DIG2]      = "asus-dig2",
3020         [ALC880_UNIWILL_DIG]    = "uniwill",
3021         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3022         [ALC880_FUJITSU]        = "fujitsu",
3023         [ALC880_F1734]          = "F1734",
3024         [ALC880_LG]             = "lg",
3025         [ALC880_LG_LW]          = "lg-lw",
3026         [ALC880_MEDION_RIM]     = "medion",
3027 #ifdef CONFIG_SND_DEBUG
3028         [ALC880_TEST]           = "test",
3029 #endif
3030         [ALC880_AUTO]           = "auto",
3031 };
3032
3033 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3034         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3035         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3036         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3037         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3038         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3039         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3040         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3041         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3042         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3043         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3044         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3045         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3046         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3047         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3048         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3049         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3050         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3051         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3052         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3053         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3054         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3055         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3056         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3057         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3058         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3059         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
3060         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3061         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3062         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3063         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3064         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3065         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3066         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3067         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3068         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3069         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3070         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3071         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3072         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3073         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3074         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3075         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3076         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3077         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3078         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3079         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3080         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3081         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3082         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3083         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3084         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3085         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3086         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3087         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3088         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3089         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3090         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3091         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3092         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3093         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3094         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3095         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3096         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3097         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3098         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3099         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3100         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3101         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3102         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
3103         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3104         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3105         {}
3106 };
3107
3108 /*
3109  * ALC880 codec presets
3110  */
3111 static struct alc_config_preset alc880_presets[] = {
3112         [ALC880_3ST] = {
3113                 .mixers = { alc880_three_stack_mixer },
3114                 .init_verbs = { alc880_volume_init_verbs,
3115                                 alc880_pin_3stack_init_verbs },
3116                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3117                 .dac_nids = alc880_dac_nids,
3118                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3119                 .channel_mode = alc880_threestack_modes,
3120                 .need_dac_fix = 1,
3121                 .input_mux = &alc880_capture_source,
3122         },
3123         [ALC880_3ST_DIG] = {
3124                 .mixers = { alc880_three_stack_mixer },
3125                 .init_verbs = { alc880_volume_init_verbs,
3126                                 alc880_pin_3stack_init_verbs },
3127                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3128                 .dac_nids = alc880_dac_nids,
3129                 .dig_out_nid = ALC880_DIGOUT_NID,
3130                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3131                 .channel_mode = alc880_threestack_modes,
3132                 .need_dac_fix = 1,
3133                 .input_mux = &alc880_capture_source,
3134         },
3135         [ALC880_TCL_S700] = {
3136                 .mixers = { alc880_tcl_s700_mixer },
3137                 .init_verbs = { alc880_volume_init_verbs,
3138                                 alc880_pin_tcl_S700_init_verbs,
3139                                 alc880_gpio2_init_verbs },
3140                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3141                 .dac_nids = alc880_dac_nids,
3142                 .hp_nid = 0x03,
3143                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3144                 .channel_mode = alc880_2_jack_modes,
3145                 .input_mux = &alc880_capture_source,
3146         },
3147         [ALC880_5ST] = {
3148                 .mixers = { alc880_three_stack_mixer,
3149                             alc880_five_stack_mixer},
3150                 .init_verbs = { alc880_volume_init_verbs,
3151                                 alc880_pin_5stack_init_verbs },
3152                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3153                 .dac_nids = alc880_dac_nids,
3154                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3155                 .channel_mode = alc880_fivestack_modes,
3156                 .input_mux = &alc880_capture_source,
3157         },
3158         [ALC880_5ST_DIG] = {
3159                 .mixers = { alc880_three_stack_mixer,
3160                             alc880_five_stack_mixer },
3161                 .init_verbs = { alc880_volume_init_verbs,
3162                                 alc880_pin_5stack_init_verbs },
3163                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3164                 .dac_nids = alc880_dac_nids,
3165                 .dig_out_nid = ALC880_DIGOUT_NID,
3166                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3167                 .channel_mode = alc880_fivestack_modes,
3168                 .input_mux = &alc880_capture_source,
3169         },
3170         [ALC880_6ST] = {
3171                 .mixers = { alc880_six_stack_mixer },
3172                 .init_verbs = { alc880_volume_init_verbs,
3173                                 alc880_pin_6stack_init_verbs },
3174                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3175                 .dac_nids = alc880_6st_dac_nids,
3176                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3177                 .channel_mode = alc880_sixstack_modes,
3178                 .input_mux = &alc880_6stack_capture_source,
3179         },
3180         [ALC880_6ST_DIG] = {
3181                 .mixers = { alc880_six_stack_mixer },
3182                 .init_verbs = { alc880_volume_init_verbs,
3183                                 alc880_pin_6stack_init_verbs },
3184                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3185                 .dac_nids = alc880_6st_dac_nids,
3186                 .dig_out_nid = ALC880_DIGOUT_NID,
3187                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3188                 .channel_mode = alc880_sixstack_modes,
3189                 .input_mux = &alc880_6stack_capture_source,
3190         },
3191         [ALC880_W810] = {
3192                 .mixers = { alc880_w810_base_mixer },
3193                 .init_verbs = { alc880_volume_init_verbs,
3194                                 alc880_pin_w810_init_verbs,
3195                                 alc880_gpio2_init_verbs },
3196                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3197                 .dac_nids = alc880_w810_dac_nids,
3198                 .dig_out_nid = ALC880_DIGOUT_NID,
3199                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3200                 .channel_mode = alc880_w810_modes,
3201                 .input_mux = &alc880_capture_source,
3202         },
3203         [ALC880_Z71V] = {
3204                 .mixers = { alc880_z71v_mixer },
3205                 .init_verbs = { alc880_volume_init_verbs,
3206                                 alc880_pin_z71v_init_verbs },
3207                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3208                 .dac_nids = alc880_z71v_dac_nids,
3209                 .dig_out_nid = ALC880_DIGOUT_NID,
3210                 .hp_nid = 0x03,
3211                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3212                 .channel_mode = alc880_2_jack_modes,
3213                 .input_mux = &alc880_capture_source,
3214         },
3215         [ALC880_F1734] = {
3216                 .mixers = { alc880_f1734_mixer },
3217                 .init_verbs = { alc880_volume_init_verbs,
3218                                 alc880_pin_f1734_init_verbs },
3219                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3220                 .dac_nids = alc880_f1734_dac_nids,
3221                 .hp_nid = 0x02,
3222                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3223                 .channel_mode = alc880_2_jack_modes,
3224                 .input_mux = &alc880_f1734_capture_source,
3225                 .unsol_event = alc880_uniwill_p53_unsol_event,
3226                 .init_hook = alc880_uniwill_p53_hp_automute,
3227         },
3228         [ALC880_ASUS] = {
3229                 .mixers = { alc880_asus_mixer },
3230                 .init_verbs = { alc880_volume_init_verbs,
3231                                 alc880_pin_asus_init_verbs,
3232                                 alc880_gpio1_init_verbs },
3233                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3234                 .dac_nids = alc880_asus_dac_nids,
3235                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3236                 .channel_mode = alc880_asus_modes,
3237                 .need_dac_fix = 1,
3238                 .input_mux = &alc880_capture_source,
3239         },
3240         [ALC880_ASUS_DIG] = {
3241                 .mixers = { alc880_asus_mixer },
3242                 .init_verbs = { alc880_volume_init_verbs,
3243                                 alc880_pin_asus_init_verbs,
3244                                 alc880_gpio1_init_verbs },
3245                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3246                 .dac_nids = alc880_asus_dac_nids,
3247                 .dig_out_nid = ALC880_DIGOUT_NID,
3248                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3249                 .channel_mode = alc880_asus_modes,
3250                 .need_dac_fix = 1,
3251                 .input_mux = &alc880_capture_source,
3252         },
3253         [ALC880_ASUS_DIG2] = {
3254                 .mixers = { alc880_asus_mixer },
3255                 .init_verbs = { alc880_volume_init_verbs,
3256                                 alc880_pin_asus_init_verbs,
3257                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3258                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3259                 .dac_nids = alc880_asus_dac_nids,
3260                 .dig_out_nid = ALC880_DIGOUT_NID,
3261                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3262                 .channel_mode = alc880_asus_modes,
3263                 .need_dac_fix = 1,
3264                 .input_mux = &alc880_capture_source,
3265         },
3266         [ALC880_ASUS_W1V] = {
3267                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3268                 .init_verbs = { alc880_volume_init_verbs,
3269                                 alc880_pin_asus_init_verbs,
3270                                 alc880_gpio1_init_verbs },
3271                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3272                 .dac_nids = alc880_asus_dac_nids,
3273                 .dig_out_nid = ALC880_DIGOUT_NID,
3274                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3275                 .channel_mode = alc880_asus_modes,
3276                 .need_dac_fix = 1,
3277                 .input_mux = &alc880_capture_source,
3278         },
3279         [ALC880_UNIWILL_DIG] = {
3280                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3281                 .init_verbs = { alc880_volume_init_verbs,
3282                                 alc880_pin_asus_init_verbs },
3283                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3284                 .dac_nids = alc880_asus_dac_nids,
3285                 .dig_out_nid = ALC880_DIGOUT_NID,
3286                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3287                 .channel_mode = alc880_asus_modes,
3288                 .need_dac_fix = 1,
3289                 .input_mux = &alc880_capture_source,
3290         },
3291         [ALC880_UNIWILL] = {
3292                 .mixers = { alc880_uniwill_mixer },
3293                 .init_verbs = { alc880_volume_init_verbs,
3294                                 alc880_uniwill_init_verbs },
3295                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3296                 .dac_nids = alc880_asus_dac_nids,
3297                 .dig_out_nid = ALC880_DIGOUT_NID,
3298                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3299                 .channel_mode = alc880_threestack_modes,
3300                 .need_dac_fix = 1,
3301                 .input_mux = &alc880_capture_source,
3302                 .unsol_event = alc880_uniwill_unsol_event,
3303                 .init_hook = alc880_uniwill_automute,
3304         },
3305         [ALC880_UNIWILL_P53] = {
3306                 .mixers = { alc880_uniwill_p53_mixer },
3307                 .init_verbs = { alc880_volume_init_verbs,
3308                                 alc880_uniwill_p53_init_verbs },
3309                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3310                 .dac_nids = alc880_asus_dac_nids,
3311                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3312                 .channel_mode = alc880_threestack_modes,
3313                 .input_mux = &alc880_capture_source,
3314                 .unsol_event = alc880_uniwill_p53_unsol_event,
3315                 .init_hook = alc880_uniwill_p53_hp_automute,
3316         },
3317         [ALC880_FUJITSU] = {
3318                 .mixers = { alc880_fujitsu_mixer,
3319                             alc880_pcbeep_mixer, },
3320                 .init_verbs = { alc880_volume_init_verbs,
3321                                 alc880_uniwill_p53_init_verbs,
3322                                 alc880_beep_init_verbs },
3323                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3324                 .dac_nids = alc880_dac_nids,
3325                 .dig_out_nid = ALC880_DIGOUT_NID,
3326                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3327                 .channel_mode = alc880_2_jack_modes,
3328                 .input_mux = &alc880_capture_source,
3329                 .unsol_event = alc880_uniwill_p53_unsol_event,
3330                 .init_hook = alc880_uniwill_p53_hp_automute,
3331         },
3332         [ALC880_CLEVO] = {
3333                 .mixers = { alc880_three_stack_mixer },
3334                 .init_verbs = { alc880_volume_init_verbs,
3335                                 alc880_pin_clevo_init_verbs },
3336                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3337                 .dac_nids = alc880_dac_nids,
3338                 .hp_nid = 0x03,
3339                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3340                 .channel_mode = alc880_threestack_modes,
3341                 .need_dac_fix = 1,
3342                 .input_mux = &alc880_capture_source,
3343         },
3344         [ALC880_LG] = {
3345                 .mixers = { alc880_lg_mixer },
3346                 .init_verbs = { alc880_volume_init_verbs,
3347                                 alc880_lg_init_verbs },
3348                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3349                 .dac_nids = alc880_lg_dac_nids,
3350                 .dig_out_nid = ALC880_DIGOUT_NID,
3351                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3352                 .channel_mode = alc880_lg_ch_modes,
3353                 .need_dac_fix = 1,
3354                 .input_mux = &alc880_lg_capture_source,
3355                 .unsol_event = alc880_lg_unsol_event,
3356                 .init_hook = alc880_lg_automute,
3357 #ifdef CONFIG_SND_HDA_POWER_SAVE
3358                 .loopbacks = alc880_lg_loopbacks,
3359 #endif
3360         },
3361         [ALC880_LG_LW] = {
3362                 .mixers = { alc880_lg_lw_mixer },
3363                 .init_verbs = { alc880_volume_init_verbs,
3364                                 alc880_lg_lw_init_verbs },
3365                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3366                 .dac_nids = alc880_dac_nids,
3367                 .dig_out_nid = ALC880_DIGOUT_NID,
3368                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3369                 .channel_mode = alc880_lg_lw_modes,
3370                 .input_mux = &alc880_lg_lw_capture_source,
3371                 .unsol_event = alc880_lg_lw_unsol_event,
3372                 .init_hook = alc880_lg_lw_automute,
3373         },
3374         [ALC880_MEDION_RIM] = {
3375                 .mixers = { alc880_medion_rim_mixer },
3376                 .init_verbs = { alc880_volume_init_verbs,
3377                                 alc880_medion_rim_init_verbs,
3378                                 alc_gpio2_init_verbs },
3379                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3380                 .dac_nids = alc880_dac_nids,
3381                 .dig_out_nid = ALC880_DIGOUT_NID,
3382                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3383                 .channel_mode = alc880_2_jack_modes,
3384                 .input_mux = &alc880_medion_rim_capture_source,
3385                 .unsol_event = alc880_medion_rim_unsol_event,
3386                 .init_hook = alc880_medion_rim_automute,
3387         },
3388 #ifdef CONFIG_SND_DEBUG
3389         [ALC880_TEST] = {
3390                 .mixers = { alc880_test_mixer },
3391                 .init_verbs = { alc880_test_init_verbs },
3392                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3393                 .dac_nids = alc880_test_dac_nids,
3394                 .dig_out_nid = ALC880_DIGOUT_NID,
3395                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3396                 .channel_mode = alc880_test_modes,
3397                 .input_mux = &alc880_test_capture_source,
3398         },
3399 #endif
3400 };
3401
3402 /*
3403  * Automatic parse of I/O pins from the BIOS configuration
3404  */
3405
3406 #define NUM_CONTROL_ALLOC       32
3407 #define NUM_VERB_ALLOC          32
3408
3409 enum {
3410         ALC_CTL_WIDGET_VOL,
3411         ALC_CTL_WIDGET_MUTE,
3412         ALC_CTL_BIND_MUTE,
3413 };
3414 static struct snd_kcontrol_new alc880_control_templates[] = {
3415         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3416         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3417         HDA_BIND_MUTE(NULL, 0, 0, 0),
3418 };
3419
3420 /* add dynamic controls */
3421 static int add_control(struct alc_spec *spec, int type, const char *name,
3422                        unsigned long val)
3423 {
3424         struct snd_kcontrol_new *knew;
3425
3426         if (spec->num_kctl_used >= spec->num_kctl_alloc) {
3427                 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
3428
3429                 /* array + terminator */
3430                 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
3431                 if (!knew)
3432                         return -ENOMEM;
3433                 if (spec->kctl_alloc) {
3434                         memcpy(knew, spec->kctl_alloc,
3435                                sizeof(*knew) * spec->num_kctl_alloc);
3436                         kfree(spec->kctl_alloc);
3437                 }
3438                 spec->kctl_alloc = knew;
3439                 spec->num_kctl_alloc = num;
3440         }
3441
3442         knew = &spec->kctl_alloc[spec->num_kctl_used];
3443         *knew = alc880_control_templates[type];
3444         knew->name = kstrdup(name, GFP_KERNEL);
3445         if (!knew->name)
3446                 return -ENOMEM;
3447         knew->private_value = val;
3448         spec->num_kctl_used++;
3449         return 0;
3450 }
3451
3452 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3453 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3454 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3455 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3456 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3457 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3458 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3459 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3460 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3461 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3462 #define ALC880_PIN_CD_NID               0x1c
3463
3464 /* fill in the dac_nids table from the parsed pin configuration */
3465 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3466                                      const struct auto_pin_cfg *cfg)
3467 {
3468         hda_nid_t nid;
3469         int assigned[4];
3470         int i, j;
3471
3472         memset(assigned, 0, sizeof(assigned));
3473         spec->multiout.dac_nids = spec->private_dac_nids;
3474
3475         /* check the pins hardwired to audio widget */
3476         for (i = 0; i < cfg->line_outs; i++) {
3477                 nid = cfg->line_out_pins[i];
3478                 if (alc880_is_fixed_pin(nid)) {
3479                         int idx = alc880_fixed_pin_idx(nid);
3480                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3481                         assigned[idx] = 1;
3482                 }
3483         }
3484         /* left pins can be connect to any audio widget */
3485         for (i = 0; i < cfg->line_outs; i++) {
3486                 nid = cfg->line_out_pins[i];
3487                 if (alc880_is_fixed_pin(nid))
3488                         continue;
3489                 /* search for an empty channel */
3490                 for (j = 0; j < cfg->line_outs; j++) {
3491                         if (!assigned[j]) {
3492                                 spec->multiout.dac_nids[i] =
3493                                         alc880_idx_to_dac(j);
3494                                 assigned[j] = 1;
3495                                 break;
3496                         }
3497                 }
3498         }
3499         spec->multiout.num_dacs = cfg->line_outs;
3500         return 0;
3501 }
3502
3503 /* add playback controls from the parsed DAC table */
3504 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3505                                              const struct auto_pin_cfg *cfg)
3506 {
3507         char name[32];
3508         static const char *chname[4] = {
3509                 "Front", "Surround", NULL /*CLFE*/, "Side"
3510         };
3511         hda_nid_t nid;
3512         int i, err;
3513
3514         for (i = 0; i < cfg->line_outs; i++) {
3515                 if (!spec->multiout.dac_nids[i])
3516                         continue;
3517                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3518                 if (i == 2) {
3519                         /* Center/LFE */
3520                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3521                                           "Center Playback Volume",
3522                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3523                                                               HDA_OUTPUT));
3524                         if (err < 0)
3525                                 return err;
3526                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3527                                           "LFE Playback Volume",
3528                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3529                                                               HDA_OUTPUT));
3530                         if (err < 0)
3531                                 return err;
3532                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3533                                           "Center Playback Switch",
3534                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
3535                                                               HDA_INPUT));
3536                         if (err < 0)
3537                                 return err;
3538                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3539                                           "LFE Playback Switch",
3540                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
3541                                                               HDA_INPUT));
3542                         if (err < 0)
3543                                 return err;
3544                 } else {
3545                         sprintf(name, "%s Playback Volume", chname[i]);
3546                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3547                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3548                                                               HDA_OUTPUT));
3549                         if (err < 0)
3550                                 return err;
3551                         sprintf(name, "%s Playback Switch", chname[i]);
3552                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3553                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
3554                                                               HDA_INPUT));
3555                         if (err < 0)
3556                                 return err;
3557                 }
3558         }
3559         return 0;
3560 }
3561
3562 /* add playback controls for speaker and HP outputs */
3563 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
3564                                         const char *pfx)
3565 {
3566         hda_nid_t nid;
3567         int err;
3568         char name[32];
3569
3570         if (!pin)
3571                 return 0;
3572
3573         if (alc880_is_fixed_pin(pin)) {
3574                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
3575                 /* specify the DAC as the extra output */
3576                 if (!spec->multiout.hp_nid)
3577                         spec->multiout.hp_nid = nid;
3578                 else
3579                         spec->multiout.extra_out_nid[0] = nid;
3580                 /* control HP volume/switch on the output mixer amp */
3581                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
3582                 sprintf(name, "%s Playback Volume", pfx);
3583                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3584                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3585                 if (err < 0)
3586                         return err;
3587                 sprintf(name, "%s Playback Switch", pfx);
3588                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3589                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
3590                 if (err < 0)
3591                         return err;
3592         } else if (alc880_is_multi_pin(pin)) {
3593                 /* set manual connection */
3594                 /* we have only a switch on HP-out PIN */
3595                 sprintf(name, "%s Playback Switch", pfx);
3596                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3597                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3598                 if (err < 0)
3599                         return err;
3600         }
3601         return 0;
3602 }
3603
3604 /* create input playback/capture controls for the given pin */
3605 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
3606                             const char *ctlname,
3607                             int idx, hda_nid_t mix_nid)
3608 {
3609         char name[32];
3610         int err;
3611
3612         sprintf(name, "%s Playback Volume", ctlname);
3613         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3614                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3615         if (err < 0)
3616                 return err;
3617         sprintf(name, "%s Playback Switch", ctlname);
3618         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3619                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3620         if (err < 0)
3621                 return err;
3622         return 0;
3623 }
3624
3625 /* create playback/capture controls for input pins */
3626 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3627                                                 const struct auto_pin_cfg *cfg)
3628 {
3629         struct hda_input_mux *imux = &spec->private_imux;
3630         int i, err, idx;
3631
3632         for (i = 0; i < AUTO_PIN_LAST; i++) {
3633                 if (alc880_is_input_pin(cfg->input_pins[i])) {
3634                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
3635                         err = new_analog_input(spec, cfg->input_pins[i],
3636                                                auto_pin_cfg_labels[i],
3637                                                idx, 0x0b);
3638                         if (err < 0)
3639                                 return err;
3640                         imux->items[imux->num_items].label =
3641                                 auto_pin_cfg_labels[i];
3642                         imux->items[imux->num_items].index =
3643                                 alc880_input_pin_idx(cfg->input_pins[i]);
3644                         imux->num_items++;
3645                 }
3646         }
3647         return 0;
3648 }
3649
3650 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
3651                                unsigned int pin_type)
3652 {
3653         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3654                             pin_type);
3655         /* unmute pin */
3656         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3657                             AMP_OUT_UNMUTE);
3658 }
3659
3660 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3661                                               hda_nid_t nid, int pin_type,
3662                                               int dac_idx)
3663 {
3664         alc_set_pin_output(codec, nid, pin_type);
3665         /* need the manual connection? */
3666         if (alc880_is_multi_pin(nid)) {
3667                 struct alc_spec *spec = codec->spec;
3668                 int idx = alc880_multi_pin_idx(nid);
3669                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
3670                                     AC_VERB_SET_CONNECT_SEL,
3671                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
3672         }
3673 }
3674
3675 static int get_pin_type(int line_out_type)
3676 {
3677         if (line_out_type == AUTO_PIN_HP_OUT)
3678                 return PIN_HP;
3679         else
3680                 return PIN_OUT;
3681 }
3682
3683 static void alc880_auto_init_multi_out(struct hda_codec *codec)
3684 {
3685         struct alc_spec *spec = codec->spec;
3686         int i;
3687         
3688         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
3689         for (i = 0; i < spec->autocfg.line_outs; i++) {
3690                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3691                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3692                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
3693         }
3694 }
3695
3696 static void alc880_auto_init_extra_out(struct hda_codec *codec)
3697 {
3698         struct alc_spec *spec = codec->spec;
3699         hda_nid_t pin;
3700
3701         pin = spec->autocfg.speaker_pins[0];
3702         if (pin) /* connect to front */
3703                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
3704         pin = spec->autocfg.hp_pins[0];
3705         if (pin) /* connect to front */
3706                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3707 }
3708
3709 static void alc880_auto_init_analog_input(struct hda_codec *codec)
3710 {
3711         struct alc_spec *spec = codec->spec;
3712         int i;
3713
3714         for (i = 0; i < AUTO_PIN_LAST; i++) {
3715                 hda_nid_t nid = spec->autocfg.input_pins[i];
3716                 if (alc880_is_input_pin(nid)) {
3717                         snd_hda_codec_write(codec, nid, 0,
3718                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
3719                                             i <= AUTO_PIN_FRONT_MIC ?
3720                                             PIN_VREF80 : PIN_IN);
3721                         if (nid != ALC880_PIN_CD_NID)
3722                                 snd_hda_codec_write(codec, nid, 0,
3723                                                     AC_VERB_SET_AMP_GAIN_MUTE,
3724                                                     AMP_OUT_MUTE);
3725                 }
3726         }
3727 }
3728
3729 /* parse the BIOS configuration and set up the alc_spec */
3730 /* return 1 if successful, 0 if the proper config is not found,
3731  * or a negative error code
3732  */
3733 static int alc880_parse_auto_config(struct hda_codec *codec)
3734 {
3735         struct alc_spec *spec = codec->spec;
3736         int err;
3737         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3738
3739         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3740                                            alc880_ignore);
3741         if (err < 0)
3742                 return err;
3743         if (!spec->autocfg.line_outs)
3744                 return 0; /* can't find valid BIOS pin config */
3745
3746         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
3747         if (err < 0)
3748                 return err;
3749         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
3750         if (err < 0)
3751                 return err;
3752         err = alc880_auto_create_extra_out(spec,
3753                                            spec->autocfg.speaker_pins[0],
3754                                            "Speaker");
3755         if (err < 0)
3756                 return err;
3757         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
3758                                            "Headphone");
3759         if (err < 0)
3760                 return err;
3761         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
3762         if (err < 0)
3763                 return err;
3764
3765         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3766
3767         if (spec->autocfg.dig_out_pin)
3768                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
3769         if (spec->autocfg.dig_in_pin)
3770                 spec->dig_in_nid = ALC880_DIGIN_NID;
3771
3772         if (spec->kctl_alloc)
3773                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3774
3775         spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
3776
3777         spec->num_mux_defs = 1;
3778         spec->input_mux = &spec->private_imux;
3779
3780         return 1;
3781 }
3782
3783 /* additional initialization for auto-configuration model */
3784 static void alc880_auto_init(struct hda_codec *codec)
3785 {
3786         struct alc_spec *spec = codec->spec;
3787         alc880_auto_init_multi_out(codec);
3788         alc880_auto_init_extra_out(codec);
3789         alc880_auto_init_analog_input(codec);
3790         if (spec->unsol_event)
3791                 alc_sku_automute(codec);
3792 }
3793
3794 /*
3795  * OK, here we have finally the patch for ALC880
3796  */
3797
3798 static int patch_alc880(struct hda_codec *codec)
3799 {
3800         struct alc_spec *spec;
3801         int board_config;
3802         int err;
3803
3804         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3805         if (spec == NULL)
3806                 return -ENOMEM;
3807
3808         codec->spec = spec;
3809
3810         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
3811                                                   alc880_models,
3812                                                   alc880_cfg_tbl);
3813         if (board_config < 0) {
3814                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
3815                        "trying auto-probe from BIOS...\n");
3816                 board_config = ALC880_AUTO;
3817         }
3818
3819         if (board_config == ALC880_AUTO) {
3820                 /* automatic parse from the BIOS config */
3821                 err = alc880_parse_auto_config(codec);
3822                 if (err < 0) {
3823                         alc_free(codec);
3824                         return err;
3825                 } else if (!err) {
3826                         printk(KERN_INFO
3827                                "hda_codec: Cannot set up configuration "
3828                                "from BIOS.  Using 3-stack mode...\n");
3829                         board_config = ALC880_3ST;
3830                 }
3831         }
3832
3833         if (board_config != ALC880_AUTO)
3834                 setup_preset(spec, &alc880_presets[board_config]);
3835
3836         spec->stream_name_analog = "ALC880 Analog";
3837         spec->stream_analog_playback = &alc880_pcm_analog_playback;
3838         spec->stream_analog_capture = &alc880_pcm_analog_capture;
3839         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
3840
3841         spec->stream_name_digital = "ALC880 Digital";
3842         spec->stream_digital_playback = &alc880_pcm_digital_playback;
3843         spec->stream_digital_capture = &alc880_pcm_digital_capture;
3844
3845         if (!spec->adc_nids && spec->input_mux) {
3846                 /* check whether NID 0x07 is valid */
3847                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
3848                 /* get type */
3849                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3850                 if (wcap != AC_WID_AUD_IN) {
3851                         spec->adc_nids = alc880_adc_nids_alt;
3852                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
3853                         spec->mixers[spec->num_mixers] =
3854                                 alc880_capture_alt_mixer;
3855                         spec->num_mixers++;
3856                 } else {
3857                         spec->adc_nids = alc880_adc_nids;
3858                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
3859                         spec->mixers[spec->num_mixers] = alc880_capture_mixer;
3860                         spec->num_mixers++;
3861                 }
3862         }
3863
3864         spec->vmaster_nid = 0x0c;
3865
3866         codec->patch_ops = alc_patch_ops;
3867         if (board_config == ALC880_AUTO)
3868                 spec->init_hook = alc880_auto_init;
3869 #ifdef CONFIG_SND_HDA_POWER_SAVE
3870         if (!spec->loopback.amplist)
3871                 spec->loopback.amplist = alc880_loopbacks;
3872 #endif
3873
3874         return 0;
3875 }
3876
3877
3878 /*
3879  * ALC260 support
3880  */
3881
3882 static hda_nid_t alc260_dac_nids[1] = {
3883         /* front */
3884         0x02,
3885 };
3886
3887 static hda_nid_t alc260_adc_nids[1] = {
3888         /* ADC0 */
3889         0x04,
3890 };
3891
3892 static hda_nid_t alc260_adc_nids_alt[1] = {
3893         /* ADC1 */
3894         0x05,
3895 };
3896
3897 static hda_nid_t alc260_hp_adc_nids[2] = {
3898         /* ADC1, 0 */
3899         0x05, 0x04
3900 };
3901
3902 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
3903  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
3904  */
3905 static hda_nid_t alc260_dual_adc_nids[2] = {
3906         /* ADC0, ADC1 */
3907         0x04, 0x05
3908 };
3909
3910 #define ALC260_DIGOUT_NID       0x03
3911 #define ALC260_DIGIN_NID        0x06
3912
3913 static struct hda_input_mux alc260_capture_source = {
3914         .num_items = 4,
3915         .items = {
3916                 { "Mic", 0x0 },
3917                 { "Front Mic", 0x1 },
3918                 { "Line", 0x2 },
3919                 { "CD", 0x4 },
3920         },
3921 };
3922
3923 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
3924  * headphone jack and the internal CD lines since these are the only pins at
3925  * which audio can appear.  For flexibility, also allow the option of
3926  * recording the mixer output on the second ADC (ADC0 doesn't have a
3927  * connection to the mixer output).
3928  */
3929 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
3930         {
3931                 .num_items = 3,
3932                 .items = {
3933                         { "Mic/Line", 0x0 },
3934                         { "CD", 0x4 },
3935                         { "Headphone", 0x2 },
3936                 },
3937         },
3938         {
3939                 .num_items = 4,
3940                 .items = {
3941                         { "Mic/Line", 0x0 },
3942                         { "CD", 0x4 },
3943                         { "Headphone", 0x2 },
3944                         { "Mixer", 0x5 },
3945                 },
3946         },
3947
3948 };
3949
3950 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
3951  * the Fujitsu S702x, but jacks are marked differently.
3952  */
3953 static struct hda_input_mux alc260_acer_capture_sources[2] = {
3954         {
3955                 .num_items = 4,
3956                 .items = {
3957                         { "Mic", 0x0 },
3958                         { "Line", 0x2 },
3959                         { "CD", 0x4 },
3960                         { "Headphone", 0x5 },
3961                 },
3962         },
3963         {
3964                 .num_items = 5,
3965                 .items = {
3966                         { "Mic", 0x0 },
3967                         { "Line", 0x2 },
3968                         { "CD", 0x4 },
3969                         { "Headphone", 0x6 },
3970                         { "Mixer", 0x5 },
3971                 },
3972         },
3973 };
3974 /*
3975  * This is just place-holder, so there's something for alc_build_pcms to look
3976  * at when it calculates the maximum number of channels. ALC260 has no mixer
3977  * element which allows changing the channel mode, so the verb list is
3978  * never used.
3979  */
3980 static struct hda_channel_mode alc260_modes[1] = {
3981         { 2, NULL },
3982 };
3983
3984
3985 /* Mixer combinations
3986  *
3987  * basic: base_output + input + pc_beep + capture
3988  * HP: base_output + input + capture_alt
3989  * HP_3013: hp_3013 + input + capture
3990  * fujitsu: fujitsu + capture
3991  * acer: acer + capture
3992  */
3993
3994 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
3995         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3996         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
3997         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3998         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
3999         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4000         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4001         { } /* end */
4002 };
4003
4004 static struct snd_kcontrol_new alc260_input_mixer[] = {
4005         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4006         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4007         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4008         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4009         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4010         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4011         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4012         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4013         { } /* end */
4014 };
4015
4016 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
4017         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
4018         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
4019         { } /* end */
4020 };
4021
4022 /* update HP, line and mono out pins according to the master switch */
4023 static void alc260_hp_master_update(struct hda_codec *codec,
4024                                     hda_nid_t hp, hda_nid_t line,
4025                                     hda_nid_t mono)
4026 {
4027         struct alc_spec *spec = codec->spec;
4028         unsigned int val = spec->master_sw ? PIN_HP : 0;
4029         /* change HP and line-out pins */
4030         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4031                             val);
4032         snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4033                             val);
4034         /* mono (speaker) depending on the HP jack sense */
4035         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4036         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4037                             val);
4038 }
4039
4040 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4041                                    struct snd_ctl_elem_value *ucontrol)
4042 {
4043         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4044         struct alc_spec *spec = codec->spec;
4045         *ucontrol->value.integer.value = spec->master_sw;
4046         return 0;
4047 }
4048
4049 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4050                                    struct snd_ctl_elem_value *ucontrol)
4051 {
4052         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4053         struct alc_spec *spec = codec->spec;
4054         int val = !!*ucontrol->value.integer.value;
4055         hda_nid_t hp, line, mono;
4056
4057         if (val == spec->master_sw)
4058                 return 0;
4059         spec->master_sw = val;
4060         hp = (kcontrol->private_value >> 16) & 0xff;
4061         line = (kcontrol->private_value >> 8) & 0xff;
4062         mono = kcontrol->private_value & 0xff;
4063         alc260_hp_master_update(codec, hp, line, mono);
4064         return 1;
4065 }
4066
4067 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4068         {
4069                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4070                 .name = "Master Playback Switch",
4071                 .info = snd_ctl_boolean_mono_info,
4072                 .get = alc260_hp_master_sw_get,
4073                 .put = alc260_hp_master_sw_put,
4074                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4075         },
4076         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4077         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4078         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4079         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4080         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4081                               HDA_OUTPUT),
4082         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4083         { } /* end */
4084 };
4085
4086 static struct hda_verb alc260_hp_unsol_verbs[] = {
4087         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4088         {},
4089 };
4090
4091 static void alc260_hp_automute(struct hda_codec *codec)
4092 {
4093         struct alc_spec *spec = codec->spec;
4094         unsigned int present;
4095
4096         present = snd_hda_codec_read(codec, 0x10, 0,
4097                                      AC_VERB_GET_PIN_SENSE, 0);
4098         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4099         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4100 }
4101
4102 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4103 {
4104         if ((res >> 26) == ALC880_HP_EVENT)
4105                 alc260_hp_automute(codec);
4106 }
4107
4108 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4109         {
4110                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4111                 .name = "Master Playback Switch",
4112                 .info = snd_ctl_boolean_mono_info,
4113                 .get = alc260_hp_master_sw_get,
4114                 .put = alc260_hp_master_sw_put,
4115                 .private_value = (0x10 << 16) | (0x15 << 8) | 0x11
4116         },
4117         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4118         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4119         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4120         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4121         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4122         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4123         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4124         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4125         { } /* end */
4126 };
4127
4128 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4129         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4130         {},
4131 };
4132
4133 static void alc260_hp_3013_automute(struct hda_codec *codec)
4134 {
4135         struct alc_spec *spec = codec->spec;
4136         unsigned int present;
4137
4138         present = snd_hda_codec_read(codec, 0x15, 0,
4139                                      AC_VERB_GET_PIN_SENSE, 0);
4140         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4141         alc260_hp_master_update(codec, 0x10, 0x15, 0x11);
4142 }
4143
4144 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4145                                        unsigned int res)
4146 {
4147         if ((res >> 26) == ALC880_HP_EVENT)
4148                 alc260_hp_3013_automute(codec);
4149 }
4150
4151 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12, 
4152  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4153  */
4154 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4155         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4156         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4157         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4158         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4159         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4160         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4161         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4162         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4163         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4164         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4165         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4166         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4167         { } /* end */
4168 };
4169
4170 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4171  * versions of the ALC260 don't act on requests to enable mic bias from NID
4172  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4173  * datasheet doesn't mention this restriction.  At this stage it's not clear
4174  * whether this behaviour is intentional or is a hardware bug in chip
4175  * revisions available in early 2006.  Therefore for now allow the
4176  * "Headphone Jack Mode" control to span all choices, but if it turns out
4177  * that the lack of mic bias for this NID is intentional we could change the
4178  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4179  *
4180  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4181  * don't appear to make the mic bias available from the "line" jack, even
4182  * though the NID used for this jack (0x14) can supply it.  The theory is
4183  * that perhaps Acer have included blocking capacitors between the ALC260
4184  * and the output jack.  If this turns out to be the case for all such
4185  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4186  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4187  *
4188  * The C20x Tablet series have a mono internal speaker which is controlled
4189  * via the chip's Mono sum widget and pin complex, so include the necessary
4190  * controls for such models.  On models without a "mono speaker" the control
4191  * won't do anything.
4192  */
4193 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4194         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4195         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4196         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4197         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4198                               HDA_OUTPUT),
4199         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4200                            HDA_INPUT),
4201         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4202         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4203         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4204         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4205         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4206         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4207         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4208         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4209         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4210         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4211         { } /* end */
4212 };
4213
4214 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4215  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4216  */
4217 static struct snd_kcontrol_new alc260_will_mixer[] = {
4218         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4219         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4220         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4221         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4222         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4223         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4224         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4225         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4226         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4227         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4228         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4229         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4230         { } /* end */
4231 };
4232
4233 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4234  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4235  */
4236 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4237         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4238         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4239         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4240         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4241         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4242         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4243         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4244         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4245         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4246         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4247         { } /* end */
4248 };
4249
4250 /* capture mixer elements */
4251 static struct snd_kcontrol_new alc260_capture_mixer[] = {
4252         HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
4253         HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
4254         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
4255         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),
4256         {
4257                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4258                 /* The multiple "Capture Source" controls confuse alsamixer
4259                  * So call somewhat different..
4260                  */
4261                 /* .name = "Capture Source", */
4262                 .name = "Input Source",
4263                 .count = 2,
4264                 .info = alc_mux_enum_info,
4265                 .get = alc_mux_enum_get,
4266                 .put = alc_mux_enum_put,
4267         },
4268         { } /* end */
4269 };
4270
4271 static struct snd_kcontrol_new alc260_capture_alt_mixer[] = {
4272         HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
4273         HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
4274         {
4275                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4276                 /* The multiple "Capture Source" controls confuse alsamixer
4277                  * So call somewhat different..
4278                  */
4279                 /* .name = "Capture Source", */
4280                 .name = "Input Source",
4281                 .count = 1,
4282                 .info = alc_mux_enum_info,
4283                 .get = alc_mux_enum_get,
4284                 .put = alc_mux_enum_put,
4285         },
4286         { } /* end */
4287 };
4288
4289 /*
4290  * initialization verbs
4291  */
4292 static struct hda_verb alc260_init_verbs[] = {
4293         /* Line In pin widget for input */
4294         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4295         /* CD pin widget for input */
4296         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4297         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4298         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4299         /* Mic2 (front panel) pin widget for input and vref at 80% */
4300         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4301         /* LINE-2 is used for line-out in rear */
4302         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4303         /* select line-out */
4304         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4305         /* LINE-OUT pin */
4306         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4307         /* enable HP */
4308         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4309         /* enable Mono */
4310         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4311         /* mute capture amp left and right */
4312         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4313         /* set connection select to line in (default select for this ADC) */
4314         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4315         /* mute capture amp left and right */
4316         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4317         /* set connection select to line in (default select for this ADC) */
4318         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4319         /* set vol=0 Line-Out mixer amp left and right */
4320         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4321         /* unmute pin widget amp left and right (no gain on this amp) */
4322         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4323         /* set vol=0 HP mixer amp left and right */
4324         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4325         /* unmute pin widget amp left and right (no gain on this amp) */
4326         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4327         /* set vol=0 Mono mixer amp left and right */
4328         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4329         /* unmute pin widget amp left and right (no gain on this amp) */
4330         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4331         /* unmute LINE-2 out pin */
4332         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4333         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4334          * Line In 2 = 0x03
4335          */
4336         /* mute analog inputs */
4337         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4338         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4339         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4340         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4341         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4342         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4343         /* mute Front out path */
4344         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4345         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4346         /* mute Headphone out path */
4347         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4348         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4349         /* mute Mono out path */
4350         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4351         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4352         { }
4353 };
4354
4355 #if 0 /* should be identical with alc260_init_verbs? */
4356 static struct hda_verb alc260_hp_init_verbs[] = {
4357         /* Headphone and output */
4358         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4359         /* mono output */
4360         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4361         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4362         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4363         /* Mic2 (front panel) pin widget for input and vref at 80% */
4364         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4365         /* Line In pin widget for input */
4366         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4367         /* Line-2 pin widget for output */
4368         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4369         /* CD pin widget for input */
4370         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4371         /* unmute amp left and right */
4372         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4373         /* set connection select to line in (default select for this ADC) */
4374         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4375         /* unmute Line-Out mixer amp left and right (volume = 0) */
4376         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4377         /* mute pin widget amp left and right (no gain on this amp) */
4378         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4379         /* unmute HP mixer amp left and right (volume = 0) */
4380         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4381         /* mute pin widget amp left and right (no gain on this amp) */
4382         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4383         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4384          * Line In 2 = 0x03
4385          */
4386         /* mute analog inputs */
4387         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4388         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4389         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4390         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4391         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4392         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4393         /* Unmute Front out path */
4394         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4395         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4396         /* Unmute Headphone out path */
4397         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4398         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4399         /* Unmute Mono out path */
4400         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4401         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4402         { }
4403 };
4404 #endif
4405
4406 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4407         /* Line out and output */
4408         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4409         /* mono output */
4410         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4411         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4412         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4413         /* Mic2 (front panel) pin widget for input and vref at 80% */
4414         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4415         /* Line In pin widget for input */
4416         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4417         /* Headphone pin widget for output */
4418         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4419         /* CD pin widget for input */
4420         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4421         /* unmute amp left and right */
4422         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4423         /* set connection select to line in (default select for this ADC) */
4424         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4425         /* unmute Line-Out mixer amp left and right (volume = 0) */
4426         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4427         /* mute pin widget amp left and right (no gain on this amp) */
4428         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4429         /* unmute HP mixer amp left and right (volume = 0) */
4430         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4431         /* mute pin widget amp left and right (no gain on this amp) */
4432         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4433         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4434          * Line In 2 = 0x03
4435          */
4436         /* mute analog inputs */
4437         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4438         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4439         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4440         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4441         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4442         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4443         /* Unmute Front out path */
4444         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4445         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4446         /* Unmute Headphone out path */
4447         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4448         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4449         /* Unmute Mono out path */
4450         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4451         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4452         { }
4453 };
4454
4455 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4456  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4457  * audio = 0x16, internal speaker = 0x10.
4458  */
4459 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4460         /* Disable all GPIOs */
4461         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4462         /* Internal speaker is connected to headphone pin */
4463         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4464         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4465         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4466         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4467         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4468         /* Ensure all other unused pins are disabled and muted. */
4469         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4470         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4471         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4472         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4473         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4474         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4475         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4476         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4477
4478         /* Disable digital (SPDIF) pins */
4479         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4480         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4481
4482         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus 
4483          * when acting as an output.
4484          */
4485         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4486
4487         /* Start with output sum widgets muted and their output gains at min */
4488         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4489         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4490         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4491         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4492         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4493         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4494         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4495         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4496         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4497
4498         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
4499         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4500         /* Unmute Line1 pin widget output buffer since it starts as an output.
4501          * If the pin mode is changed by the user the pin mode control will
4502          * take care of enabling the pin's input/output buffers as needed.
4503          * Therefore there's no need to enable the input buffer at this
4504          * stage.
4505          */
4506         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4507         /* Unmute input buffer of pin widget used for Line-in (no equiv 
4508          * mixer ctrl)
4509          */
4510         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4511
4512         /* Mute capture amp left and right */
4513         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4514         /* Set ADC connection select to match default mixer setting - line 
4515          * in (on mic1 pin)
4516          */
4517         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4518
4519         /* Do the same for the second ADC: mute capture input amp and
4520          * set ADC connection to line in (on mic1 pin)
4521          */
4522         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4523         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4524
4525         /* Mute all inputs to mixer widget (even unconnected ones) */
4526         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4527         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4528         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4529         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4530         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4531         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4532         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4533         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4534
4535         { }
4536 };
4537
4538 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
4539  * similar laptops (adapted from Fujitsu init verbs).
4540  */
4541 static struct hda_verb alc260_acer_init_verbs[] = {
4542         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
4543          * the headphone jack.  Turn this on and rely on the standard mute
4544          * methods whenever the user wants to turn these outputs off.
4545          */
4546         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4547         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4548         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
4549         /* Internal speaker/Headphone jack is connected to Line-out pin */
4550         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4551         /* Internal microphone/Mic jack is connected to Mic1 pin */
4552         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
4553         /* Line In jack is connected to Line1 pin */
4554         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4555         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
4556         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4557         /* Ensure all other unused pins are disabled and muted. */
4558         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4559         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4560         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4561         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4562         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4563         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4564         /* Disable digital (SPDIF) pins */
4565         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4566         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4567
4568         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum 
4569          * bus when acting as outputs.
4570          */
4571         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4572         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4573
4574         /* Start with output sum widgets muted and their output gains at min */
4575         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4576         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4577         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4578         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4579         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4580         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4581         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4582         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4583         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4584
4585         /* Unmute Line-out pin widget amp left and right
4586          * (no equiv mixer ctrl)
4587          */
4588         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4589         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
4590         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4591         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
4592          * inputs. If the pin mode is changed by the user the pin mode control
4593          * will take care of enabling the pin's input/output buffers as needed.
4594          * Therefore there's no need to enable the input buffer at this
4595          * stage.
4596          */
4597         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4598         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4599
4600         /* Mute capture amp left and right */
4601         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4602         /* Set ADC connection select to match default mixer setting - mic
4603          * (on mic1 pin)
4604          */
4605         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4606
4607         /* Do similar with the second ADC: mute capture input amp and
4608          * set ADC connection to mic to match ALSA's default state.
4609          */
4610         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4611         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4612
4613         /* Mute all inputs to mixer widget (even unconnected ones) */
4614         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4615         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4616         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4617         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4618         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4619         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4620         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4621         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4622
4623         { }
4624 };
4625
4626 static struct hda_verb alc260_will_verbs[] = {
4627         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4628         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
4629         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
4630         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4631         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4632         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
4633         {}
4634 };
4635
4636 static struct hda_verb alc260_replacer_672v_verbs[] = {
4637         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4638         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4639         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
4640
4641         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4642         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4643         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4644
4645         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4646         {}
4647 };
4648
4649 /* toggle speaker-output according to the hp-jack state */
4650 static void alc260_replacer_672v_automute(struct hda_codec *codec)
4651 {
4652         unsigned int present;
4653
4654         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
4655         present = snd_hda_codec_read(codec, 0x0f, 0,
4656                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
4657         if (present) {
4658                 snd_hda_codec_write_cache(codec, 0x01, 0,
4659                                           AC_VERB_SET_GPIO_DATA, 1);
4660                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4661                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4662                                           PIN_HP);
4663         } else {
4664                 snd_hda_codec_write_cache(codec, 0x01, 0,
4665                                           AC_VERB_SET_GPIO_DATA, 0);
4666                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4667                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4668                                           PIN_OUT);
4669         }
4670 }
4671
4672 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
4673                                        unsigned int res)
4674 {
4675         if ((res >> 26) == ALC880_HP_EVENT)
4676                 alc260_replacer_672v_automute(codec);
4677 }
4678
4679 /* Test configuration for debugging, modelled after the ALC880 test
4680  * configuration.
4681  */
4682 #ifdef CONFIG_SND_DEBUG
4683 static hda_nid_t alc260_test_dac_nids[1] = {
4684         0x02,
4685 };
4686 static hda_nid_t alc260_test_adc_nids[2] = {
4687         0x04, 0x05,
4688 };
4689 /* For testing the ALC260, each input MUX needs its own definition since
4690  * the signal assignments are different.  This assumes that the first ADC 
4691  * is NID 0x04.
4692  */
4693 static struct hda_input_mux alc260_test_capture_sources[2] = {
4694         {
4695                 .num_items = 7,
4696                 .items = {
4697                         { "MIC1 pin", 0x0 },
4698                         { "MIC2 pin", 0x1 },
4699                         { "LINE1 pin", 0x2 },
4700                         { "LINE2 pin", 0x3 },
4701                         { "CD pin", 0x4 },
4702                         { "LINE-OUT pin", 0x5 },
4703                         { "HP-OUT pin", 0x6 },
4704                 },
4705         },
4706         {
4707                 .num_items = 8,
4708                 .items = {
4709                         { "MIC1 pin", 0x0 },
4710                         { "MIC2 pin", 0x1 },
4711                         { "LINE1 pin", 0x2 },
4712                         { "LINE2 pin", 0x3 },
4713                         { "CD pin", 0x4 },
4714                         { "Mixer", 0x5 },
4715                         { "LINE-OUT pin", 0x6 },
4716                         { "HP-OUT pin", 0x7 },
4717                 },
4718         },
4719 };
4720 static struct snd_kcontrol_new alc260_test_mixer[] = {
4721         /* Output driver widgets */
4722         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4723         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4724         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4725         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
4726         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4727         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
4728
4729         /* Modes for retasking pin widgets
4730          * Note: the ALC260 doesn't seem to act on requests to enable mic
4731          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
4732          * mention this restriction.  At this stage it's not clear whether
4733          * this behaviour is intentional or is a hardware bug in chip
4734          * revisions available at least up until early 2006.  Therefore for
4735          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
4736          * choices, but if it turns out that the lack of mic bias for these
4737          * NIDs is intentional we could change their modes from
4738          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4739          */
4740         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
4741         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
4742         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
4743         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
4744         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
4745         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
4746
4747         /* Loopback mixer controls */
4748         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
4749         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
4750         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
4751         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
4752         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
4753         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
4754         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
4755         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
4756         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4757         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4758         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4759         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4760         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
4761         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
4762         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
4763         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
4764
4765         /* Controls for GPIO pins, assuming they are configured as outputs */
4766         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
4767         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
4768         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
4769         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
4770
4771         /* Switches to allow the digital IO pins to be enabled.  The datasheet
4772          * is ambigious as to which NID is which; testing on laptops which
4773          * make this output available should provide clarification. 
4774          */
4775         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
4776         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
4777
4778         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
4779          * this output to turn on an external amplifier.
4780          */
4781         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
4782         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
4783
4784         { } /* end */
4785 };
4786 static struct hda_verb alc260_test_init_verbs[] = {
4787         /* Enable all GPIOs as outputs with an initial value of 0 */
4788         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
4789         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4790         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
4791
4792         /* Enable retasking pins as output, initially without power amp */
4793         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4794         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4795         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4796         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4797         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4798         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4799
4800         /* Disable digital (SPDIF) pins initially, but users can enable
4801          * them via a mixer switch.  In the case of SPDIF-out, this initverb
4802          * payload also sets the generation to 0, output to be in "consumer"
4803          * PCM format, copyright asserted, no pre-emphasis and no validity
4804          * control.
4805          */
4806         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4807         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4808
4809         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the 
4810          * OUT1 sum bus when acting as an output.
4811          */
4812         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4813         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
4814         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4815         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
4816
4817         /* Start with output sum widgets muted and their output gains at min */
4818         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4819         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4820         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4821         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4822         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4823         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4824         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4825         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4826         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4827
4828         /* Unmute retasking pin widget output buffers since the default
4829          * state appears to be output.  As the pin mode is changed by the
4830          * user the pin mode control will take care of enabling the pin's
4831          * input/output buffers as needed.
4832          */
4833         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4834         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4835         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4836         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4837         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4838         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4839         /* Also unmute the mono-out pin widget */
4840         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4841
4842         /* Mute capture amp left and right */
4843         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4844         /* Set ADC connection select to match default mixer setting (mic1
4845          * pin)
4846          */
4847         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4848
4849         /* Do the same for the second ADC: mute capture input amp and
4850          * set ADC connection to mic1 pin
4851          */
4852         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4853         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4854
4855         /* Mute all inputs to mixer widget (even unconnected ones) */
4856         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4857         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4858         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4859         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4860         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4861         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4862         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4863         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4864
4865         { }
4866 };
4867 #endif
4868
4869 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
4870 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
4871
4872 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
4873 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
4874
4875 /*
4876  * for BIOS auto-configuration
4877  */
4878
4879 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
4880                                         const char *pfx)
4881 {
4882         hda_nid_t nid_vol;
4883         unsigned long vol_val, sw_val;
4884         char name[32];
4885         int err;
4886
4887         if (nid >= 0x0f && nid < 0x11) {
4888                 nid_vol = nid - 0x7;
4889                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4890                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4891         } else if (nid == 0x11) {
4892                 nid_vol = nid - 0x7;
4893                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
4894                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
4895         } else if (nid >= 0x12 && nid <= 0x15) {
4896                 nid_vol = 0x08;
4897                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4898                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4899         } else
4900                 return 0; /* N/A */
4901         
4902         snprintf(name, sizeof(name), "%s Playback Volume", pfx);
4903         err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
4904         if (err < 0)
4905                 return err;
4906         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
4907         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
4908         if (err < 0)
4909                 return err;
4910         return 1;
4911 }
4912
4913 /* add playback controls from the parsed DAC table */
4914 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
4915                                              const struct auto_pin_cfg *cfg)
4916 {
4917         hda_nid_t nid;
4918         int err;
4919
4920         spec->multiout.num_dacs = 1;
4921         spec->multiout.dac_nids = spec->private_dac_nids;
4922         spec->multiout.dac_nids[0] = 0x02;
4923
4924         nid = cfg->line_out_pins[0];
4925         if (nid) {
4926                 err = alc260_add_playback_controls(spec, nid, "Front");
4927                 if (err < 0)
4928                         return err;
4929         }
4930
4931         nid = cfg->speaker_pins[0];
4932         if (nid) {
4933                 err = alc260_add_playback_controls(spec, nid, "Speaker");
4934                 if (err < 0)
4935                         return err;
4936         }
4937
4938         nid = cfg->hp_pins[0];
4939         if (nid) {
4940                 err = alc260_add_playback_controls(spec, nid, "Headphone");
4941                 if (err < 0)
4942                         return err;
4943         }
4944         return 0;
4945 }
4946
4947 /* create playback/capture controls for input pins */
4948 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
4949                                                 const struct auto_pin_cfg *cfg)
4950 {
4951         struct hda_input_mux *imux = &spec->private_imux;
4952         int i, err, idx;
4953
4954         for (i = 0; i < AUTO_PIN_LAST; i++) {
4955                 if (cfg->input_pins[i] >= 0x12) {
4956                         idx = cfg->input_pins[i] - 0x12;
4957                         err = new_analog_input(spec, cfg->input_pins[i],
4958                                                auto_pin_cfg_labels[i], idx,
4959                                                0x07);
4960                         if (err < 0)
4961                                 return err;
4962                         imux->items[imux->num_items].label =
4963                                 auto_pin_cfg_labels[i];
4964                         imux->items[imux->num_items].index = idx;
4965                         imux->num_items++;
4966                 }
4967                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
4968                         idx = cfg->input_pins[i] - 0x09;
4969                         err = new_analog_input(spec, cfg->input_pins[i],
4970                                                auto_pin_cfg_labels[i], idx,
4971                                                0x07);
4972                         if (err < 0)
4973                                 return err;
4974                         imux->items[imux->num_items].label =
4975                                 auto_pin_cfg_labels[i];
4976                         imux->items[imux->num_items].index = idx;
4977                         imux->num_items++;
4978                 }
4979         }
4980         return 0;
4981 }
4982
4983 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
4984                                               hda_nid_t nid, int pin_type,
4985                                               int sel_idx)
4986 {
4987         alc_set_pin_output(codec, nid, pin_type);
4988         /* need the manual connection? */
4989         if (nid >= 0x12) {
4990                 int idx = nid - 0x12;
4991                 snd_hda_codec_write(codec, idx + 0x0b, 0,
4992                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
4993         }
4994 }
4995
4996 static void alc260_auto_init_multi_out(struct hda_codec *codec)
4997 {
4998         struct alc_spec *spec = codec->spec;
4999         hda_nid_t nid;
5000
5001         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
5002         nid = spec->autocfg.line_out_pins[0];
5003         if (nid) {
5004                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5005                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5006         }
5007         
5008         nid = spec->autocfg.speaker_pins[0];
5009         if (nid)
5010                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5011
5012         nid = spec->autocfg.hp_pins[0];
5013         if (nid)
5014                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5015 }
5016
5017 #define ALC260_PIN_CD_NID               0x16
5018 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5019 {
5020         struct alc_spec *spec = codec->spec;
5021         int i;
5022
5023         for (i = 0; i < AUTO_PIN_LAST; i++) {
5024                 hda_nid_t nid = spec->autocfg.input_pins[i];
5025                 if (nid >= 0x12) {
5026                         snd_hda_codec_write(codec, nid, 0,
5027                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5028                                             i <= AUTO_PIN_FRONT_MIC ?
5029                                             PIN_VREF80 : PIN_IN);
5030                         if (nid != ALC260_PIN_CD_NID)
5031                                 snd_hda_codec_write(codec, nid, 0,
5032                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5033                                                     AMP_OUT_MUTE);
5034                 }
5035         }
5036 }
5037
5038 /*
5039  * generic initialization of ADC, input mixers and output mixers
5040  */
5041 static struct hda_verb alc260_volume_init_verbs[] = {
5042         /*
5043          * Unmute ADC0-1 and set the default input to mic-in
5044          */
5045         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5046         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5047         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5048         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5049         
5050         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5051          * mixer widget
5052          * Note: PASD motherboards uses the Line In 2 as the input for
5053          * front panel mic (mic 2)
5054          */
5055         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5056         /* mute analog inputs */
5057         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5058         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5059         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5060         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5061         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5062
5063         /*
5064          * Set up output mixers (0x08 - 0x0a)
5065          */
5066         /* set vol=0 to output mixers */
5067         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5068         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5069         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5070         /* set up input amps for analog loopback */
5071         /* Amp Indices: DAC = 0, mixer = 1 */
5072         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5073         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5074         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5075         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5076         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5077         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5078         
5079         { }
5080 };
5081
5082 static int alc260_parse_auto_config(struct hda_codec *codec)
5083 {
5084         struct alc_spec *spec = codec->spec;
5085         unsigned int wcap;
5086         int err;
5087         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5088
5089         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5090                                            alc260_ignore);
5091         if (err < 0)
5092                 return err;
5093         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5094         if (err < 0)
5095                 return err;
5096         if (!spec->kctl_alloc)
5097                 return 0; /* can't find valid BIOS pin config */
5098         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5099         if (err < 0)
5100                 return err;
5101
5102         spec->multiout.max_channels = 2;
5103
5104         if (spec->autocfg.dig_out_pin)
5105                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5106         if (spec->kctl_alloc)
5107                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
5108
5109         spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs;
5110
5111         spec->num_mux_defs = 1;
5112         spec->input_mux = &spec->private_imux;
5113
5114         /* check whether NID 0x04 is valid */
5115         wcap = get_wcaps(codec, 0x04);
5116         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
5117         if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
5118                 spec->adc_nids = alc260_adc_nids_alt;
5119                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
5120                 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
5121         } else {
5122                 spec->adc_nids = alc260_adc_nids;
5123                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
5124                 spec->mixers[spec->num_mixers] = alc260_capture_mixer;
5125         }
5126         spec->num_mixers++;
5127
5128         return 1;
5129 }
5130
5131 /* additional initialization for auto-configuration model */
5132 static void alc260_auto_init(struct hda_codec *codec)
5133 {
5134         struct alc_spec *spec = codec->spec;
5135         alc260_auto_init_multi_out(codec);
5136         alc260_auto_init_analog_input(codec);
5137         if (spec->unsol_event)
5138                 alc_sku_automute(codec);
5139 }
5140
5141 #ifdef CONFIG_SND_HDA_POWER_SAVE
5142 static struct hda_amp_list alc260_loopbacks[] = {
5143         { 0x07, HDA_INPUT, 0 },
5144         { 0x07, HDA_INPUT, 1 },
5145         { 0x07, HDA_INPUT, 2 },
5146         { 0x07, HDA_INPUT, 3 },
5147         { 0x07, HDA_INPUT, 4 },
5148         { } /* end */
5149 };
5150 #endif
5151
5152 /*
5153  * ALC260 configurations
5154  */
5155 static const char *alc260_models[ALC260_MODEL_LAST] = {
5156         [ALC260_BASIC]          = "basic",
5157         [ALC260_HP]             = "hp",
5158         [ALC260_HP_3013]        = "hp-3013",
5159         [ALC260_FUJITSU_S702X]  = "fujitsu",
5160         [ALC260_ACER]           = "acer",
5161         [ALC260_WILL]           = "will",
5162         [ALC260_REPLACER_672V]  = "replacer",
5163 #ifdef CONFIG_SND_DEBUG
5164         [ALC260_TEST]           = "test",
5165 #endif
5166         [ALC260_AUTO]           = "auto",
5167 };
5168
5169 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5170         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5171         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5172         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5173         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5174         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5175         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
5176         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_3013),
5177         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5178         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5179         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5180         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5181         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5182         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5183         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5184         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5185         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5186         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5187         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5188         {}
5189 };
5190
5191 static struct alc_config_preset alc260_presets[] = {
5192         [ALC260_BASIC] = {
5193                 .mixers = { alc260_base_output_mixer,
5194                             alc260_input_mixer,
5195                             alc260_pc_beep_mixer,
5196                             alc260_capture_mixer },
5197                 .init_verbs = { alc260_init_verbs },
5198                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5199                 .dac_nids = alc260_dac_nids,
5200                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5201                 .adc_nids = alc260_adc_nids,
5202                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5203                 .channel_mode = alc260_modes,
5204                 .input_mux = &alc260_capture_source,
5205         },
5206         [ALC260_HP] = {
5207                 .mixers = { alc260_hp_output_mixer,
5208                             alc260_input_mixer,
5209                             alc260_capture_alt_mixer },
5210                 .init_verbs = { alc260_init_verbs,
5211                                 alc260_hp_unsol_verbs },
5212                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5213                 .dac_nids = alc260_dac_nids,
5214                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5215                 .adc_nids = alc260_hp_adc_nids,
5216                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5217                 .channel_mode = alc260_modes,
5218                 .input_mux = &alc260_capture_source,
5219                 .unsol_event = alc260_hp_unsol_event,
5220                 .init_hook = alc260_hp_automute,
5221         },
5222         [ALC260_HP_3013] = {
5223                 .mixers = { alc260_hp_3013_mixer,
5224                             alc260_input_mixer,
5225                             alc260_capture_alt_mixer },
5226                 .init_verbs = { alc260_hp_3013_init_verbs,
5227                                 alc260_hp_3013_unsol_verbs },
5228                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5229                 .dac_nids = alc260_dac_nids,
5230                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
5231                 .adc_nids = alc260_hp_adc_nids,
5232                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5233                 .channel_mode = alc260_modes,
5234                 .input_mux = &alc260_capture_source,
5235                 .unsol_event = alc260_hp_3013_unsol_event,
5236                 .init_hook = alc260_hp_3013_automute,
5237         },
5238         [ALC260_FUJITSU_S702X] = {
5239                 .mixers = { alc260_fujitsu_mixer,
5240                             alc260_capture_mixer },
5241                 .init_verbs = { alc260_fujitsu_init_verbs },
5242                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5243                 .dac_nids = alc260_dac_nids,
5244                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5245                 .adc_nids = alc260_dual_adc_nids,
5246                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5247                 .channel_mode = alc260_modes,
5248                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5249                 .input_mux = alc260_fujitsu_capture_sources,
5250         },
5251         [ALC260_ACER] = {
5252                 .mixers = { alc260_acer_mixer,
5253                             alc260_capture_mixer },
5254                 .init_verbs = { alc260_acer_init_verbs },
5255                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5256                 .dac_nids = alc260_dac_nids,
5257                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5258                 .adc_nids = alc260_dual_adc_nids,
5259                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5260                 .channel_mode = alc260_modes,
5261                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5262                 .input_mux = alc260_acer_capture_sources,
5263         },
5264         [ALC260_WILL] = {
5265                 .mixers = { alc260_will_mixer,
5266                             alc260_capture_mixer },
5267                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5268                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5269                 .dac_nids = alc260_dac_nids,
5270                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5271                 .adc_nids = alc260_adc_nids,
5272                 .dig_out_nid = ALC260_DIGOUT_NID,
5273                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5274                 .channel_mode = alc260_modes,
5275                 .input_mux = &alc260_capture_source,
5276         },
5277         [ALC260_REPLACER_672V] = {
5278                 .mixers = { alc260_replacer_672v_mixer,
5279                             alc260_capture_mixer },
5280                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5281                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5282                 .dac_nids = alc260_dac_nids,
5283                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5284                 .adc_nids = alc260_adc_nids,
5285                 .dig_out_nid = ALC260_DIGOUT_NID,
5286                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5287                 .channel_mode = alc260_modes,
5288                 .input_mux = &alc260_capture_source,
5289                 .unsol_event = alc260_replacer_672v_unsol_event,
5290                 .init_hook = alc260_replacer_672v_automute,
5291         },
5292 #ifdef CONFIG_SND_DEBUG
5293         [ALC260_TEST] = {
5294                 .mixers = { alc260_test_mixer,
5295                             alc260_capture_mixer },
5296                 .init_verbs = { alc260_test_init_verbs },
5297                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5298                 .dac_nids = alc260_test_dac_nids,
5299                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5300                 .adc_nids = alc260_test_adc_nids,
5301                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5302                 .channel_mode = alc260_modes,
5303                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5304                 .input_mux = alc260_test_capture_sources,
5305         },
5306 #endif
5307 };
5308
5309 static int patch_alc260(struct hda_codec *codec)
5310 {
5311         struct alc_spec *spec;
5312         int err, board_config;
5313
5314         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5315         if (spec == NULL)
5316                 return -ENOMEM;
5317
5318         codec->spec = spec;
5319
5320         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
5321                                                   alc260_models,
5322                                                   alc260_cfg_tbl);
5323         if (board_config < 0) {
5324                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
5325                            "trying auto-probe from BIOS...\n");
5326                 board_config = ALC260_AUTO;
5327         }
5328
5329         if (board_config == ALC260_AUTO) {
5330                 /* automatic parse from the BIOS config */
5331                 err = alc260_parse_auto_config(codec);
5332                 if (err < 0) {
5333                         alc_free(codec);
5334                         return err;
5335                 } else if (!err) {
5336                         printk(KERN_INFO
5337                                "hda_codec: Cannot set up configuration "
5338                                "from BIOS.  Using base mode...\n");
5339                         board_config = ALC260_BASIC;
5340                 }
5341         }
5342
5343         if (board_config != ALC260_AUTO)
5344                 setup_preset(spec, &alc260_presets[board_config]);
5345
5346         spec->stream_name_analog = "ALC260 Analog";
5347         spec->stream_analog_playback = &alc260_pcm_analog_playback;
5348         spec->stream_analog_capture = &alc260_pcm_analog_capture;
5349
5350         spec->stream_name_digital = "ALC260 Digital";
5351         spec->stream_digital_playback = &alc260_pcm_digital_playback;
5352         spec->stream_digital_capture = &alc260_pcm_digital_capture;
5353
5354         spec->vmaster_nid = 0x08;
5355
5356         codec->patch_ops = alc_patch_ops;
5357         if (board_config == ALC260_AUTO)
5358                 spec->init_hook = alc260_auto_init;
5359 #ifdef CONFIG_SND_HDA_POWER_SAVE
5360         if (!spec->loopback.amplist)
5361                 spec->loopback.amplist = alc260_loopbacks;
5362 #endif
5363
5364         return 0;
5365 }
5366
5367
5368 /*
5369  * ALC882 support
5370  *
5371  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5372  * configuration.  Each pin widget can choose any input DACs and a mixer.
5373  * Each ADC is connected from a mixer of all inputs.  This makes possible
5374  * 6-channel independent captures.
5375  *
5376  * In addition, an independent DAC for the multi-playback (not used in this
5377  * driver yet).
5378  */
5379 #define ALC882_DIGOUT_NID       0x06
5380 #define ALC882_DIGIN_NID        0x0a
5381
5382 static struct hda_channel_mode alc882_ch_modes[1] = {
5383         { 8, NULL }
5384 };
5385
5386 static hda_nid_t alc882_dac_nids[4] = {
5387         /* front, rear, clfe, rear_surr */
5388         0x02, 0x03, 0x04, 0x05
5389 };
5390
5391 /* identical with ALC880 */
5392 #define alc882_adc_nids         alc880_adc_nids
5393 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5394
5395 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5396 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5397
5398 /* input MUX */
5399 /* FIXME: should be a matrix-type input source selection */
5400
5401 static struct hda_input_mux alc882_capture_source = {
5402         .num_items = 4,
5403         .items = {
5404                 { "Mic", 0x0 },
5405                 { "Front Mic", 0x1 },
5406                 { "Line", 0x2 },
5407                 { "CD", 0x4 },
5408         },
5409 };
5410 #define alc882_mux_enum_info alc_mux_enum_info
5411 #define alc882_mux_enum_get alc_mux_enum_get
5412
5413 static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol,
5414                                struct snd_ctl_elem_value *ucontrol)
5415 {
5416         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5417         struct alc_spec *spec = codec->spec;
5418         const struct hda_input_mux *imux = spec->input_mux;
5419         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
5420         hda_nid_t nid = spec->capsrc_nids ?
5421                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
5422         unsigned int *cur_val = &spec->cur_mux[adc_idx];
5423         unsigned int i, idx;
5424
5425         idx = ucontrol->value.enumerated.item[0];
5426         if (idx >= imux->num_items)
5427                 idx = imux->num_items - 1;
5428         if (*cur_val == idx)
5429                 return 0;
5430         for (i = 0; i < imux->num_items; i++) {
5431                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
5432                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
5433                                          imux->items[i].index,
5434                                          HDA_AMP_MUTE, v);
5435         }
5436         *cur_val = idx;
5437         return 1;
5438 }
5439
5440 /*
5441  * 2ch mode
5442  */
5443 static struct hda_verb alc882_3ST_ch2_init[] = {
5444         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5445         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5446         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5447         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5448         { } /* end */
5449 };
5450
5451 /*
5452  * 6ch mode
5453  */
5454 static struct hda_verb alc882_3ST_ch6_init[] = {
5455         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5456         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5457         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5458         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5459         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5460         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5461         { } /* end */
5462 };
5463
5464 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5465         { 2, alc882_3ST_ch2_init },
5466         { 6, alc882_3ST_ch6_init },
5467 };
5468
5469 /*
5470  * 6ch mode
5471  */
5472 static struct hda_verb alc882_sixstack_ch6_init[] = {
5473         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5474         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5475         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5476         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5477         { } /* end */
5478 };
5479
5480 /*
5481  * 8ch mode
5482  */
5483 static struct hda_verb alc882_sixstack_ch8_init[] = {
5484         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5485         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5486         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5487         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5488         { } /* end */
5489 };
5490
5491 static struct hda_channel_mode alc882_sixstack_modes[2] = {
5492         { 6, alc882_sixstack_ch6_init },
5493         { 8, alc882_sixstack_ch8_init },
5494 };
5495
5496 /*
5497  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
5498  */
5499
5500 /*
5501  * 2ch mode
5502  */
5503 static struct hda_verb alc885_mbp_ch2_init[] = {
5504         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5505         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5506         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5507         { } /* end */
5508 };
5509
5510 /*
5511  * 6ch mode
5512  */
5513 static struct hda_verb alc885_mbp_ch6_init[] = {
5514         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5515         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5516         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5517         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5518         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5519         { } /* end */
5520 };
5521
5522 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
5523         { 2, alc885_mbp_ch2_init },
5524         { 6, alc885_mbp_ch6_init },
5525 };
5526
5527
5528 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
5529  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
5530  */
5531 static struct snd_kcontrol_new alc882_base_mixer[] = {
5532         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5533         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5534         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5535         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5536         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5537         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5538         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5539         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5540         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
5541         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
5542         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5543         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5544         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5545         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5546         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5547         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5548         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5549         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5550         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5551         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5552         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5553         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5554         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5555         { } /* end */
5556 };
5557
5558 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
5559         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5560         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
5561         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
5562         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
5563         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5564         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5565         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
5566         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
5567         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
5568         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
5569         { } /* end */
5570 };
5571 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
5572         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5573         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5574         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5575         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5576         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5577         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5578         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5579         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5580         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5581         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5582         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5583         { } /* end */
5584 };
5585
5586 static struct snd_kcontrol_new alc882_targa_mixer[] = {
5587         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5588         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5589         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5590         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5591         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5592         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5593         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5594         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5595         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5596         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5597         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5598         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5599         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5600         { } /* end */
5601 };
5602
5603 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
5604  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
5605  */
5606 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
5607         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5608         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5609         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5610         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
5611         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5612         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5613         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5614         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5615         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
5616         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
5617         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5618         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5619         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5620         { } /* end */
5621 };
5622
5623 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
5624         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5625         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5626         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5627         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5628         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5629         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5630         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5631         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5632         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5633         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5634         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5635         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5636         { } /* end */
5637 };
5638
5639 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
5640         {
5641                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5642                 .name = "Channel Mode",
5643                 .info = alc_ch_mode_info,
5644                 .get = alc_ch_mode_get,
5645                 .put = alc_ch_mode_put,
5646         },
5647         { } /* end */
5648 };
5649
5650 static struct hda_verb alc882_init_verbs[] = {
5651         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5652         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5653         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5654         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5655         /* Rear mixer */
5656         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5657         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5658         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5659         /* CLFE mixer */
5660         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5661         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5662         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5663         /* Side mixer */
5664         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5665         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5666         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5667
5668         /* Front Pin: output 0 (0x0c) */
5669         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5670         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5671         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5672         /* Rear Pin: output 1 (0x0d) */
5673         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5674         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5675         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5676         /* CLFE Pin: output 2 (0x0e) */
5677         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5678         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5679         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
5680         /* Side Pin: output 3 (0x0f) */
5681         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5682         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5683         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
5684         /* Mic (rear) pin: input vref at 80% */
5685         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5686         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5687         /* Front Mic pin: input vref at 80% */
5688         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5689         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5690         /* Line In pin: input */
5691         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5692         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5693         /* Line-2 In: Headphone output (output 0 - 0x0c) */
5694         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5695         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5696         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
5697         /* CD pin widget for input */
5698         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5699
5700         /* FIXME: use matrix-type input source selection */
5701         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5702         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5703         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5704         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5705         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5706         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5707         /* Input mixer2 */
5708         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5709         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5710         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5711         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5712         /* Input mixer3 */
5713         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5714         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5715         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5716         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5717         /* ADC1: mute amp left and right */
5718         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5719         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5720         /* ADC2: mute amp left and right */
5721         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5722         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5723         /* ADC3: mute amp left and right */
5724         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5725         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5726
5727         { }
5728 };
5729
5730 static struct hda_verb alc882_eapd_verbs[] = {
5731         /* change to EAPD mode */
5732         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5733         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
5734         { }
5735 };
5736
5737 /* Mac Pro test */
5738 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
5739         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5740         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5741         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
5742         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
5743         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
5744         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
5745         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
5746         { } /* end */
5747 };
5748
5749 static struct hda_verb alc882_macpro_init_verbs[] = {
5750         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5751         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5752         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5753         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5754         /* Front Pin: output 0 (0x0c) */
5755         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5756         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5757         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5758         /* Front Mic pin: input vref at 80% */
5759         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5760         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5761         /* Speaker:  output */
5762         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5763         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5764         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
5765         /* Headphone output (output 0 - 0x0c) */
5766         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5767         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5768         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5769
5770         /* FIXME: use matrix-type input source selection */
5771         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5772         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5773         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5774         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5775         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5776         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5777         /* Input mixer2 */
5778         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5779         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5780         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5781         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5782         /* Input mixer3 */
5783         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5784         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5785         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5786         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5787         /* ADC1: mute amp left and right */
5788         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5789         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5790         /* ADC2: mute amp left and right */
5791         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5792         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5793         /* ADC3: mute amp left and right */
5794         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5795         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5796
5797         { }
5798 };
5799
5800 /* Macbook Pro rev3 */
5801 static struct hda_verb alc885_mbp3_init_verbs[] = {
5802         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5803         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5804         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5805         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5806         /* Rear mixer */
5807         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5808         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5809         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5810         /* Front Pin: output 0 (0x0c) */
5811         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5812         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5813         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5814         /* HP Pin: output 0 (0x0d) */
5815         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
5816         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5817         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5818         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5819         /* Mic (rear) pin: input vref at 80% */
5820         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5821         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5822         /* Front Mic pin: input vref at 80% */
5823         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5824         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5825         /* Line In pin: use output 1 when in LineOut mode */
5826         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5827         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5828         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
5829
5830         /* FIXME: use matrix-type input source selection */
5831         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5832         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5833         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5834         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5835         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5836         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5837         /* Input mixer2 */
5838         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5839         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5840         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5841         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5842         /* Input mixer3 */
5843         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5844         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5845         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5846         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5847         /* ADC1: mute amp left and right */
5848         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5849         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5850         /* ADC2: mute amp left and right */
5851         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5852         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5853         /* ADC3: mute amp left and right */
5854         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5855         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5856
5857         { }
5858 };
5859
5860 /* iMac 24 mixer. */
5861 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
5862         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5863         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
5864         { } /* end */
5865 };
5866
5867 /* iMac 24 init verbs. */
5868 static struct hda_verb alc885_imac24_init_verbs[] = {
5869         /* Internal speakers: output 0 (0x0c) */
5870         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5871         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5872         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5873         /* Internal speakers: output 0 (0x0c) */
5874         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5875         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5876         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
5877         /* Headphone: output 0 (0x0c) */
5878         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5879         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5880         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5881         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5882         /* Front Mic: input vref at 80% */
5883         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5884         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5885         { }
5886 };
5887
5888 /* Toggle speaker-output according to the hp-jack state */
5889 static void alc885_imac24_automute(struct hda_codec *codec)
5890 {
5891         unsigned int present;
5892
5893         present = snd_hda_codec_read(codec, 0x14, 0,
5894                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5895         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
5896                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5897         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
5898                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5899 }
5900
5901 /* Processes unsolicited events. */
5902 static void alc885_imac24_unsol_event(struct hda_codec *codec,
5903                                       unsigned int res)
5904 {
5905         /* Headphone insertion or removal. */
5906         if ((res >> 26) == ALC880_HP_EVENT)
5907                 alc885_imac24_automute(codec);
5908 }
5909
5910 static void alc885_mbp3_automute(struct hda_codec *codec)
5911 {
5912         unsigned int present;
5913
5914         present = snd_hda_codec_read(codec, 0x15, 0,
5915                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5916         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
5917                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5918         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
5919                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
5920
5921 }
5922 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
5923                                     unsigned int res)
5924 {
5925         /* Headphone insertion or removal. */
5926         if ((res >> 26) == ALC880_HP_EVENT)
5927                 alc885_mbp3_automute(codec);
5928 }
5929
5930
5931 static struct hda_verb alc882_targa_verbs[] = {
5932         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5933         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5934
5935         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5936         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5937         
5938         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5939         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5940         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5941
5942         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5943         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5944         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
5945         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
5946         { } /* end */
5947 };
5948
5949 /* toggle speaker-output according to the hp-jack state */
5950 static void alc882_targa_automute(struct hda_codec *codec)
5951 {
5952         unsigned int present;
5953  
5954         present = snd_hda_codec_read(codec, 0x14, 0,
5955                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5956         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
5957                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5958         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
5959                                   present ? 1 : 3);
5960 }
5961
5962 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
5963 {
5964         /* Looks like the unsol event is incompatible with the standard
5965          * definition.  4bit tag is placed at 26 bit!
5966          */
5967         if (((res >> 26) == ALC880_HP_EVENT)) {
5968                 alc882_targa_automute(codec);
5969         }
5970 }
5971
5972 static struct hda_verb alc882_asus_a7j_verbs[] = {
5973         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5974         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5975
5976         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5977         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5978         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5979         
5980         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5981         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5982         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5983
5984         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5985         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5986         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5987         { } /* end */
5988 };
5989
5990 static struct hda_verb alc882_asus_a7m_verbs[] = {
5991         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5992         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5993
5994         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5995         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5996         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5997         
5998         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5999         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6000         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6001
6002         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6003         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6004         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6005         { } /* end */
6006 };
6007
6008 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6009 {
6010         unsigned int gpiostate, gpiomask, gpiodir;
6011
6012         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6013                                        AC_VERB_GET_GPIO_DATA, 0);
6014
6015         if (!muted)
6016                 gpiostate |= (1 << pin);
6017         else
6018                 gpiostate &= ~(1 << pin);
6019
6020         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
6021                                       AC_VERB_GET_GPIO_MASK, 0);
6022         gpiomask |= (1 << pin);
6023
6024         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
6025                                      AC_VERB_GET_GPIO_DIRECTION, 0);
6026         gpiodir |= (1 << pin);
6027
6028
6029         snd_hda_codec_write(codec, codec->afg, 0,
6030                             AC_VERB_SET_GPIO_MASK, gpiomask);
6031         snd_hda_codec_write(codec, codec->afg, 0,
6032                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
6033
6034         msleep(1);
6035
6036         snd_hda_codec_write(codec, codec->afg, 0,
6037                             AC_VERB_SET_GPIO_DATA, gpiostate);
6038 }
6039
6040 /* set up GPIO at initialization */
6041 static void alc885_macpro_init_hook(struct hda_codec *codec)
6042 {
6043         alc882_gpio_mute(codec, 0, 0);
6044         alc882_gpio_mute(codec, 1, 0);
6045 }
6046
6047 /* set up GPIO and update auto-muting at initialization */
6048 static void alc885_imac24_init_hook(struct hda_codec *codec)
6049 {
6050         alc885_macpro_init_hook(codec);
6051         alc885_imac24_automute(codec);
6052 }
6053
6054 /*
6055  * generic initialization of ADC, input mixers and output mixers
6056  */
6057 static struct hda_verb alc882_auto_init_verbs[] = {
6058         /*
6059          * Unmute ADC0-2 and set the default input to mic-in
6060          */
6061         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6062         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6063         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6064         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6065         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6066         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6067
6068         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6069          * mixer widget
6070          * Note: PASD motherboards uses the Line In 2 as the input for
6071          * front panel mic (mic 2)
6072          */
6073         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6074         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6075         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6076         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6077         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6078         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6079
6080         /*
6081          * Set up output mixers (0x0c - 0x0f)
6082          */
6083         /* set vol=0 to output mixers */
6084         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6085         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6086         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6087         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6088         /* set up input amps for analog loopback */
6089         /* Amp Indices: DAC = 0, mixer = 1 */
6090         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6091         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6092         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6093         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6094         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6095         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6096         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6097         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6098         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6099         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6100
6101         /* FIXME: use matrix-type input source selection */
6102         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6103         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6104         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6105         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6106         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6107         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6108         /* Input mixer2 */
6109         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6110         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6111         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6112         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6113         /* Input mixer3 */
6114         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6115         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6116         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6117         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6118
6119         { }
6120 };
6121
6122 /* capture mixer elements */
6123 static struct snd_kcontrol_new alc882_capture_alt_mixer[] = {
6124         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6125         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6126         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6127         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6128         {
6129                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6130                 /* The multiple "Capture Source" controls confuse alsamixer
6131                  * So call somewhat different..
6132                  */
6133                 /* .name = "Capture Source", */
6134                 .name = "Input Source",
6135                 .count = 2,
6136                 .info = alc882_mux_enum_info,
6137                 .get = alc882_mux_enum_get,
6138                 .put = alc882_mux_enum_put,
6139         },
6140         { } /* end */
6141 };
6142
6143 static struct snd_kcontrol_new alc882_capture_mixer[] = {
6144         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
6145         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
6146         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
6147         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
6148         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
6149         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
6150         {
6151                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6152                 /* The multiple "Capture Source" controls confuse alsamixer
6153                  * So call somewhat different..
6154                  */
6155                 /* .name = "Capture Source", */
6156                 .name = "Input Source",
6157                 .count = 3,
6158                 .info = alc882_mux_enum_info,
6159                 .get = alc882_mux_enum_get,
6160                 .put = alc882_mux_enum_put,
6161         },
6162         { } /* end */
6163 };
6164
6165 #ifdef CONFIG_SND_HDA_POWER_SAVE
6166 #define alc882_loopbacks        alc880_loopbacks
6167 #endif
6168
6169 /* pcm configuration: identiacal with ALC880 */
6170 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6171 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6172 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6173 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6174
6175 /*
6176  * configuration and preset
6177  */
6178 static const char *alc882_models[ALC882_MODEL_LAST] = {
6179         [ALC882_3ST_DIG]        = "3stack-dig",
6180         [ALC882_6ST_DIG]        = "6stack-dig",
6181         [ALC882_ARIMA]          = "arima",
6182         [ALC882_W2JC]           = "w2jc",
6183         [ALC882_TARGA]          = "targa",
6184         [ALC882_ASUS_A7J]       = "asus-a7j",
6185         [ALC882_ASUS_A7M]       = "asus-a7m",
6186         [ALC885_MACPRO]         = "macpro",
6187         [ALC885_MBP3]           = "mbp3",
6188         [ALC885_IMAC24]         = "imac24",
6189         [ALC882_AUTO]           = "auto",
6190 };
6191
6192 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6193         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6194         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6195         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6196         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6197         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6198         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6199         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6200         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6201         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6202         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6203         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6204         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6205         {}
6206 };
6207
6208 static struct alc_config_preset alc882_presets[] = {
6209         [ALC882_3ST_DIG] = {
6210                 .mixers = { alc882_base_mixer },
6211                 .init_verbs = { alc882_init_verbs },
6212                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6213                 .dac_nids = alc882_dac_nids,
6214                 .dig_out_nid = ALC882_DIGOUT_NID,
6215                 .dig_in_nid = ALC882_DIGIN_NID,
6216                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6217                 .channel_mode = alc882_ch_modes,
6218                 .need_dac_fix = 1,
6219                 .input_mux = &alc882_capture_source,
6220         },
6221         [ALC882_6ST_DIG] = {
6222                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6223                 .init_verbs = { alc882_init_verbs },
6224                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6225                 .dac_nids = alc882_dac_nids,
6226                 .dig_out_nid = ALC882_DIGOUT_NID,
6227                 .dig_in_nid = ALC882_DIGIN_NID,
6228                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6229                 .channel_mode = alc882_sixstack_modes,
6230                 .input_mux = &alc882_capture_source,
6231         },
6232         [ALC882_ARIMA] = {
6233                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6234                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6235                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6236                 .dac_nids = alc882_dac_nids,
6237                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6238                 .channel_mode = alc882_sixstack_modes,
6239                 .input_mux = &alc882_capture_source,
6240         },
6241         [ALC882_W2JC] = {
6242                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6243                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6244                                 alc880_gpio1_init_verbs },
6245                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6246                 .dac_nids = alc882_dac_nids,
6247                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6248                 .channel_mode = alc880_threestack_modes,
6249                 .need_dac_fix = 1,
6250                 .input_mux = &alc882_capture_source,
6251                 .dig_out_nid = ALC882_DIGOUT_NID,
6252         },
6253         [ALC885_MBP3] = {
6254                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6255                 .init_verbs = { alc885_mbp3_init_verbs,
6256                                 alc880_gpio1_init_verbs },
6257                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6258                 .dac_nids = alc882_dac_nids,
6259                 .channel_mode = alc885_mbp_6ch_modes,
6260                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
6261                 .input_mux = &alc882_capture_source,
6262                 .dig_out_nid = ALC882_DIGOUT_NID,
6263                 .dig_in_nid = ALC882_DIGIN_NID,
6264                 .unsol_event = alc885_mbp3_unsol_event,
6265                 .init_hook = alc885_mbp3_automute,
6266         },
6267         [ALC885_MACPRO] = {
6268                 .mixers = { alc882_macpro_mixer },
6269                 .init_verbs = { alc882_macpro_init_verbs },
6270                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6271                 .dac_nids = alc882_dac_nids,
6272                 .dig_out_nid = ALC882_DIGOUT_NID,
6273                 .dig_in_nid = ALC882_DIGIN_NID,
6274                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6275                 .channel_mode = alc882_ch_modes,
6276                 .input_mux = &alc882_capture_source,
6277                 .init_hook = alc885_macpro_init_hook,
6278         },
6279         [ALC885_IMAC24] = {
6280                 .mixers = { alc885_imac24_mixer },
6281                 .init_verbs = { alc885_imac24_init_verbs },
6282                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6283                 .dac_nids = alc882_dac_nids,
6284                 .dig_out_nid = ALC882_DIGOUT_NID,
6285                 .dig_in_nid = ALC882_DIGIN_NID,
6286                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6287                 .channel_mode = alc882_ch_modes,
6288                 .input_mux = &alc882_capture_source,
6289                 .unsol_event = alc885_imac24_unsol_event,
6290                 .init_hook = alc885_imac24_init_hook,
6291         },
6292         [ALC882_TARGA] = {
6293                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer,
6294                             alc882_capture_mixer },
6295                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6296                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6297                 .dac_nids = alc882_dac_nids,
6298                 .dig_out_nid = ALC882_DIGOUT_NID,
6299                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6300                 .adc_nids = alc882_adc_nids,
6301                 .capsrc_nids = alc882_capsrc_nids,
6302                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6303                 .channel_mode = alc882_3ST_6ch_modes,
6304                 .need_dac_fix = 1,
6305                 .input_mux = &alc882_capture_source,
6306                 .unsol_event = alc882_targa_unsol_event,
6307                 .init_hook = alc882_targa_automute,
6308         },
6309         [ALC882_ASUS_A7J] = {
6310                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer,
6311                             alc882_capture_mixer },
6312                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6313                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6314                 .dac_nids = alc882_dac_nids,
6315                 .dig_out_nid = ALC882_DIGOUT_NID,
6316                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6317                 .adc_nids = alc882_adc_nids,
6318                 .capsrc_nids = alc882_capsrc_nids,
6319                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6320                 .channel_mode = alc882_3ST_6ch_modes,
6321                 .need_dac_fix = 1,
6322                 .input_mux = &alc882_capture_source,
6323         },      
6324         [ALC882_ASUS_A7M] = {
6325                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6326                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6327                                 alc880_gpio1_init_verbs,
6328                                 alc882_asus_a7m_verbs },
6329                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6330                 .dac_nids = alc882_dac_nids,
6331                 .dig_out_nid = ALC882_DIGOUT_NID,
6332                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6333                 .channel_mode = alc880_threestack_modes,
6334                 .need_dac_fix = 1,
6335                 .input_mux = &alc882_capture_source,
6336         },      
6337 };
6338
6339
6340 /*
6341  * Pin config fixes
6342  */
6343 enum { 
6344         PINFIX_ABIT_AW9D_MAX
6345 };
6346
6347 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6348         { 0x15, 0x01080104 }, /* side */
6349         { 0x16, 0x01011012 }, /* rear */
6350         { 0x17, 0x01016011 }, /* clfe */
6351         { }
6352 };
6353
6354 static const struct alc_pincfg *alc882_pin_fixes[] = {
6355         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6356 };
6357
6358 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6359         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6360         {}
6361 };
6362
6363 /*
6364  * BIOS auto configuration
6365  */
6366 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6367                                               hda_nid_t nid, int pin_type,
6368                                               int dac_idx)
6369 {
6370         /* set as output */
6371         struct alc_spec *spec = codec->spec;
6372         int idx;
6373
6374         alc_set_pin_output(codec, nid, pin_type);
6375         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6376                 idx = 4;
6377         else
6378                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6379         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6380
6381 }
6382
6383 static void alc882_auto_init_multi_out(struct hda_codec *codec)
6384 {
6385         struct alc_spec *spec = codec->spec;
6386         int i;
6387
6388         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6389         for (i = 0; i <= HDA_SIDE; i++) {
6390                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6391                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6392                 if (nid)
6393                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6394                                                           i);
6395         }
6396 }
6397
6398 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6399 {
6400         struct alc_spec *spec = codec->spec;
6401         hda_nid_t pin;
6402
6403         pin = spec->autocfg.hp_pins[0];
6404         if (pin) /* connect to front */
6405                 /* use dac 0 */
6406                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6407         pin = spec->autocfg.speaker_pins[0];
6408         if (pin)
6409                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6410 }
6411
6412 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6413 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6414
6415 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6416 {
6417         struct alc_spec *spec = codec->spec;
6418         int i;
6419
6420         for (i = 0; i < AUTO_PIN_LAST; i++) {
6421                 hda_nid_t nid = spec->autocfg.input_pins[i];
6422                 unsigned int vref;
6423                 if (!nid)
6424                         continue;
6425                 vref = PIN_IN;
6426                 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6427                         unsigned int pincap;
6428                         pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
6429                         if ((pincap >> AC_PINCAP_VREF_SHIFT) &
6430                             AC_PINCAP_VREF_80)
6431                                 vref = PIN_VREF80;
6432                 }
6433                 snd_hda_codec_write(codec, nid, 0,
6434                                     AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6435                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6436                         snd_hda_codec_write(codec, nid, 0,
6437                                             AC_VERB_SET_AMP_GAIN_MUTE,
6438                                             AMP_OUT_MUTE);
6439         }
6440 }
6441
6442 static void alc882_auto_init_input_src(struct hda_codec *codec)
6443 {
6444         struct alc_spec *spec = codec->spec;
6445         const struct hda_input_mux *imux = spec->input_mux;
6446         int c;
6447
6448         for (c = 0; c < spec->num_adc_nids; c++) {
6449                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
6450                 hda_nid_t nid = spec->capsrc_nids[c];
6451                 int conns, mute, idx, item;
6452
6453                 conns = snd_hda_get_connections(codec, nid, conn_list,
6454                                                 ARRAY_SIZE(conn_list));
6455                 if (conns < 0)
6456                         continue;
6457                 for (idx = 0; idx < conns; idx++) {
6458                         /* if the current connection is the selected one,
6459                          * unmute it as default - otherwise mute it
6460                          */
6461                         mute = AMP_IN_MUTE(idx);
6462                         for (item = 0; item < imux->num_items; item++) {
6463                                 if (imux->items[item].index == idx) {
6464                                         if (spec->cur_mux[c] == item)
6465                                                 mute = AMP_IN_UNMUTE(idx);
6466                                         break;
6467                                 }
6468                         }
6469                         snd_hda_codec_write(codec, nid, 0,
6470                                             AC_VERB_SET_AMP_GAIN_MUTE, mute);
6471                 }
6472         }
6473 }
6474
6475 /* add mic boosts if needed */
6476 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6477 {
6478         struct alc_spec *spec = codec->spec;
6479         int err;
6480         hda_nid_t nid;
6481
6482         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6483         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6484                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6485                                   "Mic Boost",
6486                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6487                 if (err < 0)
6488                         return err;
6489         }
6490         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6491         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6492                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6493                                   "Front Mic Boost",
6494                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6495                 if (err < 0)
6496                         return err;
6497         }
6498         return 0;
6499 }
6500
6501 /* almost identical with ALC880 parser... */
6502 static int alc882_parse_auto_config(struct hda_codec *codec)
6503 {
6504         struct alc_spec *spec = codec->spec;
6505         int err = alc880_parse_auto_config(codec);
6506
6507         if (err < 0)
6508                 return err;
6509         else if (!err)
6510                 return 0; /* no config found */
6511
6512         err = alc_auto_add_mic_boost(codec);
6513         if (err < 0)
6514                 return err;
6515
6516         /* hack - override the init verbs */
6517         spec->init_verbs[0] = alc882_auto_init_verbs;
6518
6519         return 1; /* config found */
6520 }
6521
6522 /* additional initialization for auto-configuration model */
6523 static void alc882_auto_init(struct hda_codec *codec)
6524 {
6525         struct alc_spec *spec = codec->spec;
6526         alc882_auto_init_multi_out(codec);
6527         alc882_auto_init_hp_out(codec);
6528         alc882_auto_init_analog_input(codec);
6529         alc882_auto_init_input_src(codec);
6530         if (spec->unsol_event)
6531                 alc_sku_automute(codec);
6532 }
6533
6534 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
6535
6536 static int patch_alc882(struct hda_codec *codec)
6537 {
6538         struct alc_spec *spec;
6539         int err, board_config;
6540
6541         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6542         if (spec == NULL)
6543                 return -ENOMEM;
6544
6545         codec->spec = spec;
6546
6547         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
6548                                                   alc882_models,
6549                                                   alc882_cfg_tbl);
6550
6551         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
6552                 /* Pick up systems that don't supply PCI SSID */
6553                 switch (codec->subsystem_id) {
6554                 case 0x106b0c00: /* Mac Pro */
6555                         board_config = ALC885_MACPRO;
6556                         break;
6557                 case 0x106b1000: /* iMac 24 */
6558                 case 0x106b2800: /* AppleTV */
6559                         board_config = ALC885_IMAC24;
6560                         break;
6561                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
6562                 case 0x106b2c00: /* Macbook Pro rev3 */
6563                 case 0x106b3600: /* Macbook 3.1 */
6564                         board_config = ALC885_MBP3;
6565                         break;
6566                 default:
6567                         /* ALC889A is handled better as ALC888-compatible */
6568                         if (codec->revision_id == 0x100103) {
6569                                 alc_free(codec);
6570                                 return patch_alc883(codec);
6571                         }
6572                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
6573                                          "trying auto-probe from BIOS...\n");
6574                         board_config = ALC882_AUTO;
6575                 }
6576         }
6577
6578         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
6579
6580         if (board_config == ALC882_AUTO) {
6581                 /* automatic parse from the BIOS config */
6582                 err = alc882_parse_auto_config(codec);
6583                 if (err < 0) {
6584                         alc_free(codec);
6585                         return err;
6586                 } else if (!err) {
6587                         printk(KERN_INFO
6588                                "hda_codec: Cannot set up configuration "
6589                                "from BIOS.  Using base mode...\n");
6590                         board_config = ALC882_3ST_DIG;
6591                 }
6592         }
6593
6594         if (board_config != ALC882_AUTO)
6595                 setup_preset(spec, &alc882_presets[board_config]);
6596
6597         if (codec->vendor_id == 0x10ec0885) {
6598                 spec->stream_name_analog = "ALC885 Analog";
6599                 spec->stream_name_digital = "ALC885 Digital";
6600         } else {
6601                 spec->stream_name_analog = "ALC882 Analog";
6602                 spec->stream_name_digital = "ALC882 Digital";
6603         }
6604
6605         spec->stream_analog_playback = &alc882_pcm_analog_playback;
6606         spec->stream_analog_capture = &alc882_pcm_analog_capture;
6607         /* FIXME: setup DAC5 */
6608         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
6609         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
6610
6611         spec->stream_digital_playback = &alc882_pcm_digital_playback;
6612         spec->stream_digital_capture = &alc882_pcm_digital_capture;
6613
6614         if (!spec->adc_nids && spec->input_mux) {
6615                 /* check whether NID 0x07 is valid */
6616                 unsigned int wcap = get_wcaps(codec, 0x07);
6617                 /* get type */
6618                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
6619                 if (wcap != AC_WID_AUD_IN) {
6620                         spec->adc_nids = alc882_adc_nids_alt;
6621                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
6622                         spec->capsrc_nids = alc882_capsrc_nids_alt;
6623                         spec->mixers[spec->num_mixers] =
6624                                 alc882_capture_alt_mixer;
6625                         spec->num_mixers++;
6626                 } else {
6627                         spec->adc_nids = alc882_adc_nids;
6628                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
6629                         spec->capsrc_nids = alc882_capsrc_nids;
6630                         spec->mixers[spec->num_mixers] = alc882_capture_mixer;
6631                         spec->num_mixers++;
6632                 }
6633         }
6634
6635         spec->vmaster_nid = 0x0c;
6636
6637         codec->patch_ops = alc_patch_ops;
6638         if (board_config == ALC882_AUTO)
6639                 spec->init_hook = alc882_auto_init;
6640 #ifdef CONFIG_SND_HDA_POWER_SAVE
6641         if (!spec->loopback.amplist)
6642                 spec->loopback.amplist = alc882_loopbacks;
6643 #endif
6644
6645         return 0;
6646 }
6647
6648 /*
6649  * ALC883 support
6650  *
6651  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
6652  * configuration.  Each pin widget can choose any input DACs and a mixer.
6653  * Each ADC is connected from a mixer of all inputs.  This makes possible
6654  * 6-channel independent captures.
6655  *
6656  * In addition, an independent DAC for the multi-playback (not used in this
6657  * driver yet).
6658  */
6659 #define ALC883_DIGOUT_NID       0x06
6660 #define ALC883_DIGIN_NID        0x0a
6661
6662 static hda_nid_t alc883_dac_nids[4] = {
6663         /* front, rear, clfe, rear_surr */
6664         0x02, 0x03, 0x04, 0x05
6665 };
6666
6667 static hda_nid_t alc883_adc_nids[2] = {
6668         /* ADC1-2 */
6669         0x08, 0x09,
6670 };
6671
6672 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
6673
6674 /* input MUX */
6675 /* FIXME: should be a matrix-type input source selection */
6676
6677 static struct hda_input_mux alc883_capture_source = {
6678         .num_items = 4,
6679         .items = {
6680                 { "Mic", 0x0 },
6681                 { "Front Mic", 0x1 },
6682                 { "Line", 0x2 },
6683                 { "CD", 0x4 },
6684         },
6685 };
6686
6687 static struct hda_input_mux alc883_3stack_6ch_intel = {
6688         .num_items = 4,
6689         .items = {
6690                 { "Mic", 0x1 },
6691                 { "Front Mic", 0x0 },
6692                 { "Line", 0x2 },
6693                 { "CD", 0x4 },
6694         },
6695 };
6696
6697 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6698         .num_items = 2,
6699         .items = {
6700                 { "Mic", 0x1 },
6701                 { "Line", 0x2 },
6702         },
6703 };
6704
6705 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6706         .num_items = 4,
6707         .items = {
6708                 { "Mic", 0x0 },
6709                 { "iMic", 0x1 },
6710                 { "Line", 0x2 },
6711                 { "CD", 0x4 },
6712         },
6713 };
6714
6715 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6716         .num_items = 2,
6717         .items = {
6718                 { "Mic", 0x0 },
6719                 { "Int Mic", 0x1 },
6720         },
6721 };
6722
6723 #define alc883_mux_enum_info alc_mux_enum_info
6724 #define alc883_mux_enum_get alc_mux_enum_get
6725 /* ALC883 has the ALC882-type input selection */
6726 #define alc883_mux_enum_put alc882_mux_enum_put
6727
6728 /*
6729  * 2ch mode
6730  */
6731 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6732         { 2, NULL }
6733 };
6734
6735 /*
6736  * 2ch mode
6737  */
6738 static struct hda_verb alc883_3ST_ch2_init[] = {
6739         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6740         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6741         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6742         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6743         { } /* end */
6744 };
6745
6746 /*
6747  * 4ch mode
6748  */
6749 static struct hda_verb alc883_3ST_ch4_init[] = {
6750         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6751         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6752         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6753         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6754         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6755         { } /* end */
6756 };
6757
6758 /*
6759  * 6ch mode
6760  */
6761 static struct hda_verb alc883_3ST_ch6_init[] = {
6762         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6763         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6764         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6765         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6766         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6767         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6768         { } /* end */
6769 };
6770
6771 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
6772         { 2, alc883_3ST_ch2_init },
6773         { 4, alc883_3ST_ch4_init },
6774         { 6, alc883_3ST_ch6_init },
6775 };
6776
6777 /*
6778  * 2ch mode
6779  */
6780 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
6781         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6782         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6783         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6784         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6785         { } /* end */
6786 };
6787
6788 /*
6789  * 4ch mode
6790  */
6791 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
6792         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6793         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6794         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6795         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6796         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6797         { } /* end */
6798 };
6799
6800 /*
6801  * 6ch mode
6802  */
6803 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
6804         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6805         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6806         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
6807         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6808         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6809         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6810         { } /* end */
6811 };
6812
6813 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
6814         { 2, alc883_3ST_ch2_intel_init },
6815         { 4, alc883_3ST_ch4_intel_init },
6816         { 6, alc883_3ST_ch6_intel_init },
6817 };
6818
6819 /*
6820  * 6ch mode
6821  */
6822 static struct hda_verb alc883_sixstack_ch6_init[] = {
6823         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6824         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6825         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6826         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6827         { } /* end */
6828 };
6829
6830 /*
6831  * 8ch mode
6832  */
6833 static struct hda_verb alc883_sixstack_ch8_init[] = {
6834         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6835         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6836         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6837         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6838         { } /* end */
6839 };
6840
6841 static struct hda_channel_mode alc883_sixstack_modes[2] = {
6842         { 6, alc883_sixstack_ch6_init },
6843         { 8, alc883_sixstack_ch8_init },
6844 };
6845
6846 static struct hda_verb alc883_medion_eapd_verbs[] = {
6847         /* eanable EAPD on medion laptop */
6848         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6849         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
6850         { }
6851 };
6852
6853 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6854  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6855  */
6856
6857 static struct snd_kcontrol_new alc883_base_mixer[] = {
6858         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6859         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6860         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6861         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6862         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6863         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6864         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6865         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6866         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6867         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6868         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6869         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6870         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6871         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6872         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6873         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6874         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6875         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6876         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6877         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6878         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6879         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6880         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6881         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6882         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6883         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6884         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6885         {
6886                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6887                 /* .name = "Capture Source", */
6888                 .name = "Input Source",
6889                 .count = 2,
6890                 .info = alc883_mux_enum_info,
6891                 .get = alc883_mux_enum_get,
6892                 .put = alc883_mux_enum_put,
6893         },
6894         { } /* end */
6895 };
6896
6897 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
6898         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6899         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6900         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6901         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6902         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6903         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6904         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6905         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6906         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6907         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6908         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6909         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6910         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6911         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6912         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6913         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6914         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6915         {
6916                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6917                 /* .name = "Capture Source", */
6918                 .name = "Input Source",
6919                 .count = 2,
6920                 .info = alc883_mux_enum_info,
6921                 .get = alc883_mux_enum_get,
6922                 .put = alc883_mux_enum_put,
6923         },
6924         { } /* end */
6925 };
6926
6927 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
6928         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6929         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
6930         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6931         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6932         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6933         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6934         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6935         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6936         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6937         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6938         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6939         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6940         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6941         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6942         {
6943                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6944                 /* .name = "Capture Source", */
6945                 .name = "Input Source",
6946                 .count = 2,
6947                 .info = alc883_mux_enum_info,
6948                 .get = alc883_mux_enum_get,
6949                 .put = alc883_mux_enum_put,
6950         },
6951         { } /* end */
6952 };
6953
6954 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
6955         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6956         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
6957         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6958         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6959         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6960         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6961         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6962         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6963         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6964         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6965         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6966         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6967         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6968         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6969         {
6970                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6971                 /* .name = "Capture Source", */
6972                 .name = "Input Source",
6973                 .count = 2,
6974                 .info = alc883_mux_enum_info,
6975                 .get = alc883_mux_enum_get,
6976                 .put = alc883_mux_enum_put,
6977         },
6978         { } /* end */
6979 };
6980
6981 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
6982         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6983         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6984         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6985         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6986         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6987         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6988         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6989         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6990         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6991         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6992         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6993         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6994         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6995         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6996         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6997         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6998         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6999         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7000         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7001         {
7002                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7003                 /* .name = "Capture Source", */
7004                 .name = "Input Source",
7005                 .count = 2,
7006                 .info = alc883_mux_enum_info,
7007                 .get = alc883_mux_enum_get,
7008                 .put = alc883_mux_enum_put,
7009         },
7010         { } /* end */
7011 };
7012
7013 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7014         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7015         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7016         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7017         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7018         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7019         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7020         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7021         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7022         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7023         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7024         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7025         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7026         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7027         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7028         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7029         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7030         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7031         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7032         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7033         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7034         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7035         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7036         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7037         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7038         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7039         {
7040                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7041                 /* .name = "Capture Source", */
7042                 .name = "Input Source",
7043                 .count = 2,
7044                 .info = alc883_mux_enum_info,
7045                 .get = alc883_mux_enum_get,
7046                 .put = alc883_mux_enum_put,
7047         },
7048         { } /* end */
7049 };
7050
7051 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7052         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7053         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7054         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7055         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7056         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7057                               HDA_OUTPUT),
7058         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7059         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7060         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7061         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7062         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7063         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7064         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7065         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7066         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7067         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7068         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7069         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7070         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7071         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7072         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7073         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7074         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7075         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7076         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7077         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7078         {
7079                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7080                 /* .name = "Capture Source", */
7081                 .name = "Input Source",
7082                 .count = 2,
7083                 .info = alc883_mux_enum_info,
7084                 .get = alc883_mux_enum_get,
7085                 .put = alc883_mux_enum_put,
7086         },
7087         { } /* end */
7088 };
7089
7090 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7091         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7092         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7093         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7094         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7095         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7096         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7097         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7098         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7099         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7100         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7101         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7102         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7103         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7104         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7105         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7106         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7107         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7108         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7109         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7110         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7111         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7112         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7113         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7114
7115         {
7116                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7117                 /* .name = "Capture Source", */
7118                 .name = "Input Source",
7119                 .count = 1,
7120                 .info = alc883_mux_enum_info,
7121                 .get = alc883_mux_enum_get,
7122                 .put = alc883_mux_enum_put,
7123         },
7124         { } /* end */
7125 };
7126
7127 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
7128         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7129         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7130         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7131         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7132         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7133         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7134         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7135         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7136         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7137         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7138         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7139         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7140         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7141         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7142         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7143         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7144         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7145         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7146         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7147         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7148         {
7149                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7150                 /* .name = "Capture Source", */
7151                 .name = "Input Source",
7152                 .count = 2,
7153                 .info = alc883_mux_enum_info,
7154                 .get = alc883_mux_enum_get,
7155                 .put = alc883_mux_enum_put,
7156         },
7157         { } /* end */
7158 };
7159
7160 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
7161         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7162         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7163         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7164         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7165         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7166         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7167         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7168         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7169         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7170         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7171         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7172         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7173         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7174         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7175         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7176         {
7177                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7178                 /* .name = "Capture Source", */
7179                 .name = "Input Source",
7180                 .count = 2,
7181                 .info = alc883_mux_enum_info,
7182                 .get = alc883_mux_enum_get,
7183                 .put = alc883_mux_enum_put,
7184         },
7185         { } /* end */
7186 };
7187
7188 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7189         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7190         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7191         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7192         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7193         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7194         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7195         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7196         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7197         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7198         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7199         {
7200                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7201                 /* .name = "Capture Source", */
7202                 .name = "Input Source",
7203                 .count = 1,
7204                 .info = alc883_mux_enum_info,
7205                 .get = alc883_mux_enum_get,
7206                 .put = alc883_mux_enum_put,
7207         },
7208         { } /* end */
7209 };
7210
7211 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7212         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7213         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7214         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7215         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7216         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7217         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7218         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7219         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7220         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7221         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7222         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7223         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7224         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7225         {
7226                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7227                 /* .name = "Capture Source", */
7228                 .name = "Input Source",
7229                 .count = 2,
7230                 .info = alc883_mux_enum_info,
7231                 .get = alc883_mux_enum_get,
7232                 .put = alc883_mux_enum_put,
7233         },
7234         { } /* end */
7235 };
7236
7237 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7238         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7239         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7240         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7241         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7242         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7243         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7244         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7245         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7246         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7247         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7248         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7249         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7250         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7251         {
7252                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7253                 /* .name = "Capture Source", */
7254                 .name = "Input Source",
7255                 .count = 2,
7256                 .info = alc883_mux_enum_info,
7257                 .get = alc883_mux_enum_get,
7258                 .put = alc883_mux_enum_put,
7259         },
7260         { } /* end */
7261 };      
7262
7263 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7264         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7265         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7266         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7267         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7268         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7269         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7270         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7271         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7272         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7273         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7274         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7275         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7276         {
7277                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7278                 /* .name = "Capture Source", */
7279                 .name = "Input Source",
7280                 .count = 2,
7281                 .info = alc883_mux_enum_info,
7282                 .get = alc883_mux_enum_get,
7283                 .put = alc883_mux_enum_put,
7284         },
7285         { } /* end */
7286 };
7287
7288 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7289         {
7290                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7291                 .name = "Channel Mode",
7292                 .info = alc_ch_mode_info,
7293                 .get = alc_ch_mode_get,
7294                 .put = alc_ch_mode_put,
7295         },
7296         { } /* end */
7297 };
7298
7299 static struct hda_verb alc883_init_verbs[] = {
7300         /* ADC1: mute amp left and right */
7301         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7302         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7303         /* ADC2: mute amp left and right */
7304         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7305         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7306         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7307         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7308         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7309         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7310         /* Rear mixer */
7311         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7312         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7313         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7314         /* CLFE mixer */
7315         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7316         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7317         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7318         /* Side mixer */
7319         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7320         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7321         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7322
7323         /* mute analog input loopbacks */
7324         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7325         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7326         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7327         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7328         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7329
7330         /* Front Pin: output 0 (0x0c) */
7331         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7332         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7333         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7334         /* Rear Pin: output 1 (0x0d) */
7335         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7336         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7337         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7338         /* CLFE Pin: output 2 (0x0e) */
7339         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7340         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7341         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7342         /* Side Pin: output 3 (0x0f) */
7343         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7344         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7345         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7346         /* Mic (rear) pin: input vref at 80% */
7347         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7348         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7349         /* Front Mic pin: input vref at 80% */
7350         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7351         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7352         /* Line In pin: input */
7353         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7354         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7355         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7356         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7357         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7358         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7359         /* CD pin widget for input */
7360         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7361
7362         /* FIXME: use matrix-type input source selection */
7363         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7364         /* Input mixer2 */
7365         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7366         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7367         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7368         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7369         /* Input mixer3 */
7370         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7371         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7372         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7373         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7374         { }
7375 };
7376
7377 /* toggle speaker-output according to the hp-jack state */
7378 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7379 {
7380         unsigned int present;
7381
7382         present = snd_hda_codec_read(codec, 0x15, 0,
7383                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7384         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7385                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7386         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7387                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7388 }
7389
7390 /* auto-toggle front mic */
7391 /*
7392 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7393 {
7394         unsigned int present;
7395         unsigned char bits;
7396
7397         present = snd_hda_codec_read(codec, 0x18, 0,
7398                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7399         bits = present ? HDA_AMP_MUTE : 0;
7400         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7401 }
7402 */
7403
7404 static void alc883_mitac_automute(struct hda_codec *codec)
7405 {
7406         alc883_mitac_hp_automute(codec);
7407         /* alc883_mitac_mic_automute(codec); */
7408 }
7409
7410 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7411                                            unsigned int res)
7412 {
7413         switch (res >> 26) {
7414         case ALC880_HP_EVENT:
7415                 alc883_mitac_hp_automute(codec);
7416                 break;
7417         case ALC880_MIC_EVENT:
7418                 /* alc883_mitac_mic_automute(codec); */
7419                 break;
7420         }
7421 }
7422
7423 static struct hda_verb alc883_mitac_verbs[] = {
7424         /* HP */
7425         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7426         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7427         /* Subwoofer */
7428         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7429         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7430
7431         /* enable unsolicited event */
7432         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7433         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7434
7435         { } /* end */
7436 };
7437
7438 static struct hda_verb alc883_clevo_m720_verbs[] = {
7439         /* HP */
7440         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7441         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7442         /* Int speaker */
7443         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7444         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7445
7446         /* enable unsolicited event */
7447         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7448         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7449
7450         { } /* end */
7451 };
7452
7453 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7454         /* HP */
7455         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7456         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7457         /* Subwoofer */
7458         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7459         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7460
7461         /* enable unsolicited event */
7462         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7463
7464         { } /* end */
7465 };
7466
7467 static struct hda_verb alc883_tagra_verbs[] = {
7468         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7469         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7470
7471         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7472         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7473         
7474         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7475         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7476         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7477
7478         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7479         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7480         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7481         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7482
7483         { } /* end */
7484 };
7485
7486 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7487         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7488         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7489         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7490         { } /* end */
7491 };
7492
7493 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7494         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7495         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7496         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7497         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7498         { } /* end */
7499 };
7500
7501 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7502         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7503         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7504         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7505         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7506         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7507         { } /* end */
7508 };
7509
7510 static struct hda_verb alc883_haier_w66_verbs[] = {
7511         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7512         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7513
7514         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7515
7516         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7517         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7518         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7519         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7520         { } /* end */
7521 };
7522
7523 static struct hda_verb alc888_3st_hp_verbs[] = {
7524         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7525         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7526         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7527         { }
7528 };
7529
7530 static struct hda_verb alc888_6st_dell_verbs[] = {
7531         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7532         { }
7533 };
7534
7535 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7536         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7537         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7538         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7539         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7540         { }
7541 };
7542
7543 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7544         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7545         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7546         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7547         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7548         { }
7549 };
7550
7551 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7552         { 2, alc888_3st_hp_2ch_init },
7553         { 6, alc888_3st_hp_6ch_init },
7554 };
7555
7556 /* toggle front-jack and RCA according to the hp-jack state */
7557 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7558 {
7559         unsigned int present;
7560  
7561         present = snd_hda_codec_read(codec, 0x1b, 0,
7562                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7563         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7564                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7565         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7566                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7567 }
7568
7569 /* toggle RCA according to the front-jack state */
7570 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7571 {
7572         unsigned int present;
7573  
7574         present = snd_hda_codec_read(codec, 0x14, 0,
7575                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7576         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7577                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7578 }
7579
7580 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7581                                              unsigned int res)
7582 {
7583         if ((res >> 26) == ALC880_HP_EVENT)
7584                 alc888_lenovo_ms7195_front_automute(codec);
7585         if ((res >> 26) == ALC880_FRONT_EVENT)
7586                 alc888_lenovo_ms7195_rca_automute(codec);
7587 }
7588
7589 static struct hda_verb alc883_medion_md2_verbs[] = {
7590         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7591         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7592
7593         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7594
7595         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7596         { } /* end */
7597 };
7598
7599 /* toggle speaker-output according to the hp-jack state */
7600 static void alc883_medion_md2_automute(struct hda_codec *codec)
7601 {
7602         unsigned int present;
7603  
7604         present = snd_hda_codec_read(codec, 0x14, 0,
7605                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7606         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7607                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7608 }
7609
7610 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
7611                                           unsigned int res)
7612 {
7613         if ((res >> 26) == ALC880_HP_EVENT)
7614                 alc883_medion_md2_automute(codec);
7615 }
7616
7617 /* toggle speaker-output according to the hp-jack state */
7618 static void alc883_tagra_automute(struct hda_codec *codec)
7619 {
7620         unsigned int present;
7621         unsigned char bits;
7622
7623         present = snd_hda_codec_read(codec, 0x14, 0,
7624                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7625         bits = present ? HDA_AMP_MUTE : 0;
7626         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
7627                                  HDA_AMP_MUTE, bits);
7628         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7629                                   present ? 1 : 3);
7630 }
7631
7632 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
7633 {
7634         if ((res >> 26) == ALC880_HP_EVENT)
7635                 alc883_tagra_automute(codec);
7636 }
7637
7638 /* toggle speaker-output according to the hp-jack state */
7639 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
7640 {
7641         unsigned int present;
7642         unsigned char bits;
7643
7644         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
7645                 & AC_PINSENSE_PRESENCE;
7646         bits = present ? HDA_AMP_MUTE : 0;
7647         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7648                                  HDA_AMP_MUTE, bits);
7649 }
7650
7651 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
7652 {
7653         unsigned int present;
7654
7655         present = snd_hda_codec_read(codec, 0x18, 0,
7656                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7657         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
7658                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7659 }
7660
7661 static void alc883_clevo_m720_automute(struct hda_codec *codec)
7662 {
7663         alc883_clevo_m720_hp_automute(codec);
7664         alc883_clevo_m720_mic_automute(codec);
7665 }
7666
7667 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
7668                                            unsigned int res)
7669 {
7670         switch (res >> 26) {
7671         case ALC880_HP_EVENT:
7672                 alc883_clevo_m720_hp_automute(codec);
7673                 break;
7674         case ALC880_MIC_EVENT:
7675                 alc883_clevo_m720_mic_automute(codec);
7676                 break;
7677         }
7678 }
7679
7680 /* toggle speaker-output according to the hp-jack state */
7681 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
7682 {
7683         unsigned int present;
7684         unsigned char bits;
7685
7686         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
7687                 & AC_PINSENSE_PRESENCE;
7688         bits = present ? HDA_AMP_MUTE : 0;
7689         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7690                                  HDA_AMP_MUTE, bits);
7691 }
7692
7693 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
7694                                                   unsigned int res)
7695 {
7696         if ((res >> 26) == ALC880_HP_EVENT)
7697                 alc883_2ch_fujitsu_pi2515_automute(codec);
7698 }
7699
7700 static void alc883_haier_w66_automute(struct hda_codec *codec)
7701 {
7702         unsigned int present;
7703         unsigned char bits;
7704
7705         present = snd_hda_codec_read(codec, 0x1b, 0,
7706                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7707         bits = present ? 0x80 : 0;
7708         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7709                                  0x80, bits);
7710 }
7711
7712 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
7713                                          unsigned int res)
7714 {
7715         if ((res >> 26) == ALC880_HP_EVENT)
7716                 alc883_haier_w66_automute(codec);
7717 }
7718
7719 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
7720 {
7721         unsigned int present;
7722         unsigned char bits;
7723
7724         present = snd_hda_codec_read(codec, 0x14, 0,
7725                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7726         bits = present ? HDA_AMP_MUTE : 0;
7727         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7728                                  HDA_AMP_MUTE, bits);
7729 }
7730
7731 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
7732 {
7733         unsigned int present;
7734         unsigned char bits;
7735
7736         present = snd_hda_codec_read(codec, 0x1b, 0,
7737                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7738         bits = present ? HDA_AMP_MUTE : 0;
7739         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7740                                  HDA_AMP_MUTE, bits);
7741         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7742                                  HDA_AMP_MUTE, bits);
7743 }
7744
7745 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
7746                                            unsigned int res)
7747 {
7748         if ((res >> 26) == ALC880_HP_EVENT)
7749                 alc883_lenovo_101e_all_automute(codec);
7750         if ((res >> 26) == ALC880_FRONT_EVENT)
7751                 alc883_lenovo_101e_ispeaker_automute(codec);
7752 }
7753
7754 /* toggle speaker-output according to the hp-jack state */
7755 static void alc883_acer_aspire_automute(struct hda_codec *codec)
7756 {
7757         unsigned int present;
7758  
7759         present = snd_hda_codec_read(codec, 0x14, 0,
7760                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7761         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7762                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7763         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7764                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7765 }
7766
7767 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
7768                                            unsigned int res)
7769 {
7770         if ((res >> 26) == ALC880_HP_EVENT)
7771                 alc883_acer_aspire_automute(codec);
7772 }
7773
7774 static struct hda_verb alc883_acer_eapd_verbs[] = {
7775         /* HP Pin: output 0 (0x0c) */
7776         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7777         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7778         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7779         /* Front Pin: output 0 (0x0c) */
7780         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7781         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7782         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7783         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
7784         /* eanable EAPD on medion laptop */
7785         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7786         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
7787         /* enable unsolicited event */
7788         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7789         { }
7790 };
7791
7792 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
7793 {
7794         unsigned int present;
7795  
7796         present = snd_hda_codec_read(codec, 0x1b, 0,
7797                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7798         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7799                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7800         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7801                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7802         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7803                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7804         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7805                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7806 }
7807
7808 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
7809                                              unsigned int res)
7810 {
7811         switch (res >> 26) {
7812         case ALC880_HP_EVENT:
7813                 printk("hp_event\n");
7814                 alc888_6st_dell_front_automute(codec);
7815                 break;
7816         }
7817 }
7818
7819 /*
7820  * generic initialization of ADC, input mixers and output mixers
7821  */
7822 static struct hda_verb alc883_auto_init_verbs[] = {
7823         /*
7824          * Unmute ADC0-2 and set the default input to mic-in
7825          */
7826         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7827         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7828         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7829         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7830
7831         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7832          * mixer widget
7833          * Note: PASD motherboards uses the Line In 2 as the input for
7834          * front panel mic (mic 2)
7835          */
7836         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7837         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7838         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7839         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7840         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7841         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7842
7843         /*
7844          * Set up output mixers (0x0c - 0x0f)
7845          */
7846         /* set vol=0 to output mixers */
7847         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7848         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7849         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7850         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7851         /* set up input amps for analog loopback */
7852         /* Amp Indices: DAC = 0, mixer = 1 */
7853         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7854         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7855         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7856         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7857         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7858         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7859         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7860         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7861         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7862         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7863
7864         /* FIXME: use matrix-type input source selection */
7865         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7866         /* Input mixer1 */
7867         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7868         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7869         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7870         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
7871         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7872         /* Input mixer2 */
7873         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7874         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7875         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7876         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
7877         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7878
7879         { }
7880 };
7881
7882 /* capture mixer elements */
7883 static struct snd_kcontrol_new alc883_capture_mixer[] = {
7884         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7885         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7886         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7887         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7888         {
7889                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7890                 /* The multiple "Capture Source" controls confuse alsamixer
7891                  * So call somewhat different..
7892                  */
7893                 /* .name = "Capture Source", */
7894                 .name = "Input Source",
7895                 .count = 2,
7896                 .info = alc882_mux_enum_info,
7897                 .get = alc882_mux_enum_get,
7898                 .put = alc882_mux_enum_put,
7899         },
7900         { } /* end */
7901 };
7902
7903 #ifdef CONFIG_SND_HDA_POWER_SAVE
7904 #define alc883_loopbacks        alc880_loopbacks
7905 #endif
7906
7907 /* pcm configuration: identiacal with ALC880 */
7908 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
7909 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
7910 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
7911 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
7912 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
7913
7914 /*
7915  * configuration and preset
7916  */
7917 static const char *alc883_models[ALC883_MODEL_LAST] = {
7918         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
7919         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
7920         [ALC883_3ST_6ch]        = "3stack-6ch",
7921         [ALC883_6ST_DIG]        = "6stack-dig",
7922         [ALC883_TARGA_DIG]      = "targa-dig",
7923         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
7924         [ALC883_ACER]           = "acer",
7925         [ALC883_ACER_ASPIRE]    = "acer-aspire",
7926         [ALC883_MEDION]         = "medion",
7927         [ALC883_MEDION_MD2]     = "medion-md2",
7928         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
7929         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
7930         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
7931         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
7932         [ALC883_HAIER_W66]      = "haier-w66",
7933         [ALC888_3ST_HP]         = "3stack-hp",
7934         [ALC888_6ST_DELL]       = "6stack-dell",
7935         [ALC883_MITAC]          = "mitac",
7936         [ALC883_CLEVO_M720]     = "clevo-m720",
7937         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
7938         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
7939         [ALC883_AUTO]           = "auto",
7940 };
7941
7942 static struct snd_pci_quirk alc883_cfg_tbl[] = {
7943         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
7944         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
7945         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
7946         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
7947         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE), 
7948         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
7949         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
7950         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
7951         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
7952         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
7953         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
7954         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
7955         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
7956         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
7957         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
7958         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
7959         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
7960         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
7961         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
7962         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
7963         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
7964         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
7965         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
7966         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
7967         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
7968         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
7969         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
7970         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
7971         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
7972         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
7973         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
7974         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
7975         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
7976         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
7977         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
7978         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
7979         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
7980         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
7981         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
7982         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
7983         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
7984         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
7985         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
7986         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
7987         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
7988         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
7989         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
7990         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
7991         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7992         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7993         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7994         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
7995         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
7996         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
7997         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
7998         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
7999         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8000         {}
8001 };
8002
8003 static struct alc_config_preset alc883_presets[] = {
8004         [ALC883_3ST_2ch_DIG] = {
8005                 .mixers = { alc883_3ST_2ch_mixer },
8006                 .init_verbs = { alc883_init_verbs },
8007                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8008                 .dac_nids = alc883_dac_nids,
8009                 .dig_out_nid = ALC883_DIGOUT_NID,
8010                 .dig_in_nid = ALC883_DIGIN_NID,
8011                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8012                 .channel_mode = alc883_3ST_2ch_modes,
8013                 .input_mux = &alc883_capture_source,
8014         },
8015         [ALC883_3ST_6ch_DIG] = {
8016                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8017                 .init_verbs = { alc883_init_verbs },
8018                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8019                 .dac_nids = alc883_dac_nids,
8020                 .dig_out_nid = ALC883_DIGOUT_NID,
8021                 .dig_in_nid = ALC883_DIGIN_NID,
8022                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8023                 .channel_mode = alc883_3ST_6ch_modes,
8024                 .need_dac_fix = 1,
8025                 .input_mux = &alc883_capture_source,
8026         },
8027         [ALC883_3ST_6ch] = {
8028                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8029                 .init_verbs = { alc883_init_verbs },
8030                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8031                 .dac_nids = alc883_dac_nids,
8032                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8033                 .channel_mode = alc883_3ST_6ch_modes,
8034                 .need_dac_fix = 1,
8035                 .input_mux = &alc883_capture_source,
8036         },
8037         [ALC883_3ST_6ch_INTEL] = {
8038                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
8039                 .init_verbs = { alc883_init_verbs },
8040                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8041                 .dac_nids = alc883_dac_nids,
8042                 .dig_out_nid = ALC883_DIGOUT_NID,
8043                 .dig_in_nid = ALC883_DIGIN_NID,
8044                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
8045                 .channel_mode = alc883_3ST_6ch_intel_modes,
8046                 .need_dac_fix = 1,
8047                 .input_mux = &alc883_3stack_6ch_intel,
8048         },
8049         [ALC883_6ST_DIG] = {
8050                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8051                 .init_verbs = { alc883_init_verbs },
8052                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8053                 .dac_nids = alc883_dac_nids,
8054                 .dig_out_nid = ALC883_DIGOUT_NID,
8055                 .dig_in_nid = ALC883_DIGIN_NID,
8056                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8057                 .channel_mode = alc883_sixstack_modes,
8058                 .input_mux = &alc883_capture_source,
8059         },
8060         [ALC883_TARGA_DIG] = {
8061                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
8062                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8063                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8064                 .dac_nids = alc883_dac_nids,
8065                 .dig_out_nid = ALC883_DIGOUT_NID,
8066                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8067                 .channel_mode = alc883_3ST_6ch_modes,
8068                 .need_dac_fix = 1,
8069                 .input_mux = &alc883_capture_source,
8070                 .unsol_event = alc883_tagra_unsol_event,
8071                 .init_hook = alc883_tagra_automute,
8072         },
8073         [ALC883_TARGA_2ch_DIG] = {
8074                 .mixers = { alc883_tagra_2ch_mixer},
8075                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8076                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8077                 .dac_nids = alc883_dac_nids,
8078                 .dig_out_nid = ALC883_DIGOUT_NID,
8079                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8080                 .channel_mode = alc883_3ST_2ch_modes,
8081                 .input_mux = &alc883_capture_source,
8082                 .unsol_event = alc883_tagra_unsol_event,
8083                 .init_hook = alc883_tagra_automute,
8084         },
8085         [ALC883_ACER] = {
8086                 .mixers = { alc883_base_mixer },
8087                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
8088                  * and the headphone jack.  Turn this on and rely on the
8089                  * standard mute methods whenever the user wants to turn
8090                  * these outputs off.
8091                  */
8092                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
8093                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8094                 .dac_nids = alc883_dac_nids,
8095                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8096                 .channel_mode = alc883_3ST_2ch_modes,
8097                 .input_mux = &alc883_capture_source,
8098         },
8099         [ALC883_ACER_ASPIRE] = {
8100                 .mixers = { alc883_acer_aspire_mixer },
8101                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
8102                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8103                 .dac_nids = alc883_dac_nids,
8104                 .dig_out_nid = ALC883_DIGOUT_NID,
8105                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8106                 .channel_mode = alc883_3ST_2ch_modes,
8107                 .input_mux = &alc883_capture_source,
8108                 .unsol_event = alc883_acer_aspire_unsol_event,
8109                 .init_hook = alc883_acer_aspire_automute,
8110         },
8111         [ALC883_MEDION] = {
8112                 .mixers = { alc883_fivestack_mixer,
8113                             alc883_chmode_mixer },
8114                 .init_verbs = { alc883_init_verbs,
8115                                 alc883_medion_eapd_verbs },
8116                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8117                 .dac_nids = alc883_dac_nids,
8118                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8119                 .channel_mode = alc883_sixstack_modes,
8120                 .input_mux = &alc883_capture_source,
8121         },
8122         [ALC883_MEDION_MD2] = {
8123                 .mixers = { alc883_medion_md2_mixer},
8124                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
8125                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8126                 .dac_nids = alc883_dac_nids,
8127                 .dig_out_nid = ALC883_DIGOUT_NID,
8128                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8129                 .channel_mode = alc883_3ST_2ch_modes,
8130                 .input_mux = &alc883_capture_source,
8131                 .unsol_event = alc883_medion_md2_unsol_event,
8132                 .init_hook = alc883_medion_md2_automute,
8133         },      
8134         [ALC883_LAPTOP_EAPD] = {
8135                 .mixers = { alc883_base_mixer },
8136                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
8137                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8138                 .dac_nids = alc883_dac_nids,
8139                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8140                 .channel_mode = alc883_3ST_2ch_modes,
8141                 .input_mux = &alc883_capture_source,
8142         },
8143         [ALC883_CLEVO_M720] = {
8144                 .mixers = { alc883_clevo_m720_mixer },
8145                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
8146                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8147                 .dac_nids = alc883_dac_nids,
8148                 .dig_out_nid = ALC883_DIGOUT_NID,
8149                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8150                 .channel_mode = alc883_3ST_2ch_modes,
8151                 .input_mux = &alc883_capture_source,
8152                 .unsol_event = alc883_clevo_m720_unsol_event,
8153                 .init_hook = alc883_clevo_m720_automute,
8154         },
8155         [ALC883_LENOVO_101E_2ch] = {
8156                 .mixers = { alc883_lenovo_101e_2ch_mixer},
8157                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
8158                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8159                 .dac_nids = alc883_dac_nids,
8160                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8161                 .channel_mode = alc883_3ST_2ch_modes,
8162                 .input_mux = &alc883_lenovo_101e_capture_source,
8163                 .unsol_event = alc883_lenovo_101e_unsol_event,
8164                 .init_hook = alc883_lenovo_101e_all_automute,
8165         },
8166         [ALC883_LENOVO_NB0763] = {
8167                 .mixers = { alc883_lenovo_nb0763_mixer },
8168                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
8169                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8170                 .dac_nids = alc883_dac_nids,
8171                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8172                 .channel_mode = alc883_3ST_2ch_modes,
8173                 .need_dac_fix = 1,
8174                 .input_mux = &alc883_lenovo_nb0763_capture_source,
8175                 .unsol_event = alc883_medion_md2_unsol_event,
8176                 .init_hook = alc883_medion_md2_automute,
8177         },
8178         [ALC888_LENOVO_MS7195_DIG] = {
8179                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8180                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
8181                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8182                 .dac_nids = alc883_dac_nids,
8183                 .dig_out_nid = ALC883_DIGOUT_NID,
8184                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8185                 .channel_mode = alc883_3ST_6ch_modes,
8186                 .need_dac_fix = 1,
8187                 .input_mux = &alc883_capture_source,
8188                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
8189                 .init_hook = alc888_lenovo_ms7195_front_automute,
8190         },
8191         [ALC883_HAIER_W66] = {
8192                 .mixers = { alc883_tagra_2ch_mixer},
8193                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
8194                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8195                 .dac_nids = alc883_dac_nids,
8196                 .dig_out_nid = ALC883_DIGOUT_NID,
8197                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8198                 .channel_mode = alc883_3ST_2ch_modes,
8199                 .input_mux = &alc883_capture_source,
8200                 .unsol_event = alc883_haier_w66_unsol_event,
8201                 .init_hook = alc883_haier_w66_automute,
8202         },
8203         [ALC888_3ST_HP] = {
8204                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8205                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
8206                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8207                 .dac_nids = alc883_dac_nids,
8208                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
8209                 .channel_mode = alc888_3st_hp_modes,
8210                 .need_dac_fix = 1,
8211                 .input_mux = &alc883_capture_source,
8212         },
8213         [ALC888_6ST_DELL] = {
8214                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8215                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
8216                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8217                 .dac_nids = alc883_dac_nids,
8218                 .dig_out_nid = ALC883_DIGOUT_NID,
8219                 .dig_in_nid = ALC883_DIGIN_NID,
8220                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8221                 .channel_mode = alc883_sixstack_modes,
8222                 .input_mux = &alc883_capture_source,
8223                 .unsol_event = alc888_6st_dell_unsol_event,
8224                 .init_hook = alc888_6st_dell_front_automute,
8225         },
8226         [ALC883_MITAC] = {
8227                 .mixers = { alc883_mitac_mixer },
8228                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
8229                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8230                 .dac_nids = alc883_dac_nids,
8231                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8232                 .channel_mode = alc883_3ST_2ch_modes,
8233                 .input_mux = &alc883_capture_source,
8234                 .unsol_event = alc883_mitac_unsol_event,
8235                 .init_hook = alc883_mitac_automute,
8236         },
8237         [ALC883_FUJITSU_PI2515] = {
8238                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
8239                 .init_verbs = { alc883_init_verbs,
8240                                 alc883_2ch_fujitsu_pi2515_verbs},
8241                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8242                 .dac_nids = alc883_dac_nids,
8243                 .dig_out_nid = ALC883_DIGOUT_NID,
8244                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8245                 .channel_mode = alc883_3ST_2ch_modes,
8246                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8247                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8248                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8249         },
8250 };
8251
8252
8253 /*
8254  * BIOS auto configuration
8255  */
8256 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
8257                                               hda_nid_t nid, int pin_type,
8258                                               int dac_idx)
8259 {
8260         /* set as output */
8261         struct alc_spec *spec = codec->spec;
8262         int idx;
8263
8264         alc_set_pin_output(codec, nid, pin_type);
8265         if (spec->multiout.dac_nids[dac_idx] == 0x25)
8266                 idx = 4;
8267         else
8268                 idx = spec->multiout.dac_nids[dac_idx] - 2;
8269         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
8270
8271 }
8272
8273 static void alc883_auto_init_multi_out(struct hda_codec *codec)
8274 {
8275         struct alc_spec *spec = codec->spec;
8276         int i;
8277
8278         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
8279         for (i = 0; i <= HDA_SIDE; i++) {
8280                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
8281                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
8282                 if (nid)
8283                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
8284                                                           i);
8285         }
8286 }
8287
8288 static void alc883_auto_init_hp_out(struct hda_codec *codec)
8289 {
8290         struct alc_spec *spec = codec->spec;
8291         hda_nid_t pin;
8292
8293         pin = spec->autocfg.hp_pins[0];
8294         if (pin) /* connect to front */
8295                 /* use dac 0 */
8296                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8297         pin = spec->autocfg.speaker_pins[0];
8298         if (pin)
8299                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
8300 }
8301
8302 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
8303 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
8304
8305 static void alc883_auto_init_analog_input(struct hda_codec *codec)
8306 {
8307         struct alc_spec *spec = codec->spec;
8308         int i;
8309
8310         for (i = 0; i < AUTO_PIN_LAST; i++) {
8311                 hda_nid_t nid = spec->autocfg.input_pins[i];
8312                 if (alc883_is_input_pin(nid)) {
8313                         snd_hda_codec_write(codec, nid, 0,
8314                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
8315                                             (i <= AUTO_PIN_FRONT_MIC ?
8316                                              PIN_VREF80 : PIN_IN));
8317                         if (nid != ALC883_PIN_CD_NID)
8318                                 snd_hda_codec_write(codec, nid, 0,
8319                                                     AC_VERB_SET_AMP_GAIN_MUTE,
8320                                                     AMP_OUT_MUTE);
8321                 }
8322         }
8323 }
8324
8325 #define alc883_auto_init_input_src      alc882_auto_init_input_src
8326
8327 /* almost identical with ALC880 parser... */
8328 static int alc883_parse_auto_config(struct hda_codec *codec)
8329 {
8330         struct alc_spec *spec = codec->spec;
8331         int err = alc880_parse_auto_config(codec);
8332
8333         if (err < 0)
8334                 return err;
8335         else if (!err)
8336                 return 0; /* no config found */
8337
8338         err = alc_auto_add_mic_boost(codec);
8339         if (err < 0)
8340                 return err;
8341
8342         /* hack - override the init verbs */
8343         spec->init_verbs[0] = alc883_auto_init_verbs;
8344         spec->mixers[spec->num_mixers] = alc883_capture_mixer;
8345         spec->num_mixers++;
8346
8347         return 1; /* config found */
8348 }
8349
8350 /* additional initialization for auto-configuration model */
8351 static void alc883_auto_init(struct hda_codec *codec)
8352 {
8353         struct alc_spec *spec = codec->spec;
8354         alc883_auto_init_multi_out(codec);
8355         alc883_auto_init_hp_out(codec);
8356         alc883_auto_init_analog_input(codec);
8357         alc883_auto_init_input_src(codec);
8358         if (spec->unsol_event)
8359                 alc_sku_automute(codec);
8360 }
8361
8362 static int patch_alc883(struct hda_codec *codec)
8363 {
8364         struct alc_spec *spec;
8365         int err, board_config;
8366
8367         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8368         if (spec == NULL)
8369                 return -ENOMEM;
8370
8371         codec->spec = spec;
8372
8373         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
8374
8375         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
8376                                                   alc883_models,
8377                                                   alc883_cfg_tbl);
8378         if (board_config < 0) {
8379                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
8380                        "trying auto-probe from BIOS...\n");
8381                 board_config = ALC883_AUTO;
8382         }
8383
8384         if (board_config == ALC883_AUTO) {
8385                 /* automatic parse from the BIOS config */
8386                 err = alc883_parse_auto_config(codec);
8387                 if (err < 0) {
8388                         alc_free(codec);
8389                         return err;
8390                 } else if (!err) {
8391                         printk(KERN_INFO
8392                                "hda_codec: Cannot set up configuration "
8393                                "from BIOS.  Using base mode...\n");
8394                         board_config = ALC883_3ST_2ch_DIG;
8395                 }
8396         }
8397
8398         if (board_config != ALC883_AUTO)
8399                 setup_preset(spec, &alc883_presets[board_config]);
8400
8401         switch (codec->vendor_id) {
8402         case 0x10ec0888:
8403                 spec->stream_name_analog = "ALC888 Analog";
8404                 spec->stream_name_digital = "ALC888 Digital";
8405                 break;
8406         case 0x10ec0889:
8407                 spec->stream_name_analog = "ALC889 Analog";
8408                 spec->stream_name_digital = "ALC889 Digital";
8409                 break;
8410         default:
8411                 spec->stream_name_analog = "ALC883 Analog";
8412                 spec->stream_name_digital = "ALC883 Digital";
8413                 break;
8414         }
8415
8416         spec->stream_analog_playback = &alc883_pcm_analog_playback;
8417         spec->stream_analog_capture = &alc883_pcm_analog_capture;
8418         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
8419
8420         spec->stream_digital_playback = &alc883_pcm_digital_playback;
8421         spec->stream_digital_capture = &alc883_pcm_digital_capture;
8422
8423         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
8424         spec->adc_nids = alc883_adc_nids;
8425         spec->capsrc_nids = alc883_capsrc_nids;
8426
8427         spec->vmaster_nid = 0x0c;
8428
8429         codec->patch_ops = alc_patch_ops;
8430         if (board_config == ALC883_AUTO)
8431                 spec->init_hook = alc883_auto_init;
8432
8433 #ifdef CONFIG_SND_HDA_POWER_SAVE
8434         if (!spec->loopback.amplist)
8435                 spec->loopback.amplist = alc883_loopbacks;
8436 #endif
8437
8438         return 0;
8439 }
8440
8441 /*
8442  * ALC262 support
8443  */
8444
8445 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
8446 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
8447
8448 #define alc262_dac_nids         alc260_dac_nids
8449 #define alc262_adc_nids         alc882_adc_nids
8450 #define alc262_adc_nids_alt     alc882_adc_nids_alt
8451 #define alc262_capsrc_nids      alc882_capsrc_nids
8452 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
8453
8454 #define alc262_modes            alc260_modes
8455 #define alc262_capture_source   alc882_capture_source
8456
8457 static struct snd_kcontrol_new alc262_base_mixer[] = {
8458         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8459         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8460         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8461         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8462         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8463         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8464         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8465         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8466         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8467         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8468         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8469         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8470         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8471            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8472         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
8473         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8474         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8475         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
8476         { } /* end */
8477 };
8478
8479 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
8480         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8481         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8482         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8483         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8484         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8485         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8486         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8487         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8488         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8489         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8490         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8491         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8492         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8493            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8494         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
8495         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8496         { } /* end */
8497 };
8498
8499 /* update HP, line and mono-out pins according to the master switch */
8500 static void alc262_hp_master_update(struct hda_codec *codec)
8501 {
8502         struct alc_spec *spec = codec->spec;
8503         int val = spec->master_sw;
8504
8505         /* HP & line-out */
8506         snd_hda_codec_write_cache(codec, 0x1b, 0,
8507                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8508                                   val ? PIN_HP : 0);
8509         snd_hda_codec_write_cache(codec, 0x15, 0,
8510                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8511                                   val ? PIN_HP : 0);
8512         /* mono (speaker) depending on the HP jack sense */
8513         val = val && !spec->jack_present;
8514         snd_hda_codec_write_cache(codec, 0x16, 0,
8515                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8516                                   val ? PIN_OUT : 0);
8517 }
8518
8519 static void alc262_hp_bpc_automute(struct hda_codec *codec)
8520 {
8521         struct alc_spec *spec = codec->spec;
8522         unsigned int presence;
8523         presence = snd_hda_codec_read(codec, 0x1b, 0,
8524                                       AC_VERB_GET_PIN_SENSE, 0);
8525         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8526         alc262_hp_master_update(codec);
8527 }
8528
8529 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
8530 {
8531         if ((res >> 26) != ALC880_HP_EVENT)
8532                 return;
8533         alc262_hp_bpc_automute(codec);
8534 }
8535
8536 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
8537 {
8538         struct alc_spec *spec = codec->spec;
8539         unsigned int presence;
8540         presence = snd_hda_codec_read(codec, 0x15, 0,
8541                                       AC_VERB_GET_PIN_SENSE, 0);
8542         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8543         alc262_hp_master_update(codec);
8544 }
8545
8546 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
8547                                            unsigned int res)
8548 {
8549         if ((res >> 26) != ALC880_HP_EVENT)
8550                 return;
8551         alc262_hp_wildwest_automute(codec);
8552 }
8553
8554 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
8555                                    struct snd_ctl_elem_value *ucontrol)
8556 {
8557         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8558         struct alc_spec *spec = codec->spec;
8559         *ucontrol->value.integer.value = spec->master_sw;
8560         return 0;
8561 }
8562
8563 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
8564                                    struct snd_ctl_elem_value *ucontrol)
8565 {
8566         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8567         struct alc_spec *spec = codec->spec;
8568         int val = !!*ucontrol->value.integer.value;
8569
8570         if (val == spec->master_sw)
8571                 return 0;
8572         spec->master_sw = val;
8573         alc262_hp_master_update(codec);
8574         return 1;
8575 }
8576
8577 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
8578         {
8579                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8580                 .name = "Master Playback Switch",
8581                 .info = snd_ctl_boolean_mono_info,
8582                 .get = alc262_hp_master_sw_get,
8583                 .put = alc262_hp_master_sw_put,
8584         },
8585         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8586         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8587         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8588         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
8589                               HDA_OUTPUT),
8590         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
8591                             HDA_OUTPUT),
8592         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8593         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8594         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8595         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8596         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8597         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8598         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8599         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8600         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8601         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8602         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8603         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
8604         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
8605         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
8606         { } /* end */
8607 };
8608
8609 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
8610         {
8611                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8612                 .name = "Master Playback Switch",
8613                 .info = snd_ctl_boolean_mono_info,
8614                 .get = alc262_hp_master_sw_get,
8615                 .put = alc262_hp_master_sw_put,
8616         },
8617         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8618         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8619         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8620         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8621         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
8622                               HDA_OUTPUT),
8623         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
8624                             HDA_OUTPUT),
8625         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
8626         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
8627         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
8628         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8629         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8630         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8631         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8632         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8633         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
8634         { } /* end */
8635 };
8636
8637 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
8638         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8639         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8640         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
8641         { } /* end */
8642 };
8643
8644 /* mute/unmute internal speaker according to the hp jack and mute state */
8645 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
8646 {
8647         struct alc_spec *spec = codec->spec;
8648
8649         if (force || !spec->sense_updated) {
8650                 unsigned int present;
8651                 present = snd_hda_codec_read(codec, 0x15, 0,
8652                                              AC_VERB_GET_PIN_SENSE, 0);
8653                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
8654                 spec->sense_updated = 1;
8655         }
8656         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
8657                                  spec->jack_present ? HDA_AMP_MUTE : 0);
8658 }
8659
8660 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
8661                                         unsigned int res)
8662 {
8663         if ((res >> 26) != ALC880_HP_EVENT)
8664                 return;
8665         alc262_hp_t5735_automute(codec, 1);
8666 }
8667
8668 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
8669 {
8670         alc262_hp_t5735_automute(codec, 1);
8671 }
8672
8673 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
8674         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8675         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8676         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8677         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8678         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8679         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8680         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8681         { } /* end */
8682 };
8683
8684 static struct hda_verb alc262_hp_t5735_verbs[] = {
8685         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8686         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8687
8688         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8689         { }
8690 };
8691
8692 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
8693         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8694         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8695         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
8696         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
8697         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8698         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8699         { } /* end */
8700 };
8701
8702 static struct hda_verb alc262_hp_rp5700_verbs[] = {
8703         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8704         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8705         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8706         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8707         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8708         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8709         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8710         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8711         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
8712         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
8713         {}
8714 };
8715
8716 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
8717         .num_items = 1,
8718         .items = {
8719                 { "Line", 0x1 },
8720         },
8721 };
8722
8723 /* bind hp and internal speaker mute (with plug check) */
8724 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
8725                                      struct snd_ctl_elem_value *ucontrol)
8726 {
8727         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8728         long *valp = ucontrol->value.integer.value;
8729         int change;
8730
8731         /* change hp mute */
8732         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
8733                                           HDA_AMP_MUTE,
8734                                           valp[0] ? 0 : HDA_AMP_MUTE);
8735         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
8736                                            HDA_AMP_MUTE,
8737                                            valp[1] ? 0 : HDA_AMP_MUTE);
8738         if (change) {
8739                 /* change speaker according to HP jack state */
8740                 struct alc_spec *spec = codec->spec;
8741                 unsigned int mute;
8742                 if (spec->jack_present)
8743                         mute = HDA_AMP_MUTE;
8744                 else
8745                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
8746                                                       HDA_OUTPUT, 0);
8747                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8748                                          HDA_AMP_MUTE, mute);
8749         }
8750         return change;
8751 }
8752
8753 static struct snd_kcontrol_new alc262_sony_mixer[] = {
8754         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8755         {
8756                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8757                 .name = "Master Playback Switch",
8758                 .info = snd_hda_mixer_amp_switch_info,
8759                 .get = snd_hda_mixer_amp_switch_get,
8760                 .put = alc262_sony_master_sw_put,
8761                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
8762         },
8763         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8764         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8765         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8766         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8767         { } /* end */
8768 };
8769
8770 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
8771         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8772         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8773         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8774         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8775         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8776         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8777         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8778         { } /* end */
8779 };
8780
8781 #define alc262_capture_mixer            alc882_capture_mixer
8782 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
8783
8784 /*
8785  * generic initialization of ADC, input mixers and output mixers
8786  */
8787 static struct hda_verb alc262_init_verbs[] = {
8788         /*
8789          * Unmute ADC0-2 and set the default input to mic-in
8790          */
8791         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8792         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8793         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8794         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8795         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8796         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8797
8798         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8799          * mixer widget
8800          * Note: PASD motherboards uses the Line In 2 as the input for
8801          * front panel mic (mic 2)
8802          */
8803         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8804         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8805         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8806         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8807         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8808         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8809
8810         /*
8811          * Set up output mixers (0x0c - 0x0e)
8812          */
8813         /* set vol=0 to output mixers */
8814         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8815         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8816         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8817         /* set up input amps for analog loopback */
8818         /* Amp Indices: DAC = 0, mixer = 1 */
8819         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8820         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8821         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8822         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8823         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8824         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8825
8826         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8827         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8828         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8829         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8830         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8831         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8832
8833         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8834         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8835         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8836         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8837         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8838         
8839         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8840         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8841         
8842         /* FIXME: use matrix-type input source selection */
8843         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8844         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8845         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8846         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8847         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8848         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8849         /* Input mixer2 */
8850         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8851         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8852         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8853         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8854         /* Input mixer3 */
8855         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8856         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8857         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8858         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8859
8860         { }
8861 };
8862
8863 static struct hda_verb alc262_hippo_unsol_verbs[] = {
8864         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8865         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8866         {}
8867 };
8868
8869 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
8870         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8871         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8872         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8873
8874         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8875         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8876         {}
8877 };
8878
8879 static struct hda_verb alc262_sony_unsol_verbs[] = {
8880         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8881         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8882         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
8883
8884         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8885         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8886         {}
8887 };
8888
8889 /* mute/unmute internal speaker according to the hp jack and mute state */
8890 static void alc262_hippo_automute(struct hda_codec *codec)
8891 {
8892         struct alc_spec *spec = codec->spec;
8893         unsigned int mute;
8894         unsigned int present;
8895
8896         /* need to execute and sync at first */
8897         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
8898         present = snd_hda_codec_read(codec, 0x15, 0,
8899                                      AC_VERB_GET_PIN_SENSE, 0);
8900         spec->jack_present = (present & 0x80000000) != 0;
8901         if (spec->jack_present) {
8902                 /* mute internal speaker */
8903                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8904                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8905         } else {
8906                 /* unmute internal speaker if necessary */
8907                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
8908                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8909                                          HDA_AMP_MUTE, mute);
8910         }
8911 }
8912
8913 /* unsolicited event for HP jack sensing */
8914 static void alc262_hippo_unsol_event(struct hda_codec *codec,
8915                                        unsigned int res)
8916 {
8917         if ((res >> 26) != ALC880_HP_EVENT)
8918                 return;
8919         alc262_hippo_automute(codec);
8920 }
8921
8922 static void alc262_hippo1_automute(struct hda_codec *codec)
8923 {
8924         unsigned int mute;
8925         unsigned int present;
8926
8927         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8928         present = snd_hda_codec_read(codec, 0x1b, 0,
8929                                      AC_VERB_GET_PIN_SENSE, 0);
8930         present = (present & 0x80000000) != 0;
8931         if (present) {
8932                 /* mute internal speaker */
8933                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8934                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8935         } else {
8936                 /* unmute internal speaker if necessary */
8937                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8938                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8939                                          HDA_AMP_MUTE, mute);
8940         }
8941 }
8942
8943 /* unsolicited event for HP jack sensing */
8944 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
8945                                        unsigned int res)
8946 {
8947         if ((res >> 26) != ALC880_HP_EVENT)
8948                 return;
8949         alc262_hippo1_automute(codec);
8950 }
8951
8952 /*
8953  * nec model
8954  *  0x15 = headphone
8955  *  0x16 = internal speaker
8956  *  0x18 = external mic
8957  */
8958
8959 static struct snd_kcontrol_new alc262_nec_mixer[] = {
8960         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
8961         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
8962
8963         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8964         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8965         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8966
8967         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8968         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8969         { } /* end */
8970 };
8971
8972 static struct hda_verb alc262_nec_verbs[] = {
8973         /* Unmute Speaker */
8974         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8975
8976         /* Headphone */
8977         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8978         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8979
8980         /* External mic to headphone */
8981         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8982         /* External mic to speaker */
8983         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8984         {}
8985 };
8986
8987 /*
8988  * fujitsu model
8989  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
8990  *  0x1b = port replicator headphone out
8991  */
8992
8993 #define ALC_HP_EVENT    0x37
8994
8995 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
8996         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8997         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8998         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8999         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9000         {}
9001 };
9002
9003 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
9004         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9005         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9006         {}
9007 };
9008
9009 static struct hda_input_mux alc262_fujitsu_capture_source = {
9010         .num_items = 3,
9011         .items = {
9012                 { "Mic", 0x0 },
9013                 { "Int Mic", 0x1 },
9014                 { "CD", 0x4 },
9015         },
9016 };
9017
9018 static struct hda_input_mux alc262_HP_capture_source = {
9019         .num_items = 5,
9020         .items = {
9021                 { "Mic", 0x0 },
9022                 { "Front Mic", 0x1 },
9023                 { "Line", 0x2 },
9024                 { "CD", 0x4 },
9025                 { "AUX IN", 0x6 },
9026         },
9027 };
9028
9029 static struct hda_input_mux alc262_HP_D7000_capture_source = {
9030         .num_items = 4,
9031         .items = {
9032                 { "Mic", 0x0 },
9033                 { "Front Mic", 0x2 },
9034                 { "Line", 0x1 },
9035                 { "CD", 0x4 },
9036         },
9037 };
9038
9039 /* mute/unmute internal speaker according to the hp jacks and mute state */
9040 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
9041 {
9042         struct alc_spec *spec = codec->spec;
9043         unsigned int mute;
9044
9045         if (force || !spec->sense_updated) {
9046                 unsigned int present;
9047                 /* need to execute and sync at first */
9048                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
9049                 /* check laptop HP jack */
9050                 present = snd_hda_codec_read(codec, 0x14, 0,
9051                                              AC_VERB_GET_PIN_SENSE, 0);
9052                 /* need to execute and sync at first */
9053                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9054                 /* check docking HP jack */
9055                 present |= snd_hda_codec_read(codec, 0x1b, 0,
9056                                               AC_VERB_GET_PIN_SENSE, 0);
9057                 if (present & AC_PINSENSE_PRESENCE)
9058                         spec->jack_present = 1;
9059                 else
9060                         spec->jack_present = 0;
9061                 spec->sense_updated = 1;
9062         }
9063         /* unmute internal speaker only if both HPs are unplugged and
9064          * master switch is on
9065          */
9066         if (spec->jack_present)
9067                 mute = HDA_AMP_MUTE;
9068         else
9069                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9070         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9071                                  HDA_AMP_MUTE, mute);
9072 }
9073
9074 /* unsolicited event for HP jack sensing */
9075 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
9076                                        unsigned int res)
9077 {
9078         if ((res >> 26) != ALC_HP_EVENT)
9079                 return;
9080         alc262_fujitsu_automute(codec, 1);
9081 }
9082
9083 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
9084 {
9085         alc262_fujitsu_automute(codec, 1);
9086 }
9087
9088 /* bind volumes of both NID 0x0c and 0x0d */
9089 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
9090         .ops = &snd_hda_bind_vol,
9091         .values = {
9092                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
9093                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
9094                 0
9095         },
9096 };
9097
9098 /* mute/unmute internal speaker according to the hp jack and mute state */
9099 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
9100 {
9101         struct alc_spec *spec = codec->spec;
9102         unsigned int mute;
9103
9104         if (force || !spec->sense_updated) {
9105                 unsigned int present_int_hp;
9106                 /* need to execute and sync at first */
9107                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9108                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
9109                                         AC_VERB_GET_PIN_SENSE, 0);
9110                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
9111                 spec->sense_updated = 1;
9112         }
9113         if (spec->jack_present) {
9114                 /* mute internal speaker */
9115                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9116                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9117                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9118                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9119         } else {
9120                 /* unmute internal speaker if necessary */
9121                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9122                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9123                                          HDA_AMP_MUTE, mute);
9124                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9125                                          HDA_AMP_MUTE, mute);
9126         }
9127 }
9128
9129 /* unsolicited event for HP jack sensing */
9130 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
9131                                        unsigned int res)
9132 {
9133         if ((res >> 26) != ALC_HP_EVENT)
9134                 return;
9135         alc262_lenovo_3000_automute(codec, 1);
9136 }
9137
9138 /* bind hp and internal speaker mute (with plug check) */
9139 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
9140                                          struct snd_ctl_elem_value *ucontrol)
9141 {
9142         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9143         long *valp = ucontrol->value.integer.value;
9144         int change;
9145
9146         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9147                                                  HDA_AMP_MUTE,
9148                                                  valp ? 0 : HDA_AMP_MUTE);
9149         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9150                                                  HDA_AMP_MUTE,
9151                                                  valp ? 0 : HDA_AMP_MUTE);
9152
9153         if (change)
9154                 alc262_fujitsu_automute(codec, 0);
9155         return change;
9156 }
9157
9158 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
9159         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9160         {
9161                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9162                 .name = "Master Playback Switch",
9163                 .info = snd_hda_mixer_amp_switch_info,
9164                 .get = snd_hda_mixer_amp_switch_get,
9165                 .put = alc262_fujitsu_master_sw_put,
9166                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9167         },
9168         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9169         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9170         HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
9171         HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
9172         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9173         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9174         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9175         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9176         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9177         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9178         { } /* end */
9179 };
9180
9181 /* bind hp and internal speaker mute (with plug check) */
9182 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
9183                                          struct snd_ctl_elem_value *ucontrol)
9184 {
9185         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9186         long *valp = ucontrol->value.integer.value;
9187         int change;
9188
9189         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9190                                                  HDA_AMP_MUTE,
9191                                                  valp ? 0 : HDA_AMP_MUTE);
9192
9193         if (change)
9194                 alc262_lenovo_3000_automute(codec, 0);
9195         return change;
9196 }
9197
9198 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
9199         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9200         {
9201                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9202                 .name = "Master Playback Switch",
9203                 .info = snd_hda_mixer_amp_switch_info,
9204                 .get = snd_hda_mixer_amp_switch_get,
9205                 .put = alc262_lenovo_3000_master_sw_put,
9206                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
9207         },
9208         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9209         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9210         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9211         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9212         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9213         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9214         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9215         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9216         { } /* end */
9217 };
9218
9219 /* additional init verbs for Benq laptops */
9220 static struct hda_verb alc262_EAPD_verbs[] = {
9221         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9222         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
9223         {}
9224 };
9225
9226 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
9227         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9228         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9229
9230         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9231         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
9232         {}
9233 };
9234
9235 /* Samsung Q1 Ultra Vista model setup */
9236 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
9237         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9238         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
9239         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9240         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9241         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
9242         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
9243         { } /* end */
9244 };
9245
9246 static struct hda_verb alc262_ultra_verbs[] = {
9247         /* output mixer */
9248         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9249         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9250         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9251         /* speaker */
9252         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9253         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9254         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9255         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9256         /* HP */
9257         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9258         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9259         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9260         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9261         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9262         /* internal mic */
9263         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9264         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9265         /* ADC, choose mic */
9266         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9267         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9268         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9269         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9270         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9271         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9272         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9273         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9274         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
9275         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
9276         {}
9277 };
9278
9279 /* mute/unmute internal speaker according to the hp jack and mute state */
9280 static void alc262_ultra_automute(struct hda_codec *codec)
9281 {
9282         struct alc_spec *spec = codec->spec;
9283         unsigned int mute;
9284
9285         mute = 0;
9286         /* auto-mute only when HP is used as HP */
9287         if (!spec->cur_mux[0]) {
9288                 unsigned int present;
9289                 /* need to execute and sync at first */
9290                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9291                 present = snd_hda_codec_read(codec, 0x15, 0,
9292                                              AC_VERB_GET_PIN_SENSE, 0);
9293                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9294                 if (spec->jack_present)
9295                         mute = HDA_AMP_MUTE;
9296         }
9297         /* mute/unmute internal speaker */
9298         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9299                                  HDA_AMP_MUTE, mute);
9300         /* mute/unmute HP */
9301         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9302                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
9303 }
9304
9305 /* unsolicited event for HP jack sensing */
9306 static void alc262_ultra_unsol_event(struct hda_codec *codec,
9307                                        unsigned int res)
9308 {
9309         if ((res >> 26) != ALC880_HP_EVENT)
9310                 return;
9311         alc262_ultra_automute(codec);
9312 }
9313
9314 static struct hda_input_mux alc262_ultra_capture_source = {
9315         .num_items = 2,
9316         .items = {
9317                 { "Mic", 0x1 },
9318                 { "Headphone", 0x7 },
9319         },
9320 };
9321
9322 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
9323                                      struct snd_ctl_elem_value *ucontrol)
9324 {
9325         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9326         struct alc_spec *spec = codec->spec;
9327         int ret;
9328
9329         ret = alc882_mux_enum_put(kcontrol, ucontrol);
9330         if (!ret)
9331                 return 0;
9332         /* reprogram the HP pin as mic or HP according to the input source */
9333         snd_hda_codec_write_cache(codec, 0x15, 0,
9334                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9335                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
9336         alc262_ultra_automute(codec); /* mute/unmute HP */
9337         return ret;
9338 }
9339
9340 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
9341         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
9342         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
9343         {
9344                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9345                 .name = "Capture Source",
9346                 .info = alc882_mux_enum_info,
9347                 .get = alc882_mux_enum_get,
9348                 .put = alc262_ultra_mux_enum_put,
9349         },
9350         { } /* end */
9351 };
9352
9353 /* add playback controls from the parsed DAC table */
9354 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
9355                                              const struct auto_pin_cfg *cfg)
9356 {
9357         hda_nid_t nid;
9358         int err;
9359
9360         spec->multiout.num_dacs = 1;    /* only use one dac */
9361         spec->multiout.dac_nids = spec->private_dac_nids;
9362         spec->multiout.dac_nids[0] = 2;
9363
9364         nid = cfg->line_out_pins[0];
9365         if (nid) {
9366                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9367                                   "Front Playback Volume",
9368                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
9369                 if (err < 0)
9370                         return err;
9371                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9372                                   "Front Playback Switch",
9373                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
9374                 if (err < 0)
9375                         return err;
9376         }
9377
9378         nid = cfg->speaker_pins[0];
9379         if (nid) {
9380                 if (nid == 0x16) {
9381                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9382                                           "Speaker Playback Volume",
9383                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9384                                                               HDA_OUTPUT));
9385                         if (err < 0)
9386                                 return err;
9387                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9388                                           "Speaker Playback Switch",
9389                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9390                                                               HDA_OUTPUT));
9391                         if (err < 0)
9392                                 return err;
9393                 } else {
9394                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9395                                           "Speaker Playback Switch",
9396                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9397                                                               HDA_OUTPUT));
9398                         if (err < 0)
9399                                 return err;
9400                 }
9401         }
9402         nid = cfg->hp_pins[0];
9403         if (nid) {
9404                 /* spec->multiout.hp_nid = 2; */
9405                 if (nid == 0x16) {
9406                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9407                                           "Headphone Playback Volume",
9408                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9409                                                               HDA_OUTPUT));
9410                         if (err < 0)
9411                                 return err;
9412                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9413                                           "Headphone Playback Switch",
9414                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9415                                                               HDA_OUTPUT));
9416                         if (err < 0)
9417                                 return err;
9418                 } else {
9419                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9420                                           "Headphone Playback Switch",
9421                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9422                                                               HDA_OUTPUT));
9423                         if (err < 0)
9424                                 return err;
9425                 }
9426         }
9427         return 0;
9428 }
9429
9430 /* identical with ALC880 */
9431 #define alc262_auto_create_analog_input_ctls \
9432         alc880_auto_create_analog_input_ctls
9433
9434 /*
9435  * generic initialization of ADC, input mixers and output mixers
9436  */
9437 static struct hda_verb alc262_volume_init_verbs[] = {
9438         /*
9439          * Unmute ADC0-2 and set the default input to mic-in
9440          */
9441         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9442         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9443         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9444         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9445         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9446         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9447
9448         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9449          * mixer widget
9450          * Note: PASD motherboards uses the Line In 2 as the input for
9451          * front panel mic (mic 2)
9452          */
9453         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9454         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9455         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9456         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9457         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9458         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9459
9460         /*
9461          * Set up output mixers (0x0c - 0x0f)
9462          */
9463         /* set vol=0 to output mixers */
9464         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9465         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9466         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9467         
9468         /* set up input amps for analog loopback */
9469         /* Amp Indices: DAC = 0, mixer = 1 */
9470         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9471         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9472         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9473         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9474         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9475         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9476
9477         /* FIXME: use matrix-type input source selection */
9478         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9479         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9480         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9481         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9482         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9483         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9484         /* Input mixer2 */
9485         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9486         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9487         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9488         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9489         /* Input mixer3 */
9490         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9491         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9492         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9493         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9494
9495         { }
9496 };
9497
9498 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
9499         /*
9500          * Unmute ADC0-2 and set the default input to mic-in
9501          */
9502         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9503         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9504         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9505         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9506         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9507         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9508
9509         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9510          * mixer widget
9511          * Note: PASD motherboards uses the Line In 2 as the input for
9512          * front panel mic (mic 2)
9513          */
9514         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9515         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9516         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9517         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9518         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9519         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9520         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9521         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9522         
9523         /*
9524          * Set up output mixers (0x0c - 0x0e)
9525          */
9526         /* set vol=0 to output mixers */
9527         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9528         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9529         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9530
9531         /* set up input amps for analog loopback */
9532         /* Amp Indices: DAC = 0, mixer = 1 */
9533         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9534         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9535         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9536         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9537         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9538         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9539
9540         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9541         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9542         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9543
9544         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9545         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9546
9547         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9548         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9549
9550         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9551         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9552         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9553         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9554         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9555
9556         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9557         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9558         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9559         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9560         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9561         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9562
9563
9564         /* FIXME: use matrix-type input source selection */
9565         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9566         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9567         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9568         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9569         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9570         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9571         /* Input mixer2 */
9572         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9573         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9574         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9575         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9576         /* Input mixer3 */
9577         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9578         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9579         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9580         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9581
9582         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9583
9584         { }
9585 };
9586
9587 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
9588         /*
9589          * Unmute ADC0-2 and set the default input to mic-in
9590          */
9591         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9592         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9593         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9594         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9595         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9596         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9597
9598         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9599          * mixer widget
9600          * Note: PASD motherboards uses the Line In 2 as the input for front
9601          * panel mic (mic 2)
9602          */
9603         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9604         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9605         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9606         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9607         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9608         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9609         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9610         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9611         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
9612         /*
9613          * Set up output mixers (0x0c - 0x0e)
9614          */
9615         /* set vol=0 to output mixers */
9616         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9617         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9618         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9619
9620         /* set up input amps for analog loopback */
9621         /* Amp Indices: DAC = 0, mixer = 1 */
9622         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9623         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9624         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9625         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9626         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9627         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9628
9629
9630         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
9631         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
9632         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
9633         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
9634         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
9635         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
9636         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
9637
9638         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9639         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9640
9641         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9642         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9643
9644         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
9645         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9646         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9647         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9648         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9649         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9650
9651         /* FIXME: use matrix-type input source selection */
9652         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9653         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9654         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
9655         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
9656         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
9657         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
9658         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
9659         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
9660         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
9661         /* Input mixer2 */
9662         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9663         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9664         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9665         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9666         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9667         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
9668         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
9669         /* Input mixer3 */
9670         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9671         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9672         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9673         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9674         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9675         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
9676         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
9677
9678         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9679
9680         { }
9681 };
9682
9683 #ifdef CONFIG_SND_HDA_POWER_SAVE
9684 #define alc262_loopbacks        alc880_loopbacks
9685 #endif
9686
9687 /* pcm configuration: identiacal with ALC880 */
9688 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
9689 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
9690 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
9691 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
9692
9693 /*
9694  * BIOS auto configuration
9695  */
9696 static int alc262_parse_auto_config(struct hda_codec *codec)
9697 {
9698         struct alc_spec *spec = codec->spec;
9699         int err;
9700         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
9701
9702         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9703                                            alc262_ignore);
9704         if (err < 0)
9705                 return err;
9706         if (!spec->autocfg.line_outs)
9707                 return 0; /* can't find valid BIOS pin config */
9708         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
9709         if (err < 0)
9710                 return err;
9711         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
9712         if (err < 0)
9713                 return err;
9714
9715         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
9716
9717         if (spec->autocfg.dig_out_pin)
9718                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
9719         if (spec->autocfg.dig_in_pin)
9720                 spec->dig_in_nid = ALC262_DIGIN_NID;
9721
9722         if (spec->kctl_alloc)
9723                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
9724
9725         spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs;
9726         spec->num_mux_defs = 1;
9727         spec->input_mux = &spec->private_imux;
9728
9729         err = alc_auto_add_mic_boost(codec);
9730         if (err < 0)
9731                 return err;
9732
9733         return 1;
9734 }
9735
9736 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
9737 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
9738 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
9739 #define alc262_auto_init_input_src      alc882_auto_init_input_src
9740
9741
9742 /* init callback for auto-configuration model -- overriding the default init */
9743 static void alc262_auto_init(struct hda_codec *codec)
9744 {
9745         struct alc_spec *spec = codec->spec;
9746         alc262_auto_init_multi_out(codec);
9747         alc262_auto_init_hp_out(codec);
9748         alc262_auto_init_analog_input(codec);
9749         alc262_auto_init_input_src(codec);
9750         if (spec->unsol_event)
9751                 alc_sku_automute(codec);
9752 }
9753
9754 /*
9755  * configuration and preset
9756  */
9757 static const char *alc262_models[ALC262_MODEL_LAST] = {
9758         [ALC262_BASIC]          = "basic",
9759         [ALC262_HIPPO]          = "hippo",
9760         [ALC262_HIPPO_1]        = "hippo_1",
9761         [ALC262_FUJITSU]        = "fujitsu",
9762         [ALC262_HP_BPC]         = "hp-bpc",
9763         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
9764         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
9765         [ALC262_HP_RP5700]      = "hp-rp5700",
9766         [ALC262_BENQ_ED8]       = "benq",
9767         [ALC262_BENQ_T31]       = "benq-t31",
9768         [ALC262_SONY_ASSAMD]    = "sony-assamd",
9769         [ALC262_ULTRA]          = "ultra",
9770         [ALC262_LENOVO_3000]    = "lenovo-3000",
9771         [ALC262_NEC]            = "nec",
9772         [ALC262_AUTO]           = "auto",
9773 };
9774
9775 static struct snd_pci_quirk alc262_cfg_tbl[] = {
9776         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
9777         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
9778         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
9779         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
9780         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
9781         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
9782         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
9783         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
9784         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
9785         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
9786         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
9787         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
9788         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
9789         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
9790         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
9791         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
9792         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
9793         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
9794         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
9795         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
9796         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
9797         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
9798                       ALC262_HP_TC_T5735),
9799         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
9800         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9801         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
9802         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9803         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9804         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
9805         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
9806                       ALC262_SONY_ASSAMD),
9807         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
9808         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
9809         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
9810         SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
9811         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
9812         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
9813         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
9814         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
9815         {}
9816 };
9817
9818 static struct alc_config_preset alc262_presets[] = {
9819         [ALC262_BASIC] = {
9820                 .mixers = { alc262_base_mixer },
9821                 .init_verbs = { alc262_init_verbs },
9822                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9823                 .dac_nids = alc262_dac_nids,
9824                 .hp_nid = 0x03,
9825                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9826                 .channel_mode = alc262_modes,
9827                 .input_mux = &alc262_capture_source,
9828         },
9829         [ALC262_HIPPO] = {
9830                 .mixers = { alc262_base_mixer },
9831                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
9832                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9833                 .dac_nids = alc262_dac_nids,
9834                 .hp_nid = 0x03,
9835                 .dig_out_nid = ALC262_DIGOUT_NID,
9836                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9837                 .channel_mode = alc262_modes,
9838                 .input_mux = &alc262_capture_source,
9839                 .unsol_event = alc262_hippo_unsol_event,
9840                 .init_hook = alc262_hippo_automute,
9841         },
9842         [ALC262_HIPPO_1] = {
9843                 .mixers = { alc262_hippo1_mixer },
9844                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
9845                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9846                 .dac_nids = alc262_dac_nids,
9847                 .hp_nid = 0x02,
9848                 .dig_out_nid = ALC262_DIGOUT_NID,
9849                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9850                 .channel_mode = alc262_modes,
9851                 .input_mux = &alc262_capture_source,
9852                 .unsol_event = alc262_hippo1_unsol_event,
9853                 .init_hook = alc262_hippo1_automute,
9854         },
9855         [ALC262_FUJITSU] = {
9856                 .mixers = { alc262_fujitsu_mixer },
9857                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
9858                                 alc262_fujitsu_unsol_verbs },
9859                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9860                 .dac_nids = alc262_dac_nids,
9861                 .hp_nid = 0x03,
9862                 .dig_out_nid = ALC262_DIGOUT_NID,
9863                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9864                 .channel_mode = alc262_modes,
9865                 .input_mux = &alc262_fujitsu_capture_source,
9866                 .unsol_event = alc262_fujitsu_unsol_event,
9867                 .init_hook = alc262_fujitsu_init_hook,
9868         },
9869         [ALC262_HP_BPC] = {
9870                 .mixers = { alc262_HP_BPC_mixer },
9871                 .init_verbs = { alc262_HP_BPC_init_verbs },
9872                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9873                 .dac_nids = alc262_dac_nids,
9874                 .hp_nid = 0x03,
9875                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9876                 .channel_mode = alc262_modes,
9877                 .input_mux = &alc262_HP_capture_source,
9878                 .unsol_event = alc262_hp_bpc_unsol_event,
9879                 .init_hook = alc262_hp_bpc_automute,
9880         },
9881         [ALC262_HP_BPC_D7000_WF] = {
9882                 .mixers = { alc262_HP_BPC_WildWest_mixer },
9883                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
9884                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9885                 .dac_nids = alc262_dac_nids,
9886                 .hp_nid = 0x03,
9887                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9888                 .channel_mode = alc262_modes,
9889                 .input_mux = &alc262_HP_D7000_capture_source,
9890                 .unsol_event = alc262_hp_wildwest_unsol_event,
9891                 .init_hook = alc262_hp_wildwest_automute,
9892         },
9893         [ALC262_HP_BPC_D7000_WL] = {
9894                 .mixers = { alc262_HP_BPC_WildWest_mixer,
9895                             alc262_HP_BPC_WildWest_option_mixer },
9896                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
9897                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9898                 .dac_nids = alc262_dac_nids,
9899                 .hp_nid = 0x03,
9900                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9901                 .channel_mode = alc262_modes,
9902                 .input_mux = &alc262_HP_D7000_capture_source,
9903                 .unsol_event = alc262_hp_wildwest_unsol_event,
9904                 .init_hook = alc262_hp_wildwest_automute,
9905         },
9906         [ALC262_HP_TC_T5735] = {
9907                 .mixers = { alc262_hp_t5735_mixer },
9908                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
9909                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9910                 .dac_nids = alc262_dac_nids,
9911                 .hp_nid = 0x03,
9912                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9913                 .channel_mode = alc262_modes,
9914                 .input_mux = &alc262_capture_source,
9915                 .unsol_event = alc262_hp_t5735_unsol_event,
9916                 .init_hook = alc262_hp_t5735_init_hook,
9917         },
9918         [ALC262_HP_RP5700] = {
9919                 .mixers = { alc262_hp_rp5700_mixer },
9920                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
9921                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9922                 .dac_nids = alc262_dac_nids,
9923                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9924                 .channel_mode = alc262_modes,
9925                 .input_mux = &alc262_hp_rp5700_capture_source,
9926         },
9927         [ALC262_BENQ_ED8] = {
9928                 .mixers = { alc262_base_mixer },
9929                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
9930                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9931                 .dac_nids = alc262_dac_nids,
9932                 .hp_nid = 0x03,
9933                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9934                 .channel_mode = alc262_modes,
9935                 .input_mux = &alc262_capture_source,
9936         },
9937         [ALC262_SONY_ASSAMD] = {
9938                 .mixers = { alc262_sony_mixer },
9939                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
9940                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9941                 .dac_nids = alc262_dac_nids,
9942                 .hp_nid = 0x02,
9943                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9944                 .channel_mode = alc262_modes,
9945                 .input_mux = &alc262_capture_source,
9946                 .unsol_event = alc262_hippo_unsol_event,
9947                 .init_hook = alc262_hippo_automute,
9948         },
9949         [ALC262_BENQ_T31] = {
9950                 .mixers = { alc262_benq_t31_mixer },
9951                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
9952                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9953                 .dac_nids = alc262_dac_nids,
9954                 .hp_nid = 0x03,
9955                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9956                 .channel_mode = alc262_modes,
9957                 .input_mux = &alc262_capture_source,
9958                 .unsol_event = alc262_hippo_unsol_event,
9959                 .init_hook = alc262_hippo_automute,
9960         },      
9961         [ALC262_ULTRA] = {
9962                 .mixers = { alc262_ultra_mixer, alc262_ultra_capture_mixer },
9963                 .init_verbs = { alc262_ultra_verbs },
9964                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9965                 .dac_nids = alc262_dac_nids,
9966                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9967                 .channel_mode = alc262_modes,
9968                 .input_mux = &alc262_ultra_capture_source,
9969                 .adc_nids = alc262_adc_nids, /* ADC0 */
9970                 .capsrc_nids = alc262_capsrc_nids,
9971                 .num_adc_nids = 1, /* single ADC */
9972                 .unsol_event = alc262_ultra_unsol_event,
9973                 .init_hook = alc262_ultra_automute,
9974         },
9975         [ALC262_LENOVO_3000] = {
9976                 .mixers = { alc262_lenovo_3000_mixer },
9977                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
9978                                 alc262_lenovo_3000_unsol_verbs },
9979                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9980                 .dac_nids = alc262_dac_nids,
9981                 .hp_nid = 0x03,
9982                 .dig_out_nid = ALC262_DIGOUT_NID,
9983                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9984                 .channel_mode = alc262_modes,
9985                 .input_mux = &alc262_fujitsu_capture_source,
9986                 .unsol_event = alc262_lenovo_3000_unsol_event,
9987         },
9988         [ALC262_NEC] = {
9989                 .mixers = { alc262_nec_mixer },
9990                 .init_verbs = { alc262_nec_verbs },
9991                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9992                 .dac_nids = alc262_dac_nids,
9993                 .hp_nid = 0x03,
9994                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9995                 .channel_mode = alc262_modes,
9996                 .input_mux = &alc262_capture_source,
9997         },
9998 };
9999
10000 static int patch_alc262(struct hda_codec *codec)
10001 {
10002         struct alc_spec *spec;
10003         int board_config;
10004         int err;
10005
10006         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10007         if (spec == NULL)
10008                 return -ENOMEM;
10009
10010         codec->spec = spec;
10011 #if 0
10012         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
10013          * under-run
10014          */
10015         {
10016         int tmp;
10017         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10018         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
10019         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10020         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
10021         }
10022 #endif
10023
10024         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
10025
10026         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
10027                                                   alc262_models,
10028                                                   alc262_cfg_tbl);
10029
10030         if (board_config < 0) {
10031                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
10032                        "trying auto-probe from BIOS...\n");
10033                 board_config = ALC262_AUTO;
10034         }
10035
10036         if (board_config == ALC262_AUTO) {
10037                 /* automatic parse from the BIOS config */
10038                 err = alc262_parse_auto_config(codec);
10039                 if (err < 0) {
10040                         alc_free(codec);
10041                         return err;
10042                 } else if (!err) {
10043                         printk(KERN_INFO
10044                                "hda_codec: Cannot set up configuration "
10045                                "from BIOS.  Using base mode...\n");
10046                         board_config = ALC262_BASIC;
10047                 }
10048         }
10049
10050         if (board_config != ALC262_AUTO)
10051                 setup_preset(spec, &alc262_presets[board_config]);
10052
10053         spec->stream_name_analog = "ALC262 Analog";
10054         spec->stream_analog_playback = &alc262_pcm_analog_playback;
10055         spec->stream_analog_capture = &alc262_pcm_analog_capture;
10056                 
10057         spec->stream_name_digital = "ALC262 Digital";
10058         spec->stream_digital_playback = &alc262_pcm_digital_playback;
10059         spec->stream_digital_capture = &alc262_pcm_digital_capture;
10060
10061         if (!spec->adc_nids && spec->input_mux) {
10062                 /* check whether NID 0x07 is valid */
10063                 unsigned int wcap = get_wcaps(codec, 0x07);
10064
10065                 /* get type */
10066                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10067                 if (wcap != AC_WID_AUD_IN) {
10068                         spec->adc_nids = alc262_adc_nids_alt;
10069                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
10070                         spec->capsrc_nids = alc262_capsrc_nids_alt;
10071                         spec->mixers[spec->num_mixers] =
10072                                 alc262_capture_alt_mixer;
10073                         spec->num_mixers++;
10074                 } else {
10075                         spec->adc_nids = alc262_adc_nids;
10076                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
10077                         spec->capsrc_nids = alc262_capsrc_nids;
10078                         spec->mixers[spec->num_mixers] = alc262_capture_mixer;
10079                         spec->num_mixers++;
10080                 }
10081         }
10082
10083         spec->vmaster_nid = 0x0c;
10084
10085         codec->patch_ops = alc_patch_ops;
10086         if (board_config == ALC262_AUTO)
10087                 spec->init_hook = alc262_auto_init;
10088 #ifdef CONFIG_SND_HDA_POWER_SAVE
10089         if (!spec->loopback.amplist)
10090                 spec->loopback.amplist = alc262_loopbacks;
10091 #endif
10092                 
10093         return 0;
10094 }
10095
10096 /*
10097  *  ALC268 channel source setting (2 channel)
10098  */
10099 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
10100 #define alc268_modes            alc260_modes
10101         
10102 static hda_nid_t alc268_dac_nids[2] = {
10103         /* front, hp */
10104         0x02, 0x03
10105 };
10106
10107 static hda_nid_t alc268_adc_nids[2] = {
10108         /* ADC0-1 */
10109         0x08, 0x07
10110 };
10111
10112 static hda_nid_t alc268_adc_nids_alt[1] = {
10113         /* ADC0 */
10114         0x08
10115 };
10116
10117 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
10118
10119 static struct snd_kcontrol_new alc268_base_mixer[] = {
10120         /* output mixer control */
10121         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10122         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10123         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10124         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10125         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10126         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10127         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10128         { }
10129 };
10130
10131 /* bind Beep switches of both NID 0x0f and 0x10 */
10132 static struct hda_bind_ctls alc268_bind_beep_sw = {
10133         .ops = &snd_hda_bind_sw,
10134         .values = {
10135                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
10136                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
10137                 0
10138         },
10139 };
10140
10141 static struct snd_kcontrol_new alc268_beep_mixer[] = {
10142         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
10143         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
10144         { }
10145 };
10146
10147 static struct hda_verb alc268_eapd_verbs[] = {
10148         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10149         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10150         { }
10151 };
10152
10153 /* Toshiba specific */
10154 #define alc268_toshiba_automute alc262_hippo_automute
10155
10156 static struct hda_verb alc268_toshiba_verbs[] = {
10157         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10158         { } /* end */
10159 };
10160
10161 /* Acer specific */
10162 /* bind volumes of both NID 0x02 and 0x03 */
10163 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
10164         .ops = &snd_hda_bind_vol,
10165         .values = {
10166                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
10167                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
10168                 0
10169         },
10170 };
10171
10172 /* mute/unmute internal speaker according to the hp jack and mute state */
10173 static void alc268_acer_automute(struct hda_codec *codec, int force)
10174 {
10175         struct alc_spec *spec = codec->spec;
10176         unsigned int mute;
10177
10178         if (force || !spec->sense_updated) {
10179                 unsigned int present;
10180                 present = snd_hda_codec_read(codec, 0x14, 0,
10181                                          AC_VERB_GET_PIN_SENSE, 0);
10182                 spec->jack_present = (present & 0x80000000) != 0;
10183                 spec->sense_updated = 1;
10184         }
10185         if (spec->jack_present)
10186                 mute = HDA_AMP_MUTE; /* mute internal speaker */
10187         else /* unmute internal speaker if necessary */
10188                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10189         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10190                                  HDA_AMP_MUTE, mute);
10191 }
10192
10193
10194 /* bind hp and internal speaker mute (with plug check) */
10195 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
10196                                      struct snd_ctl_elem_value *ucontrol)
10197 {
10198         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10199         long *valp = ucontrol->value.integer.value;
10200         int change;
10201
10202         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
10203                                           HDA_AMP_MUTE,
10204                                           valp[0] ? 0 : HDA_AMP_MUTE);
10205         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
10206                                            HDA_AMP_MUTE,
10207                                            valp[1] ? 0 : HDA_AMP_MUTE);
10208         if (change)
10209                 alc268_acer_automute(codec, 0);
10210         return change;
10211 }
10212
10213 static struct snd_kcontrol_new alc268_acer_mixer[] = {
10214         /* output mixer control */
10215         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
10216         {
10217                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10218                 .name = "Master Playback Switch",
10219                 .info = snd_hda_mixer_amp_switch_info,
10220                 .get = snd_hda_mixer_amp_switch_get,
10221                 .put = alc268_acer_master_sw_put,
10222                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10223         },
10224         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10225         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
10226         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10227         { }
10228 };
10229
10230 static struct hda_verb alc268_acer_verbs[] = {
10231         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
10232         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10233         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10234         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10235         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10236         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10237
10238         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10239         { }
10240 };
10241
10242 /* unsolicited event for HP jack sensing */
10243 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
10244                                        unsigned int res)
10245 {
10246         if ((res >> 26) != ALC880_HP_EVENT)
10247                 return;
10248         alc268_toshiba_automute(codec);
10249 }
10250
10251 static void alc268_acer_unsol_event(struct hda_codec *codec,
10252                                        unsigned int res)
10253 {
10254         if ((res >> 26) != ALC880_HP_EVENT)
10255                 return;
10256         alc268_acer_automute(codec, 1);
10257 }
10258
10259 static void alc268_acer_init_hook(struct hda_codec *codec)
10260 {
10261         alc268_acer_automute(codec, 1);
10262 }
10263
10264 static struct snd_kcontrol_new alc268_dell_mixer[] = {
10265         /* output mixer control */
10266         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10267         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10268         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10269         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10270         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10271         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
10272         { }
10273 };
10274
10275 static struct hda_verb alc268_dell_verbs[] = {
10276         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10277         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10278         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10279         { }
10280 };
10281
10282 /* mute/unmute internal speaker according to the hp jack and mute state */
10283 static void alc268_dell_automute(struct hda_codec *codec)
10284 {
10285         unsigned int present;
10286         unsigned int mute;
10287
10288         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
10289         if (present & 0x80000000)
10290                 mute = HDA_AMP_MUTE;
10291         else
10292                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
10293         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10294                                  HDA_AMP_MUTE, mute);
10295 }
10296
10297 static void alc268_dell_unsol_event(struct hda_codec *codec,
10298                                     unsigned int res)
10299 {
10300         if ((res >> 26) != ALC880_HP_EVENT)
10301                 return;
10302         alc268_dell_automute(codec);
10303 }
10304
10305 #define alc268_dell_init_hook   alc268_dell_automute
10306
10307 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
10308         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10309         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10310         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10311         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10312         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10313         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
10314         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
10315         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10316         { }
10317 };
10318
10319 static struct hda_verb alc267_quanta_il1_verbs[] = {
10320         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10321         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
10322         { }
10323 };
10324
10325 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
10326 {
10327         unsigned int present;
10328
10329         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
10330                 & AC_PINSENSE_PRESENCE;
10331         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
10332                             present ? 0 : PIN_OUT);
10333 }
10334
10335 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
10336 {
10337         unsigned int present;
10338
10339         present = snd_hda_codec_read(codec, 0x18, 0,
10340                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10341         snd_hda_codec_write(codec, 0x23, 0,
10342                             AC_VERB_SET_CONNECT_SEL,
10343                             present ? 0x00 : 0x01);
10344 }
10345
10346 static void alc267_quanta_il1_automute(struct hda_codec *codec)
10347 {
10348         alc267_quanta_il1_hp_automute(codec);
10349         alc267_quanta_il1_mic_automute(codec);
10350 }
10351
10352 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
10353                                            unsigned int res)
10354 {
10355         switch (res >> 26) {
10356         case ALC880_HP_EVENT:
10357                 alc267_quanta_il1_hp_automute(codec);
10358                 break;
10359         case ALC880_MIC_EVENT:
10360                 alc267_quanta_il1_mic_automute(codec);
10361                 break;
10362         }
10363 }
10364
10365 /*
10366  * generic initialization of ADC, input mixers and output mixers
10367  */
10368 static struct hda_verb alc268_base_init_verbs[] = {
10369         /* Unmute DAC0-1 and set vol = 0 */
10370         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10371         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10372         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10373         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10374         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10375         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10376
10377         /*
10378          * Set up output mixers (0x0c - 0x0e)
10379          */
10380         /* set vol=0 to output mixers */
10381         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10382         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10383         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10384         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
10385
10386         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10387         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10388
10389         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10390         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10391         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10392         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10393         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10394         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10395         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10396         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10397
10398         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10399         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10400         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10401         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10402         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10403         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10404         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10405
10406         /* set PCBEEP vol = 0, mute connections */
10407         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10408         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10409         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10410
10411         /* Unmute Selector 23h,24h and set the default input to mic-in */
10412         
10413         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
10414         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10415         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
10416         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10417
10418         { }
10419 };
10420
10421 /*
10422  * generic initialization of ADC, input mixers and output mixers
10423  */
10424 static struct hda_verb alc268_volume_init_verbs[] = {
10425         /* set output DAC */
10426         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10427         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10428         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10429         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10430
10431         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10432         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10433         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10434         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10435         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10436
10437         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10438         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10439         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10440         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10441         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10442
10443         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10444         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10445         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10446         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10447
10448         /* set PCBEEP vol = 0, mute connections */
10449         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10450         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10451         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10452
10453         { }
10454 };
10455
10456 #define alc268_mux_enum_info alc_mux_enum_info
10457 #define alc268_mux_enum_get alc_mux_enum_get
10458 #define alc268_mux_enum_put alc_mux_enum_put
10459
10460 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
10461         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10462         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
10463         {
10464                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10465                 /* The multiple "Capture Source" controls confuse alsamixer
10466                  * So call somewhat different..
10467                  */
10468                 /* .name = "Capture Source", */
10469                 .name = "Input Source",
10470                 .count = 1,
10471                 .info = alc268_mux_enum_info,
10472                 .get = alc268_mux_enum_get,
10473                 .put = alc268_mux_enum_put,
10474         },
10475         { } /* end */
10476 };
10477
10478 static struct snd_kcontrol_new alc268_capture_mixer[] = {
10479         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10480         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
10481         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
10482         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
10483         {
10484                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10485                 /* The multiple "Capture Source" controls confuse alsamixer
10486                  * So call somewhat different..
10487                  */
10488                 /* .name = "Capture Source", */
10489                 .name = "Input Source",
10490                 .count = 2,
10491                 .info = alc268_mux_enum_info,
10492                 .get = alc268_mux_enum_get,
10493                 .put = alc268_mux_enum_put,
10494         },
10495         { } /* end */
10496 };
10497
10498 static struct hda_input_mux alc268_capture_source = {
10499         .num_items = 4,
10500         .items = {
10501                 { "Mic", 0x0 },
10502                 { "Front Mic", 0x1 },
10503                 { "Line", 0x2 },
10504                 { "CD", 0x3 },
10505         },
10506 };
10507
10508 static struct hda_input_mux alc268_acer_capture_source = {
10509         .num_items = 3,
10510         .items = {
10511                 { "Mic", 0x0 },
10512                 { "Internal Mic", 0x6 },
10513                 { "Line", 0x2 },
10514         },
10515 };
10516
10517 #ifdef CONFIG_SND_DEBUG
10518 static struct snd_kcontrol_new alc268_test_mixer[] = {
10519         /* Volume widgets */
10520         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10521         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10522         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
10523         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
10524         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
10525         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
10526         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
10527         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
10528         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
10529         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
10530         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
10531         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
10532         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
10533         /* The below appears problematic on some hardwares */
10534         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
10535         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10536         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
10537         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
10538         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
10539
10540         /* Modes for retasking pin widgets */
10541         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
10542         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
10543         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
10544         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
10545
10546         /* Controls for GPIO pins, assuming they are configured as outputs */
10547         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
10548         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
10549         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
10550         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
10551
10552         /* Switches to allow the digital SPDIF output pin to be enabled.
10553          * The ALC268 does not have an SPDIF input.
10554          */
10555         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
10556
10557         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
10558          * this output to turn on an external amplifier.
10559          */
10560         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
10561         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
10562
10563         { } /* end */
10564 };
10565 #endif
10566
10567 /* create input playback/capture controls for the given pin */
10568 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
10569                                     const char *ctlname, int idx)
10570 {
10571         char name[32];
10572         int err;
10573
10574         sprintf(name, "%s Playback Volume", ctlname);
10575         if (nid == 0x14) {
10576                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
10577                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
10578                                                       HDA_OUTPUT));
10579                 if (err < 0)
10580                         return err;
10581         } else if (nid == 0x15) {
10582                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
10583                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
10584                                                       HDA_OUTPUT));
10585                 if (err < 0)
10586                         return err;
10587         } else
10588                 return -1;
10589         sprintf(name, "%s Playback Switch", ctlname);
10590         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
10591                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
10592         if (err < 0)
10593                 return err;
10594         return 0;
10595 }
10596
10597 /* add playback controls from the parsed DAC table */
10598 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
10599                                              const struct auto_pin_cfg *cfg)
10600 {
10601         hda_nid_t nid;
10602         int err;
10603
10604         spec->multiout.num_dacs = 2;    /* only use one dac */
10605         spec->multiout.dac_nids = spec->private_dac_nids;
10606         spec->multiout.dac_nids[0] = 2;
10607         spec->multiout.dac_nids[1] = 3;
10608
10609         nid = cfg->line_out_pins[0];
10610         if (nid)
10611                 alc268_new_analog_output(spec, nid, "Front", 0);        
10612
10613         nid = cfg->speaker_pins[0];
10614         if (nid == 0x1d) {
10615                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10616                                   "Speaker Playback Volume",
10617                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
10618                 if (err < 0)
10619                         return err;
10620         }
10621         nid = cfg->hp_pins[0];
10622         if (nid)
10623                 alc268_new_analog_output(spec, nid, "Headphone", 0);
10624
10625         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
10626         if (nid == 0x16) {
10627                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10628                                   "Mono Playback Switch",
10629                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
10630                 if (err < 0)
10631                         return err;
10632         }
10633         return 0;       
10634 }
10635
10636 /* create playback/capture controls for input pins */
10637 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
10638                                                 const struct auto_pin_cfg *cfg)
10639 {
10640         struct hda_input_mux *imux = &spec->private_imux;
10641         int i, idx1;
10642
10643         for (i = 0; i < AUTO_PIN_LAST; i++) {
10644                 switch(cfg->input_pins[i]) {
10645                 case 0x18:
10646                         idx1 = 0;       /* Mic 1 */
10647                         break;
10648                 case 0x19:
10649                         idx1 = 1;       /* Mic 2 */
10650                         break;
10651                 case 0x1a:
10652                         idx1 = 2;       /* Line In */
10653                         break;
10654                 case 0x1c:      
10655                         idx1 = 3;       /* CD */
10656                         break;
10657                 case 0x12:
10658                 case 0x13:
10659                         idx1 = 6;       /* digital mics */
10660                         break;
10661                 default:
10662                         continue;
10663                 }
10664                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
10665                 imux->items[imux->num_items].index = idx1;
10666                 imux->num_items++;      
10667         }
10668         return 0;
10669 }
10670
10671 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
10672 {
10673         struct alc_spec *spec = codec->spec;
10674         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
10675         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10676         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
10677         unsigned int    dac_vol1, dac_vol2;
10678
10679         if (speaker_nid) {
10680                 snd_hda_codec_write(codec, speaker_nid, 0,
10681                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
10682                 snd_hda_codec_write(codec, 0x0f, 0,
10683                                     AC_VERB_SET_AMP_GAIN_MUTE,
10684                                     AMP_IN_UNMUTE(1));
10685                 snd_hda_codec_write(codec, 0x10, 0,
10686                                     AC_VERB_SET_AMP_GAIN_MUTE,
10687                                     AMP_IN_UNMUTE(1));
10688         } else {
10689                 snd_hda_codec_write(codec, 0x0f, 0,
10690                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
10691                 snd_hda_codec_write(codec, 0x10, 0,
10692                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
10693         }
10694
10695         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
10696         if (line_nid == 0x14)   
10697                 dac_vol2 = AMP_OUT_ZERO;
10698         else if (line_nid == 0x15)
10699                 dac_vol1 = AMP_OUT_ZERO;
10700         if (hp_nid == 0x14)     
10701                 dac_vol2 = AMP_OUT_ZERO;
10702         else if (hp_nid == 0x15)
10703                 dac_vol1 = AMP_OUT_ZERO;
10704         if (line_nid != 0x16 || hp_nid != 0x16 ||
10705             spec->autocfg.line_out_pins[1] != 0x16 ||
10706             spec->autocfg.line_out_pins[2] != 0x16)
10707                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
10708
10709         snd_hda_codec_write(codec, 0x02, 0,
10710                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
10711         snd_hda_codec_write(codec, 0x03, 0,
10712                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
10713 }
10714
10715 /* pcm configuration: identiacal with ALC880 */
10716 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
10717 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
10718 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
10719 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
10720
10721 /*
10722  * BIOS auto configuration
10723  */
10724 static int alc268_parse_auto_config(struct hda_codec *codec)
10725 {
10726         struct alc_spec *spec = codec->spec;
10727         int err;
10728         static hda_nid_t alc268_ignore[] = { 0 };
10729
10730         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10731                                            alc268_ignore);
10732         if (err < 0)
10733                 return err;
10734         if (!spec->autocfg.line_outs)
10735                 return 0; /* can't find valid BIOS pin config */
10736
10737         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
10738         if (err < 0)
10739                 return err;
10740         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
10741         if (err < 0)
10742                 return err;
10743
10744         spec->multiout.max_channels = 2;
10745
10746         /* digital only support output */
10747         if (spec->autocfg.dig_out_pin)
10748                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
10749
10750         if (spec->kctl_alloc)
10751                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10752
10753         if (spec->autocfg.speaker_pins[0] != 0x1d)
10754                 spec->mixers[spec->num_mixers++] = alc268_beep_mixer;
10755
10756         spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs;
10757         spec->num_mux_defs = 1;
10758         spec->input_mux = &spec->private_imux;
10759
10760         err = alc_auto_add_mic_boost(codec);
10761         if (err < 0)
10762                 return err;
10763
10764         return 1;
10765 }
10766
10767 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
10768 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
10769 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
10770
10771 /* init callback for auto-configuration model -- overriding the default init */
10772 static void alc268_auto_init(struct hda_codec *codec)
10773 {
10774         struct alc_spec *spec = codec->spec;
10775         alc268_auto_init_multi_out(codec);
10776         alc268_auto_init_hp_out(codec);
10777         alc268_auto_init_mono_speaker_out(codec);
10778         alc268_auto_init_analog_input(codec);
10779         if (spec->unsol_event)
10780                 alc_sku_automute(codec);
10781 }
10782
10783 /*
10784  * configuration and preset
10785  */
10786 static const char *alc268_models[ALC268_MODEL_LAST] = {
10787         [ALC267_QUANTA_IL1]     = "quanta-il1",
10788         [ALC268_3ST]            = "3stack",
10789         [ALC268_TOSHIBA]        = "toshiba",
10790         [ALC268_ACER]           = "acer",
10791         [ALC268_DELL]           = "dell",
10792         [ALC268_ZEPTO]          = "zepto",
10793 #ifdef CONFIG_SND_DEBUG
10794         [ALC268_TEST]           = "test",
10795 #endif
10796         [ALC268_AUTO]           = "auto",
10797 };
10798
10799 static struct snd_pci_quirk alc268_cfg_tbl[] = {
10800         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
10801         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
10802         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
10803         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
10804         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
10805         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
10806         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
10807         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
10808         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
10809         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
10810         SND_PCI_QUIRK(0x1179, 0xff64, "TOSHIBA L305", ALC268_TOSHIBA),
10811         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
10812         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
10813         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
10814         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
10815         {}
10816 };
10817
10818 static struct alc_config_preset alc268_presets[] = {
10819         [ALC267_QUANTA_IL1] = {
10820                 .mixers = { alc267_quanta_il1_mixer },
10821                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10822                                 alc267_quanta_il1_verbs },
10823                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10824                 .dac_nids = alc268_dac_nids,
10825                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10826                 .adc_nids = alc268_adc_nids_alt,
10827                 .hp_nid = 0x03,
10828                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10829                 .channel_mode = alc268_modes,
10830                 .input_mux = &alc268_capture_source,
10831                 .unsol_event = alc267_quanta_il1_unsol_event,
10832                 .init_hook = alc267_quanta_il1_automute,
10833         },
10834         [ALC268_3ST] = {
10835                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10836                             alc268_beep_mixer },
10837                 .init_verbs = { alc268_base_init_verbs },
10838                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10839                 .dac_nids = alc268_dac_nids,
10840                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10841                 .adc_nids = alc268_adc_nids_alt,
10842                 .capsrc_nids = alc268_capsrc_nids,
10843                 .hp_nid = 0x03,
10844                 .dig_out_nid = ALC268_DIGOUT_NID,
10845                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10846                 .channel_mode = alc268_modes,
10847                 .input_mux = &alc268_capture_source,
10848         },
10849         [ALC268_TOSHIBA] = {
10850                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10851                             alc268_beep_mixer },
10852                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10853                                 alc268_toshiba_verbs },
10854                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10855                 .dac_nids = alc268_dac_nids,
10856                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10857                 .adc_nids = alc268_adc_nids_alt,
10858                 .capsrc_nids = alc268_capsrc_nids,
10859                 .hp_nid = 0x03,
10860                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10861                 .channel_mode = alc268_modes,
10862                 .input_mux = &alc268_capture_source,
10863                 .unsol_event = alc268_toshiba_unsol_event,
10864                 .init_hook = alc268_toshiba_automute,
10865         },
10866         [ALC268_ACER] = {
10867                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
10868                             alc268_beep_mixer },
10869                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10870                                 alc268_acer_verbs },
10871                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10872                 .dac_nids = alc268_dac_nids,
10873                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10874                 .adc_nids = alc268_adc_nids_alt,
10875                 .capsrc_nids = alc268_capsrc_nids,
10876                 .hp_nid = 0x02,
10877                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10878                 .channel_mode = alc268_modes,
10879                 .input_mux = &alc268_acer_capture_source,
10880                 .unsol_event = alc268_acer_unsol_event,
10881                 .init_hook = alc268_acer_init_hook,
10882         },
10883         [ALC268_DELL] = {
10884                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
10885                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10886                                 alc268_dell_verbs },
10887                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10888                 .dac_nids = alc268_dac_nids,
10889                 .hp_nid = 0x02,
10890                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10891                 .channel_mode = alc268_modes,
10892                 .unsol_event = alc268_dell_unsol_event,
10893                 .init_hook = alc268_dell_init_hook,
10894                 .input_mux = &alc268_capture_source,
10895         },
10896         [ALC268_ZEPTO] = {
10897                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10898                             alc268_beep_mixer },
10899                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10900                                 alc268_toshiba_verbs },
10901                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10902                 .dac_nids = alc268_dac_nids,
10903                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10904                 .adc_nids = alc268_adc_nids_alt,
10905                 .capsrc_nids = alc268_capsrc_nids,
10906                 .hp_nid = 0x03,
10907                 .dig_out_nid = ALC268_DIGOUT_NID,
10908                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10909                 .channel_mode = alc268_modes,
10910                 .input_mux = &alc268_capture_source,
10911                 .unsol_event = alc268_toshiba_unsol_event,
10912                 .init_hook = alc268_toshiba_automute
10913         },
10914 #ifdef CONFIG_SND_DEBUG
10915         [ALC268_TEST] = {
10916                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
10917                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10918                                 alc268_volume_init_verbs },
10919                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10920                 .dac_nids = alc268_dac_nids,
10921                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10922                 .adc_nids = alc268_adc_nids_alt,
10923                 .capsrc_nids = alc268_capsrc_nids,
10924                 .hp_nid = 0x03,
10925                 .dig_out_nid = ALC268_DIGOUT_NID,
10926                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10927                 .channel_mode = alc268_modes,
10928                 .input_mux = &alc268_capture_source,
10929         },
10930 #endif
10931 };
10932
10933 static int patch_alc268(struct hda_codec *codec)
10934 {
10935         struct alc_spec *spec;
10936         int board_config;
10937         int err;
10938
10939         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
10940         if (spec == NULL)
10941                 return -ENOMEM;
10942
10943         codec->spec = spec;
10944
10945         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
10946                                                   alc268_models,
10947                                                   alc268_cfg_tbl);
10948
10949         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
10950                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
10951                        "trying auto-probe from BIOS...\n");
10952                 board_config = ALC268_AUTO;
10953         }
10954
10955         if (board_config == ALC268_AUTO) {
10956                 /* automatic parse from the BIOS config */
10957                 err = alc268_parse_auto_config(codec);
10958                 if (err < 0) {
10959                         alc_free(codec);
10960                         return err;
10961                 } else if (!err) {
10962                         printk(KERN_INFO
10963                                "hda_codec: Cannot set up configuration "
10964                                "from BIOS.  Using base mode...\n");
10965                         board_config = ALC268_3ST;
10966                 }
10967         }
10968
10969         if (board_config != ALC268_AUTO)
10970                 setup_preset(spec, &alc268_presets[board_config]);
10971
10972         if (codec->vendor_id == 0x10ec0267) {
10973                 spec->stream_name_analog = "ALC267 Analog";
10974                 spec->stream_name_digital = "ALC267 Digital";
10975         } else {
10976                 spec->stream_name_analog = "ALC268 Analog";
10977                 spec->stream_name_digital = "ALC268 Digital";
10978         }
10979
10980         spec->stream_analog_playback = &alc268_pcm_analog_playback;
10981         spec->stream_analog_capture = &alc268_pcm_analog_capture;
10982         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
10983
10984         spec->stream_digital_playback = &alc268_pcm_digital_playback;
10985
10986         if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
10987                 /* override the amp caps for beep generator */
10988                 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
10989                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
10990                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
10991                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
10992                                           (0 << AC_AMPCAP_MUTE_SHIFT));
10993
10994         if (!spec->adc_nids && spec->input_mux) {
10995                 /* check whether NID 0x07 is valid */
10996                 unsigned int wcap = get_wcaps(codec, 0x07);
10997                 int i;
10998
10999                 /* get type */
11000                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
11001                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
11002                         spec->adc_nids = alc268_adc_nids_alt;
11003                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
11004                         spec->mixers[spec->num_mixers] =
11005                                         alc268_capture_alt_mixer;
11006                         spec->num_mixers++;
11007                 } else {
11008                         spec->adc_nids = alc268_adc_nids;
11009                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
11010                         spec->mixers[spec->num_mixers] =
11011                                 alc268_capture_mixer;
11012                         spec->num_mixers++;
11013                 }
11014                 spec->capsrc_nids = alc268_capsrc_nids;
11015                 /* set default input source */
11016                 for (i = 0; i < spec->num_adc_nids; i++)
11017                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
11018                                 0, AC_VERB_SET_CONNECT_SEL,
11019                                 spec->input_mux->items[0].index);
11020         }
11021
11022         spec->vmaster_nid = 0x02;
11023
11024         codec->patch_ops = alc_patch_ops;
11025         if (board_config == ALC268_AUTO)
11026                 spec->init_hook = alc268_auto_init;
11027                 
11028         return 0;
11029 }
11030
11031 /*
11032  *  ALC269 channel source setting (2 channel)
11033  */
11034 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
11035
11036 #define alc269_dac_nids         alc260_dac_nids
11037
11038 static hda_nid_t alc269_adc_nids[1] = {
11039         /* ADC1 */
11040         0x08,
11041 };
11042
11043 static hda_nid_t alc269_capsrc_nids[1] = {
11044         0x23,
11045 };
11046
11047 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
11048  *       not a mux!
11049  */
11050
11051 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
11052         .num_items = 2,
11053         .items = {
11054                 { "i-Mic", 0x5 },
11055                 { "e-Mic", 0x0 },
11056         },
11057 };
11058
11059 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
11060         .num_items = 2,
11061         .items = {
11062                 { "i-Mic", 0x1 },
11063                 { "e-Mic", 0x0 },
11064         },
11065 };
11066
11067 #define alc269_modes            alc260_modes
11068 #define alc269_capture_source   alc880_lg_lw_capture_source
11069
11070 static struct snd_kcontrol_new alc269_base_mixer[] = {
11071         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11072         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11073         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11074         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11075         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11076         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11077         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11078         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11079         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11080         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11081         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11082         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
11083         { } /* end */
11084 };
11085
11086 /* bind volumes of both NID 0x0c and 0x0d */
11087 static struct hda_bind_ctls alc269_epc_bind_vol = {
11088         .ops = &snd_hda_bind_vol,
11089         .values = {
11090                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
11091                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
11092                 0
11093         },
11094 };
11095
11096 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
11097         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11098         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
11099         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11100         { } /* end */
11101 };
11102
11103 /* capture mixer elements */
11104 static struct snd_kcontrol_new alc269_capture_mixer[] = {
11105         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11106         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11107         {
11108                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11109                 /* The multiple "Capture Source" controls confuse alsamixer
11110                  * So call somewhat different..
11111                  */
11112                 /* .name = "Capture Source", */
11113                 .name = "Input Source",
11114                 .count = 1,
11115                 .info = alc_mux_enum_info,
11116                 .get = alc_mux_enum_get,
11117                 .put = alc_mux_enum_put,
11118         },
11119         { } /* end */
11120 };
11121
11122 /* capture mixer elements */
11123 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
11124         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11125         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11126         { } /* end */
11127 };
11128
11129 /*
11130  * generic initialization of ADC, input mixers and output mixers
11131  */
11132 static struct hda_verb alc269_init_verbs[] = {
11133         /*
11134          * Unmute ADC0 and set the default input to mic-in
11135          */
11136         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11137
11138         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
11139          * analog-loopback mixer widget
11140          * Note: PASD motherboards uses the Line In 2 as the input for
11141          * front panel mic (mic 2)
11142          */
11143         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11144         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11145         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11146         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11147         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11148         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11149
11150         /*
11151          * Set up output mixers (0x0c - 0x0e)
11152          */
11153         /* set vol=0 to output mixers */
11154         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11155         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11156
11157         /* set up input amps for analog loopback */
11158         /* Amp Indices: DAC = 0, mixer = 1 */
11159         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11160         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11161         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11162         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11163         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11164         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11165
11166         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11167         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11168         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11169         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11170         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11171         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11172         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11173
11174         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11175         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11176         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11177         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11178         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11179         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11180         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11181
11182         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
11183         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11184
11185         /* FIXME: use matrix-type input source selection */
11186         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
11187         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11188         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11189         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11190         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11191         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11192
11193         /* set EAPD */
11194         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11195         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
11196         { }
11197 };
11198
11199 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
11200         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11201         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
11202         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
11203         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
11204         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11205         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11206         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11207         {}
11208 };
11209
11210 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
11211         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11212         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
11213         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
11214         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
11215         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11216         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11217         {}
11218 };
11219
11220 /* toggle speaker-output according to the hp-jack state */
11221 static void alc269_speaker_automute(struct hda_codec *codec)
11222 {
11223         unsigned int present;
11224         unsigned int bits;
11225
11226         present = snd_hda_codec_read(codec, 0x15, 0,
11227                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11228         bits = present ? AMP_IN_MUTE(0) : 0;
11229         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
11230                                  AMP_IN_MUTE(0), bits);
11231         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
11232                                  AMP_IN_MUTE(0), bits);
11233 }
11234
11235 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
11236 {
11237         unsigned int present;
11238
11239         present = snd_hda_codec_read(codec, 0x18, 0, AC_VERB_GET_PIN_SENSE, 0)
11240                 & AC_PINSENSE_PRESENCE;
11241         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
11242                             present ? 0 : 5);
11243 }
11244
11245 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
11246 {
11247         unsigned int present;
11248
11249         present = snd_hda_codec_read(codec, 0x18, 0, AC_VERB_GET_PIN_SENSE, 0)
11250                 & AC_PINSENSE_PRESENCE;
11251         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11252                             present ? AMP_IN_UNMUTE(0) : AMP_IN_MUTE(0));
11253         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11254                             present ? AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1));
11255 }
11256
11257 /* unsolicited event for HP jack sensing */
11258 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
11259                                           unsigned int res)
11260 {
11261         if ((res >> 26) == ALC880_HP_EVENT)
11262                 alc269_speaker_automute(codec);
11263
11264         if ((res >> 26) == ALC880_MIC_EVENT)
11265                 alc269_eeepc_dmic_automute(codec);
11266 }
11267
11268 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
11269 {
11270         alc269_speaker_automute(codec);
11271         alc269_eeepc_dmic_automute(codec);
11272 }
11273
11274 /* unsolicited event for HP jack sensing */
11275 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
11276                                           unsigned int res)
11277 {
11278         if ((res >> 26) == ALC880_HP_EVENT)
11279                 alc269_speaker_automute(codec);
11280
11281         if ((res >> 26) == ALC880_MIC_EVENT)
11282                 alc269_eeepc_amic_automute(codec);
11283 }
11284
11285 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
11286 {
11287         alc269_speaker_automute(codec);
11288         alc269_eeepc_amic_automute(codec);
11289 }
11290
11291 /* add playback controls from the parsed DAC table */
11292 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
11293                                              const struct auto_pin_cfg *cfg)
11294 {
11295         hda_nid_t nid;
11296         int err;
11297
11298         spec->multiout.num_dacs = 1;    /* only use one dac */
11299         spec->multiout.dac_nids = spec->private_dac_nids;
11300         spec->multiout.dac_nids[0] = 2;
11301
11302         nid = cfg->line_out_pins[0];
11303         if (nid) {
11304                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
11305                                   "Front Playback Volume",
11306                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
11307                 if (err < 0)
11308                         return err;
11309                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11310                                   "Front Playback Switch",
11311                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
11312                 if (err < 0)
11313                         return err;
11314         }
11315
11316         nid = cfg->speaker_pins[0];
11317         if (nid) {
11318                 if (!cfg->line_out_pins[0]) {
11319                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11320                                           "Speaker Playback Volume",
11321                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
11322                                                               HDA_OUTPUT));
11323                         if (err < 0)
11324                                 return err;
11325                 }
11326                 if (nid == 0x16) {
11327                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11328                                           "Speaker Playback Switch",
11329                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
11330                                                               HDA_OUTPUT));
11331                         if (err < 0)
11332                                 return err;
11333                 } else {
11334                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11335                                           "Speaker Playback Switch",
11336                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
11337                                                               HDA_OUTPUT));
11338                         if (err < 0)
11339                                 return err;
11340                 }
11341         }
11342         nid = cfg->hp_pins[0];
11343         if (nid) {
11344                 /* spec->multiout.hp_nid = 2; */
11345                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
11346                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11347                                           "Headphone Playback Volume",
11348                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
11349                                                               HDA_OUTPUT));
11350                         if (err < 0)
11351                                 return err;
11352                 }
11353                 if (nid == 0x16) {
11354                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11355                                           "Headphone Playback Switch",
11356                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
11357                                                               HDA_OUTPUT));
11358                         if (err < 0)
11359                                 return err;
11360                 } else {
11361                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11362                                           "Headphone Playback Switch",
11363                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
11364                                                               HDA_OUTPUT));
11365                         if (err < 0)
11366                                 return err;
11367                 }
11368         }
11369         return 0;
11370 }
11371
11372 #define alc269_auto_create_analog_input_ctls \
11373         alc880_auto_create_analog_input_ctls
11374
11375 #ifdef CONFIG_SND_HDA_POWER_SAVE
11376 #define alc269_loopbacks        alc880_loopbacks
11377 #endif
11378
11379 /* pcm configuration: identiacal with ALC880 */
11380 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
11381 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
11382 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
11383 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
11384
11385 /*
11386  * BIOS auto configuration
11387  */
11388 static int alc269_parse_auto_config(struct hda_codec *codec)
11389 {
11390         struct alc_spec *spec = codec->spec;
11391         int err;
11392         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
11393
11394         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11395                                            alc269_ignore);
11396         if (err < 0)
11397                 return err;
11398
11399         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
11400         if (err < 0)
11401                 return err;
11402         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
11403         if (err < 0)
11404                 return err;
11405
11406         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11407
11408         if (spec->autocfg.dig_out_pin)
11409                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
11410
11411         if (spec->kctl_alloc)
11412                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
11413
11414         spec->init_verbs[spec->num_init_verbs++] = alc269_init_verbs;
11415         spec->num_mux_defs = 1;
11416         spec->input_mux = &spec->private_imux;
11417         /* set default input source */
11418         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
11419                                   0, AC_VERB_SET_CONNECT_SEL,
11420                                   spec->input_mux->items[0].index);
11421
11422         err = alc_auto_add_mic_boost(codec);
11423         if (err < 0)
11424                 return err;
11425
11426         spec->mixers[spec->num_mixers] = alc269_capture_mixer;
11427         spec->num_mixers++;
11428
11429         return 1;
11430 }
11431
11432 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
11433 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
11434 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
11435
11436
11437 /* init callback for auto-configuration model -- overriding the default init */
11438 static void alc269_auto_init(struct hda_codec *codec)
11439 {
11440         struct alc_spec *spec = codec->spec;
11441         alc269_auto_init_multi_out(codec);
11442         alc269_auto_init_hp_out(codec);
11443         alc269_auto_init_analog_input(codec);
11444         if (spec->unsol_event)
11445                 alc_sku_automute(codec);
11446 }
11447
11448 /*
11449  * configuration and preset
11450  */
11451 static const char *alc269_models[ALC269_MODEL_LAST] = {
11452         [ALC269_BASIC]          = "basic",
11453 };
11454
11455 static struct snd_pci_quirk alc269_cfg_tbl[] = {
11456         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
11457                       ALC269_ASUS_EEEPC_P703),
11458         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
11459                       ALC269_ASUS_EEEPC_P901),
11460         {}
11461 };
11462
11463 static struct alc_config_preset alc269_presets[] = {
11464         [ALC269_BASIC] = {
11465                 .mixers = { alc269_base_mixer, alc269_capture_mixer },
11466                 .init_verbs = { alc269_init_verbs },
11467                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
11468                 .dac_nids = alc269_dac_nids,
11469                 .hp_nid = 0x03,
11470                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
11471                 .channel_mode = alc269_modes,
11472                 .input_mux = &alc269_capture_source,
11473         },
11474         [ALC269_ASUS_EEEPC_P703] = {
11475                 .mixers = { alc269_eeepc_mixer, alc269_epc_capture_mixer },
11476                 .init_verbs = { alc269_init_verbs,
11477                                 alc269_eeepc_amic_init_verbs },
11478                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
11479                 .dac_nids = alc269_dac_nids,
11480                 .hp_nid = 0x03,
11481                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
11482                 .channel_mode = alc269_modes,
11483                 .input_mux = &alc269_eeepc_amic_capture_source,
11484                 .unsol_event = alc269_eeepc_amic_unsol_event,
11485                 .init_hook = alc269_eeepc_amic_inithook,
11486         },
11487         [ALC269_ASUS_EEEPC_P901] = {
11488                 .mixers = { alc269_eeepc_mixer, alc269_epc_capture_mixer},
11489                 .init_verbs = { alc269_init_verbs,
11490                                 alc269_eeepc_dmic_init_verbs },
11491                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
11492                 .dac_nids = alc269_dac_nids,
11493                 .hp_nid = 0x03,
11494                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
11495                 .channel_mode = alc269_modes,
11496                 .input_mux = &alc269_eeepc_dmic_capture_source,
11497                 .unsol_event = alc269_eeepc_dmic_unsol_event,
11498                 .init_hook = alc269_eeepc_dmic_inithook,
11499         },
11500 };
11501
11502 static int patch_alc269(struct hda_codec *codec)
11503 {
11504         struct alc_spec *spec;
11505         int board_config;
11506         int err;
11507
11508         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11509         if (spec == NULL)
11510                 return -ENOMEM;
11511
11512         codec->spec = spec;
11513
11514         alc_fix_pll_init(codec, 0x20, 0x04, 15);
11515
11516         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
11517                                                   alc269_models,
11518                                                   alc269_cfg_tbl);
11519
11520         if (board_config < 0) {
11521                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
11522                        "trying auto-probe from BIOS...\n");
11523                 board_config = ALC269_AUTO;
11524         }
11525
11526         if (board_config == ALC269_AUTO) {
11527                 /* automatic parse from the BIOS config */
11528                 err = alc269_parse_auto_config(codec);
11529                 if (err < 0) {
11530                         alc_free(codec);
11531                         return err;
11532                 } else if (!err) {
11533                         printk(KERN_INFO
11534                                "hda_codec: Cannot set up configuration "
11535                                "from BIOS.  Using base mode...\n");
11536                         board_config = ALC269_BASIC;
11537                 }
11538         }
11539
11540         if (board_config != ALC269_AUTO)
11541                 setup_preset(spec, &alc269_presets[board_config]);
11542
11543         spec->stream_name_analog = "ALC269 Analog";
11544         spec->stream_analog_playback = &alc269_pcm_analog_playback;
11545         spec->stream_analog_capture = &alc269_pcm_analog_capture;
11546
11547         spec->stream_name_digital = "ALC269 Digital";
11548         spec->stream_digital_playback = &alc269_pcm_digital_playback;
11549         spec->stream_digital_capture = &alc269_pcm_digital_capture;
11550
11551         spec->adc_nids = alc269_adc_nids;
11552         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
11553         spec->capsrc_nids = alc269_capsrc_nids;
11554
11555         codec->patch_ops = alc_patch_ops;
11556         if (board_config == ALC269_AUTO)
11557                 spec->init_hook = alc269_auto_init;
11558 #ifdef CONFIG_SND_HDA_POWER_SAVE
11559         if (!spec->loopback.amplist)
11560                 spec->loopback.amplist = alc269_loopbacks;
11561 #endif
11562
11563         return 0;
11564 }
11565
11566 /*
11567  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
11568  */
11569
11570 /*
11571  * set the path ways for 2 channel output
11572  * need to set the codec line out and mic 1 pin widgets to inputs
11573  */
11574 static struct hda_verb alc861_threestack_ch2_init[] = {
11575         /* set pin widget 1Ah (line in) for input */
11576         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11577         /* set pin widget 18h (mic1/2) for input, for mic also enable
11578          * the vref
11579          */
11580         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11581
11582         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
11583 #if 0
11584         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
11585         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
11586 #endif
11587         { } /* end */
11588 };
11589 /*
11590  * 6ch mode
11591  * need to set the codec line out and mic 1 pin widgets to outputs
11592  */
11593 static struct hda_verb alc861_threestack_ch6_init[] = {
11594         /* set pin widget 1Ah (line in) for output (Back Surround)*/
11595         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11596         /* set pin widget 18h (mic1) for output (CLFE)*/
11597         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11598
11599         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
11600         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
11601
11602         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
11603 #if 0
11604         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
11605         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
11606 #endif
11607         { } /* end */
11608 };
11609
11610 static struct hda_channel_mode alc861_threestack_modes[2] = {
11611         { 2, alc861_threestack_ch2_init },
11612         { 6, alc861_threestack_ch6_init },
11613 };
11614 /* Set mic1 as input and unmute the mixer */
11615 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
11616         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11617         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
11618         { } /* end */
11619 };
11620 /* Set mic1 as output and mute mixer */
11621 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
11622         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11623         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
11624         { } /* end */
11625 };
11626
11627 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
11628         { 2, alc861_uniwill_m31_ch2_init },
11629         { 4, alc861_uniwill_m31_ch4_init },
11630 };
11631
11632 /* Set mic1 and line-in as input and unmute the mixer */
11633 static struct hda_verb alc861_asus_ch2_init[] = {
11634         /* set pin widget 1Ah (line in) for input */
11635         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11636         /* set pin widget 18h (mic1/2) for input, for mic also enable
11637          * the vref
11638          */
11639         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11640
11641         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
11642 #if 0
11643         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
11644         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
11645 #endif
11646         { } /* end */
11647 };
11648 /* Set mic1 nad line-in as output and mute mixer */
11649 static struct hda_verb alc861_asus_ch6_init[] = {
11650         /* set pin widget 1Ah (line in) for output (Back Surround)*/
11651         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11652         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
11653         /* set pin widget 18h (mic1) for output (CLFE)*/
11654         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11655         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
11656         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
11657         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
11658
11659         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
11660 #if 0
11661         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
11662         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
11663 #endif
11664         { } /* end */
11665 };
11666
11667 static struct hda_channel_mode alc861_asus_modes[2] = {
11668         { 2, alc861_asus_ch2_init },
11669         { 6, alc861_asus_ch6_init },
11670 };
11671
11672 /* patch-ALC861 */
11673
11674 static struct snd_kcontrol_new alc861_base_mixer[] = {
11675         /* output mixer control */
11676         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11677         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11678         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11679         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11680         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
11681
11682         /*Input mixer control */
11683         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11684            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11685         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11686         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11687         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11688         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11689         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11690         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11691         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11692         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11693
11694         /* Capture mixer control */
11695         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11696         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11697         {
11698                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11699                 .name = "Capture Source",
11700                 .count = 1,
11701                 .info = alc_mux_enum_info,
11702                 .get = alc_mux_enum_get,
11703                 .put = alc_mux_enum_put,
11704         },
11705         { } /* end */
11706 };
11707
11708 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
11709         /* output mixer control */
11710         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11711         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11712         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11713         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11714         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
11715
11716         /* Input mixer control */
11717         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11718            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11719         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11720         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11721         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11722         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11723         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11724         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11725         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11726         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11727
11728         /* Capture mixer control */
11729         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11730         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11731         {
11732                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11733                 .name = "Capture Source",
11734                 .count = 1,
11735                 .info = alc_mux_enum_info,
11736                 .get = alc_mux_enum_get,
11737                 .put = alc_mux_enum_put,
11738         },
11739         {
11740                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11741                 .name = "Channel Mode",
11742                 .info = alc_ch_mode_info,
11743                 .get = alc_ch_mode_get,
11744                 .put = alc_ch_mode_put,
11745                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
11746         },
11747         { } /* end */
11748 };
11749
11750 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
11751         /* output mixer control */
11752         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11753         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11754         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11755         
11756         /*Capture mixer control */
11757         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11758         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11759         {
11760                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11761                 .name = "Capture Source",
11762                 .count = 1,
11763                 .info = alc_mux_enum_info,
11764                 .get = alc_mux_enum_get,
11765                 .put = alc_mux_enum_put,
11766         },
11767
11768         { } /* end */
11769 };
11770
11771 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
11772         /* output mixer control */
11773         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11774         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11775         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11776         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11777         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
11778
11779         /* Input mixer control */
11780         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11781            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11782         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11783         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11784         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11785         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11786         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11787         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11788         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11789         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11790
11791         /* Capture mixer control */
11792         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11793         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11794         {
11795                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11796                 .name = "Capture Source",
11797                 .count = 1,
11798                 .info = alc_mux_enum_info,
11799                 .get = alc_mux_enum_get,
11800                 .put = alc_mux_enum_put,
11801         },
11802         {
11803                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11804                 .name = "Channel Mode",
11805                 .info = alc_ch_mode_info,
11806                 .get = alc_ch_mode_get,
11807                 .put = alc_ch_mode_put,
11808                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
11809         },
11810         { } /* end */
11811 };
11812
11813 static struct snd_kcontrol_new alc861_asus_mixer[] = {
11814         /* output mixer control */
11815         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11816         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11817         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11818         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11819         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
11820
11821         /* Input mixer control */
11822         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11823         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11824         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11825         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11826         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11827         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11828         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11829         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11830         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11831         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
11832
11833         /* Capture mixer control */
11834         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11835         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11836         {
11837                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11838                 .name = "Capture Source",
11839                 .count = 1,
11840                 .info = alc_mux_enum_info,
11841                 .get = alc_mux_enum_get,
11842                 .put = alc_mux_enum_put,
11843         },
11844         {
11845                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11846                 .name = "Channel Mode",
11847                 .info = alc_ch_mode_info,
11848                 .get = alc_ch_mode_get,
11849                 .put = alc_ch_mode_put,
11850                 .private_value = ARRAY_SIZE(alc861_asus_modes),
11851         },
11852         { }
11853 };
11854
11855 /* additional mixer */
11856 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
11857         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11858         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11859         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
11860         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
11861         { }
11862 };
11863
11864 /*
11865  * generic initialization of ADC, input mixers and output mixers
11866  */
11867 static struct hda_verb alc861_base_init_verbs[] = {
11868         /*
11869          * Unmute ADC0 and set the default input to mic-in
11870          */
11871         /* port-A for surround (rear panel) */
11872         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11873         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
11874         /* port-B for mic-in (rear panel) with vref */
11875         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11876         /* port-C for line-in (rear panel) */
11877         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11878         /* port-D for Front */
11879         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11880         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11881         /* port-E for HP out (front panel) */
11882         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
11883         /* route front PCM to HP */
11884         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11885         /* port-F for mic-in (front panel) with vref */
11886         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11887         /* port-G for CLFE (rear panel) */
11888         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11889         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11890         /* port-H for side (rear panel) */
11891         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11892         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
11893         /* CD-in */
11894         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11895         /* route front mic to ADC1*/
11896         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11897         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11898         
11899         /* Unmute DAC0~3 & spdif out*/
11900         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11901         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11902         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11903         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11904         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11905         
11906         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11907         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11908         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11909         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11910         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11911         
11912         /* Unmute Stereo Mixer 15 */
11913         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11914         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11915         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11916         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
11917
11918         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11919         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11920         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11921         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11922         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11923         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11924         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11925         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11926         /* hp used DAC 3 (Front) */
11927         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11928         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11929
11930         { }
11931 };
11932
11933 static struct hda_verb alc861_threestack_init_verbs[] = {
11934         /*
11935          * Unmute ADC0 and set the default input to mic-in
11936          */
11937         /* port-A for surround (rear panel) */
11938         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11939         /* port-B for mic-in (rear panel) with vref */
11940         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11941         /* port-C for line-in (rear panel) */
11942         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11943         /* port-D for Front */
11944         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11945         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11946         /* port-E for HP out (front panel) */
11947         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
11948         /* route front PCM to HP */
11949         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11950         /* port-F for mic-in (front panel) with vref */
11951         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11952         /* port-G for CLFE (rear panel) */
11953         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11954         /* port-H for side (rear panel) */
11955         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11956         /* CD-in */
11957         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11958         /* route front mic to ADC1*/
11959         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11960         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11961         /* Unmute DAC0~3 & spdif out*/
11962         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11963         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11964         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11965         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11966         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11967         
11968         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11969         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11970         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11971         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11972         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11973         
11974         /* Unmute Stereo Mixer 15 */
11975         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11976         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11977         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11978         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
11979
11980         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11981         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11982         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11983         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11984         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11985         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11986         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11987         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11988         /* hp used DAC 3 (Front) */
11989         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11990         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11991         { }
11992 };
11993
11994 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
11995         /*
11996          * Unmute ADC0 and set the default input to mic-in
11997          */
11998         /* port-A for surround (rear panel) */
11999         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12000         /* port-B for mic-in (rear panel) with vref */
12001         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12002         /* port-C for line-in (rear panel) */
12003         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12004         /* port-D for Front */
12005         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12006         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12007         /* port-E for HP out (front panel) */
12008         /* this has to be set to VREF80 */
12009         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12010         /* route front PCM to HP */
12011         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12012         /* port-F for mic-in (front panel) with vref */
12013         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12014         /* port-G for CLFE (rear panel) */
12015         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12016         /* port-H for side (rear panel) */
12017         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12018         /* CD-in */
12019         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12020         /* route front mic to ADC1*/
12021         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12022         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12023         /* Unmute DAC0~3 & spdif out*/
12024         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12025         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12026         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12027         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12028         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12029         
12030         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12031         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12032         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12033         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12034         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12035         
12036         /* Unmute Stereo Mixer 15 */
12037         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12038         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12039         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12040         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12041
12042         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12043         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12044         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12045         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12046         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12047         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12048         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12049         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12050         /* hp used DAC 3 (Front) */
12051         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12052         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12053         { }
12054 };
12055
12056 static struct hda_verb alc861_asus_init_verbs[] = {
12057         /*
12058          * Unmute ADC0 and set the default input to mic-in
12059          */
12060         /* port-A for surround (rear panel)
12061          * according to codec#0 this is the HP jack
12062          */
12063         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
12064         /* route front PCM to HP */
12065         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
12066         /* port-B for mic-in (rear panel) with vref */
12067         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12068         /* port-C for line-in (rear panel) */
12069         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12070         /* port-D for Front */
12071         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12072         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12073         /* port-E for HP out (front panel) */
12074         /* this has to be set to VREF80 */
12075         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12076         /* route front PCM to HP */
12077         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12078         /* port-F for mic-in (front panel) with vref */
12079         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12080         /* port-G for CLFE (rear panel) */
12081         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12082         /* port-H for side (rear panel) */
12083         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12084         /* CD-in */
12085         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12086         /* route front mic to ADC1*/
12087         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12088         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12089         /* Unmute DAC0~3 & spdif out*/
12090         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12091         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12092         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12093         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12094         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12095         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12096         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12097         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12098         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12099         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12100         
12101         /* Unmute Stereo Mixer 15 */
12102         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12103         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12104         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12105         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12106
12107         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12108         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12109         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12110         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12111         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12112         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12113         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12114         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12115         /* hp used DAC 3 (Front) */
12116         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12117         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12118         { }
12119 };
12120
12121 /* additional init verbs for ASUS laptops */
12122 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
12123         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
12124         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
12125         { }
12126 };
12127
12128 /*
12129  * generic initialization of ADC, input mixers and output mixers
12130  */
12131 static struct hda_verb alc861_auto_init_verbs[] = {
12132         /*
12133          * Unmute ADC0 and set the default input to mic-in
12134          */
12135         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
12136         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12137         
12138         /* Unmute DAC0~3 & spdif out*/
12139         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12140         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12141         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12142         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12143         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12144         
12145         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12146         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12147         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12148         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12149         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12150         
12151         /* Unmute Stereo Mixer 15 */
12152         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12153         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12154         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12155         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
12156
12157         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12158         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12159         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12160         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12161         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12162         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12163         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12164         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12165
12166         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12167         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12168         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12169         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12170         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12171         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12172         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12173         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12174
12175         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
12176
12177         { }
12178 };
12179
12180 static struct hda_verb alc861_toshiba_init_verbs[] = {
12181         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12182
12183         { }
12184 };
12185
12186 /* toggle speaker-output according to the hp-jack state */
12187 static void alc861_toshiba_automute(struct hda_codec *codec)
12188 {
12189         unsigned int present;
12190
12191         present = snd_hda_codec_read(codec, 0x0f, 0,
12192                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12193         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
12194                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
12195         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
12196                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
12197 }
12198
12199 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
12200                                        unsigned int res)
12201 {
12202         if ((res >> 26) == ALC880_HP_EVENT)
12203                 alc861_toshiba_automute(codec);
12204 }
12205
12206 /* pcm configuration: identiacal with ALC880 */
12207 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
12208 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
12209 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
12210 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
12211
12212
12213 #define ALC861_DIGOUT_NID       0x07
12214
12215 static struct hda_channel_mode alc861_8ch_modes[1] = {
12216         { 8, NULL }
12217 };
12218
12219 static hda_nid_t alc861_dac_nids[4] = {
12220         /* front, surround, clfe, side */
12221         0x03, 0x06, 0x05, 0x04
12222 };
12223
12224 static hda_nid_t alc660_dac_nids[3] = {
12225         /* front, clfe, surround */
12226         0x03, 0x05, 0x06
12227 };
12228
12229 static hda_nid_t alc861_adc_nids[1] = {
12230         /* ADC0-2 */
12231         0x08,
12232 };
12233
12234 static struct hda_input_mux alc861_capture_source = {
12235         .num_items = 5,
12236         .items = {
12237                 { "Mic", 0x0 },
12238                 { "Front Mic", 0x3 },
12239                 { "Line", 0x1 },
12240                 { "CD", 0x4 },
12241                 { "Mixer", 0x5 },
12242         },
12243 };
12244
12245 /* fill in the dac_nids table from the parsed pin configuration */
12246 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
12247                                      const struct auto_pin_cfg *cfg)
12248 {
12249         int i;
12250         hda_nid_t nid;
12251
12252         spec->multiout.dac_nids = spec->private_dac_nids;
12253         for (i = 0; i < cfg->line_outs; i++) {
12254                 nid = cfg->line_out_pins[i];
12255                 if (nid) {
12256                         if (i >= ARRAY_SIZE(alc861_dac_nids))
12257                                 continue;
12258                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
12259                 }
12260         }
12261         spec->multiout.num_dacs = cfg->line_outs;
12262         return 0;
12263 }
12264
12265 /* add playback controls from the parsed DAC table */
12266 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
12267                                              const struct auto_pin_cfg *cfg)
12268 {
12269         char name[32];
12270         static const char *chname[4] = {
12271                 "Front", "Surround", NULL /*CLFE*/, "Side"
12272         };
12273         hda_nid_t nid;
12274         int i, idx, err;
12275
12276         for (i = 0; i < cfg->line_outs; i++) {
12277                 nid = spec->multiout.dac_nids[i];
12278                 if (!nid)
12279                         continue;
12280                 if (nid == 0x05) {
12281                         /* Center/LFE */
12282                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12283                                           "Center Playback Switch",
12284                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
12285                                                               HDA_OUTPUT));
12286                         if (err < 0)
12287                                 return err;
12288                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12289                                           "LFE Playback Switch",
12290                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12291                                                               HDA_OUTPUT));
12292                         if (err < 0)
12293                                 return err;
12294                 } else {
12295                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
12296                              idx++)
12297                                 if (nid == alc861_dac_nids[idx])
12298                                         break;
12299                         sprintf(name, "%s Playback Switch", chname[idx]);
12300                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
12301                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12302                                                               HDA_OUTPUT));
12303                         if (err < 0)
12304                                 return err;
12305                 }
12306         }
12307         return 0;
12308 }
12309
12310 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
12311 {
12312         int err;
12313         hda_nid_t nid;
12314
12315         if (!pin)
12316                 return 0;
12317
12318         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
12319                 nid = 0x03;
12320                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12321                                   "Headphone Playback Switch",
12322                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12323                 if (err < 0)
12324                         return err;
12325                 spec->multiout.hp_nid = nid;
12326         }
12327         return 0;
12328 }
12329
12330 /* create playback/capture controls for input pins */
12331 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
12332                                                 const struct auto_pin_cfg *cfg)
12333 {
12334         struct hda_input_mux *imux = &spec->private_imux;
12335         int i, err, idx, idx1;
12336
12337         for (i = 0; i < AUTO_PIN_LAST; i++) {
12338                 switch (cfg->input_pins[i]) {
12339                 case 0x0c:
12340                         idx1 = 1;
12341                         idx = 2;        /* Line In */
12342                         break;
12343                 case 0x0f:
12344                         idx1 = 2;
12345                         idx = 2;        /* Line In */
12346                         break;
12347                 case 0x0d:
12348                         idx1 = 0;
12349                         idx = 1;        /* Mic In */
12350                         break;
12351                 case 0x10:
12352                         idx1 = 3;
12353                         idx = 1;        /* Mic In */
12354                         break;
12355                 case 0x11:
12356                         idx1 = 4;
12357                         idx = 0;        /* CD */
12358                         break;
12359                 default:
12360                         continue;
12361                 }
12362
12363                 err = new_analog_input(spec, cfg->input_pins[i],
12364                                        auto_pin_cfg_labels[i], idx, 0x15);
12365                 if (err < 0)
12366                         return err;
12367
12368                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
12369                 imux->items[imux->num_items].index = idx1;
12370                 imux->num_items++;
12371         }
12372         return 0;
12373 }
12374
12375 static struct snd_kcontrol_new alc861_capture_mixer[] = {
12376         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12377         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12378
12379         {
12380                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12381                 /* The multiple "Capture Source" controls confuse alsamixer
12382                  * So call somewhat different..
12383                  */
12384                 /* .name = "Capture Source", */
12385                 .name = "Input Source",
12386                 .count = 1,
12387                 .info = alc_mux_enum_info,
12388                 .get = alc_mux_enum_get,
12389                 .put = alc_mux_enum_put,
12390         },
12391         { } /* end */
12392 };
12393
12394 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
12395                                               hda_nid_t nid,
12396                                               int pin_type, int dac_idx)
12397 {
12398         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
12399                             pin_type);
12400         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12401                             AMP_OUT_UNMUTE);
12402 }
12403
12404 static void alc861_auto_init_multi_out(struct hda_codec *codec)
12405 {
12406         struct alc_spec *spec = codec->spec;
12407         int i;
12408
12409         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
12410         for (i = 0; i < spec->autocfg.line_outs; i++) {
12411                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
12412                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
12413                 if (nid)
12414                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
12415                                                           spec->multiout.dac_nids[i]);
12416         }
12417 }
12418
12419 static void alc861_auto_init_hp_out(struct hda_codec *codec)
12420 {
12421         struct alc_spec *spec = codec->spec;
12422         hda_nid_t pin;
12423
12424         pin = spec->autocfg.hp_pins[0];
12425         if (pin) /* connect to front */
12426                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
12427                                                   spec->multiout.dac_nids[0]);
12428         pin = spec->autocfg.speaker_pins[0];
12429         if (pin)
12430                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
12431 }
12432
12433 static void alc861_auto_init_analog_input(struct hda_codec *codec)
12434 {
12435         struct alc_spec *spec = codec->spec;
12436         int i;
12437
12438         for (i = 0; i < AUTO_PIN_LAST; i++) {
12439                 hda_nid_t nid = spec->autocfg.input_pins[i];
12440                 if (nid >= 0x0c && nid <= 0x11) {
12441                         snd_hda_codec_write(codec, nid, 0,
12442                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
12443                                             i <= AUTO_PIN_FRONT_MIC ?
12444                                             PIN_VREF80 : PIN_IN);
12445                 }
12446         }
12447 }
12448
12449 /* parse the BIOS configuration and set up the alc_spec */
12450 /* return 1 if successful, 0 if the proper config is not found,
12451  * or a negative error code
12452  */
12453 static int alc861_parse_auto_config(struct hda_codec *codec)
12454 {
12455         struct alc_spec *spec = codec->spec;
12456         int err;
12457         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
12458
12459         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12460                                            alc861_ignore);
12461         if (err < 0)
12462                 return err;
12463         if (!spec->autocfg.line_outs)
12464                 return 0; /* can't find valid BIOS pin config */
12465
12466         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
12467         if (err < 0)
12468                 return err;
12469         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
12470         if (err < 0)
12471                 return err;
12472         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
12473         if (err < 0)
12474                 return err;
12475         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
12476         if (err < 0)
12477                 return err;
12478
12479         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12480
12481         if (spec->autocfg.dig_out_pin)
12482                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
12483
12484         if (spec->kctl_alloc)
12485                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
12486
12487         spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs;
12488
12489         spec->num_mux_defs = 1;
12490         spec->input_mux = &spec->private_imux;
12491
12492         spec->adc_nids = alc861_adc_nids;
12493         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
12494         spec->mixers[spec->num_mixers] = alc861_capture_mixer;
12495         spec->num_mixers++;
12496
12497         return 1;
12498 }
12499
12500 /* additional initialization for auto-configuration model */
12501 static void alc861_auto_init(struct hda_codec *codec)
12502 {
12503         struct alc_spec *spec = codec->spec;
12504         alc861_auto_init_multi_out(codec);
12505         alc861_auto_init_hp_out(codec);
12506         alc861_auto_init_analog_input(codec);
12507         if (spec->unsol_event)
12508                 alc_sku_automute(codec);
12509 }
12510
12511 #ifdef CONFIG_SND_HDA_POWER_SAVE
12512 static struct hda_amp_list alc861_loopbacks[] = {
12513         { 0x15, HDA_INPUT, 0 },
12514         { 0x15, HDA_INPUT, 1 },
12515         { 0x15, HDA_INPUT, 2 },
12516         { 0x15, HDA_INPUT, 3 },
12517         { } /* end */
12518 };
12519 #endif
12520
12521
12522 /*
12523  * configuration and preset
12524  */
12525 static const char *alc861_models[ALC861_MODEL_LAST] = {
12526         [ALC861_3ST]            = "3stack",
12527         [ALC660_3ST]            = "3stack-660",
12528         [ALC861_3ST_DIG]        = "3stack-dig",
12529         [ALC861_6ST_DIG]        = "6stack-dig",
12530         [ALC861_UNIWILL_M31]    = "uniwill-m31",
12531         [ALC861_TOSHIBA]        = "toshiba",
12532         [ALC861_ASUS]           = "asus",
12533         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
12534         [ALC861_AUTO]           = "auto",
12535 };
12536
12537 static struct snd_pci_quirk alc861_cfg_tbl[] = {
12538         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
12539         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
12540         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
12541         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
12542         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
12543         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
12544         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
12545         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
12546          *        Any other models that need this preset?
12547          */
12548         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
12549         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
12550         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
12551         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
12552         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
12553         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
12554         /* FIXME: the below seems conflict */
12555         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
12556         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
12557         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
12558         {}
12559 };
12560
12561 static struct alc_config_preset alc861_presets[] = {
12562         [ALC861_3ST] = {
12563                 .mixers = { alc861_3ST_mixer },
12564                 .init_verbs = { alc861_threestack_init_verbs },
12565                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12566                 .dac_nids = alc861_dac_nids,
12567                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
12568                 .channel_mode = alc861_threestack_modes,
12569                 .need_dac_fix = 1,
12570                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12571                 .adc_nids = alc861_adc_nids,
12572                 .input_mux = &alc861_capture_source,
12573         },
12574         [ALC861_3ST_DIG] = {
12575                 .mixers = { alc861_base_mixer },
12576                 .init_verbs = { alc861_threestack_init_verbs },
12577                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12578                 .dac_nids = alc861_dac_nids,
12579                 .dig_out_nid = ALC861_DIGOUT_NID,
12580                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
12581                 .channel_mode = alc861_threestack_modes,
12582                 .need_dac_fix = 1,
12583                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12584                 .adc_nids = alc861_adc_nids,
12585                 .input_mux = &alc861_capture_source,
12586         },
12587         [ALC861_6ST_DIG] = {
12588                 .mixers = { alc861_base_mixer },
12589                 .init_verbs = { alc861_base_init_verbs },
12590                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12591                 .dac_nids = alc861_dac_nids,
12592                 .dig_out_nid = ALC861_DIGOUT_NID,
12593                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
12594                 .channel_mode = alc861_8ch_modes,
12595                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12596                 .adc_nids = alc861_adc_nids,
12597                 .input_mux = &alc861_capture_source,
12598         },
12599         [ALC660_3ST] = {
12600                 .mixers = { alc861_3ST_mixer },
12601                 .init_verbs = { alc861_threestack_init_verbs },
12602                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
12603                 .dac_nids = alc660_dac_nids,
12604                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
12605                 .channel_mode = alc861_threestack_modes,
12606                 .need_dac_fix = 1,
12607                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12608                 .adc_nids = alc861_adc_nids,
12609                 .input_mux = &alc861_capture_source,
12610         },
12611         [ALC861_UNIWILL_M31] = {
12612                 .mixers = { alc861_uniwill_m31_mixer },
12613                 .init_verbs = { alc861_uniwill_m31_init_verbs },
12614                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12615                 .dac_nids = alc861_dac_nids,
12616                 .dig_out_nid = ALC861_DIGOUT_NID,
12617                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
12618                 .channel_mode = alc861_uniwill_m31_modes,
12619                 .need_dac_fix = 1,
12620                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12621                 .adc_nids = alc861_adc_nids,
12622                 .input_mux = &alc861_capture_source,
12623         },
12624         [ALC861_TOSHIBA] = {
12625                 .mixers = { alc861_toshiba_mixer },
12626                 .init_verbs = { alc861_base_init_verbs,
12627                                 alc861_toshiba_init_verbs },
12628                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12629                 .dac_nids = alc861_dac_nids,
12630                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
12631                 .channel_mode = alc883_3ST_2ch_modes,
12632                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12633                 .adc_nids = alc861_adc_nids,
12634                 .input_mux = &alc861_capture_source,
12635                 .unsol_event = alc861_toshiba_unsol_event,
12636                 .init_hook = alc861_toshiba_automute,
12637         },
12638         [ALC861_ASUS] = {
12639                 .mixers = { alc861_asus_mixer },
12640                 .init_verbs = { alc861_asus_init_verbs },
12641                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12642                 .dac_nids = alc861_dac_nids,
12643                 .dig_out_nid = ALC861_DIGOUT_NID,
12644                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
12645                 .channel_mode = alc861_asus_modes,
12646                 .need_dac_fix = 1,
12647                 .hp_nid = 0x06,
12648                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12649                 .adc_nids = alc861_adc_nids,
12650                 .input_mux = &alc861_capture_source,
12651         },
12652         [ALC861_ASUS_LAPTOP] = {
12653                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
12654                 .init_verbs = { alc861_asus_init_verbs,
12655                                 alc861_asus_laptop_init_verbs },
12656                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12657                 .dac_nids = alc861_dac_nids,
12658                 .dig_out_nid = ALC861_DIGOUT_NID,
12659                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
12660                 .channel_mode = alc883_3ST_2ch_modes,
12661                 .need_dac_fix = 1,
12662                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12663                 .adc_nids = alc861_adc_nids,
12664                 .input_mux = &alc861_capture_source,
12665         },
12666 };
12667
12668
12669 static int patch_alc861(struct hda_codec *codec)
12670 {
12671         struct alc_spec *spec;
12672         int board_config;
12673         int err;
12674
12675         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12676         if (spec == NULL)
12677                 return -ENOMEM;
12678
12679         codec->spec = spec;
12680
12681         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
12682                                                   alc861_models,
12683                                                   alc861_cfg_tbl);
12684
12685         if (board_config < 0) {
12686                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
12687                        "trying auto-probe from BIOS...\n");
12688                 board_config = ALC861_AUTO;
12689         }
12690
12691         if (board_config == ALC861_AUTO) {
12692                 /* automatic parse from the BIOS config */
12693                 err = alc861_parse_auto_config(codec);
12694                 if (err < 0) {
12695                         alc_free(codec);
12696                         return err;
12697                 } else if (!err) {
12698                         printk(KERN_INFO
12699                                "hda_codec: Cannot set up configuration "
12700                                "from BIOS.  Using base mode...\n");
12701                    board_config = ALC861_3ST_DIG;
12702                 }
12703         }
12704
12705         if (board_config != ALC861_AUTO)
12706                 setup_preset(spec, &alc861_presets[board_config]);
12707
12708         spec->stream_name_analog = "ALC861 Analog";
12709         spec->stream_analog_playback = &alc861_pcm_analog_playback;
12710         spec->stream_analog_capture = &alc861_pcm_analog_capture;
12711
12712         spec->stream_name_digital = "ALC861 Digital";
12713         spec->stream_digital_playback = &alc861_pcm_digital_playback;
12714         spec->stream_digital_capture = &alc861_pcm_digital_capture;
12715
12716         spec->vmaster_nid = 0x03;
12717
12718         codec->patch_ops = alc_patch_ops;
12719         if (board_config == ALC861_AUTO)
12720                 spec->init_hook = alc861_auto_init;
12721 #ifdef CONFIG_SND_HDA_POWER_SAVE
12722         if (!spec->loopback.amplist)
12723                 spec->loopback.amplist = alc861_loopbacks;
12724 #endif
12725                 
12726         return 0;
12727 }
12728
12729 /*
12730  * ALC861-VD support
12731  *
12732  * Based on ALC882
12733  *
12734  * In addition, an independent DAC
12735  */
12736 #define ALC861VD_DIGOUT_NID     0x06
12737
12738 static hda_nid_t alc861vd_dac_nids[4] = {
12739         /* front, surr, clfe, side surr */
12740         0x02, 0x03, 0x04, 0x05
12741 };
12742
12743 /* dac_nids for ALC660vd are in a different order - according to
12744  * Realtek's driver.
12745  * This should probably tesult in a different mixer for 6stack models
12746  * of ALC660vd codecs, but for now there is only 3stack mixer
12747  * - and it is the same as in 861vd.
12748  * adc_nids in ALC660vd are (is) the same as in 861vd
12749  */
12750 static hda_nid_t alc660vd_dac_nids[3] = {
12751         /* front, rear, clfe, rear_surr */
12752         0x02, 0x04, 0x03
12753 };
12754
12755 static hda_nid_t alc861vd_adc_nids[1] = {
12756         /* ADC0 */
12757         0x09,
12758 };
12759
12760 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
12761
12762 /* input MUX */
12763 /* FIXME: should be a matrix-type input source selection */
12764 static struct hda_input_mux alc861vd_capture_source = {
12765         .num_items = 4,
12766         .items = {
12767                 { "Mic", 0x0 },
12768                 { "Front Mic", 0x1 },
12769                 { "Line", 0x2 },
12770                 { "CD", 0x4 },
12771         },
12772 };
12773
12774 static struct hda_input_mux alc861vd_dallas_capture_source = {
12775         .num_items = 2,
12776         .items = {
12777                 { "Ext Mic", 0x0 },
12778                 { "Int Mic", 0x1 },
12779         },
12780 };
12781
12782 static struct hda_input_mux alc861vd_hp_capture_source = {
12783         .num_items = 2,
12784         .items = {
12785                 { "Front Mic", 0x0 },
12786                 { "ATAPI Mic", 0x1 },
12787         },
12788 };
12789
12790 #define alc861vd_mux_enum_info alc_mux_enum_info
12791 #define alc861vd_mux_enum_get alc_mux_enum_get
12792 /* ALC861VD has the ALC882-type input selection (but has only one ADC) */
12793 #define alc861vd_mux_enum_put alc882_mux_enum_put
12794
12795 /*
12796  * 2ch mode
12797  */
12798 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
12799         { 2, NULL }
12800 };
12801
12802 /*
12803  * 6ch mode
12804  */
12805 static struct hda_verb alc861vd_6stack_ch6_init[] = {
12806         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12807         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12808         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12809         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12810         { } /* end */
12811 };
12812
12813 /*
12814  * 8ch mode
12815  */
12816 static struct hda_verb alc861vd_6stack_ch8_init[] = {
12817         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12818         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12819         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12820         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12821         { } /* end */
12822 };
12823
12824 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
12825         { 6, alc861vd_6stack_ch6_init },
12826         { 8, alc861vd_6stack_ch8_init },
12827 };
12828
12829 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
12830         {
12831                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12832                 .name = "Channel Mode",
12833                 .info = alc_ch_mode_info,
12834                 .get = alc_ch_mode_get,
12835                 .put = alc_ch_mode_put,
12836         },
12837         { } /* end */
12838 };
12839
12840 static struct snd_kcontrol_new alc861vd_capture_mixer[] = {
12841         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
12842         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
12843
12844         {
12845                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12846                 /* The multiple "Capture Source" controls confuse alsamixer
12847                  * So call somewhat different..
12848                  */
12849                 /* .name = "Capture Source", */
12850                 .name = "Input Source",
12851                 .count = 1,
12852                 .info = alc861vd_mux_enum_info,
12853                 .get = alc861vd_mux_enum_get,
12854                 .put = alc861vd_mux_enum_put,
12855         },
12856         { } /* end */
12857 };
12858
12859 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
12860  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
12861  */
12862 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
12863         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12864         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12865
12866         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12867         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
12868
12869         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
12870                                 HDA_OUTPUT),
12871         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
12872                                 HDA_OUTPUT),
12873         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
12874         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
12875
12876         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
12877         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
12878
12879         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12880
12881         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12882         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12883         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12884
12885         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12886         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12887         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12888
12889         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12890         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12891
12892         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12893         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12894
12895         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
12896         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
12897
12898         { } /* end */
12899 };
12900
12901 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
12902         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12903         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12904
12905         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12906
12907         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12908         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12909         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12910
12911         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12912         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12913         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12914
12915         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12916         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12917
12918         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12919         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12920
12921         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
12922         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
12923
12924         { } /* end */
12925 };
12926
12927 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
12928         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12929         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
12930         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12931
12932         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12933
12934         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12935         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12936         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12937
12938         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12939         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12940         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12941
12942         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12943         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12944
12945         { } /* end */
12946 };
12947
12948 /* Pin assignment: Speaker=0x14, HP = 0x15,
12949  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
12950  */
12951 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
12952         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12953         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
12954         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12955         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
12956         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
12957         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12958         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12959         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
12960         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12961         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12962         HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
12963         HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
12964         { } /* end */
12965 };
12966
12967 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
12968  *                 Front Mic=0x18, ATAPI Mic = 0x19,
12969  */
12970 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
12971         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12972         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12973         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12974         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
12975         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12976         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12977         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12978         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12979         
12980         { } /* end */
12981 };
12982
12983 /*
12984  * generic initialization of ADC, input mixers and output mixers
12985  */
12986 static struct hda_verb alc861vd_volume_init_verbs[] = {
12987         /*
12988          * Unmute ADC0 and set the default input to mic-in
12989          */
12990         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
12991         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12992
12993         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
12994          * the analog-loopback mixer widget
12995          */
12996         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12997         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12998         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12999         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13000         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13001         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13002
13003         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
13004         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13005         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13006         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13007         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
13008
13009         /*
13010          * Set up output mixers (0x02 - 0x05)
13011          */
13012         /* set vol=0 to output mixers */
13013         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13014         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13015         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13016         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13017
13018         /* set up input amps for analog loopback */
13019         /* Amp Indices: DAC = 0, mixer = 1 */
13020         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13021         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13022         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13023         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13024         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13025         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13026         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13027         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13028
13029         { }
13030 };
13031
13032 /*
13033  * 3-stack pin configuration:
13034  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
13035  */
13036 static struct hda_verb alc861vd_3stack_init_verbs[] = {
13037         /*
13038          * Set pin mode and muting
13039          */
13040         /* set front pin widgets 0x14 for output */
13041         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13042         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13043         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13044
13045         /* Mic (rear) pin: input vref at 80% */
13046         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13047         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13048         /* Front Mic pin: input vref at 80% */
13049         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13050         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13051         /* Line In pin: input */
13052         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13053         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13054         /* Line-2 In: Headphone output (output 0 - 0x0c) */
13055         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13056         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13057         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13058         /* CD pin widget for input */
13059         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13060
13061         { }
13062 };
13063
13064 /*
13065  * 6-stack pin configuration:
13066  */
13067 static struct hda_verb alc861vd_6stack_init_verbs[] = {
13068         /*
13069          * Set pin mode and muting
13070          */
13071         /* set front pin widgets 0x14 for output */
13072         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13073         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13074         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13075
13076         /* Rear Pin: output 1 (0x0d) */
13077         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13078         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13079         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13080         /* CLFE Pin: output 2 (0x0e) */
13081         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13082         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13083         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
13084         /* Side Pin: output 3 (0x0f) */
13085         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13086         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13087         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
13088
13089         /* Mic (rear) pin: input vref at 80% */
13090         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13091         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13092         /* Front Mic pin: input vref at 80% */
13093         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13094         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13095         /* Line In pin: input */
13096         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13097         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13098         /* Line-2 In: Headphone output (output 0 - 0x0c) */
13099         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13100         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13101         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13102         /* CD pin widget for input */
13103         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13104
13105         { }
13106 };
13107
13108 static struct hda_verb alc861vd_eapd_verbs[] = {
13109         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13110         { }
13111 };
13112
13113 static struct hda_verb alc660vd_eapd_verbs[] = {
13114         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13115         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
13116         { }
13117 };
13118
13119 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
13120         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13121         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13122         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
13123         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13124         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT}, 
13125         {}
13126 };
13127
13128 /* toggle speaker-output according to the hp-jack state */
13129 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
13130 {
13131         unsigned int present;
13132         unsigned char bits;
13133
13134         present = snd_hda_codec_read(codec, 0x1b, 0,
13135                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13136         bits = present ? HDA_AMP_MUTE : 0;
13137         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
13138                                  HDA_AMP_MUTE, bits);
13139 }
13140
13141 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
13142 {
13143         unsigned int present;
13144         unsigned char bits;
13145
13146         present = snd_hda_codec_read(codec, 0x18, 0,
13147                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13148         bits = present ? HDA_AMP_MUTE : 0;
13149         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
13150                                  HDA_AMP_MUTE, bits);
13151 }
13152
13153 static void alc861vd_lenovo_automute(struct hda_codec *codec)
13154 {
13155         alc861vd_lenovo_hp_automute(codec);
13156         alc861vd_lenovo_mic_automute(codec);
13157 }
13158
13159 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
13160                                         unsigned int res)
13161 {
13162         switch (res >> 26) {
13163         case ALC880_HP_EVENT:
13164                 alc861vd_lenovo_hp_automute(codec);
13165                 break;
13166         case ALC880_MIC_EVENT:
13167                 alc861vd_lenovo_mic_automute(codec);
13168                 break;
13169         }
13170 }
13171
13172 static struct hda_verb alc861vd_dallas_verbs[] = {
13173         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13174         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13175         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13176         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13177
13178         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13179         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13180         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13181         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13182         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13183         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13184         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13185         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13186         
13187         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13188         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13189         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13190         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13191         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13192         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13193         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13194         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13195
13196         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
13197         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13198         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
13199         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13200         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13201         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13202         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13203         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13204
13205         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13206         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13207         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13208         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13209
13210         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13211         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},  
13212         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13213
13214         { } /* end */
13215 };
13216
13217 /* toggle speaker-output according to the hp-jack state */
13218 static void alc861vd_dallas_automute(struct hda_codec *codec)
13219 {
13220         unsigned int present;
13221
13222         present = snd_hda_codec_read(codec, 0x15, 0,
13223                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13224         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
13225                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
13226 }
13227
13228 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
13229 {
13230         if ((res >> 26) == ALC880_HP_EVENT)
13231                 alc861vd_dallas_automute(codec);
13232 }
13233
13234 #ifdef CONFIG_SND_HDA_POWER_SAVE
13235 #define alc861vd_loopbacks      alc880_loopbacks
13236 #endif
13237
13238 /* pcm configuration: identiacal with ALC880 */
13239 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
13240 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
13241 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
13242 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
13243
13244 /*
13245  * configuration and preset
13246  */
13247 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
13248         [ALC660VD_3ST]          = "3stack-660",
13249         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
13250         [ALC861VD_3ST]          = "3stack",
13251         [ALC861VD_3ST_DIG]      = "3stack-digout",
13252         [ALC861VD_6ST_DIG]      = "6stack-digout",
13253         [ALC861VD_LENOVO]       = "lenovo",
13254         [ALC861VD_DALLAS]       = "dallas",
13255         [ALC861VD_HP]           = "hp",
13256         [ALC861VD_AUTO]         = "auto",
13257 };
13258
13259 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
13260         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
13261         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
13262         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
13263         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
13264         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC861VD_LENOVO),
13265         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
13266         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
13267         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
13268         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
13269         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
13270         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
13271         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
13272         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
13273         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
13274         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
13275         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 N200", ALC861VD_LENOVO),
13276         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
13277         {}
13278 };
13279
13280 static struct alc_config_preset alc861vd_presets[] = {
13281         [ALC660VD_3ST] = {
13282                 .mixers = { alc861vd_3st_mixer },
13283                 .init_verbs = { alc861vd_volume_init_verbs,
13284                                  alc861vd_3stack_init_verbs },
13285                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
13286                 .dac_nids = alc660vd_dac_nids,
13287                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13288                 .channel_mode = alc861vd_3stack_2ch_modes,
13289                 .input_mux = &alc861vd_capture_source,
13290         },
13291         [ALC660VD_3ST_DIG] = {
13292                 .mixers = { alc861vd_3st_mixer },
13293                 .init_verbs = { alc861vd_volume_init_verbs,
13294                                  alc861vd_3stack_init_verbs },
13295                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
13296                 .dac_nids = alc660vd_dac_nids,
13297                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13298                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13299                 .channel_mode = alc861vd_3stack_2ch_modes,
13300                 .input_mux = &alc861vd_capture_source,
13301         },
13302         [ALC861VD_3ST] = {
13303                 .mixers = { alc861vd_3st_mixer },
13304                 .init_verbs = { alc861vd_volume_init_verbs,
13305                                  alc861vd_3stack_init_verbs },
13306                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13307                 .dac_nids = alc861vd_dac_nids,
13308                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13309                 .channel_mode = alc861vd_3stack_2ch_modes,
13310                 .input_mux = &alc861vd_capture_source,
13311         },
13312         [ALC861VD_3ST_DIG] = {
13313                 .mixers = { alc861vd_3st_mixer },
13314                 .init_verbs = { alc861vd_volume_init_verbs,
13315                                  alc861vd_3stack_init_verbs },
13316                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13317                 .dac_nids = alc861vd_dac_nids,
13318                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13319                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13320                 .channel_mode = alc861vd_3stack_2ch_modes,
13321                 .input_mux = &alc861vd_capture_source,
13322         },
13323         [ALC861VD_6ST_DIG] = {
13324                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
13325                 .init_verbs = { alc861vd_volume_init_verbs,
13326                                 alc861vd_6stack_init_verbs },
13327                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13328                 .dac_nids = alc861vd_dac_nids,
13329                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13330                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
13331                 .channel_mode = alc861vd_6stack_modes,
13332                 .input_mux = &alc861vd_capture_source,
13333         },
13334         [ALC861VD_LENOVO] = {
13335                 .mixers = { alc861vd_lenovo_mixer },
13336                 .init_verbs = { alc861vd_volume_init_verbs,
13337                                 alc861vd_3stack_init_verbs,
13338                                 alc861vd_eapd_verbs,
13339                                 alc861vd_lenovo_unsol_verbs },
13340                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
13341                 .dac_nids = alc660vd_dac_nids,
13342                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13343                 .channel_mode = alc861vd_3stack_2ch_modes,
13344                 .input_mux = &alc861vd_capture_source,
13345                 .unsol_event = alc861vd_lenovo_unsol_event,
13346                 .init_hook = alc861vd_lenovo_automute,
13347         },
13348         [ALC861VD_DALLAS] = {
13349                 .mixers = { alc861vd_dallas_mixer },
13350                 .init_verbs = { alc861vd_dallas_verbs },
13351                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13352                 .dac_nids = alc861vd_dac_nids,
13353                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13354                 .channel_mode = alc861vd_3stack_2ch_modes,
13355                 .input_mux = &alc861vd_dallas_capture_source,
13356                 .unsol_event = alc861vd_dallas_unsol_event,
13357                 .init_hook = alc861vd_dallas_automute,
13358         },
13359         [ALC861VD_HP] = {
13360                 .mixers = { alc861vd_hp_mixer },
13361                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
13362                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13363                 .dac_nids = alc861vd_dac_nids,
13364                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13365                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13366                 .channel_mode = alc861vd_3stack_2ch_modes,
13367                 .input_mux = &alc861vd_hp_capture_source,
13368                 .unsol_event = alc861vd_dallas_unsol_event,
13369                 .init_hook = alc861vd_dallas_automute,
13370         },              
13371 };
13372
13373 /*
13374  * BIOS auto configuration
13375  */
13376 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
13377                                 hda_nid_t nid, int pin_type, int dac_idx)
13378 {
13379         alc_set_pin_output(codec, nid, pin_type);
13380 }
13381
13382 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
13383 {
13384         struct alc_spec *spec = codec->spec;
13385         int i;
13386
13387         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
13388         for (i = 0; i <= HDA_SIDE; i++) {
13389                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13390                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13391                 if (nid)
13392                         alc861vd_auto_set_output_and_unmute(codec, nid,
13393                                                             pin_type, i);
13394         }
13395 }
13396
13397
13398 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
13399 {
13400         struct alc_spec *spec = codec->spec;
13401         hda_nid_t pin;
13402
13403         pin = spec->autocfg.hp_pins[0];
13404         if (pin) /* connect to front and  use dac 0 */
13405                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
13406         pin = spec->autocfg.speaker_pins[0];
13407         if (pin)
13408                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13409 }
13410
13411 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
13412 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
13413
13414 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
13415 {
13416         struct alc_spec *spec = codec->spec;
13417         int i;
13418
13419         for (i = 0; i < AUTO_PIN_LAST; i++) {
13420                 hda_nid_t nid = spec->autocfg.input_pins[i];
13421                 if (alc861vd_is_input_pin(nid)) {
13422                         snd_hda_codec_write(codec, nid, 0,
13423                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
13424                                         i <= AUTO_PIN_FRONT_MIC ?
13425                                                         PIN_VREF80 : PIN_IN);
13426                         if (nid != ALC861VD_PIN_CD_NID)
13427                                 snd_hda_codec_write(codec, nid, 0,
13428                                                 AC_VERB_SET_AMP_GAIN_MUTE,
13429                                                 AMP_OUT_MUTE);
13430                 }
13431         }
13432 }
13433
13434 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
13435
13436 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
13437 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
13438
13439 /* add playback controls from the parsed DAC table */
13440 /* Based on ALC880 version. But ALC861VD has separate,
13441  * different NIDs for mute/unmute switch and volume control */
13442 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
13443                                              const struct auto_pin_cfg *cfg)
13444 {
13445         char name[32];
13446         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
13447         hda_nid_t nid_v, nid_s;
13448         int i, err;
13449
13450         for (i = 0; i < cfg->line_outs; i++) {
13451                 if (!spec->multiout.dac_nids[i])
13452                         continue;
13453                 nid_v = alc861vd_idx_to_mixer_vol(
13454                                 alc880_dac_to_idx(
13455                                         spec->multiout.dac_nids[i]));
13456                 nid_s = alc861vd_idx_to_mixer_switch(
13457                                 alc880_dac_to_idx(
13458                                         spec->multiout.dac_nids[i]));
13459
13460                 if (i == 2) {
13461                         /* Center/LFE */
13462                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13463                                           "Center Playback Volume",
13464                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
13465                                                               HDA_OUTPUT));
13466                         if (err < 0)
13467                                 return err;
13468                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13469                                           "LFE Playback Volume",
13470                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
13471                                                               HDA_OUTPUT));
13472                         if (err < 0)
13473                                 return err;
13474                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13475                                           "Center Playback Switch",
13476                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
13477                                                               HDA_INPUT));
13478                         if (err < 0)
13479                                 return err;
13480                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13481                                           "LFE Playback Switch",
13482                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
13483                                                               HDA_INPUT));
13484                         if (err < 0)
13485                                 return err;
13486                 } else {
13487                         sprintf(name, "%s Playback Volume", chname[i]);
13488                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
13489                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
13490                                                               HDA_OUTPUT));
13491                         if (err < 0)
13492                                 return err;
13493                         sprintf(name, "%s Playback Switch", chname[i]);
13494                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13495                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
13496                                                               HDA_INPUT));
13497                         if (err < 0)
13498                                 return err;
13499                 }
13500         }
13501         return 0;
13502 }
13503
13504 /* add playback controls for speaker and HP outputs */
13505 /* Based on ALC880 version. But ALC861VD has separate,
13506  * different NIDs for mute/unmute switch and volume control */
13507 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
13508                                         hda_nid_t pin, const char *pfx)
13509 {
13510         hda_nid_t nid_v, nid_s;
13511         int err;
13512         char name[32];
13513
13514         if (!pin)
13515                 return 0;
13516
13517         if (alc880_is_fixed_pin(pin)) {
13518                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
13519                 /* specify the DAC as the extra output */
13520                 if (!spec->multiout.hp_nid)
13521                         spec->multiout.hp_nid = nid_v;
13522                 else
13523                         spec->multiout.extra_out_nid[0] = nid_v;
13524                 /* control HP volume/switch on the output mixer amp */
13525                 nid_v = alc861vd_idx_to_mixer_vol(
13526                                 alc880_fixed_pin_idx(pin));
13527                 nid_s = alc861vd_idx_to_mixer_switch(
13528                                 alc880_fixed_pin_idx(pin));
13529
13530                 sprintf(name, "%s Playback Volume", pfx);
13531                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
13532                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
13533                 if (err < 0)
13534                         return err;
13535                 sprintf(name, "%s Playback Switch", pfx);
13536                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13537                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
13538                 if (err < 0)
13539                         return err;
13540         } else if (alc880_is_multi_pin(pin)) {
13541                 /* set manual connection */
13542                 /* we have only a switch on HP-out PIN */
13543                 sprintf(name, "%s Playback Switch", pfx);
13544                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
13545                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
13546                 if (err < 0)
13547                         return err;
13548         }
13549         return 0;
13550 }
13551
13552 /* parse the BIOS configuration and set up the alc_spec
13553  * return 1 if successful, 0 if the proper config is not found,
13554  * or a negative error code
13555  * Based on ALC880 version - had to change it to override
13556  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
13557 static int alc861vd_parse_auto_config(struct hda_codec *codec)
13558 {
13559         struct alc_spec *spec = codec->spec;
13560         int err;
13561         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
13562
13563         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13564                                            alc861vd_ignore);
13565         if (err < 0)
13566                 return err;
13567         if (!spec->autocfg.line_outs)
13568                 return 0; /* can't find valid BIOS pin config */
13569
13570         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
13571         if (err < 0)
13572                 return err;
13573         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
13574         if (err < 0)
13575                 return err;
13576         err = alc861vd_auto_create_extra_out(spec,
13577                                              spec->autocfg.speaker_pins[0],
13578                                              "Speaker");
13579         if (err < 0)
13580                 return err;
13581         err = alc861vd_auto_create_extra_out(spec,
13582                                              spec->autocfg.hp_pins[0],
13583                                              "Headphone");
13584         if (err < 0)
13585                 return err;
13586         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
13587         if (err < 0)
13588                 return err;
13589
13590         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13591
13592         if (spec->autocfg.dig_out_pin)
13593                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
13594
13595         if (spec->kctl_alloc)
13596                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
13597
13598         spec->init_verbs[spec->num_init_verbs++]
13599                 = alc861vd_volume_init_verbs;
13600
13601         spec->num_mux_defs = 1;
13602         spec->input_mux = &spec->private_imux;
13603
13604         err = alc_auto_add_mic_boost(codec);
13605         if (err < 0)
13606                 return err;
13607
13608         return 1;
13609 }
13610
13611 /* additional initialization for auto-configuration model */
13612 static void alc861vd_auto_init(struct hda_codec *codec)
13613 {
13614         struct alc_spec *spec = codec->spec;
13615         alc861vd_auto_init_multi_out(codec);
13616         alc861vd_auto_init_hp_out(codec);
13617         alc861vd_auto_init_analog_input(codec);
13618         alc861vd_auto_init_input_src(codec);
13619         if (spec->unsol_event)
13620                 alc_sku_automute(codec);
13621 }
13622
13623 static int patch_alc861vd(struct hda_codec *codec)
13624 {
13625         struct alc_spec *spec;
13626         int err, board_config;
13627
13628         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13629         if (spec == NULL)
13630                 return -ENOMEM;
13631
13632         codec->spec = spec;
13633
13634         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
13635                                                   alc861vd_models,
13636                                                   alc861vd_cfg_tbl);
13637
13638         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
13639                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
13640                         "ALC861VD, trying auto-probe from BIOS...\n");
13641                 board_config = ALC861VD_AUTO;
13642         }
13643
13644         if (board_config == ALC861VD_AUTO) {
13645                 /* automatic parse from the BIOS config */
13646                 err = alc861vd_parse_auto_config(codec);
13647                 if (err < 0) {
13648                         alc_free(codec);
13649                         return err;
13650                 } else if (!err) {
13651                         printk(KERN_INFO
13652                                "hda_codec: Cannot set up configuration "
13653                                "from BIOS.  Using base mode...\n");
13654                         board_config = ALC861VD_3ST;
13655                 }
13656         }
13657
13658         if (board_config != ALC861VD_AUTO)
13659                 setup_preset(spec, &alc861vd_presets[board_config]);
13660
13661         if (codec->vendor_id == 0x10ec0660) {
13662                 spec->stream_name_analog = "ALC660-VD Analog";
13663                 spec->stream_name_digital = "ALC660-VD Digital";
13664                 /* always turn on EAPD */
13665                 spec->init_verbs[spec->num_init_verbs++] = alc660vd_eapd_verbs;
13666         } else {
13667                 spec->stream_name_analog = "ALC861VD Analog";
13668                 spec->stream_name_digital = "ALC861VD Digital";
13669         }
13670
13671         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
13672         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
13673
13674         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
13675         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
13676
13677         spec->adc_nids = alc861vd_adc_nids;
13678         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
13679         spec->capsrc_nids = alc861vd_capsrc_nids;
13680
13681         spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
13682         spec->num_mixers++;
13683
13684         spec->vmaster_nid = 0x02;
13685
13686         codec->patch_ops = alc_patch_ops;
13687
13688         if (board_config == ALC861VD_AUTO)
13689                 spec->init_hook = alc861vd_auto_init;
13690 #ifdef CONFIG_SND_HDA_POWER_SAVE
13691         if (!spec->loopback.amplist)
13692                 spec->loopback.amplist = alc861vd_loopbacks;
13693 #endif
13694
13695         return 0;
13696 }
13697
13698 /*
13699  * ALC662 support
13700  *
13701  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
13702  * configuration.  Each pin widget can choose any input DACs and a mixer.
13703  * Each ADC is connected from a mixer of all inputs.  This makes possible
13704  * 6-channel independent captures.
13705  *
13706  * In addition, an independent DAC for the multi-playback (not used in this
13707  * driver yet).
13708  */
13709 #define ALC662_DIGOUT_NID       0x06
13710 #define ALC662_DIGIN_NID        0x0a
13711
13712 static hda_nid_t alc662_dac_nids[4] = {
13713         /* front, rear, clfe, rear_surr */
13714         0x02, 0x03, 0x04
13715 };
13716
13717 static hda_nid_t alc662_adc_nids[1] = {
13718         /* ADC1-2 */
13719         0x09,
13720 };
13721
13722 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
13723
13724 /* input MUX */
13725 /* FIXME: should be a matrix-type input source selection */
13726 static struct hda_input_mux alc662_capture_source = {
13727         .num_items = 4,
13728         .items = {
13729                 { "Mic", 0x0 },
13730                 { "Front Mic", 0x1 },
13731                 { "Line", 0x2 },
13732                 { "CD", 0x4 },
13733         },
13734 };
13735
13736 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
13737         .num_items = 2,
13738         .items = {
13739                 { "Mic", 0x1 },
13740                 { "Line", 0x2 },
13741         },
13742 };
13743
13744 static struct hda_input_mux alc662_eeepc_capture_source = {
13745         .num_items = 2,
13746         .items = {
13747                 { "i-Mic", 0x1 },
13748                 { "e-Mic", 0x0 },
13749         },
13750 };
13751
13752 static struct hda_input_mux alc663_capture_source = {
13753         .num_items = 3,
13754         .items = {
13755                 { "Mic", 0x0 },
13756                 { "Front Mic", 0x1 },
13757                 { "Line", 0x2 },
13758         },
13759 };
13760
13761 static struct hda_input_mux alc663_m51va_capture_source = {
13762         .num_items = 2,
13763         .items = {
13764                 { "Ext-Mic", 0x0 },
13765                 { "D-Mic", 0x9 },
13766         },
13767 };
13768
13769 #define alc662_mux_enum_info alc_mux_enum_info
13770 #define alc662_mux_enum_get alc_mux_enum_get
13771 #define alc662_mux_enum_put alc882_mux_enum_put
13772
13773 /*
13774  * 2ch mode
13775  */
13776 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
13777         { 2, NULL }
13778 };
13779
13780 /*
13781  * 2ch mode
13782  */
13783 static struct hda_verb alc662_3ST_ch2_init[] = {
13784         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
13785         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
13786         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
13787         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
13788         { } /* end */
13789 };
13790
13791 /*
13792  * 6ch mode
13793  */
13794 static struct hda_verb alc662_3ST_ch6_init[] = {
13795         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13796         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
13797         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
13798         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13799         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
13800         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
13801         { } /* end */
13802 };
13803
13804 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
13805         { 2, alc662_3ST_ch2_init },
13806         { 6, alc662_3ST_ch6_init },
13807 };
13808
13809 /*
13810  * 2ch mode
13811  */
13812 static struct hda_verb alc662_sixstack_ch6_init[] = {
13813         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13814         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13815         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13816         { } /* end */
13817 };
13818
13819 /*
13820  * 6ch mode
13821  */
13822 static struct hda_verb alc662_sixstack_ch8_init[] = {
13823         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13824         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13825         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13826         { } /* end */
13827 };
13828
13829 static struct hda_channel_mode alc662_5stack_modes[2] = {
13830         { 2, alc662_sixstack_ch6_init },
13831         { 6, alc662_sixstack_ch8_init },
13832 };
13833
13834 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
13835  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
13836  */
13837
13838 static struct snd_kcontrol_new alc662_base_mixer[] = {
13839         /* output mixer control */
13840         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
13841         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
13842         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
13843         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
13844         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13845         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13846         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
13847         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
13848         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13849
13850         /*Input mixer control */
13851         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
13852         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
13853         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
13854         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
13855         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
13856         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
13857         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
13858         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
13859         { } /* end */
13860 };
13861
13862 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
13863         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13864         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
13865         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13866         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13867         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13868         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13869         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13870         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13871         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13872         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13873         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13874         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13875         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13876         { } /* end */
13877 };
13878
13879 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
13880         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13881         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
13882         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13883         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
13884         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13885         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13886         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
13887         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
13888         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13889         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13890         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13891         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13892         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13893         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13894         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13895         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13896         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13897         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13898         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13899         { } /* end */
13900 };
13901
13902 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
13903         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13904         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
13905         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13906         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
13907         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13908         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13909         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13910         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13911         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13912         { } /* end */
13913 };
13914
13915 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
13916         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13917
13918         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13919         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13920
13921         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
13922         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13923         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13924
13925         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
13926         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13927         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13928         { } /* end */
13929 };
13930
13931 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
13932         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13933         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13934         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13935         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
13936         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13937         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13938         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
13939         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
13940         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13941         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
13942         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13943         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13944         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13945         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13946         { } /* end */
13947 };
13948
13949 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
13950         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13951         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13952         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
13953         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13954         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13955         HDA_CODEC_MUTE("DMic Playback Switch", 0x23, 0x9, HDA_INPUT),
13956         { } /* end */
13957 };
13958
13959 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
13960         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13961         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13962         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13963         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13964         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
13965
13966         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13967         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13968         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13969         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13970         { } /* end */
13971 };
13972
13973 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
13974         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13975         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13976         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
13977
13978         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13979         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13980         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13981         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13982         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13983         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13984         { } /* end */
13985 };
13986
13987 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
13988         {
13989                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13990                 .name = "Channel Mode",
13991                 .info = alc_ch_mode_info,
13992                 .get = alc_ch_mode_get,
13993                 .put = alc_ch_mode_put,
13994         },
13995         { } /* end */
13996 };
13997
13998 static struct hda_verb alc662_init_verbs[] = {
13999         /* ADC: mute amp left and right */
14000         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14001         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14002         /* Front mixer: unmute input/output amp left and right (volume = 0) */
14003
14004         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14005         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14006         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14007         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14008         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14009
14010         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14011         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14012         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14013         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14014         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14015         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14016
14017         /* Front Pin: output 0 (0x0c) */
14018         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14019         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14020
14021         /* Rear Pin: output 1 (0x0d) */
14022         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14023         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14024
14025         /* CLFE Pin: output 2 (0x0e) */
14026         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14027         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14028
14029         /* Mic (rear) pin: input vref at 80% */
14030         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14031         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14032         /* Front Mic pin: input vref at 80% */
14033         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14034         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14035         /* Line In pin: input */
14036         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14037         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14038         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14039         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14040         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14041         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14042         /* CD pin widget for input */
14043         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14044
14045         /* FIXME: use matrix-type input source selection */
14046         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
14047         /* Input mixer */
14048         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14049         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14050         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14051         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14052
14053         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14054         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14055         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14056         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14057
14058         /* always trun on EAPD */
14059         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14060         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
14061
14062         { }
14063 };
14064
14065 static struct hda_verb alc662_sue_init_verbs[] = {
14066         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
14067         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
14068         {}
14069 };
14070
14071 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
14072         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14073         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14074         {}
14075 };
14076
14077 /* Set Unsolicited Event*/
14078 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
14079         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14080         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14081         {}
14082 };
14083
14084 /*
14085  * generic initialization of ADC, input mixers and output mixers
14086  */
14087 static struct hda_verb alc662_auto_init_verbs[] = {
14088         /*
14089          * Unmute ADC and set the default input to mic-in
14090          */
14091         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14092         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14093
14094         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
14095          * mixer widget
14096          * Note: PASD motherboards uses the Line In 2 as the input for front
14097          * panel mic (mic 2)
14098          */
14099         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14100         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14101         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14102         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14103         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14104         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14105
14106         /*
14107          * Set up output mixers (0x0c - 0x0f)
14108          */
14109         /* set vol=0 to output mixers */
14110         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14111         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14112         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14113
14114         /* set up input amps for analog loopback */
14115         /* Amp Indices: DAC = 0, mixer = 1 */
14116         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14117         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14118         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14119         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14120         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14121         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14122
14123
14124         /* FIXME: use matrix-type input source selection */
14125         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
14126         /* Input mixer */
14127         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14128         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14129         { }
14130 };
14131
14132 /* additional verbs for ALC663 */
14133 static struct hda_verb alc663_auto_init_verbs[] = {
14134         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14135         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14136         { }
14137 };
14138
14139 static struct hda_verb alc663_m51va_init_verbs[] = {
14140         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14141         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14142         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
14143
14144         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
14145
14146         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14147         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14148         {}
14149 };
14150
14151 static struct hda_verb alc663_g71v_init_verbs[] = {
14152         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14153         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
14154         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
14155
14156         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14157         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14158         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
14159
14160         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
14161         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
14162         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
14163         {}
14164 };
14165
14166 static struct hda_verb alc663_g50v_init_verbs[] = {
14167         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14168         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14169         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
14170
14171         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14172         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14173         {}
14174 };
14175
14176 /* capture mixer elements */
14177 static struct snd_kcontrol_new alc662_capture_mixer[] = {
14178         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
14179         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
14180         {
14181                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14182                 /* The multiple "Capture Source" controls confuse alsamixer
14183                  * So call somewhat different..
14184                  */
14185                 /* .name = "Capture Source", */
14186                 .name = "Input Source",
14187                 .count = 1,
14188                 .info = alc662_mux_enum_info,
14189                 .get = alc662_mux_enum_get,
14190                 .put = alc662_mux_enum_put,
14191         },
14192         { } /* end */
14193 };
14194
14195 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
14196 {
14197         unsigned int present;
14198         unsigned char bits;
14199
14200         present = snd_hda_codec_read(codec, 0x14, 0,
14201                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14202         bits = present ? HDA_AMP_MUTE : 0;
14203         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
14204                                  HDA_AMP_MUTE, bits);
14205 }
14206
14207 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
14208 {
14209         unsigned int present;
14210         unsigned char bits;
14211
14212         present = snd_hda_codec_read(codec, 0x1b, 0,
14213                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14214         bits = present ? HDA_AMP_MUTE : 0;
14215         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
14216                                  HDA_AMP_MUTE, bits);
14217         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14218                                  HDA_AMP_MUTE, bits);
14219 }
14220
14221 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
14222                                            unsigned int res)
14223 {
14224         if ((res >> 26) == ALC880_HP_EVENT)
14225                 alc662_lenovo_101e_all_automute(codec);
14226         if ((res >> 26) == ALC880_FRONT_EVENT)
14227                 alc662_lenovo_101e_ispeaker_automute(codec);
14228 }
14229
14230 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
14231 {
14232         unsigned int present;
14233
14234         present = snd_hda_codec_read(codec, 0x18, 0,
14235                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14236         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14237                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14238         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14239                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14240         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14241                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
14242         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14243                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
14244 }
14245
14246 /* unsolicited event for HP jack sensing */
14247 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
14248                                      unsigned int res)
14249 {
14250         if ((res >> 26) == ALC880_HP_EVENT)
14251                 alc262_hippo1_automute( codec );
14252
14253         if ((res >> 26) == ALC880_MIC_EVENT)
14254                 alc662_eeepc_mic_automute(codec);
14255 }
14256
14257 static void alc662_eeepc_inithook(struct hda_codec *codec)
14258 {
14259         alc262_hippo1_automute( codec );
14260         alc662_eeepc_mic_automute(codec);
14261 }
14262
14263 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
14264 {
14265         unsigned int mute;
14266         unsigned int present;
14267
14268         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
14269         present = snd_hda_codec_read(codec, 0x14, 0,
14270                                      AC_VERB_GET_PIN_SENSE, 0);
14271         present = (present & 0x80000000) != 0;
14272         if (present) {
14273                 /* mute internal speaker */
14274                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
14275                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
14276         } else {
14277                 /* unmute internal speaker if necessary */
14278                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
14279                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
14280                                          HDA_AMP_MUTE, mute);
14281         }
14282 }
14283
14284 /* unsolicited event for HP jack sensing */
14285 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
14286                                           unsigned int res)
14287 {
14288         if ((res >> 26) == ALC880_HP_EVENT)
14289                 alc662_eeepc_ep20_automute(codec);
14290 }
14291
14292 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
14293 {
14294         alc662_eeepc_ep20_automute(codec);
14295 }
14296
14297 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
14298 {
14299         unsigned int present;
14300         unsigned char bits;
14301
14302         present = snd_hda_codec_read(codec, 0x21, 0,
14303                                      AC_VERB_GET_PIN_SENSE, 0)
14304                 & AC_PINSENSE_PRESENCE;
14305         bits = present ? HDA_AMP_MUTE : 0;
14306         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14307                                  HDA_AMP_MUTE, bits);
14308 }
14309
14310 static void alc663_m51va_mic_automute(struct hda_codec *codec)
14311 {
14312         unsigned int present;
14313
14314         present = snd_hda_codec_read(codec, 0x18, 0,
14315                                      AC_VERB_GET_PIN_SENSE, 0)
14316                 & AC_PINSENSE_PRESENCE;
14317         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14318                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14319         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14320                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14321         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14322                             0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
14323         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14324                             0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
14325 }
14326
14327 static void alc663_m51va_unsol_event(struct hda_codec *codec,
14328                                            unsigned int res)
14329 {
14330         switch (res >> 26) {
14331         case ALC880_HP_EVENT:
14332                 alc663_m51va_speaker_automute(codec);
14333                 break;
14334         case ALC880_MIC_EVENT:
14335                 alc663_m51va_mic_automute(codec);
14336                 break;
14337         }
14338 }
14339
14340 static void alc663_m51va_inithook(struct hda_codec *codec)
14341 {
14342         alc663_m51va_speaker_automute(codec);
14343         alc663_m51va_mic_automute(codec);
14344 }
14345
14346 static void alc663_g71v_hp_automute(struct hda_codec *codec)
14347 {
14348         unsigned int present;
14349         unsigned char bits;
14350
14351         present = snd_hda_codec_read(codec, 0x21, 0,
14352                                      AC_VERB_GET_PIN_SENSE, 0)
14353                 & AC_PINSENSE_PRESENCE;
14354         bits = present ? HDA_AMP_MUTE : 0;
14355         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
14356                                  HDA_AMP_MUTE, bits);
14357         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14358                                  HDA_AMP_MUTE, bits);
14359 }
14360
14361 static void alc663_g71v_front_automute(struct hda_codec *codec)
14362 {
14363         unsigned int present;
14364         unsigned char bits;
14365
14366         present = snd_hda_codec_read(codec, 0x15, 0,
14367                                      AC_VERB_GET_PIN_SENSE, 0)
14368                 & AC_PINSENSE_PRESENCE;
14369         bits = present ? HDA_AMP_MUTE : 0;
14370         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14371                                  HDA_AMP_MUTE, bits);
14372 }
14373
14374 static void alc663_g71v_unsol_event(struct hda_codec *codec,
14375                                            unsigned int res)
14376 {
14377         switch (res >> 26) {
14378         case ALC880_HP_EVENT:
14379                 alc663_g71v_hp_automute(codec);
14380                 break;
14381         case ALC880_FRONT_EVENT:
14382                 alc663_g71v_front_automute(codec);
14383                 break;
14384         case ALC880_MIC_EVENT:
14385                 alc662_eeepc_mic_automute(codec);
14386                 break;
14387         }
14388 }
14389
14390 static void alc663_g71v_inithook(struct hda_codec *codec)
14391 {
14392         alc663_g71v_front_automute(codec);
14393         alc663_g71v_hp_automute(codec);
14394         alc662_eeepc_mic_automute(codec);
14395 }
14396
14397 static void alc663_g50v_unsol_event(struct hda_codec *codec,
14398                                            unsigned int res)
14399 {
14400         switch (res >> 26) {
14401         case ALC880_HP_EVENT:
14402                 alc663_m51va_speaker_automute(codec);
14403                 break;
14404         case ALC880_MIC_EVENT:
14405                 alc662_eeepc_mic_automute(codec);
14406                 break;
14407         }
14408 }
14409
14410 static void alc663_g50v_inithook(struct hda_codec *codec)
14411 {
14412         alc663_m51va_speaker_automute(codec);
14413         alc662_eeepc_mic_automute(codec);
14414 }
14415
14416 #ifdef CONFIG_SND_HDA_POWER_SAVE
14417 #define alc662_loopbacks        alc880_loopbacks
14418 #endif
14419
14420
14421 /* pcm configuration: identiacal with ALC880 */
14422 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
14423 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
14424 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
14425 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
14426
14427 /*
14428  * configuration and preset
14429  */
14430 static const char *alc662_models[ALC662_MODEL_LAST] = {
14431         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
14432         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
14433         [ALC662_3ST_6ch]        = "3stack-6ch",
14434         [ALC662_5ST_DIG]        = "6stack-dig",
14435         [ALC662_LENOVO_101E]    = "lenovo-101e",
14436         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
14437         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
14438         [ALC663_ASUS_M51VA] = "m51va",
14439         [ALC663_ASUS_G71V] = "g71v",
14440         [ALC663_ASUS_H13] = "h13",
14441         [ALC663_ASUS_G50V] = "g50v",
14442         [ALC662_AUTO]           = "auto",
14443 };
14444
14445 static struct snd_pci_quirk alc662_cfg_tbl[] = {
14446         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS G71V", ALC663_ASUS_G71V),
14447         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
14448         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS M51VA", ALC663_ASUS_G50V),
14449         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
14450         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
14451         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
14452         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
14453         SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13),
14454         SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13),
14455         SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13),
14456         {}
14457 };
14458
14459 static struct alc_config_preset alc662_presets[] = {
14460         [ALC662_3ST_2ch_DIG] = {
14461                 .mixers = { alc662_3ST_2ch_mixer, alc662_capture_mixer },
14462                 .init_verbs = { alc662_init_verbs },
14463                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14464                 .dac_nids = alc662_dac_nids,
14465                 .dig_out_nid = ALC662_DIGOUT_NID,
14466                 .dig_in_nid = ALC662_DIGIN_NID,
14467                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14468                 .channel_mode = alc662_3ST_2ch_modes,
14469                 .input_mux = &alc662_capture_source,
14470         },
14471         [ALC662_3ST_6ch_DIG] = {
14472                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
14473                             alc662_capture_mixer },
14474                 .init_verbs = { alc662_init_verbs },
14475                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14476                 .dac_nids = alc662_dac_nids,
14477                 .dig_out_nid = ALC662_DIGOUT_NID,
14478                 .dig_in_nid = ALC662_DIGIN_NID,
14479                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
14480                 .channel_mode = alc662_3ST_6ch_modes,
14481                 .need_dac_fix = 1,
14482                 .input_mux = &alc662_capture_source,
14483         },
14484         [ALC662_3ST_6ch] = {
14485                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
14486                             alc662_capture_mixer },
14487                 .init_verbs = { alc662_init_verbs },
14488                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14489                 .dac_nids = alc662_dac_nids,
14490                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
14491                 .channel_mode = alc662_3ST_6ch_modes,
14492                 .need_dac_fix = 1,
14493                 .input_mux = &alc662_capture_source,
14494         },
14495         [ALC662_5ST_DIG] = {
14496                 .mixers = { alc662_base_mixer, alc662_chmode_mixer,
14497                             alc662_capture_mixer },
14498                 .init_verbs = { alc662_init_verbs },
14499                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14500                 .dac_nids = alc662_dac_nids,
14501                 .dig_out_nid = ALC662_DIGOUT_NID,
14502                 .dig_in_nid = ALC662_DIGIN_NID,
14503                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
14504                 .channel_mode = alc662_5stack_modes,
14505                 .input_mux = &alc662_capture_source,
14506         },
14507         [ALC662_LENOVO_101E] = {
14508                 .mixers = { alc662_lenovo_101e_mixer, alc662_capture_mixer },
14509                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
14510                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14511                 .dac_nids = alc662_dac_nids,
14512                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14513                 .channel_mode = alc662_3ST_2ch_modes,
14514                 .input_mux = &alc662_lenovo_101e_capture_source,
14515                 .unsol_event = alc662_lenovo_101e_unsol_event,
14516                 .init_hook = alc662_lenovo_101e_all_automute,
14517         },
14518         [ALC662_ASUS_EEEPC_P701] = {
14519                 .mixers = { alc662_eeepc_p701_mixer, alc662_capture_mixer },
14520                 .init_verbs = { alc662_init_verbs,
14521                                 alc662_eeepc_sue_init_verbs },
14522                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14523                 .dac_nids = alc662_dac_nids,
14524                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14525                 .channel_mode = alc662_3ST_2ch_modes,
14526                 .input_mux = &alc662_eeepc_capture_source,
14527                 .unsol_event = alc662_eeepc_unsol_event,
14528                 .init_hook = alc662_eeepc_inithook,
14529         },
14530         [ALC662_ASUS_EEEPC_EP20] = {
14531                 .mixers = { alc662_eeepc_ep20_mixer, alc662_capture_mixer,
14532                             alc662_chmode_mixer },
14533                 .init_verbs = { alc662_init_verbs,
14534                                 alc662_eeepc_ep20_sue_init_verbs },
14535                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14536                 .dac_nids = alc662_dac_nids,
14537                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
14538                 .channel_mode = alc662_3ST_6ch_modes,
14539                 .input_mux = &alc662_lenovo_101e_capture_source,
14540                 .unsol_event = alc662_eeepc_ep20_unsol_event,
14541                 .init_hook = alc662_eeepc_ep20_inithook,
14542         },
14543         [ALC663_ASUS_M51VA] = {
14544                 .mixers = { alc663_m51va_mixer, alc662_capture_mixer},
14545                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
14546                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14547                 .dac_nids = alc662_dac_nids,
14548                 .dig_out_nid = ALC662_DIGOUT_NID,
14549                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14550                 .channel_mode = alc662_3ST_2ch_modes,
14551                 .input_mux = &alc663_m51va_capture_source,
14552                 .unsol_event = alc663_m51va_unsol_event,
14553                 .init_hook = alc663_m51va_inithook,
14554         },
14555         [ALC663_ASUS_G71V] = {
14556                 .mixers = { alc663_g71v_mixer, alc662_capture_mixer},
14557                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
14558                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14559                 .dac_nids = alc662_dac_nids,
14560                 .dig_out_nid = ALC662_DIGOUT_NID,
14561                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14562                 .channel_mode = alc662_3ST_2ch_modes,
14563                 .input_mux = &alc662_eeepc_capture_source,
14564                 .unsol_event = alc663_g71v_unsol_event,
14565                 .init_hook = alc663_g71v_inithook,
14566         },
14567         [ALC663_ASUS_H13] = {
14568                 .mixers = { alc663_m51va_mixer, alc662_capture_mixer},
14569                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
14570                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14571                 .dac_nids = alc662_dac_nids,
14572                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14573                 .channel_mode = alc662_3ST_2ch_modes,
14574                 .input_mux = &alc663_m51va_capture_source,
14575                 .unsol_event = alc663_m51va_unsol_event,
14576                 .init_hook = alc663_m51va_inithook,
14577         },
14578         [ALC663_ASUS_G50V] = {
14579                 .mixers = { alc663_g50v_mixer, alc662_capture_mixer},
14580                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
14581                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14582                 .dac_nids = alc662_dac_nids,
14583                 .dig_out_nid = ALC662_DIGOUT_NID,
14584                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
14585                 .channel_mode = alc662_3ST_6ch_modes,
14586                 .input_mux = &alc663_capture_source,
14587                 .unsol_event = alc663_g50v_unsol_event,
14588                 .init_hook = alc663_g50v_inithook,
14589         },
14590 };
14591
14592
14593 /*
14594  * BIOS auto configuration
14595  */
14596
14597 /* add playback controls from the parsed DAC table */
14598 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
14599                                              const struct auto_pin_cfg *cfg)
14600 {
14601         char name[32];
14602         static const char *chname[4] = {
14603                 "Front", "Surround", NULL /*CLFE*/, "Side"
14604         };
14605         hda_nid_t nid;
14606         int i, err;
14607
14608         for (i = 0; i < cfg->line_outs; i++) {
14609                 if (!spec->multiout.dac_nids[i])
14610                         continue;
14611                 nid = alc880_idx_to_dac(i);
14612                 if (i == 2) {
14613                         /* Center/LFE */
14614                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14615                                           "Center Playback Volume",
14616                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
14617                                                               HDA_OUTPUT));
14618                         if (err < 0)
14619                                 return err;
14620                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14621                                           "LFE Playback Volume",
14622                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
14623                                                               HDA_OUTPUT));
14624                         if (err < 0)
14625                                 return err;
14626                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14627                                           "Center Playback Switch",
14628                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
14629                                                               HDA_INPUT));
14630                         if (err < 0)
14631                                 return err;
14632                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14633                                           "LFE Playback Switch",
14634                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
14635                                                               HDA_INPUT));
14636                         if (err < 0)
14637                                 return err;
14638                 } else {
14639                         sprintf(name, "%s Playback Volume", chname[i]);
14640                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14641                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
14642                                                               HDA_OUTPUT));
14643                         if (err < 0)
14644                                 return err;
14645                         sprintf(name, "%s Playback Switch", chname[i]);
14646                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14647                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
14648                                                               HDA_INPUT));
14649                         if (err < 0)
14650                                 return err;
14651                 }
14652         }
14653         return 0;
14654 }
14655
14656 /* add playback controls for speaker and HP outputs */
14657 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
14658                                         const char *pfx)
14659 {
14660         hda_nid_t nid;
14661         int err;
14662         char name[32];
14663
14664         if (!pin)
14665                 return 0;
14666
14667         if (pin == 0x17) {
14668                 /* ALC663 has a mono output pin on 0x17 */
14669                 sprintf(name, "%s Playback Switch", pfx);
14670                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14671                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
14672                 return err;
14673         }
14674
14675         if (alc880_is_fixed_pin(pin)) {
14676                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14677                 /* printk("DAC nid=%x\n",nid); */
14678                 /* specify the DAC as the extra output */
14679                 if (!spec->multiout.hp_nid)
14680                         spec->multiout.hp_nid = nid;
14681                 else
14682                         spec->multiout.extra_out_nid[0] = nid;
14683                 /* control HP volume/switch on the output mixer amp */
14684                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14685                 sprintf(name, "%s Playback Volume", pfx);
14686                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14687                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
14688                 if (err < 0)
14689                         return err;
14690                 sprintf(name, "%s Playback Switch", pfx);
14691                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14692                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
14693                 if (err < 0)
14694                         return err;
14695         } else if (alc880_is_multi_pin(pin)) {
14696                 /* set manual connection */
14697                 /* we have only a switch on HP-out PIN */
14698                 sprintf(name, "%s Playback Switch", pfx);
14699                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14700                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
14701                 if (err < 0)
14702                         return err;
14703         }
14704         return 0;
14705 }
14706
14707 /* create playback/capture controls for input pins */
14708 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
14709                                                 const struct auto_pin_cfg *cfg)
14710 {
14711         struct hda_input_mux *imux = &spec->private_imux;
14712         int i, err, idx;
14713
14714         for (i = 0; i < AUTO_PIN_LAST; i++) {
14715                 if (alc880_is_input_pin(cfg->input_pins[i])) {
14716                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
14717                         err = new_analog_input(spec, cfg->input_pins[i],
14718                                                auto_pin_cfg_labels[i],
14719                                                idx, 0x0b);
14720                         if (err < 0)
14721                                 return err;
14722                         imux->items[imux->num_items].label =
14723                                 auto_pin_cfg_labels[i];
14724                         imux->items[imux->num_items].index =
14725                                 alc880_input_pin_idx(cfg->input_pins[i]);
14726                         imux->num_items++;
14727                 }
14728         }
14729         return 0;
14730 }
14731
14732 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
14733                                               hda_nid_t nid, int pin_type,
14734                                               int dac_idx)
14735 {
14736         alc_set_pin_output(codec, nid, pin_type);
14737         /* need the manual connection? */
14738         if (alc880_is_multi_pin(nid)) {
14739                 struct alc_spec *spec = codec->spec;
14740                 int idx = alc880_multi_pin_idx(nid);
14741                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
14742                                     AC_VERB_SET_CONNECT_SEL,
14743                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
14744         }
14745 }
14746
14747 static void alc662_auto_init_multi_out(struct hda_codec *codec)
14748 {
14749         struct alc_spec *spec = codec->spec;
14750         int i;
14751
14752         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
14753         for (i = 0; i <= HDA_SIDE; i++) {
14754                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14755                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14756                 if (nid)
14757                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
14758                                                           i);
14759         }
14760 }
14761
14762 static void alc662_auto_init_hp_out(struct hda_codec *codec)
14763 {
14764         struct alc_spec *spec = codec->spec;
14765         hda_nid_t pin;
14766
14767         pin = spec->autocfg.hp_pins[0];
14768         if (pin) /* connect to front */
14769                 /* use dac 0 */
14770                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
14771         pin = spec->autocfg.speaker_pins[0];
14772         if (pin)
14773                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14774 }
14775
14776 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
14777 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
14778
14779 static void alc662_auto_init_analog_input(struct hda_codec *codec)
14780 {
14781         struct alc_spec *spec = codec->spec;
14782         int i;
14783
14784         for (i = 0; i < AUTO_PIN_LAST; i++) {
14785                 hda_nid_t nid = spec->autocfg.input_pins[i];
14786                 if (alc662_is_input_pin(nid)) {
14787                         snd_hda_codec_write(codec, nid, 0,
14788                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
14789                                             (i <= AUTO_PIN_FRONT_MIC ?
14790                                              PIN_VREF80 : PIN_IN));
14791                         if (nid != ALC662_PIN_CD_NID)
14792                                 snd_hda_codec_write(codec, nid, 0,
14793                                                     AC_VERB_SET_AMP_GAIN_MUTE,
14794                                                     AMP_OUT_MUTE);
14795                 }
14796         }
14797 }
14798
14799 #define alc662_auto_init_input_src      alc882_auto_init_input_src
14800
14801 static int alc662_parse_auto_config(struct hda_codec *codec)
14802 {
14803         struct alc_spec *spec = codec->spec;
14804         int err;
14805         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
14806
14807         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14808                                            alc662_ignore);
14809         if (err < 0)
14810                 return err;
14811         if (!spec->autocfg.line_outs)
14812                 return 0; /* can't find valid BIOS pin config */
14813
14814         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
14815         if (err < 0)
14816                 return err;
14817         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
14818         if (err < 0)
14819                 return err;
14820         err = alc662_auto_create_extra_out(spec,
14821                                            spec->autocfg.speaker_pins[0],
14822                                            "Speaker");
14823         if (err < 0)
14824                 return err;
14825         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
14826                                            "Headphone");
14827         if (err < 0)
14828                 return err;
14829         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
14830         if (err < 0)
14831                 return err;
14832
14833         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14834
14835         if (spec->autocfg.dig_out_pin)
14836                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
14837
14838         if (spec->kctl_alloc)
14839                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
14840
14841         spec->num_mux_defs = 1;
14842         spec->input_mux = &spec->private_imux;
14843         
14844         spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs;
14845         if (codec->vendor_id == 0x10ec0663)
14846                 spec->init_verbs[spec->num_init_verbs++] =
14847                         alc663_auto_init_verbs;
14848
14849         err = alc_auto_add_mic_boost(codec);
14850         if (err < 0)
14851                 return err;
14852
14853         spec->mixers[spec->num_mixers] = alc662_capture_mixer;
14854         spec->num_mixers++;
14855         return 1;
14856 }
14857
14858 /* additional initialization for auto-configuration model */
14859 static void alc662_auto_init(struct hda_codec *codec)
14860 {
14861         struct alc_spec *spec = codec->spec;
14862         alc662_auto_init_multi_out(codec);
14863         alc662_auto_init_hp_out(codec);
14864         alc662_auto_init_analog_input(codec);
14865         alc662_auto_init_input_src(codec);
14866         if (spec->unsol_event)
14867                 alc_sku_automute(codec);
14868 }
14869
14870 static int patch_alc662(struct hda_codec *codec)
14871 {
14872         struct alc_spec *spec;
14873         int err, board_config;
14874
14875         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14876         if (!spec)
14877                 return -ENOMEM;
14878
14879         codec->spec = spec;
14880
14881         alc_fix_pll_init(codec, 0x20, 0x04, 15);
14882
14883         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
14884                                                   alc662_models,
14885                                                   alc662_cfg_tbl);
14886         if (board_config < 0) {
14887                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
14888                        "trying auto-probe from BIOS...\n");
14889                 board_config = ALC662_AUTO;
14890         }
14891
14892         if (board_config == ALC662_AUTO) {
14893                 /* automatic parse from the BIOS config */
14894                 err = alc662_parse_auto_config(codec);
14895                 if (err < 0) {
14896                         alc_free(codec);
14897                         return err;
14898                 } else if (!err) {
14899                         printk(KERN_INFO
14900                                "hda_codec: Cannot set up configuration "
14901                                "from BIOS.  Using base mode...\n");
14902                         board_config = ALC662_3ST_2ch_DIG;
14903                 }
14904         }
14905
14906         if (board_config != ALC662_AUTO)
14907                 setup_preset(spec, &alc662_presets[board_config]);
14908
14909         if (codec->vendor_id == 0x10ec0663) {
14910                 spec->stream_name_analog = "ALC663 Analog";
14911                 spec->stream_name_digital = "ALC663 Digital";
14912         } else {
14913                 spec->stream_name_analog = "ALC662 Analog";
14914                 spec->stream_name_digital = "ALC662 Digital";
14915         }
14916
14917         spec->stream_analog_playback = &alc662_pcm_analog_playback;
14918         spec->stream_analog_capture = &alc662_pcm_analog_capture;
14919
14920         spec->stream_digital_playback = &alc662_pcm_digital_playback;
14921         spec->stream_digital_capture = &alc662_pcm_digital_capture;
14922
14923         spec->adc_nids = alc662_adc_nids;
14924         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
14925         spec->capsrc_nids = alc662_capsrc_nids;
14926
14927         spec->vmaster_nid = 0x02;
14928
14929         codec->patch_ops = alc_patch_ops;
14930         if (board_config == ALC662_AUTO)
14931                 spec->init_hook = alc662_auto_init;
14932 #ifdef CONFIG_SND_HDA_POWER_SAVE
14933         if (!spec->loopback.amplist)
14934                 spec->loopback.amplist = alc662_loopbacks;
14935 #endif
14936
14937         return 0;
14938 }
14939
14940 /*
14941  * patch entries
14942  */
14943 struct hda_codec_preset snd_hda_preset_realtek[] = {
14944         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
14945         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
14946         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
14947         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
14948         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
14949         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
14950           .patch = patch_alc861 },
14951         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
14952         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
14953         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
14954         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
14955           .patch = patch_alc883 },
14956         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
14957           .patch = patch_alc662 },
14958         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
14959         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
14960         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
14961         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
14962         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
14963           .patch = patch_alc882 }, /* should be patch_alc883() in future */
14964         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
14965         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
14966         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
14967         {} /* terminator */
14968 };