]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - sound/pci/hda/patch_realtek.c
4bd26725355c35e14b58182f18abdc5f7adcbeff
[linux-2.6-omap-h63xx.git] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
33 #include "hda_patch.h"
34
35 #define ALC880_FRONT_EVENT              0x01
36 #define ALC880_DCVOL_EVENT              0x02
37 #define ALC880_HP_EVENT                 0x04
38 #define ALC880_MIC_EVENT                0x08
39
40 /* ALC880 board config type */
41 enum {
42         ALC880_3ST,
43         ALC880_3ST_DIG,
44         ALC880_5ST,
45         ALC880_5ST_DIG,
46         ALC880_W810,
47         ALC880_Z71V,
48         ALC880_6ST,
49         ALC880_6ST_DIG,
50         ALC880_F1734,
51         ALC880_ASUS,
52         ALC880_ASUS_DIG,
53         ALC880_ASUS_W1V,
54         ALC880_ASUS_DIG2,
55         ALC880_FUJITSU,
56         ALC880_UNIWILL_DIG,
57         ALC880_UNIWILL,
58         ALC880_UNIWILL_P53,
59         ALC880_CLEVO,
60         ALC880_TCL_S700,
61         ALC880_LG,
62         ALC880_LG_LW,
63         ALC880_MEDION_RIM,
64 #ifdef CONFIG_SND_DEBUG
65         ALC880_TEST,
66 #endif
67         ALC880_AUTO,
68         ALC880_MODEL_LAST /* last tag */
69 };
70
71 /* ALC260 models */
72 enum {
73         ALC260_BASIC,
74         ALC260_HP,
75         ALC260_HP_3013,
76         ALC260_FUJITSU_S702X,
77         ALC260_ACER,
78         ALC260_WILL,
79         ALC260_REPLACER_672V,
80 #ifdef CONFIG_SND_DEBUG
81         ALC260_TEST,
82 #endif
83         ALC260_AUTO,
84         ALC260_MODEL_LAST /* last tag */
85 };
86
87 /* ALC262 models */
88 enum {
89         ALC262_BASIC,
90         ALC262_HIPPO,
91         ALC262_HIPPO_1,
92         ALC262_FUJITSU,
93         ALC262_HP_BPC,
94         ALC262_HP_BPC_D7000_WL,
95         ALC262_HP_BPC_D7000_WF,
96         ALC262_HP_TC_T5735,
97         ALC262_HP_RP5700,
98         ALC262_BENQ_ED8,
99         ALC262_SONY_ASSAMD,
100         ALC262_BENQ_T31,
101         ALC262_ULTRA,
102         ALC262_LENOVO_3000,
103         ALC262_NEC,
104         ALC262_AUTO,
105         ALC262_MODEL_LAST /* last tag */
106 };
107
108 /* ALC268 models */
109 enum {
110         ALC267_QUANTA_IL1,
111         ALC268_3ST,
112         ALC268_TOSHIBA,
113         ALC268_ACER,
114         ALC268_DELL,
115         ALC268_ZEPTO,
116 #ifdef CONFIG_SND_DEBUG
117         ALC268_TEST,
118 #endif
119         ALC268_AUTO,
120         ALC268_MODEL_LAST /* last tag */
121 };
122
123 /* ALC269 models */
124 enum {
125         ALC269_BASIC,
126         ALC269_ASUS_EEEPC_P703,
127         ALC269_ASUS_EEEPC_P901,
128         ALC269_AUTO,
129         ALC269_MODEL_LAST /* last tag */
130 };
131
132 /* ALC861 models */
133 enum {
134         ALC861_3ST,
135         ALC660_3ST,
136         ALC861_3ST_DIG,
137         ALC861_6ST_DIG,
138         ALC861_UNIWILL_M31,
139         ALC861_TOSHIBA,
140         ALC861_ASUS,
141         ALC861_ASUS_LAPTOP,
142         ALC861_AUTO,
143         ALC861_MODEL_LAST,
144 };
145
146 /* ALC861-VD models */
147 enum {
148         ALC660VD_3ST,
149         ALC660VD_3ST_DIG,
150         ALC861VD_3ST,
151         ALC861VD_3ST_DIG,
152         ALC861VD_6ST_DIG,
153         ALC861VD_LENOVO,
154         ALC861VD_DALLAS,
155         ALC861VD_HP,
156         ALC861VD_AUTO,
157         ALC861VD_MODEL_LAST,
158 };
159
160 /* ALC662 models */
161 enum {
162         ALC662_3ST_2ch_DIG,
163         ALC662_3ST_6ch_DIG,
164         ALC662_3ST_6ch,
165         ALC662_5ST_DIG,
166         ALC662_LENOVO_101E,
167         ALC662_ASUS_EEEPC_P701,
168         ALC662_ASUS_EEEPC_EP20,
169         ALC663_ASUS_M51VA,
170         ALC663_ASUS_G71V,
171         ALC663_ASUS_H13,
172         ALC663_ASUS_G50V,
173         ALC662_AUTO,
174         ALC662_MODEL_LAST,
175 };
176
177 /* ALC882 models */
178 enum {
179         ALC882_3ST_DIG,
180         ALC882_6ST_DIG,
181         ALC882_ARIMA,
182         ALC882_W2JC,
183         ALC882_TARGA,
184         ALC882_ASUS_A7J,
185         ALC882_ASUS_A7M,
186         ALC885_MACPRO,
187         ALC885_MBP3,
188         ALC885_IMAC24,
189         ALC882_AUTO,
190         ALC882_MODEL_LAST,
191 };
192
193 /* ALC883 models */
194 enum {
195         ALC883_3ST_2ch_DIG,
196         ALC883_3ST_6ch_DIG,
197         ALC883_3ST_6ch,
198         ALC883_6ST_DIG,
199         ALC883_TARGA_DIG,
200         ALC883_TARGA_2ch_DIG,
201         ALC883_ACER,
202         ALC883_ACER_ASPIRE,
203         ALC883_MEDION,
204         ALC883_MEDION_MD2,      
205         ALC883_LAPTOP_EAPD,
206         ALC883_LENOVO_101E_2ch,
207         ALC883_LENOVO_NB0763,
208         ALC888_LENOVO_MS7195_DIG,
209         ALC883_HAIER_W66,               
210         ALC888_3ST_HP,
211         ALC888_6ST_DELL,
212         ALC883_MITAC,
213         ALC883_CLEVO_M720,
214         ALC883_FUJITSU_PI2515,
215         ALC883_3ST_6ch_INTEL,
216         ALC883_AUTO,
217         ALC883_MODEL_LAST,
218 };
219
220 /* for GPIO Poll */
221 #define GPIO_MASK       0x03
222
223 struct alc_spec {
224         /* codec parameterization */
225         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
226         unsigned int num_mixers;
227
228         const struct hda_verb *init_verbs[5];   /* initialization verbs
229                                                  * don't forget NULL
230                                                  * termination!
231                                                  */
232         unsigned int num_init_verbs;
233
234         char *stream_name_analog;       /* analog PCM stream */
235         struct hda_pcm_stream *stream_analog_playback;
236         struct hda_pcm_stream *stream_analog_capture;
237         struct hda_pcm_stream *stream_analog_alt_playback;
238         struct hda_pcm_stream *stream_analog_alt_capture;
239
240         char *stream_name_digital;      /* digital PCM stream */
241         struct hda_pcm_stream *stream_digital_playback;
242         struct hda_pcm_stream *stream_digital_capture;
243
244         /* playback */
245         struct hda_multi_out multiout;  /* playback set-up
246                                          * max_channels, dacs must be set
247                                          * dig_out_nid and hp_nid are optional
248                                          */
249         hda_nid_t alt_dac_nid;
250
251         /* capture */
252         unsigned int num_adc_nids;
253         hda_nid_t *adc_nids;
254         hda_nid_t *capsrc_nids;
255         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
256
257         /* capture source */
258         unsigned int num_mux_defs;
259         const struct hda_input_mux *input_mux;
260         unsigned int cur_mux[3];
261
262         /* channel model */
263         const struct hda_channel_mode *channel_mode;
264         int num_channel_mode;
265         int need_dac_fix;
266
267         /* PCM information */
268         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
269
270         /* dynamic controls, init_verbs and input_mux */
271         struct auto_pin_cfg autocfg;
272         unsigned int num_kctl_alloc, num_kctl_used;
273         struct snd_kcontrol_new *kctl_alloc;
274         struct hda_input_mux private_imux;
275         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
276
277         /* hooks */
278         void (*init_hook)(struct hda_codec *codec);
279         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
280
281         /* for pin sensing */
282         unsigned int sense_updated: 1;
283         unsigned int jack_present: 1;
284         unsigned int master_sw: 1;
285
286         /* for virtual master */
287         hda_nid_t vmaster_nid;
288 #ifdef CONFIG_SND_HDA_POWER_SAVE
289         struct hda_loopback_check loopback;
290 #endif
291
292         /* for PLL fix */
293         hda_nid_t pll_nid;
294         unsigned int pll_coef_idx, pll_coef_bit;
295 };
296
297 /*
298  * configuration template - to be copied to the spec instance
299  */
300 struct alc_config_preset {
301         struct snd_kcontrol_new *mixers[5]; /* should be identical size
302                                              * with spec
303                                              */
304         const struct hda_verb *init_verbs[5];
305         unsigned int num_dacs;
306         hda_nid_t *dac_nids;
307         hda_nid_t dig_out_nid;          /* optional */
308         hda_nid_t hp_nid;               /* optional */
309         unsigned int num_adc_nids;
310         hda_nid_t *adc_nids;
311         hda_nid_t *capsrc_nids;
312         hda_nid_t dig_in_nid;
313         unsigned int num_channel_mode;
314         const struct hda_channel_mode *channel_mode;
315         int need_dac_fix;
316         unsigned int num_mux_defs;
317         const struct hda_input_mux *input_mux;
318         void (*unsol_event)(struct hda_codec *, unsigned int);
319         void (*init_hook)(struct hda_codec *);
320 #ifdef CONFIG_SND_HDA_POWER_SAVE
321         struct hda_amp_list *loopbacks;
322 #endif
323 };
324
325
326 /*
327  * input MUX handling
328  */
329 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
330                              struct snd_ctl_elem_info *uinfo)
331 {
332         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
333         struct alc_spec *spec = codec->spec;
334         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
335         if (mux_idx >= spec->num_mux_defs)
336                 mux_idx = 0;
337         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
338 }
339
340 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
341                             struct snd_ctl_elem_value *ucontrol)
342 {
343         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
344         struct alc_spec *spec = codec->spec;
345         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
346
347         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
348         return 0;
349 }
350
351 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
352                             struct snd_ctl_elem_value *ucontrol)
353 {
354         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
355         struct alc_spec *spec = codec->spec;
356         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
357         unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
358         hda_nid_t nid = spec->capsrc_nids ?
359                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
360         return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
361                                      nid, &spec->cur_mux[adc_idx]);
362 }
363
364
365 /*
366  * channel mode setting
367  */
368 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
369                             struct snd_ctl_elem_info *uinfo)
370 {
371         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
372         struct alc_spec *spec = codec->spec;
373         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
374                                     spec->num_channel_mode);
375 }
376
377 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
378                            struct snd_ctl_elem_value *ucontrol)
379 {
380         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
381         struct alc_spec *spec = codec->spec;
382         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
383                                    spec->num_channel_mode,
384                                    spec->multiout.max_channels);
385 }
386
387 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
388                            struct snd_ctl_elem_value *ucontrol)
389 {
390         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
391         struct alc_spec *spec = codec->spec;
392         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
393                                       spec->num_channel_mode,
394                                       &spec->multiout.max_channels);
395         if (err >= 0 && spec->need_dac_fix)
396                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
397         return err;
398 }
399
400 /*
401  * Control the mode of pin widget settings via the mixer.  "pc" is used
402  * instead of "%" to avoid consequences of accidently treating the % as 
403  * being part of a format specifier.  Maximum allowed length of a value is
404  * 63 characters plus NULL terminator.
405  *
406  * Note: some retasking pin complexes seem to ignore requests for input
407  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
408  * are requested.  Therefore order this list so that this behaviour will not
409  * cause problems when mixer clients move through the enum sequentially.
410  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
411  * March 2006.
412  */
413 static char *alc_pin_mode_names[] = {
414         "Mic 50pc bias", "Mic 80pc bias",
415         "Line in", "Line out", "Headphone out",
416 };
417 static unsigned char alc_pin_mode_values[] = {
418         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
419 };
420 /* The control can present all 5 options, or it can limit the options based
421  * in the pin being assumed to be exclusively an input or an output pin.  In
422  * addition, "input" pins may or may not process the mic bias option
423  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
424  * accept requests for bias as of chip versions up to March 2006) and/or
425  * wiring in the computer.
426  */
427 #define ALC_PIN_DIR_IN              0x00
428 #define ALC_PIN_DIR_OUT             0x01
429 #define ALC_PIN_DIR_INOUT           0x02
430 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
431 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
432
433 /* Info about the pin modes supported by the different pin direction modes. 
434  * For each direction the minimum and maximum values are given.
435  */
436 static signed char alc_pin_mode_dir_info[5][2] = {
437         { 0, 2 },    /* ALC_PIN_DIR_IN */
438         { 3, 4 },    /* ALC_PIN_DIR_OUT */
439         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
440         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
441         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
442 };
443 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
444 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
445 #define alc_pin_mode_n_items(_dir) \
446         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
447
448 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
449                              struct snd_ctl_elem_info *uinfo)
450 {
451         unsigned int item_num = uinfo->value.enumerated.item;
452         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
453
454         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
455         uinfo->count = 1;
456         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
457
458         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
459                 item_num = alc_pin_mode_min(dir);
460         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
461         return 0;
462 }
463
464 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
465                             struct snd_ctl_elem_value *ucontrol)
466 {
467         unsigned int i;
468         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
469         hda_nid_t nid = kcontrol->private_value & 0xffff;
470         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
471         long *valp = ucontrol->value.integer.value;
472         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
473                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
474                                                  0x00);
475
476         /* Find enumerated value for current pinctl setting */
477         i = alc_pin_mode_min(dir);
478         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
479                 i++;
480         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
481         return 0;
482 }
483
484 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
485                             struct snd_ctl_elem_value *ucontrol)
486 {
487         signed int change;
488         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
489         hda_nid_t nid = kcontrol->private_value & 0xffff;
490         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
491         long val = *ucontrol->value.integer.value;
492         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
493                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
494                                                  0x00);
495
496         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
497                 val = alc_pin_mode_min(dir);
498
499         change = pinctl != alc_pin_mode_values[val];
500         if (change) {
501                 /* Set pin mode to that requested */
502                 snd_hda_codec_write_cache(codec, nid, 0,
503                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
504                                           alc_pin_mode_values[val]);
505
506                 /* Also enable the retasking pin's input/output as required 
507                  * for the requested pin mode.  Enum values of 2 or less are
508                  * input modes.
509                  *
510                  * Dynamically switching the input/output buffers probably
511                  * reduces noise slightly (particularly on input) so we'll
512                  * do it.  However, having both input and output buffers
513                  * enabled simultaneously doesn't seem to be problematic if
514                  * this turns out to be necessary in the future.
515                  */
516                 if (val <= 2) {
517                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
518                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
519                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
520                                                  HDA_AMP_MUTE, 0);
521                 } else {
522                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
523                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
524                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
525                                                  HDA_AMP_MUTE, 0);
526                 }
527         }
528         return change;
529 }
530
531 #define ALC_PIN_MODE(xname, nid, dir) \
532         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
533           .info = alc_pin_mode_info, \
534           .get = alc_pin_mode_get, \
535           .put = alc_pin_mode_put, \
536           .private_value = nid | (dir<<16) }
537
538 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
539  * together using a mask with more than one bit set.  This control is
540  * currently used only by the ALC260 test model.  At this stage they are not
541  * needed for any "production" models.
542  */
543 #ifdef CONFIG_SND_DEBUG
544 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
545
546 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
547                              struct snd_ctl_elem_value *ucontrol)
548 {
549         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
550         hda_nid_t nid = kcontrol->private_value & 0xffff;
551         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
552         long *valp = ucontrol->value.integer.value;
553         unsigned int val = snd_hda_codec_read(codec, nid, 0,
554                                               AC_VERB_GET_GPIO_DATA, 0x00);
555
556         *valp = (val & mask) != 0;
557         return 0;
558 }
559 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
560                              struct snd_ctl_elem_value *ucontrol)
561 {
562         signed int change;
563         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
564         hda_nid_t nid = kcontrol->private_value & 0xffff;
565         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
566         long val = *ucontrol->value.integer.value;
567         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
568                                                     AC_VERB_GET_GPIO_DATA,
569                                                     0x00);
570
571         /* Set/unset the masked GPIO bit(s) as needed */
572         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
573         if (val == 0)
574                 gpio_data &= ~mask;
575         else
576                 gpio_data |= mask;
577         snd_hda_codec_write_cache(codec, nid, 0,
578                                   AC_VERB_SET_GPIO_DATA, gpio_data);
579
580         return change;
581 }
582 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
583         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
584           .info = alc_gpio_data_info, \
585           .get = alc_gpio_data_get, \
586           .put = alc_gpio_data_put, \
587           .private_value = nid | (mask<<16) }
588 #endif   /* CONFIG_SND_DEBUG */
589
590 /* A switch control to allow the enabling of the digital IO pins on the
591  * ALC260.  This is incredibly simplistic; the intention of this control is
592  * to provide something in the test model allowing digital outputs to be
593  * identified if present.  If models are found which can utilise these
594  * outputs a more complete mixer control can be devised for those models if
595  * necessary.
596  */
597 #ifdef CONFIG_SND_DEBUG
598 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
599
600 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
601                               struct snd_ctl_elem_value *ucontrol)
602 {
603         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
604         hda_nid_t nid = kcontrol->private_value & 0xffff;
605         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
606         long *valp = ucontrol->value.integer.value;
607         unsigned int val = snd_hda_codec_read(codec, nid, 0,
608                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
609
610         *valp = (val & mask) != 0;
611         return 0;
612 }
613 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
614                               struct snd_ctl_elem_value *ucontrol)
615 {
616         signed int change;
617         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
618         hda_nid_t nid = kcontrol->private_value & 0xffff;
619         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
620         long val = *ucontrol->value.integer.value;
621         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
622                                                     AC_VERB_GET_DIGI_CONVERT_1,
623                                                     0x00);
624
625         /* Set/unset the masked control bit(s) as needed */
626         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
627         if (val==0)
628                 ctrl_data &= ~mask;
629         else
630                 ctrl_data |= mask;
631         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
632                                   ctrl_data);
633
634         return change;
635 }
636 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
637         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
638           .info = alc_spdif_ctrl_info, \
639           .get = alc_spdif_ctrl_get, \
640           .put = alc_spdif_ctrl_put, \
641           .private_value = nid | (mask<<16) }
642 #endif   /* CONFIG_SND_DEBUG */
643
644 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
645  * Again, this is only used in the ALC26x test models to help identify when
646  * the EAPD line must be asserted for features to work.
647  */
648 #ifdef CONFIG_SND_DEBUG
649 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
650
651 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
652                               struct snd_ctl_elem_value *ucontrol)
653 {
654         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
655         hda_nid_t nid = kcontrol->private_value & 0xffff;
656         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
657         long *valp = ucontrol->value.integer.value;
658         unsigned int val = snd_hda_codec_read(codec, nid, 0,
659                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
660
661         *valp = (val & mask) != 0;
662         return 0;
663 }
664
665 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
666                               struct snd_ctl_elem_value *ucontrol)
667 {
668         int change;
669         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
670         hda_nid_t nid = kcontrol->private_value & 0xffff;
671         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
672         long val = *ucontrol->value.integer.value;
673         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
674                                                     AC_VERB_GET_EAPD_BTLENABLE,
675                                                     0x00);
676
677         /* Set/unset the masked control bit(s) as needed */
678         change = (!val ? 0 : mask) != (ctrl_data & mask);
679         if (!val)
680                 ctrl_data &= ~mask;
681         else
682                 ctrl_data |= mask;
683         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
684                                   ctrl_data);
685
686         return change;
687 }
688
689 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
690         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
691           .info = alc_eapd_ctrl_info, \
692           .get = alc_eapd_ctrl_get, \
693           .put = alc_eapd_ctrl_put, \
694           .private_value = nid | (mask<<16) }
695 #endif   /* CONFIG_SND_DEBUG */
696
697 /*
698  * set up from the preset table
699  */
700 static void setup_preset(struct alc_spec *spec,
701                          const struct alc_config_preset *preset)
702 {
703         int i;
704
705         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
706                 spec->mixers[spec->num_mixers++] = preset->mixers[i];
707         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
708              i++)
709                 spec->init_verbs[spec->num_init_verbs++] =
710                         preset->init_verbs[i];
711         
712         spec->channel_mode = preset->channel_mode;
713         spec->num_channel_mode = preset->num_channel_mode;
714         spec->need_dac_fix = preset->need_dac_fix;
715
716         spec->multiout.max_channels = spec->channel_mode[0].channels;
717
718         spec->multiout.num_dacs = preset->num_dacs;
719         spec->multiout.dac_nids = preset->dac_nids;
720         spec->multiout.dig_out_nid = preset->dig_out_nid;
721         spec->multiout.hp_nid = preset->hp_nid;
722         
723         spec->num_mux_defs = preset->num_mux_defs;
724         if (!spec->num_mux_defs)
725                 spec->num_mux_defs = 1;
726         spec->input_mux = preset->input_mux;
727
728         spec->num_adc_nids = preset->num_adc_nids;
729         spec->adc_nids = preset->adc_nids;
730         spec->capsrc_nids = preset->capsrc_nids;
731         spec->dig_in_nid = preset->dig_in_nid;
732
733         spec->unsol_event = preset->unsol_event;
734         spec->init_hook = preset->init_hook;
735 #ifdef CONFIG_SND_HDA_POWER_SAVE
736         spec->loopback.amplist = preset->loopbacks;
737 #endif
738 }
739
740 /* Enable GPIO mask and set output */
741 static struct hda_verb alc_gpio1_init_verbs[] = {
742         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
743         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
744         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
745         { }
746 };
747
748 static struct hda_verb alc_gpio2_init_verbs[] = {
749         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
750         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
751         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
752         { }
753 };
754
755 static struct hda_verb alc_gpio3_init_verbs[] = {
756         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
757         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
758         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
759         { }
760 };
761
762 /*
763  * Fix hardware PLL issue
764  * On some codecs, the analog PLL gating control must be off while
765  * the default value is 1.
766  */
767 static void alc_fix_pll(struct hda_codec *codec)
768 {
769         struct alc_spec *spec = codec->spec;
770         unsigned int val;
771
772         if (!spec->pll_nid)
773                 return;
774         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
775                             spec->pll_coef_idx);
776         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
777                                  AC_VERB_GET_PROC_COEF, 0);
778         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
779                             spec->pll_coef_idx);
780         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
781                             val & ~(1 << spec->pll_coef_bit));
782 }
783
784 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
785                              unsigned int coef_idx, unsigned int coef_bit)
786 {
787         struct alc_spec *spec = codec->spec;
788         spec->pll_nid = nid;
789         spec->pll_coef_idx = coef_idx;
790         spec->pll_coef_bit = coef_bit;
791         alc_fix_pll(codec);
792 }
793
794 static void alc_sku_automute(struct hda_codec *codec)
795 {
796         struct alc_spec *spec = codec->spec;
797         unsigned int present;
798         unsigned int hp_nid = spec->autocfg.hp_pins[0];
799         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
800
801         /* need to execute and sync at first */
802         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
803         present = snd_hda_codec_read(codec, hp_nid, 0,
804                                      AC_VERB_GET_PIN_SENSE, 0);
805         spec->jack_present = (present & 0x80000000) != 0;
806         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
807                             spec->jack_present ? 0 : PIN_OUT);
808 }
809
810 /* unsolicited event for HP jack sensing */
811 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
812 {
813         if (codec->vendor_id == 0x10ec0880)
814                 res >>= 28;
815         else
816                 res >>= 26;
817         if (res != ALC880_HP_EVENT)
818                 return;
819
820         alc_sku_automute(codec);
821 }
822
823 /* additional initialization for ALC888 variants */
824 static void alc888_coef_init(struct hda_codec *codec)
825 {
826         unsigned int tmp;
827
828         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
829         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
830         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
831         if ((tmp & 0xf0) == 2)
832                 /* alc888S-VC */
833                 snd_hda_codec_read(codec, 0x20, 0,
834                                    AC_VERB_SET_PROC_COEF, 0x830);
835          else
836                  /* alc888-VB */
837                  snd_hda_codec_read(codec, 0x20, 0,
838                                     AC_VERB_SET_PROC_COEF, 0x3030);
839 }
840
841 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
842  *      31 ~ 16 :       Manufacture ID
843  *      15 ~ 8  :       SKU ID
844  *      7  ~ 0  :       Assembly ID
845  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
846  */
847 static void alc_subsystem_id(struct hda_codec *codec,
848                              unsigned int porta, unsigned int porte,
849                              unsigned int portd)
850 {
851         unsigned int ass, tmp, i;
852         unsigned nid;
853         struct alc_spec *spec = codec->spec;
854
855         ass = codec->subsystem_id & 0xffff;
856         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
857                 goto do_sku;
858
859         /*      
860          * 31~30        : port conetcivity
861          * 29~21        : reserve
862          * 20           : PCBEEP input
863          * 19~16        : Check sum (15:1)
864          * 15~1         : Custom
865          * 0            : override
866         */
867         nid = 0x1d;
868         if (codec->vendor_id == 0x10ec0260)
869                 nid = 0x17;
870         ass = snd_hda_codec_read(codec, nid, 0,
871                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
872         if (!(ass & 1) && !(ass & 0x100000))
873                 return;
874         if ((ass >> 30) != 1)   /* no physical connection */
875                 return;
876
877         /* check sum */
878         tmp = 0;
879         for (i = 1; i < 16; i++) {
880                 if ((ass >> i) & 1)
881                         tmp++;
882         }
883         if (((ass >> 16) & 0xf) != tmp)
884                 return;
885 do_sku:
886         /*
887          * 0 : override
888          * 1 :  Swap Jack
889          * 2 : 0 --> Desktop, 1 --> Laptop
890          * 3~5 : External Amplifier control
891          * 7~6 : Reserved
892         */
893         tmp = (ass & 0x38) >> 3;        /* external Amp control */
894         switch (tmp) {
895         case 1:
896                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
897                 break;
898         case 3:
899                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
900                 break;
901         case 7:
902                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
903                 break;
904         case 5: /* set EAPD output high */
905                 switch (codec->vendor_id) {
906                 case 0x10ec0260:
907                         snd_hda_codec_write(codec, 0x0f, 0,
908                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
909                         snd_hda_codec_write(codec, 0x10, 0,
910                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
911                         break;
912                 case 0x10ec0262:
913                 case 0x10ec0267:
914                 case 0x10ec0268:
915                 case 0x10ec0269:
916                 case 0x10ec0660:
917                 case 0x10ec0662:
918                 case 0x10ec0663:
919                 case 0x10ec0862:
920                 case 0x10ec0889:
921                         snd_hda_codec_write(codec, 0x14, 0,
922                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
923                         snd_hda_codec_write(codec, 0x15, 0,
924                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
925                         break;
926                 }
927                 switch (codec->vendor_id) {
928                 case 0x10ec0260:
929                         snd_hda_codec_write(codec, 0x1a, 0,
930                                             AC_VERB_SET_COEF_INDEX, 7);
931                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
932                                                  AC_VERB_GET_PROC_COEF, 0);
933                         snd_hda_codec_write(codec, 0x1a, 0,
934                                             AC_VERB_SET_COEF_INDEX, 7);
935                         snd_hda_codec_write(codec, 0x1a, 0,
936                                             AC_VERB_SET_PROC_COEF,
937                                             tmp | 0x2010);
938                         break;
939                 case 0x10ec0262:
940                 case 0x10ec0880:
941                 case 0x10ec0882:
942                 case 0x10ec0883:
943                 case 0x10ec0885:
944                 case 0x10ec0889:
945                         snd_hda_codec_write(codec, 0x20, 0,
946                                             AC_VERB_SET_COEF_INDEX, 7);
947                         tmp = snd_hda_codec_read(codec, 0x20, 0,
948                                                  AC_VERB_GET_PROC_COEF, 0);
949                         snd_hda_codec_write(codec, 0x20, 0,
950                                             AC_VERB_SET_COEF_INDEX, 7); 
951                         snd_hda_codec_write(codec, 0x20, 0,
952                                             AC_VERB_SET_PROC_COEF,
953                                             tmp | 0x2010);
954                         break;
955                 case 0x10ec0888:
956                         /*alc888_coef_init(codec);*/ /* called in alc_init() */
957                         break;
958                 case 0x10ec0267:
959                 case 0x10ec0268:
960                         snd_hda_codec_write(codec, 0x20, 0,
961                                             AC_VERB_SET_COEF_INDEX, 7);
962                         tmp = snd_hda_codec_read(codec, 0x20, 0,
963                                                  AC_VERB_GET_PROC_COEF, 0);
964                         snd_hda_codec_write(codec, 0x20, 0,
965                                             AC_VERB_SET_COEF_INDEX, 7); 
966                         snd_hda_codec_write(codec, 0x20, 0,
967                                             AC_VERB_SET_PROC_COEF,
968                                             tmp | 0x3000);
969                         break;
970                 }
971         default:
972                 break;
973         }
974         
975         /* is laptop or Desktop and enable the function "Mute internal speaker
976          * when the external headphone out jack is plugged"
977          */
978         if (!(ass & 0x8000))
979                 return;
980         /*
981          * 10~8 : Jack location
982          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
983          * 14~13: Resvered
984          * 15   : 1 --> enable the function "Mute internal speaker
985          *              when the external headphone out jack is plugged"
986          */
987         if (!spec->autocfg.speaker_pins[0]) {
988                 if (spec->autocfg.line_out_pins[0])
989                         spec->autocfg.speaker_pins[0] =
990                                 spec->autocfg.line_out_pins[0];
991                 else
992                         return;
993         }
994
995         if (!spec->autocfg.hp_pins[0]) {
996                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
997                 if (tmp == 0)
998                         spec->autocfg.hp_pins[0] = porta;
999                 else if (tmp == 1)
1000                         spec->autocfg.hp_pins[0] = porte;
1001                 else if (tmp == 2)
1002                         spec->autocfg.hp_pins[0] = portd;
1003                 else
1004                         return;
1005         }
1006
1007         snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1008                             AC_VERB_SET_UNSOLICITED_ENABLE,
1009                             AC_USRSP_EN | ALC880_HP_EVENT);
1010         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                         board_config = ALC885_IMAC24;
6559                         break;
6560                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
6561                 case 0x106b2c00: /* Macbook Pro rev3 */
6562                 case 0x106b3600: /* Macbook 3.1 */
6563                         board_config = ALC885_MBP3;
6564                         break;
6565                 default:
6566                         /* ALC889A is handled better as ALC888-compatible */
6567                         if (codec->revision_id == 0x100103) {
6568                                 alc_free(codec);
6569                                 return patch_alc883(codec);
6570                         }
6571                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
6572                                          "trying auto-probe from BIOS...\n");
6573                         board_config = ALC882_AUTO;
6574                 }
6575         }
6576
6577         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
6578
6579         if (board_config == ALC882_AUTO) {
6580                 /* automatic parse from the BIOS config */
6581                 err = alc882_parse_auto_config(codec);
6582                 if (err < 0) {
6583                         alc_free(codec);
6584                         return err;
6585                 } else if (!err) {
6586                         printk(KERN_INFO
6587                                "hda_codec: Cannot set up configuration "
6588                                "from BIOS.  Using base mode...\n");
6589                         board_config = ALC882_3ST_DIG;
6590                 }
6591         }
6592
6593         if (board_config != ALC882_AUTO)
6594                 setup_preset(spec, &alc882_presets[board_config]);
6595
6596         if (codec->vendor_id == 0x10ec0885) {
6597                 spec->stream_name_analog = "ALC885 Analog";
6598                 spec->stream_name_digital = "ALC885 Digital";
6599         } else {
6600                 spec->stream_name_analog = "ALC882 Analog";
6601                 spec->stream_name_digital = "ALC882 Digital";
6602         }
6603
6604         spec->stream_analog_playback = &alc882_pcm_analog_playback;
6605         spec->stream_analog_capture = &alc882_pcm_analog_capture;
6606         /* FIXME: setup DAC5 */
6607         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
6608         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
6609
6610         spec->stream_digital_playback = &alc882_pcm_digital_playback;
6611         spec->stream_digital_capture = &alc882_pcm_digital_capture;
6612
6613         if (!spec->adc_nids && spec->input_mux) {
6614                 /* check whether NID 0x07 is valid */
6615                 unsigned int wcap = get_wcaps(codec, 0x07);
6616                 /* get type */
6617                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
6618                 if (wcap != AC_WID_AUD_IN) {
6619                         spec->adc_nids = alc882_adc_nids_alt;
6620                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
6621                         spec->capsrc_nids = alc882_capsrc_nids_alt;
6622                         spec->mixers[spec->num_mixers] =
6623                                 alc882_capture_alt_mixer;
6624                         spec->num_mixers++;
6625                 } else {
6626                         spec->adc_nids = alc882_adc_nids;
6627                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
6628                         spec->capsrc_nids = alc882_capsrc_nids;
6629                         spec->mixers[spec->num_mixers] = alc882_capture_mixer;
6630                         spec->num_mixers++;
6631                 }
6632         }
6633
6634         spec->vmaster_nid = 0x0c;
6635
6636         codec->patch_ops = alc_patch_ops;
6637         if (board_config == ALC882_AUTO)
6638                 spec->init_hook = alc882_auto_init;
6639 #ifdef CONFIG_SND_HDA_POWER_SAVE
6640         if (!spec->loopback.amplist)
6641                 spec->loopback.amplist = alc882_loopbacks;
6642 #endif
6643
6644         return 0;
6645 }
6646
6647 /*
6648  * ALC883 support
6649  *
6650  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
6651  * configuration.  Each pin widget can choose any input DACs and a mixer.
6652  * Each ADC is connected from a mixer of all inputs.  This makes possible
6653  * 6-channel independent captures.
6654  *
6655  * In addition, an independent DAC for the multi-playback (not used in this
6656  * driver yet).
6657  */
6658 #define ALC883_DIGOUT_NID       0x06
6659 #define ALC883_DIGIN_NID        0x0a
6660
6661 static hda_nid_t alc883_dac_nids[4] = {
6662         /* front, rear, clfe, rear_surr */
6663         0x02, 0x03, 0x04, 0x05
6664 };
6665
6666 static hda_nid_t alc883_adc_nids[2] = {
6667         /* ADC1-2 */
6668         0x08, 0x09,
6669 };
6670
6671 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
6672
6673 /* input MUX */
6674 /* FIXME: should be a matrix-type input source selection */
6675
6676 static struct hda_input_mux alc883_capture_source = {
6677         .num_items = 4,
6678         .items = {
6679                 { "Mic", 0x0 },
6680                 { "Front Mic", 0x1 },
6681                 { "Line", 0x2 },
6682                 { "CD", 0x4 },
6683         },
6684 };
6685
6686 static struct hda_input_mux alc883_3stack_6ch_intel = {
6687         .num_items = 4,
6688         .items = {
6689                 { "Mic", 0x1 },
6690                 { "Front Mic", 0x0 },
6691                 { "Line", 0x2 },
6692                 { "CD", 0x4 },
6693         },
6694 };
6695
6696 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6697         .num_items = 2,
6698         .items = {
6699                 { "Mic", 0x1 },
6700                 { "Line", 0x2 },
6701         },
6702 };
6703
6704 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6705         .num_items = 4,
6706         .items = {
6707                 { "Mic", 0x0 },
6708                 { "iMic", 0x1 },
6709                 { "Line", 0x2 },
6710                 { "CD", 0x4 },
6711         },
6712 };
6713
6714 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6715         .num_items = 2,
6716         .items = {
6717                 { "Mic", 0x0 },
6718                 { "Int Mic", 0x1 },
6719         },
6720 };
6721
6722 #define alc883_mux_enum_info alc_mux_enum_info
6723 #define alc883_mux_enum_get alc_mux_enum_get
6724 /* ALC883 has the ALC882-type input selection */
6725 #define alc883_mux_enum_put alc882_mux_enum_put
6726
6727 /*
6728  * 2ch mode
6729  */
6730 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6731         { 2, NULL }
6732 };
6733
6734 /*
6735  * 2ch mode
6736  */
6737 static struct hda_verb alc883_3ST_ch2_init[] = {
6738         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6739         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6740         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6741         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6742         { } /* end */
6743 };
6744
6745 /*
6746  * 4ch mode
6747  */
6748 static struct hda_verb alc883_3ST_ch4_init[] = {
6749         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6750         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6751         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6752         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6753         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6754         { } /* end */
6755 };
6756
6757 /*
6758  * 6ch mode
6759  */
6760 static struct hda_verb alc883_3ST_ch6_init[] = {
6761         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6762         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6763         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6764         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6765         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6766         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6767         { } /* end */
6768 };
6769
6770 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
6771         { 2, alc883_3ST_ch2_init },
6772         { 4, alc883_3ST_ch4_init },
6773         { 6, alc883_3ST_ch6_init },
6774 };
6775
6776 /*
6777  * 2ch mode
6778  */
6779 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
6780         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6781         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6782         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6783         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6784         { } /* end */
6785 };
6786
6787 /*
6788  * 4ch mode
6789  */
6790 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
6791         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6792         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6793         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6794         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6795         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6796         { } /* end */
6797 };
6798
6799 /*
6800  * 6ch mode
6801  */
6802 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
6803         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6804         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6805         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
6806         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6807         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6808         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6809         { } /* end */
6810 };
6811
6812 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
6813         { 2, alc883_3ST_ch2_intel_init },
6814         { 4, alc883_3ST_ch4_intel_init },
6815         { 6, alc883_3ST_ch6_intel_init },
6816 };
6817
6818 /*
6819  * 6ch mode
6820  */
6821 static struct hda_verb alc883_sixstack_ch6_init[] = {
6822         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6823         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6824         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6825         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6826         { } /* end */
6827 };
6828
6829 /*
6830  * 8ch mode
6831  */
6832 static struct hda_verb alc883_sixstack_ch8_init[] = {
6833         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6834         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6835         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6836         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6837         { } /* end */
6838 };
6839
6840 static struct hda_channel_mode alc883_sixstack_modes[2] = {
6841         { 6, alc883_sixstack_ch6_init },
6842         { 8, alc883_sixstack_ch8_init },
6843 };
6844
6845 static struct hda_verb alc883_medion_eapd_verbs[] = {
6846         /* eanable EAPD on medion laptop */
6847         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6848         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
6849         { }
6850 };
6851
6852 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6853  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6854  */
6855
6856 static struct snd_kcontrol_new alc883_base_mixer[] = {
6857         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6858         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6859         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6860         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6861         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6862         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6863         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6864         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6865         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6866         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6867         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6868         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6869         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6870         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6871         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6872         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6873         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6874         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6875         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6876         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6877         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6878         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6879         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6880         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6881         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6882         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6883         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6884         {
6885                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6886                 /* .name = "Capture Source", */
6887                 .name = "Input Source",
6888                 .count = 2,
6889                 .info = alc883_mux_enum_info,
6890                 .get = alc883_mux_enum_get,
6891                 .put = alc883_mux_enum_put,
6892         },
6893         { } /* end */
6894 };
6895
6896 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
6897         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6898         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6899         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6900         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6901         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6902         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6903         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6904         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6905         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6906         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6907         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6908         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6909         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6910         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6911         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6912         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6913         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6914         {
6915                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6916                 /* .name = "Capture Source", */
6917                 .name = "Input Source",
6918                 .count = 2,
6919                 .info = alc883_mux_enum_info,
6920                 .get = alc883_mux_enum_get,
6921                 .put = alc883_mux_enum_put,
6922         },
6923         { } /* end */
6924 };
6925
6926 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
6927         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6928         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
6929         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6930         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6931         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6932         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6933         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6934         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6935         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6936         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6937         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6938         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6939         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6940         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6941         {
6942                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6943                 /* .name = "Capture Source", */
6944                 .name = "Input Source",
6945                 .count = 2,
6946                 .info = alc883_mux_enum_info,
6947                 .get = alc883_mux_enum_get,
6948                 .put = alc883_mux_enum_put,
6949         },
6950         { } /* end */
6951 };
6952
6953 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
6954         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6955         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
6956         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6957         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6958         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6959         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6960         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6961         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6962         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6963         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6964         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6965         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6966         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6967         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6968         {
6969                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6970                 /* .name = "Capture Source", */
6971                 .name = "Input Source",
6972                 .count = 2,
6973                 .info = alc883_mux_enum_info,
6974                 .get = alc883_mux_enum_get,
6975                 .put = alc883_mux_enum_put,
6976         },
6977         { } /* end */
6978 };
6979
6980 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
6981         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6982         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6983         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6984         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6985         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6986         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6987         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6988         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6989         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6990         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6991         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6992         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6993         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6994         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6995         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6996         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6997         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6998         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6999         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7000         {
7001                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7002                 /* .name = "Capture Source", */
7003                 .name = "Input Source",
7004                 .count = 2,
7005                 .info = alc883_mux_enum_info,
7006                 .get = alc883_mux_enum_get,
7007                 .put = alc883_mux_enum_put,
7008         },
7009         { } /* end */
7010 };
7011
7012 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7013         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7014         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7015         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7016         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7017         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7018         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7019         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7020         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7021         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7022         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7023         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7024         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7025         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7026         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7027         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7028         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7029         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7030         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7031         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7032         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7033         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7034         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7035         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7036         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7037         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7038         {
7039                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7040                 /* .name = "Capture Source", */
7041                 .name = "Input Source",
7042                 .count = 2,
7043                 .info = alc883_mux_enum_info,
7044                 .get = alc883_mux_enum_get,
7045                 .put = alc883_mux_enum_put,
7046         },
7047         { } /* end */
7048 };
7049
7050 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7051         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7052         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7053         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7054         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7055         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7056                               HDA_OUTPUT),
7057         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7058         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7059         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7060         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7061         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7062         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7063         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7064         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7065         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7066         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7067         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7068         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7069         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7070         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7071         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7072         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7073         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7074         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7075         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7076         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7077         {
7078                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7079                 /* .name = "Capture Source", */
7080                 .name = "Input Source",
7081                 .count = 2,
7082                 .info = alc883_mux_enum_info,
7083                 .get = alc883_mux_enum_get,
7084                 .put = alc883_mux_enum_put,
7085         },
7086         { } /* end */
7087 };
7088
7089 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7090         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7091         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7092         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7093         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7094         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7095         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7096         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7097         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7098         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7099         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7100         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7101         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7102         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7103         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7104         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7105         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7106         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7107         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7108         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7109         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7110         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7111         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7112         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7113
7114         {
7115                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7116                 /* .name = "Capture Source", */
7117                 .name = "Input Source",
7118                 .count = 1,
7119                 .info = alc883_mux_enum_info,
7120                 .get = alc883_mux_enum_get,
7121                 .put = alc883_mux_enum_put,
7122         },
7123         { } /* end */
7124 };
7125
7126 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
7127         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7128         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7129         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7130         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7131         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7132         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7133         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7134         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7135         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7136         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7137         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7138         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7139         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7140         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7141         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7142         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7143         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7144         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7145         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7146         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7147         {
7148                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7149                 /* .name = "Capture Source", */
7150                 .name = "Input Source",
7151                 .count = 2,
7152                 .info = alc883_mux_enum_info,
7153                 .get = alc883_mux_enum_get,
7154                 .put = alc883_mux_enum_put,
7155         },
7156         { } /* end */
7157 };
7158
7159 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
7160         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7161         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7162         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7163         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7164         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7165         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7166         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7167         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7168         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7169         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7170         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7171         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7172         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7173         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7174         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7175         {
7176                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7177                 /* .name = "Capture Source", */
7178                 .name = "Input Source",
7179                 .count = 2,
7180                 .info = alc883_mux_enum_info,
7181                 .get = alc883_mux_enum_get,
7182                 .put = alc883_mux_enum_put,
7183         },
7184         { } /* end */
7185 };
7186
7187 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7188         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7189         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7190         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7191         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7192         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7193         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7194         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7195         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7196         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7197         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7198         {
7199                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7200                 /* .name = "Capture Source", */
7201                 .name = "Input Source",
7202                 .count = 1,
7203                 .info = alc883_mux_enum_info,
7204                 .get = alc883_mux_enum_get,
7205                 .put = alc883_mux_enum_put,
7206         },
7207         { } /* end */
7208 };
7209
7210 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7211         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7212         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7213         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7214         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7215         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7216         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7217         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7218         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7219         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7220         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7221         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7222         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7223         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7224         {
7225                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7226                 /* .name = "Capture Source", */
7227                 .name = "Input Source",
7228                 .count = 2,
7229                 .info = alc883_mux_enum_info,
7230                 .get = alc883_mux_enum_get,
7231                 .put = alc883_mux_enum_put,
7232         },
7233         { } /* end */
7234 };
7235
7236 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7237         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7238         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7239         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7240         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7241         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7242         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7243         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7244         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7245         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7246         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7247         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7248         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7249         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7250         {
7251                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7252                 /* .name = "Capture Source", */
7253                 .name = "Input Source",
7254                 .count = 2,
7255                 .info = alc883_mux_enum_info,
7256                 .get = alc883_mux_enum_get,
7257                 .put = alc883_mux_enum_put,
7258         },
7259         { } /* end */
7260 };      
7261
7262 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7263         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7264         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7265         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7266         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7267         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7268         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7269         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7270         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7271         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7272         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7273         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7274         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7275         {
7276                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7277                 /* .name = "Capture Source", */
7278                 .name = "Input Source",
7279                 .count = 2,
7280                 .info = alc883_mux_enum_info,
7281                 .get = alc883_mux_enum_get,
7282                 .put = alc883_mux_enum_put,
7283         },
7284         { } /* end */
7285 };
7286
7287 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7288         {
7289                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7290                 .name = "Channel Mode",
7291                 .info = alc_ch_mode_info,
7292                 .get = alc_ch_mode_get,
7293                 .put = alc_ch_mode_put,
7294         },
7295         { } /* end */
7296 };
7297
7298 static struct hda_verb alc883_init_verbs[] = {
7299         /* ADC1: mute amp left and right */
7300         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7301         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7302         /* ADC2: mute amp left and right */
7303         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7304         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7305         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7306         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7307         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7308         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7309         /* Rear mixer */
7310         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7311         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7312         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7313         /* CLFE mixer */
7314         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7315         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7316         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7317         /* Side mixer */
7318         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7319         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7320         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7321
7322         /* mute analog input loopbacks */
7323         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7324         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7325         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7326         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7327         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7328
7329         /* Front Pin: output 0 (0x0c) */
7330         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7331         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7332         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7333         /* Rear Pin: output 1 (0x0d) */
7334         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7335         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7336         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7337         /* CLFE Pin: output 2 (0x0e) */
7338         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7339         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7340         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7341         /* Side Pin: output 3 (0x0f) */
7342         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7343         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7344         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7345         /* Mic (rear) pin: input vref at 80% */
7346         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7347         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7348         /* Front Mic pin: input vref at 80% */
7349         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7350         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7351         /* Line In pin: input */
7352         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7353         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7354         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7355         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7356         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7357         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7358         /* CD pin widget for input */
7359         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7360
7361         /* FIXME: use matrix-type input source selection */
7362         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7363         /* Input mixer2 */
7364         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7365         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7366         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7367         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7368         /* Input mixer3 */
7369         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7370         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7371         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7372         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7373         { }
7374 };
7375
7376 /* toggle speaker-output according to the hp-jack state */
7377 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7378 {
7379         unsigned int present;
7380
7381         present = snd_hda_codec_read(codec, 0x15, 0,
7382                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7383         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7384                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7385         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7386                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7387 }
7388
7389 /* auto-toggle front mic */
7390 /*
7391 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7392 {
7393         unsigned int present;
7394         unsigned char bits;
7395
7396         present = snd_hda_codec_read(codec, 0x18, 0,
7397                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7398         bits = present ? HDA_AMP_MUTE : 0;
7399         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7400 }
7401 */
7402
7403 static void alc883_mitac_automute(struct hda_codec *codec)
7404 {
7405         alc883_mitac_hp_automute(codec);
7406         /* alc883_mitac_mic_automute(codec); */
7407 }
7408
7409 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7410                                            unsigned int res)
7411 {
7412         switch (res >> 26) {
7413         case ALC880_HP_EVENT:
7414                 alc883_mitac_hp_automute(codec);
7415                 break;
7416         case ALC880_MIC_EVENT:
7417                 /* alc883_mitac_mic_automute(codec); */
7418                 break;
7419         }
7420 }
7421
7422 static struct hda_verb alc883_mitac_verbs[] = {
7423         /* HP */
7424         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7425         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7426         /* Subwoofer */
7427         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7428         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7429
7430         /* enable unsolicited event */
7431         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7432         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7433
7434         { } /* end */
7435 };
7436
7437 static struct hda_verb alc883_clevo_m720_verbs[] = {
7438         /* HP */
7439         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7440         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7441         /* Int speaker */
7442         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7443         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7444
7445         /* enable unsolicited event */
7446         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7447         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7448
7449         { } /* end */
7450 };
7451
7452 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7453         /* HP */
7454         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7455         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7456         /* Subwoofer */
7457         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7458         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7459
7460         /* enable unsolicited event */
7461         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7462
7463         { } /* end */
7464 };
7465
7466 static struct hda_verb alc883_tagra_verbs[] = {
7467         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7468         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7469
7470         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7471         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7472         
7473         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7474         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7475         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7476
7477         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7478         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7479         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7480         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7481
7482         { } /* end */
7483 };
7484
7485 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7486         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7487         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7488         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7489         { } /* end */
7490 };
7491
7492 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7493         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7494         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7495         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7496         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7497         { } /* end */
7498 };
7499
7500 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7501         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7502         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7503         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7504         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7505         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7506         { } /* end */
7507 };
7508
7509 static struct hda_verb alc883_haier_w66_verbs[] = {
7510         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7511         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7512
7513         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7514
7515         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7516         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7517         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7518         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7519         { } /* end */
7520 };
7521
7522 static struct hda_verb alc888_3st_hp_verbs[] = {
7523         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7524         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7525         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7526         { }
7527 };
7528
7529 static struct hda_verb alc888_6st_dell_verbs[] = {
7530         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7531         { }
7532 };
7533
7534 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7535         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7536         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7537         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7538         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7539         { }
7540 };
7541
7542 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7543         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7544         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7545         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7546         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7547         { }
7548 };
7549
7550 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7551         { 2, alc888_3st_hp_2ch_init },
7552         { 6, alc888_3st_hp_6ch_init },
7553 };
7554
7555 /* toggle front-jack and RCA according to the hp-jack state */
7556 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7557 {
7558         unsigned int present;
7559  
7560         present = snd_hda_codec_read(codec, 0x1b, 0,
7561                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7562         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7563                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7564         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7565                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7566 }
7567
7568 /* toggle RCA according to the front-jack state */
7569 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7570 {
7571         unsigned int present;
7572  
7573         present = snd_hda_codec_read(codec, 0x14, 0,
7574                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7575         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7576                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7577 }
7578
7579 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7580                                              unsigned int res)
7581 {
7582         if ((res >> 26) == ALC880_HP_EVENT)
7583                 alc888_lenovo_ms7195_front_automute(codec);
7584         if ((res >> 26) == ALC880_FRONT_EVENT)
7585                 alc888_lenovo_ms7195_rca_automute(codec);
7586 }
7587
7588 static struct hda_verb alc883_medion_md2_verbs[] = {
7589         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7590         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7591
7592         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7593
7594         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7595         { } /* end */
7596 };
7597
7598 /* toggle speaker-output according to the hp-jack state */
7599 static void alc883_medion_md2_automute(struct hda_codec *codec)
7600 {
7601         unsigned int present;
7602  
7603         present = snd_hda_codec_read(codec, 0x14, 0,
7604                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7605         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7606                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7607 }
7608
7609 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
7610                                           unsigned int res)
7611 {
7612         if ((res >> 26) == ALC880_HP_EVENT)
7613                 alc883_medion_md2_automute(codec);
7614 }
7615
7616 /* toggle speaker-output according to the hp-jack state */
7617 static void alc883_tagra_automute(struct hda_codec *codec)
7618 {
7619         unsigned int present;
7620         unsigned char bits;
7621
7622         present = snd_hda_codec_read(codec, 0x14, 0,
7623                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7624         bits = present ? HDA_AMP_MUTE : 0;
7625         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
7626                                  HDA_AMP_MUTE, bits);
7627         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7628                                   present ? 1 : 3);
7629 }
7630
7631 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
7632 {
7633         if ((res >> 26) == ALC880_HP_EVENT)
7634                 alc883_tagra_automute(codec);
7635 }
7636
7637 /* toggle speaker-output according to the hp-jack state */
7638 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
7639 {
7640         unsigned int present;
7641         unsigned char bits;
7642
7643         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
7644                 & AC_PINSENSE_PRESENCE;
7645         bits = present ? HDA_AMP_MUTE : 0;
7646         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7647                                  HDA_AMP_MUTE, bits);
7648 }
7649
7650 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
7651 {
7652         unsigned int present;
7653
7654         present = snd_hda_codec_read(codec, 0x18, 0,
7655                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7656         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
7657                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7658 }
7659
7660 static void alc883_clevo_m720_automute(struct hda_codec *codec)
7661 {
7662         alc883_clevo_m720_hp_automute(codec);
7663         alc883_clevo_m720_mic_automute(codec);
7664 }
7665
7666 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
7667                                            unsigned int res)
7668 {
7669         switch (res >> 26) {
7670         case ALC880_HP_EVENT:
7671                 alc883_clevo_m720_hp_automute(codec);
7672                 break;
7673         case ALC880_MIC_EVENT:
7674                 alc883_clevo_m720_mic_automute(codec);
7675                 break;
7676         }
7677 }
7678
7679 /* toggle speaker-output according to the hp-jack state */
7680 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
7681 {
7682         unsigned int present;
7683         unsigned char bits;
7684
7685         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
7686                 & AC_PINSENSE_PRESENCE;
7687         bits = present ? HDA_AMP_MUTE : 0;
7688         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7689                                  HDA_AMP_MUTE, bits);
7690 }
7691
7692 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
7693                                                   unsigned int res)
7694 {
7695         if ((res >> 26) == ALC880_HP_EVENT)
7696                 alc883_2ch_fujitsu_pi2515_automute(codec);
7697 }
7698
7699 static void alc883_haier_w66_automute(struct hda_codec *codec)
7700 {
7701         unsigned int present;
7702         unsigned char bits;
7703
7704         present = snd_hda_codec_read(codec, 0x1b, 0,
7705                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7706         bits = present ? 0x80 : 0;
7707         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7708                                  0x80, bits);
7709 }
7710
7711 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
7712                                          unsigned int res)
7713 {
7714         if ((res >> 26) == ALC880_HP_EVENT)
7715                 alc883_haier_w66_automute(codec);
7716 }
7717
7718 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
7719 {
7720         unsigned int present;
7721         unsigned char bits;
7722
7723         present = snd_hda_codec_read(codec, 0x14, 0,
7724                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7725         bits = present ? HDA_AMP_MUTE : 0;
7726         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7727                                  HDA_AMP_MUTE, bits);
7728 }
7729
7730 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
7731 {
7732         unsigned int present;
7733         unsigned char bits;
7734
7735         present = snd_hda_codec_read(codec, 0x1b, 0,
7736                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7737         bits = present ? HDA_AMP_MUTE : 0;
7738         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7739                                  HDA_AMP_MUTE, bits);
7740         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7741                                  HDA_AMP_MUTE, bits);
7742 }
7743
7744 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
7745                                            unsigned int res)
7746 {
7747         if ((res >> 26) == ALC880_HP_EVENT)
7748                 alc883_lenovo_101e_all_automute(codec);
7749         if ((res >> 26) == ALC880_FRONT_EVENT)
7750                 alc883_lenovo_101e_ispeaker_automute(codec);
7751 }
7752
7753 /* toggle speaker-output according to the hp-jack state */
7754 static void alc883_acer_aspire_automute(struct hda_codec *codec)
7755 {
7756         unsigned int present;
7757  
7758         present = snd_hda_codec_read(codec, 0x14, 0,
7759                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7760         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7761                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7762         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7763                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7764 }
7765
7766 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
7767                                            unsigned int res)
7768 {
7769         if ((res >> 26) == ALC880_HP_EVENT)
7770                 alc883_acer_aspire_automute(codec);
7771 }
7772
7773 static struct hda_verb alc883_acer_eapd_verbs[] = {
7774         /* HP Pin: output 0 (0x0c) */
7775         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7776         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7777         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7778         /* Front Pin: output 0 (0x0c) */
7779         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7780         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7781         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7782         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
7783         /* eanable EAPD on medion laptop */
7784         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7785         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
7786         /* enable unsolicited event */
7787         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7788         { }
7789 };
7790
7791 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
7792 {
7793         unsigned int present;
7794  
7795         present = snd_hda_codec_read(codec, 0x1b, 0,
7796                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7797         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7798                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7799         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7800                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7801         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7802                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7803         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7804                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7805 }
7806
7807 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
7808                                              unsigned int res)
7809 {
7810         switch (res >> 26) {
7811         case ALC880_HP_EVENT:
7812                 printk("hp_event\n");
7813                 alc888_6st_dell_front_automute(codec);
7814                 break;
7815         }
7816 }
7817
7818 /*
7819  * generic initialization of ADC, input mixers and output mixers
7820  */
7821 static struct hda_verb alc883_auto_init_verbs[] = {
7822         /*
7823          * Unmute ADC0-2 and set the default input to mic-in
7824          */
7825         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7826         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7827         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7828         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7829
7830         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7831          * mixer widget
7832          * Note: PASD motherboards uses the Line In 2 as the input for
7833          * front panel mic (mic 2)
7834          */
7835         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7836         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7837         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7838         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7839         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7840         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7841
7842         /*
7843          * Set up output mixers (0x0c - 0x0f)
7844          */
7845         /* set vol=0 to output mixers */
7846         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7847         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7848         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7849         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7850         /* set up input amps for analog loopback */
7851         /* Amp Indices: DAC = 0, mixer = 1 */
7852         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7853         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7854         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7855         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7856         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7857         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7858         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7859         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7860         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7861         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7862
7863         /* FIXME: use matrix-type input source selection */
7864         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7865         /* Input mixer1 */
7866         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7867         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7868         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7869         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
7870         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7871         /* Input mixer2 */
7872         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7873         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7874         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7875         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
7876         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7877
7878         { }
7879 };
7880
7881 /* capture mixer elements */
7882 static struct snd_kcontrol_new alc883_capture_mixer[] = {
7883         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7884         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7885         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7886         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7887         {
7888                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7889                 /* The multiple "Capture Source" controls confuse alsamixer
7890                  * So call somewhat different..
7891                  */
7892                 /* .name = "Capture Source", */
7893                 .name = "Input Source",
7894                 .count = 2,
7895                 .info = alc882_mux_enum_info,
7896                 .get = alc882_mux_enum_get,
7897                 .put = alc882_mux_enum_put,
7898         },
7899         { } /* end */
7900 };
7901
7902 #ifdef CONFIG_SND_HDA_POWER_SAVE
7903 #define alc883_loopbacks        alc880_loopbacks
7904 #endif
7905
7906 /* pcm configuration: identiacal with ALC880 */
7907 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
7908 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
7909 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
7910 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
7911 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
7912
7913 /*
7914  * configuration and preset
7915  */
7916 static const char *alc883_models[ALC883_MODEL_LAST] = {
7917         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
7918         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
7919         [ALC883_3ST_6ch]        = "3stack-6ch",
7920         [ALC883_6ST_DIG]        = "6stack-dig",
7921         [ALC883_TARGA_DIG]      = "targa-dig",
7922         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
7923         [ALC883_ACER]           = "acer",
7924         [ALC883_ACER_ASPIRE]    = "acer-aspire",
7925         [ALC883_MEDION]         = "medion",
7926         [ALC883_MEDION_MD2]     = "medion-md2",
7927         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
7928         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
7929         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
7930         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
7931         [ALC883_HAIER_W66]      = "haier-w66",
7932         [ALC888_3ST_HP]         = "3stack-hp",
7933         [ALC888_6ST_DELL]       = "6stack-dell",
7934         [ALC883_MITAC]          = "mitac",
7935         [ALC883_CLEVO_M720]     = "clevo-m720",
7936         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
7937         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
7938         [ALC883_AUTO]           = "auto",
7939 };
7940
7941 static struct snd_pci_quirk alc883_cfg_tbl[] = {
7942         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
7943         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
7944         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
7945         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
7946         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
7947         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
7948         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
7949         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
7950         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
7951         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
7952         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
7953         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
7954         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
7955         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
7956         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
7957         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
7958         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
7959         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
7960         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
7961         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
7962         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
7963         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
7964         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
7965         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
7966         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
7967         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
7968         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
7969         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
7970         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
7971         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
7972         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
7973         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
7974         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
7975         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
7976         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
7977         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
7978         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
7979         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
7980         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
7981         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
7982         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
7983         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
7984         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
7985         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
7986         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
7987         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
7988         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
7989         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
7990         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7991         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7992         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7993         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
7994         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
7995         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
7996         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
7997         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
7998         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
7999         {}
8000 };
8001
8002 static struct alc_config_preset alc883_presets[] = {
8003         [ALC883_3ST_2ch_DIG] = {
8004                 .mixers = { alc883_3ST_2ch_mixer },
8005                 .init_verbs = { alc883_init_verbs },
8006                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8007                 .dac_nids = alc883_dac_nids,
8008                 .dig_out_nid = ALC883_DIGOUT_NID,
8009                 .dig_in_nid = ALC883_DIGIN_NID,
8010                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8011                 .channel_mode = alc883_3ST_2ch_modes,
8012                 .input_mux = &alc883_capture_source,
8013         },
8014         [ALC883_3ST_6ch_DIG] = {
8015                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8016                 .init_verbs = { alc883_init_verbs },
8017                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8018                 .dac_nids = alc883_dac_nids,
8019                 .dig_out_nid = ALC883_DIGOUT_NID,
8020                 .dig_in_nid = ALC883_DIGIN_NID,
8021                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8022                 .channel_mode = alc883_3ST_6ch_modes,
8023                 .need_dac_fix = 1,
8024                 .input_mux = &alc883_capture_source,
8025         },
8026         [ALC883_3ST_6ch] = {
8027                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8028                 .init_verbs = { alc883_init_verbs },
8029                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8030                 .dac_nids = alc883_dac_nids,
8031                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8032                 .channel_mode = alc883_3ST_6ch_modes,
8033                 .need_dac_fix = 1,
8034                 .input_mux = &alc883_capture_source,
8035         },
8036         [ALC883_3ST_6ch_INTEL] = {
8037                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
8038                 .init_verbs = { alc883_init_verbs },
8039                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8040                 .dac_nids = alc883_dac_nids,
8041                 .dig_out_nid = ALC883_DIGOUT_NID,
8042                 .dig_in_nid = ALC883_DIGIN_NID,
8043                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
8044                 .channel_mode = alc883_3ST_6ch_intel_modes,
8045                 .need_dac_fix = 1,
8046                 .input_mux = &alc883_3stack_6ch_intel,
8047         },
8048         [ALC883_6ST_DIG] = {
8049                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8050                 .init_verbs = { alc883_init_verbs },
8051                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8052                 .dac_nids = alc883_dac_nids,
8053                 .dig_out_nid = ALC883_DIGOUT_NID,
8054                 .dig_in_nid = ALC883_DIGIN_NID,
8055                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8056                 .channel_mode = alc883_sixstack_modes,
8057                 .input_mux = &alc883_capture_source,
8058         },
8059         [ALC883_TARGA_DIG] = {
8060                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
8061                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8062                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8063                 .dac_nids = alc883_dac_nids,
8064                 .dig_out_nid = ALC883_DIGOUT_NID,
8065                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8066                 .channel_mode = alc883_3ST_6ch_modes,
8067                 .need_dac_fix = 1,
8068                 .input_mux = &alc883_capture_source,
8069                 .unsol_event = alc883_tagra_unsol_event,
8070                 .init_hook = alc883_tagra_automute,
8071         },
8072         [ALC883_TARGA_2ch_DIG] = {
8073                 .mixers = { alc883_tagra_2ch_mixer},
8074                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8075                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8076                 .dac_nids = alc883_dac_nids,
8077                 .dig_out_nid = ALC883_DIGOUT_NID,
8078                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8079                 .channel_mode = alc883_3ST_2ch_modes,
8080                 .input_mux = &alc883_capture_source,
8081                 .unsol_event = alc883_tagra_unsol_event,
8082                 .init_hook = alc883_tagra_automute,
8083         },
8084         [ALC883_ACER] = {
8085                 .mixers = { alc883_base_mixer },
8086                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
8087                  * and the headphone jack.  Turn this on and rely on the
8088                  * standard mute methods whenever the user wants to turn
8089                  * these outputs off.
8090                  */
8091                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
8092                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8093                 .dac_nids = alc883_dac_nids,
8094                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8095                 .channel_mode = alc883_3ST_2ch_modes,
8096                 .input_mux = &alc883_capture_source,
8097         },
8098         [ALC883_ACER_ASPIRE] = {
8099                 .mixers = { alc883_acer_aspire_mixer },
8100                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
8101                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8102                 .dac_nids = alc883_dac_nids,
8103                 .dig_out_nid = ALC883_DIGOUT_NID,
8104                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8105                 .channel_mode = alc883_3ST_2ch_modes,
8106                 .input_mux = &alc883_capture_source,
8107                 .unsol_event = alc883_acer_aspire_unsol_event,
8108                 .init_hook = alc883_acer_aspire_automute,
8109         },
8110         [ALC883_MEDION] = {
8111                 .mixers = { alc883_fivestack_mixer,
8112                             alc883_chmode_mixer },
8113                 .init_verbs = { alc883_init_verbs,
8114                                 alc883_medion_eapd_verbs },
8115                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8116                 .dac_nids = alc883_dac_nids,
8117                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8118                 .channel_mode = alc883_sixstack_modes,
8119                 .input_mux = &alc883_capture_source,
8120         },
8121         [ALC883_MEDION_MD2] = {
8122                 .mixers = { alc883_medion_md2_mixer},
8123                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
8124                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8125                 .dac_nids = alc883_dac_nids,
8126                 .dig_out_nid = ALC883_DIGOUT_NID,
8127                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8128                 .channel_mode = alc883_3ST_2ch_modes,
8129                 .input_mux = &alc883_capture_source,
8130                 .unsol_event = alc883_medion_md2_unsol_event,
8131                 .init_hook = alc883_medion_md2_automute,
8132         },      
8133         [ALC883_LAPTOP_EAPD] = {
8134                 .mixers = { alc883_base_mixer },
8135                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
8136                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8137                 .dac_nids = alc883_dac_nids,
8138                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8139                 .channel_mode = alc883_3ST_2ch_modes,
8140                 .input_mux = &alc883_capture_source,
8141         },
8142         [ALC883_CLEVO_M720] = {
8143                 .mixers = { alc883_clevo_m720_mixer },
8144                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
8145                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8146                 .dac_nids = alc883_dac_nids,
8147                 .dig_out_nid = ALC883_DIGOUT_NID,
8148                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8149                 .channel_mode = alc883_3ST_2ch_modes,
8150                 .input_mux = &alc883_capture_source,
8151                 .unsol_event = alc883_clevo_m720_unsol_event,
8152                 .init_hook = alc883_clevo_m720_automute,
8153         },
8154         [ALC883_LENOVO_101E_2ch] = {
8155                 .mixers = { alc883_lenovo_101e_2ch_mixer},
8156                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
8157                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8158                 .dac_nids = alc883_dac_nids,
8159                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8160                 .channel_mode = alc883_3ST_2ch_modes,
8161                 .input_mux = &alc883_lenovo_101e_capture_source,
8162                 .unsol_event = alc883_lenovo_101e_unsol_event,
8163                 .init_hook = alc883_lenovo_101e_all_automute,
8164         },
8165         [ALC883_LENOVO_NB0763] = {
8166                 .mixers = { alc883_lenovo_nb0763_mixer },
8167                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
8168                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8169                 .dac_nids = alc883_dac_nids,
8170                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8171                 .channel_mode = alc883_3ST_2ch_modes,
8172                 .need_dac_fix = 1,
8173                 .input_mux = &alc883_lenovo_nb0763_capture_source,
8174                 .unsol_event = alc883_medion_md2_unsol_event,
8175                 .init_hook = alc883_medion_md2_automute,
8176         },
8177         [ALC888_LENOVO_MS7195_DIG] = {
8178                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8179                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
8180                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8181                 .dac_nids = alc883_dac_nids,
8182                 .dig_out_nid = ALC883_DIGOUT_NID,
8183                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8184                 .channel_mode = alc883_3ST_6ch_modes,
8185                 .need_dac_fix = 1,
8186                 .input_mux = &alc883_capture_source,
8187                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
8188                 .init_hook = alc888_lenovo_ms7195_front_automute,
8189         },
8190         [ALC883_HAIER_W66] = {
8191                 .mixers = { alc883_tagra_2ch_mixer},
8192                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
8193                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8194                 .dac_nids = alc883_dac_nids,
8195                 .dig_out_nid = ALC883_DIGOUT_NID,
8196                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8197                 .channel_mode = alc883_3ST_2ch_modes,
8198                 .input_mux = &alc883_capture_source,
8199                 .unsol_event = alc883_haier_w66_unsol_event,
8200                 .init_hook = alc883_haier_w66_automute,
8201         },
8202         [ALC888_3ST_HP] = {
8203                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8204                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
8205                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8206                 .dac_nids = alc883_dac_nids,
8207                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
8208                 .channel_mode = alc888_3st_hp_modes,
8209                 .need_dac_fix = 1,
8210                 .input_mux = &alc883_capture_source,
8211         },
8212         [ALC888_6ST_DELL] = {
8213                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8214                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
8215                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8216                 .dac_nids = alc883_dac_nids,
8217                 .dig_out_nid = ALC883_DIGOUT_NID,
8218                 .dig_in_nid = ALC883_DIGIN_NID,
8219                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8220                 .channel_mode = alc883_sixstack_modes,
8221                 .input_mux = &alc883_capture_source,
8222                 .unsol_event = alc888_6st_dell_unsol_event,
8223                 .init_hook = alc888_6st_dell_front_automute,
8224         },
8225         [ALC883_MITAC] = {
8226                 .mixers = { alc883_mitac_mixer },
8227                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
8228                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8229                 .dac_nids = alc883_dac_nids,
8230                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8231                 .channel_mode = alc883_3ST_2ch_modes,
8232                 .input_mux = &alc883_capture_source,
8233                 .unsol_event = alc883_mitac_unsol_event,
8234                 .init_hook = alc883_mitac_automute,
8235         },
8236         [ALC883_FUJITSU_PI2515] = {
8237                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
8238                 .init_verbs = { alc883_init_verbs,
8239                                 alc883_2ch_fujitsu_pi2515_verbs},
8240                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8241                 .dac_nids = alc883_dac_nids,
8242                 .dig_out_nid = ALC883_DIGOUT_NID,
8243                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8244                 .channel_mode = alc883_3ST_2ch_modes,
8245                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8246                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8247                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8248         },
8249 };
8250
8251
8252 /*
8253  * BIOS auto configuration
8254  */
8255 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
8256                                               hda_nid_t nid, int pin_type,
8257                                               int dac_idx)
8258 {
8259         /* set as output */
8260         struct alc_spec *spec = codec->spec;
8261         int idx;
8262
8263         alc_set_pin_output(codec, nid, pin_type);
8264         if (spec->multiout.dac_nids[dac_idx] == 0x25)
8265                 idx = 4;
8266         else
8267                 idx = spec->multiout.dac_nids[dac_idx] - 2;
8268         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
8269
8270 }
8271
8272 static void alc883_auto_init_multi_out(struct hda_codec *codec)
8273 {
8274         struct alc_spec *spec = codec->spec;
8275         int i;
8276
8277         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
8278         for (i = 0; i <= HDA_SIDE; i++) {
8279                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
8280                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
8281                 if (nid)
8282                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
8283                                                           i);
8284         }
8285 }
8286
8287 static void alc883_auto_init_hp_out(struct hda_codec *codec)
8288 {
8289         struct alc_spec *spec = codec->spec;
8290         hda_nid_t pin;
8291
8292         pin = spec->autocfg.hp_pins[0];
8293         if (pin) /* connect to front */
8294                 /* use dac 0 */
8295                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8296         pin = spec->autocfg.speaker_pins[0];
8297         if (pin)
8298                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
8299 }
8300
8301 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
8302 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
8303
8304 static void alc883_auto_init_analog_input(struct hda_codec *codec)
8305 {
8306         struct alc_spec *spec = codec->spec;
8307         int i;
8308
8309         for (i = 0; i < AUTO_PIN_LAST; i++) {
8310                 hda_nid_t nid = spec->autocfg.input_pins[i];
8311                 if (alc883_is_input_pin(nid)) {
8312                         snd_hda_codec_write(codec, nid, 0,
8313                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
8314                                             (i <= AUTO_PIN_FRONT_MIC ?
8315                                              PIN_VREF80 : PIN_IN));
8316                         if (nid != ALC883_PIN_CD_NID)
8317                                 snd_hda_codec_write(codec, nid, 0,
8318                                                     AC_VERB_SET_AMP_GAIN_MUTE,
8319                                                     AMP_OUT_MUTE);
8320                 }
8321         }
8322 }
8323
8324 #define alc883_auto_init_input_src      alc882_auto_init_input_src
8325
8326 /* almost identical with ALC880 parser... */
8327 static int alc883_parse_auto_config(struct hda_codec *codec)
8328 {
8329         struct alc_spec *spec = codec->spec;
8330         int err = alc880_parse_auto_config(codec);
8331
8332         if (err < 0)
8333                 return err;
8334         else if (!err)
8335                 return 0; /* no config found */
8336
8337         err = alc_auto_add_mic_boost(codec);
8338         if (err < 0)
8339                 return err;
8340
8341         /* hack - override the init verbs */
8342         spec->init_verbs[0] = alc883_auto_init_verbs;
8343         spec->mixers[spec->num_mixers] = alc883_capture_mixer;
8344         spec->num_mixers++;
8345
8346         return 1; /* config found */
8347 }
8348
8349 /* additional initialization for auto-configuration model */
8350 static void alc883_auto_init(struct hda_codec *codec)
8351 {
8352         struct alc_spec *spec = codec->spec;
8353         alc883_auto_init_multi_out(codec);
8354         alc883_auto_init_hp_out(codec);
8355         alc883_auto_init_analog_input(codec);
8356         alc883_auto_init_input_src(codec);
8357         if (spec->unsol_event)
8358                 alc_sku_automute(codec);
8359 }
8360
8361 static int patch_alc883(struct hda_codec *codec)
8362 {
8363         struct alc_spec *spec;
8364         int err, board_config;
8365
8366         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8367         if (spec == NULL)
8368                 return -ENOMEM;
8369
8370         codec->spec = spec;
8371
8372         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
8373
8374         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
8375                                                   alc883_models,
8376                                                   alc883_cfg_tbl);
8377         if (board_config < 0) {
8378                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
8379                        "trying auto-probe from BIOS...\n");
8380                 board_config = ALC883_AUTO;
8381         }
8382
8383         if (board_config == ALC883_AUTO) {
8384                 /* automatic parse from the BIOS config */
8385                 err = alc883_parse_auto_config(codec);
8386                 if (err < 0) {
8387                         alc_free(codec);
8388                         return err;
8389                 } else if (!err) {
8390                         printk(KERN_INFO
8391                                "hda_codec: Cannot set up configuration "
8392                                "from BIOS.  Using base mode...\n");
8393                         board_config = ALC883_3ST_2ch_DIG;
8394                 }
8395         }
8396
8397         if (board_config != ALC883_AUTO)
8398                 setup_preset(spec, &alc883_presets[board_config]);
8399
8400         switch (codec->vendor_id) {
8401         case 0x10ec0888:
8402                 spec->stream_name_analog = "ALC888 Analog";
8403                 spec->stream_name_digital = "ALC888 Digital";
8404                 break;
8405         case 0x10ec0889:
8406                 spec->stream_name_analog = "ALC889 Analog";
8407                 spec->stream_name_digital = "ALC889 Digital";
8408                 break;
8409         default:
8410                 spec->stream_name_analog = "ALC883 Analog";
8411                 spec->stream_name_digital = "ALC883 Digital";
8412                 break;
8413         }
8414
8415         spec->stream_analog_playback = &alc883_pcm_analog_playback;
8416         spec->stream_analog_capture = &alc883_pcm_analog_capture;
8417         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
8418
8419         spec->stream_digital_playback = &alc883_pcm_digital_playback;
8420         spec->stream_digital_capture = &alc883_pcm_digital_capture;
8421
8422         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
8423         spec->adc_nids = alc883_adc_nids;
8424         spec->capsrc_nids = alc883_capsrc_nids;
8425
8426         spec->vmaster_nid = 0x0c;
8427
8428         codec->patch_ops = alc_patch_ops;
8429         if (board_config == ALC883_AUTO)
8430                 spec->init_hook = alc883_auto_init;
8431
8432 #ifdef CONFIG_SND_HDA_POWER_SAVE
8433         if (!spec->loopback.amplist)
8434                 spec->loopback.amplist = alc883_loopbacks;
8435 #endif
8436
8437         return 0;
8438 }
8439
8440 /*
8441  * ALC262 support
8442  */
8443
8444 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
8445 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
8446
8447 #define alc262_dac_nids         alc260_dac_nids
8448 #define alc262_adc_nids         alc882_adc_nids
8449 #define alc262_adc_nids_alt     alc882_adc_nids_alt
8450 #define alc262_capsrc_nids      alc882_capsrc_nids
8451 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
8452
8453 #define alc262_modes            alc260_modes
8454 #define alc262_capture_source   alc882_capture_source
8455
8456 static struct snd_kcontrol_new alc262_base_mixer[] = {
8457         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8458         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8459         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8460         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8461         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8462         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8463         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8464         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8465         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8466         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8467         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8468         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8469         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8470            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8471         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
8472         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8473         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8474         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
8475         { } /* end */
8476 };
8477
8478 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
8479         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8480         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8481         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8482         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8483         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8484         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8485         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8486         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8487         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8488         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8489         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8490         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8491         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8492            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
8493         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
8494         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8495         { } /* end */
8496 };
8497
8498 /* update HP, line and mono-out pins according to the master switch */
8499 static void alc262_hp_master_update(struct hda_codec *codec)
8500 {
8501         struct alc_spec *spec = codec->spec;
8502         int val = spec->master_sw;
8503
8504         /* HP & line-out */
8505         snd_hda_codec_write_cache(codec, 0x1b, 0,
8506                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8507                                   val ? PIN_HP : 0);
8508         snd_hda_codec_write_cache(codec, 0x15, 0,
8509                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8510                                   val ? PIN_HP : 0);
8511         /* mono (speaker) depending on the HP jack sense */
8512         val = val && !spec->jack_present;
8513         snd_hda_codec_write_cache(codec, 0x16, 0,
8514                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
8515                                   val ? PIN_OUT : 0);
8516 }
8517
8518 static void alc262_hp_bpc_automute(struct hda_codec *codec)
8519 {
8520         struct alc_spec *spec = codec->spec;
8521         unsigned int presence;
8522         presence = snd_hda_codec_read(codec, 0x1b, 0,
8523                                       AC_VERB_GET_PIN_SENSE, 0);
8524         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8525         alc262_hp_master_update(codec);
8526 }
8527
8528 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
8529 {
8530         if ((res >> 26) != ALC880_HP_EVENT)
8531                 return;
8532         alc262_hp_bpc_automute(codec);
8533 }
8534
8535 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
8536 {
8537         struct alc_spec *spec = codec->spec;
8538         unsigned int presence;
8539         presence = snd_hda_codec_read(codec, 0x15, 0,
8540                                       AC_VERB_GET_PIN_SENSE, 0);
8541         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
8542         alc262_hp_master_update(codec);
8543 }
8544
8545 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
8546                                            unsigned int res)
8547 {
8548         if ((res >> 26) != ALC880_HP_EVENT)
8549                 return;
8550         alc262_hp_wildwest_automute(codec);
8551 }
8552
8553 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
8554                                    struct snd_ctl_elem_value *ucontrol)
8555 {
8556         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8557         struct alc_spec *spec = codec->spec;
8558         *ucontrol->value.integer.value = spec->master_sw;
8559         return 0;
8560 }
8561
8562 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
8563                                    struct snd_ctl_elem_value *ucontrol)
8564 {
8565         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8566         struct alc_spec *spec = codec->spec;
8567         int val = !!*ucontrol->value.integer.value;
8568
8569         if (val == spec->master_sw)
8570                 return 0;
8571         spec->master_sw = val;
8572         alc262_hp_master_update(codec);
8573         return 1;
8574 }
8575
8576 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
8577         {
8578                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8579                 .name = "Master Playback Switch",
8580                 .info = snd_ctl_boolean_mono_info,
8581                 .get = alc262_hp_master_sw_get,
8582                 .put = alc262_hp_master_sw_put,
8583         },
8584         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8585         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8586         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8587         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
8588                               HDA_OUTPUT),
8589         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
8590                             HDA_OUTPUT),
8591         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8592         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8593         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8594         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8595         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8596         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8597         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8598         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8599         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8600         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8601         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8602         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
8603         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
8604         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
8605         { } /* end */
8606 };
8607
8608 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
8609         {
8610                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8611                 .name = "Master Playback Switch",
8612                 .info = snd_ctl_boolean_mono_info,
8613                 .get = alc262_hp_master_sw_get,
8614                 .put = alc262_hp_master_sw_put,
8615         },
8616         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8617         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8618         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8619         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8620         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
8621                               HDA_OUTPUT),
8622         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
8623                             HDA_OUTPUT),
8624         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
8625         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
8626         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
8627         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8628         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8629         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8630         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8631         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
8632         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
8633         { } /* end */
8634 };
8635
8636 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
8637         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8638         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8639         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
8640         { } /* end */
8641 };
8642
8643 /* mute/unmute internal speaker according to the hp jack and mute state */
8644 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
8645 {
8646         struct alc_spec *spec = codec->spec;
8647
8648         if (force || !spec->sense_updated) {
8649                 unsigned int present;
8650                 present = snd_hda_codec_read(codec, 0x15, 0,
8651                                              AC_VERB_GET_PIN_SENSE, 0);
8652                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
8653                 spec->sense_updated = 1;
8654         }
8655         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
8656                                  spec->jack_present ? HDA_AMP_MUTE : 0);
8657 }
8658
8659 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
8660                                         unsigned int res)
8661 {
8662         if ((res >> 26) != ALC880_HP_EVENT)
8663                 return;
8664         alc262_hp_t5735_automute(codec, 1);
8665 }
8666
8667 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
8668 {
8669         alc262_hp_t5735_automute(codec, 1);
8670 }
8671
8672 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
8673         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8674         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8675         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8676         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8677         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8678         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8679         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8680         { } /* end */
8681 };
8682
8683 static struct hda_verb alc262_hp_t5735_verbs[] = {
8684         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8685         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8686
8687         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8688         { }
8689 };
8690
8691 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
8692         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8693         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8694         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
8695         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
8696         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
8697         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
8698         { } /* end */
8699 };
8700
8701 static struct hda_verb alc262_hp_rp5700_verbs[] = {
8702         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8703         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8704         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8705         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8706         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8707         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8708         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8709         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8710         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
8711         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
8712         {}
8713 };
8714
8715 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
8716         .num_items = 1,
8717         .items = {
8718                 { "Line", 0x1 },
8719         },
8720 };
8721
8722 /* bind hp and internal speaker mute (with plug check) */
8723 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
8724                                      struct snd_ctl_elem_value *ucontrol)
8725 {
8726         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8727         long *valp = ucontrol->value.integer.value;
8728         int change;
8729
8730         /* change hp mute */
8731         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
8732                                           HDA_AMP_MUTE,
8733                                           valp[0] ? 0 : HDA_AMP_MUTE);
8734         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
8735                                            HDA_AMP_MUTE,
8736                                            valp[1] ? 0 : HDA_AMP_MUTE);
8737         if (change) {
8738                 /* change speaker according to HP jack state */
8739                 struct alc_spec *spec = codec->spec;
8740                 unsigned int mute;
8741                 if (spec->jack_present)
8742                         mute = HDA_AMP_MUTE;
8743                 else
8744                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
8745                                                       HDA_OUTPUT, 0);
8746                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8747                                          HDA_AMP_MUTE, mute);
8748         }
8749         return change;
8750 }
8751
8752 static struct snd_kcontrol_new alc262_sony_mixer[] = {
8753         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8754         {
8755                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8756                 .name = "Master Playback Switch",
8757                 .info = snd_hda_mixer_amp_switch_info,
8758                 .get = snd_hda_mixer_amp_switch_get,
8759                 .put = alc262_sony_master_sw_put,
8760                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
8761         },
8762         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8763         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8764         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8765         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8766         { } /* end */
8767 };
8768
8769 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
8770         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8771         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8772         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8773         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8774         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8775         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8776         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8777         { } /* end */
8778 };
8779
8780 #define alc262_capture_mixer            alc882_capture_mixer
8781 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
8782
8783 /*
8784  * generic initialization of ADC, input mixers and output mixers
8785  */
8786 static struct hda_verb alc262_init_verbs[] = {
8787         /*
8788          * Unmute ADC0-2 and set the default input to mic-in
8789          */
8790         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8791         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8792         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8793         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8794         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8795         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8796
8797         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8798          * mixer widget
8799          * Note: PASD motherboards uses the Line In 2 as the input for
8800          * front panel mic (mic 2)
8801          */
8802         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8803         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8804         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8805         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8806         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8807         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8808
8809         /*
8810          * Set up output mixers (0x0c - 0x0e)
8811          */
8812         /* set vol=0 to output mixers */
8813         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8814         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8815         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8816         /* set up input amps for analog loopback */
8817         /* Amp Indices: DAC = 0, mixer = 1 */
8818         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8819         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8820         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8821         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8822         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8823         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8824
8825         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8826         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8827         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8828         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8829         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8830         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8831
8832         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8833         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8834         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8835         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8836         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8837         
8838         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8839         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8840         
8841         /* FIXME: use matrix-type input source selection */
8842         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8843         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8844         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8845         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8846         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8847         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8848         /* Input mixer2 */
8849         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8850         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8851         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8852         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8853         /* Input mixer3 */
8854         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8855         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8856         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8857         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8858
8859         { }
8860 };
8861
8862 static struct hda_verb alc262_hippo_unsol_verbs[] = {
8863         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8864         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8865         {}
8866 };
8867
8868 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
8869         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8870         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8871         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8872
8873         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8874         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8875         {}
8876 };
8877
8878 static struct hda_verb alc262_sony_unsol_verbs[] = {
8879         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8880         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8881         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
8882
8883         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8884         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8885         {}
8886 };
8887
8888 /* mute/unmute internal speaker according to the hp jack and mute state */
8889 static void alc262_hippo_automute(struct hda_codec *codec)
8890 {
8891         struct alc_spec *spec = codec->spec;
8892         unsigned int mute;
8893         unsigned int present;
8894
8895         /* need to execute and sync at first */
8896         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
8897         present = snd_hda_codec_read(codec, 0x15, 0,
8898                                      AC_VERB_GET_PIN_SENSE, 0);
8899         spec->jack_present = (present & 0x80000000) != 0;
8900         if (spec->jack_present) {
8901                 /* mute internal speaker */
8902                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8903                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8904         } else {
8905                 /* unmute internal speaker if necessary */
8906                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
8907                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8908                                          HDA_AMP_MUTE, mute);
8909         }
8910 }
8911
8912 /* unsolicited event for HP jack sensing */
8913 static void alc262_hippo_unsol_event(struct hda_codec *codec,
8914                                        unsigned int res)
8915 {
8916         if ((res >> 26) != ALC880_HP_EVENT)
8917                 return;
8918         alc262_hippo_automute(codec);
8919 }
8920
8921 static void alc262_hippo1_automute(struct hda_codec *codec)
8922 {
8923         unsigned int mute;
8924         unsigned int present;
8925
8926         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8927         present = snd_hda_codec_read(codec, 0x1b, 0,
8928                                      AC_VERB_GET_PIN_SENSE, 0);
8929         present = (present & 0x80000000) != 0;
8930         if (present) {
8931                 /* mute internal speaker */
8932                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8933                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8934         } else {
8935                 /* unmute internal speaker if necessary */
8936                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8937                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8938                                          HDA_AMP_MUTE, mute);
8939         }
8940 }
8941
8942 /* unsolicited event for HP jack sensing */
8943 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
8944                                        unsigned int res)
8945 {
8946         if ((res >> 26) != ALC880_HP_EVENT)
8947                 return;
8948         alc262_hippo1_automute(codec);
8949 }
8950
8951 /*
8952  * nec model
8953  *  0x15 = headphone
8954  *  0x16 = internal speaker
8955  *  0x18 = external mic
8956  */
8957
8958 static struct snd_kcontrol_new alc262_nec_mixer[] = {
8959         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
8960         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
8961
8962         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8963         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8964         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8965
8966         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8967         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8968         { } /* end */
8969 };
8970
8971 static struct hda_verb alc262_nec_verbs[] = {
8972         /* Unmute Speaker */
8973         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8974
8975         /* Headphone */
8976         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8977         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8978
8979         /* External mic to headphone */
8980         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8981         /* External mic to speaker */
8982         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8983         {}
8984 };
8985
8986 /*
8987  * fujitsu model
8988  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
8989  *  0x1b = port replicator headphone out
8990  */
8991
8992 #define ALC_HP_EVENT    0x37
8993
8994 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
8995         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8996         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8997         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8998         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8999         {}
9000 };
9001
9002 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
9003         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9004         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9005         {}
9006 };
9007
9008 static struct hda_input_mux alc262_fujitsu_capture_source = {
9009         .num_items = 3,
9010         .items = {
9011                 { "Mic", 0x0 },
9012                 { "Int Mic", 0x1 },
9013                 { "CD", 0x4 },
9014         },
9015 };
9016
9017 static struct hda_input_mux alc262_HP_capture_source = {
9018         .num_items = 5,
9019         .items = {
9020                 { "Mic", 0x0 },
9021                 { "Front Mic", 0x1 },
9022                 { "Line", 0x2 },
9023                 { "CD", 0x4 },
9024                 { "AUX IN", 0x6 },
9025         },
9026 };
9027
9028 static struct hda_input_mux alc262_HP_D7000_capture_source = {
9029         .num_items = 4,
9030         .items = {
9031                 { "Mic", 0x0 },
9032                 { "Front Mic", 0x2 },
9033                 { "Line", 0x1 },
9034                 { "CD", 0x4 },
9035         },
9036 };
9037
9038 /* mute/unmute internal speaker according to the hp jacks and mute state */
9039 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
9040 {
9041         struct alc_spec *spec = codec->spec;
9042         unsigned int mute;
9043
9044         if (force || !spec->sense_updated) {
9045                 unsigned int present;
9046                 /* need to execute and sync at first */
9047                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
9048                 /* check laptop HP jack */
9049                 present = snd_hda_codec_read(codec, 0x14, 0,
9050                                              AC_VERB_GET_PIN_SENSE, 0);
9051                 /* need to execute and sync at first */
9052                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9053                 /* check docking HP jack */
9054                 present |= snd_hda_codec_read(codec, 0x1b, 0,
9055                                               AC_VERB_GET_PIN_SENSE, 0);
9056                 if (present & AC_PINSENSE_PRESENCE)
9057                         spec->jack_present = 1;
9058                 else
9059                         spec->jack_present = 0;
9060                 spec->sense_updated = 1;
9061         }
9062         /* unmute internal speaker only if both HPs are unplugged and
9063          * master switch is on
9064          */
9065         if (spec->jack_present)
9066                 mute = HDA_AMP_MUTE;
9067         else
9068                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9069         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9070                                  HDA_AMP_MUTE, mute);
9071 }
9072
9073 /* unsolicited event for HP jack sensing */
9074 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
9075                                        unsigned int res)
9076 {
9077         if ((res >> 26) != ALC_HP_EVENT)
9078                 return;
9079         alc262_fujitsu_automute(codec, 1);
9080 }
9081
9082 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
9083 {
9084         alc262_fujitsu_automute(codec, 1);
9085 }
9086
9087 /* bind volumes of both NID 0x0c and 0x0d */
9088 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
9089         .ops = &snd_hda_bind_vol,
9090         .values = {
9091                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
9092                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
9093                 0
9094         },
9095 };
9096
9097 /* mute/unmute internal speaker according to the hp jack and mute state */
9098 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
9099 {
9100         struct alc_spec *spec = codec->spec;
9101         unsigned int mute;
9102
9103         if (force || !spec->sense_updated) {
9104                 unsigned int present_int_hp;
9105                 /* need to execute and sync at first */
9106                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9107                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
9108                                         AC_VERB_GET_PIN_SENSE, 0);
9109                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
9110                 spec->sense_updated = 1;
9111         }
9112         if (spec->jack_present) {
9113                 /* mute internal speaker */
9114                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9115                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9116                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9117                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9118         } else {
9119                 /* unmute internal speaker if necessary */
9120                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9121                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9122                                          HDA_AMP_MUTE, mute);
9123                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9124                                          HDA_AMP_MUTE, mute);
9125         }
9126 }
9127
9128 /* unsolicited event for HP jack sensing */
9129 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
9130                                        unsigned int res)
9131 {
9132         if ((res >> 26) != ALC_HP_EVENT)
9133                 return;
9134         alc262_lenovo_3000_automute(codec, 1);
9135 }
9136
9137 /* bind hp and internal speaker mute (with plug check) */
9138 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
9139                                          struct snd_ctl_elem_value *ucontrol)
9140 {
9141         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9142         long *valp = ucontrol->value.integer.value;
9143         int change;
9144
9145         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9146                                                  HDA_AMP_MUTE,
9147                                                  valp ? 0 : HDA_AMP_MUTE);
9148         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9149                                                  HDA_AMP_MUTE,
9150                                                  valp ? 0 : HDA_AMP_MUTE);
9151
9152         if (change)
9153                 alc262_fujitsu_automute(codec, 0);
9154         return change;
9155 }
9156
9157 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
9158         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9159         {
9160                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9161                 .name = "Master Playback Switch",
9162                 .info = snd_hda_mixer_amp_switch_info,
9163                 .get = snd_hda_mixer_amp_switch_get,
9164                 .put = alc262_fujitsu_master_sw_put,
9165                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9166         },
9167         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9168         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9169         HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
9170         HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
9171         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9172         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9173         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9174         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9175         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9176         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9177         { } /* end */
9178 };
9179
9180 /* bind hp and internal speaker mute (with plug check) */
9181 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
9182                                          struct snd_ctl_elem_value *ucontrol)
9183 {
9184         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9185         long *valp = ucontrol->value.integer.value;
9186         int change;
9187
9188         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9189                                                  HDA_AMP_MUTE,
9190                                                  valp ? 0 : HDA_AMP_MUTE);
9191
9192         if (change)
9193                 alc262_lenovo_3000_automute(codec, 0);
9194         return change;
9195 }
9196
9197 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
9198         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9199         {
9200                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9201                 .name = "Master Playback Switch",
9202                 .info = snd_hda_mixer_amp_switch_info,
9203                 .get = snd_hda_mixer_amp_switch_get,
9204                 .put = alc262_lenovo_3000_master_sw_put,
9205                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
9206         },
9207         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9208         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9209         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9210         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9211         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9212         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9213         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9214         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9215         { } /* end */
9216 };
9217
9218 /* additional init verbs for Benq laptops */
9219 static struct hda_verb alc262_EAPD_verbs[] = {
9220         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9221         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
9222         {}
9223 };
9224
9225 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
9226         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9227         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9228
9229         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9230         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
9231         {}
9232 };
9233
9234 /* Samsung Q1 Ultra Vista model setup */
9235 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
9236         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9237         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
9238         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9239         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9240         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
9241         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
9242         { } /* end */
9243 };
9244
9245 static struct hda_verb alc262_ultra_verbs[] = {
9246         /* output mixer */
9247         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9248         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9249         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9250         /* speaker */
9251         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9252         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9253         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9254         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9255         /* HP */
9256         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9257         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9258         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9259         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9260         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9261         /* internal mic */
9262         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9263         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9264         /* ADC, choose mic */
9265         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9266         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9267         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9268         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9269         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9270         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9271         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9272         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9273         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
9274         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
9275         {}
9276 };
9277
9278 /* mute/unmute internal speaker according to the hp jack and mute state */
9279 static void alc262_ultra_automute(struct hda_codec *codec)
9280 {
9281         struct alc_spec *spec = codec->spec;
9282         unsigned int mute;
9283
9284         mute = 0;
9285         /* auto-mute only when HP is used as HP */
9286         if (!spec->cur_mux[0]) {
9287                 unsigned int present;
9288                 /* need to execute and sync at first */
9289                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9290                 present = snd_hda_codec_read(codec, 0x15, 0,
9291                                              AC_VERB_GET_PIN_SENSE, 0);
9292                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9293                 if (spec->jack_present)
9294                         mute = HDA_AMP_MUTE;
9295         }
9296         /* mute/unmute internal speaker */
9297         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9298                                  HDA_AMP_MUTE, mute);
9299         /* mute/unmute HP */
9300         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9301                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
9302 }
9303
9304 /* unsolicited event for HP jack sensing */
9305 static void alc262_ultra_unsol_event(struct hda_codec *codec,
9306                                        unsigned int res)
9307 {
9308         if ((res >> 26) != ALC880_HP_EVENT)
9309                 return;
9310         alc262_ultra_automute(codec);
9311 }
9312
9313 static struct hda_input_mux alc262_ultra_capture_source = {
9314         .num_items = 2,
9315         .items = {
9316                 { "Mic", 0x1 },
9317                 { "Headphone", 0x7 },
9318         },
9319 };
9320
9321 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
9322                                      struct snd_ctl_elem_value *ucontrol)
9323 {
9324         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9325         struct alc_spec *spec = codec->spec;
9326         int ret;
9327
9328         ret = alc882_mux_enum_put(kcontrol, ucontrol);
9329         if (!ret)
9330                 return 0;
9331         /* reprogram the HP pin as mic or HP according to the input source */
9332         snd_hda_codec_write_cache(codec, 0x15, 0,
9333                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9334                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
9335         alc262_ultra_automute(codec); /* mute/unmute HP */
9336         return ret;
9337 }
9338
9339 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
9340         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
9341         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
9342         {
9343                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9344                 .name = "Capture Source",
9345                 .info = alc882_mux_enum_info,
9346                 .get = alc882_mux_enum_get,
9347                 .put = alc262_ultra_mux_enum_put,
9348         },
9349         { } /* end */
9350 };
9351
9352 /* add playback controls from the parsed DAC table */
9353 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
9354                                              const struct auto_pin_cfg *cfg)
9355 {
9356         hda_nid_t nid;
9357         int err;
9358
9359         spec->multiout.num_dacs = 1;    /* only use one dac */
9360         spec->multiout.dac_nids = spec->private_dac_nids;
9361         spec->multiout.dac_nids[0] = 2;
9362
9363         nid = cfg->line_out_pins[0];
9364         if (nid) {
9365                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9366                                   "Front Playback Volume",
9367                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
9368                 if (err < 0)
9369                         return err;
9370                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9371                                   "Front Playback Switch",
9372                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
9373                 if (err < 0)
9374                         return err;
9375         }
9376
9377         nid = cfg->speaker_pins[0];
9378         if (nid) {
9379                 if (nid == 0x16) {
9380                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9381                                           "Speaker Playback Volume",
9382                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9383                                                               HDA_OUTPUT));
9384                         if (err < 0)
9385                                 return err;
9386                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9387                                           "Speaker Playback Switch",
9388                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9389                                                               HDA_OUTPUT));
9390                         if (err < 0)
9391                                 return err;
9392                 } else {
9393                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9394                                           "Speaker Playback Switch",
9395                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9396                                                               HDA_OUTPUT));
9397                         if (err < 0)
9398                                 return err;
9399                 }
9400         }
9401         nid = cfg->hp_pins[0];
9402         if (nid) {
9403                 /* spec->multiout.hp_nid = 2; */
9404                 if (nid == 0x16) {
9405                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9406                                           "Headphone Playback Volume",
9407                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
9408                                                               HDA_OUTPUT));
9409                         if (err < 0)
9410                                 return err;
9411                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9412                                           "Headphone Playback Switch",
9413                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9414                                                               HDA_OUTPUT));
9415                         if (err < 0)
9416                                 return err;
9417                 } else {
9418                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9419                                           "Headphone Playback Switch",
9420                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9421                                                               HDA_OUTPUT));
9422                         if (err < 0)
9423                                 return err;
9424                 }
9425         }
9426         return 0;
9427 }
9428
9429 /* identical with ALC880 */
9430 #define alc262_auto_create_analog_input_ctls \
9431         alc880_auto_create_analog_input_ctls
9432
9433 /*
9434  * generic initialization of ADC, input mixers and output mixers
9435  */
9436 static struct hda_verb alc262_volume_init_verbs[] = {
9437         /*
9438          * Unmute ADC0-2 and set the default input to mic-in
9439          */
9440         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9441         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9442         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9443         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9444         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9445         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9446
9447         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9448          * mixer widget
9449          * Note: PASD motherboards uses the Line In 2 as the input for
9450          * front panel mic (mic 2)
9451          */
9452         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9453         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9454         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9455         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9456         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9457         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9458
9459         /*
9460          * Set up output mixers (0x0c - 0x0f)
9461          */
9462         /* set vol=0 to output mixers */
9463         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9464         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9465         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9466         
9467         /* set up input amps for analog loopback */
9468         /* Amp Indices: DAC = 0, mixer = 1 */
9469         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9470         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9471         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9472         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9473         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9474         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9475
9476         /* FIXME: use matrix-type input source selection */
9477         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9478         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9479         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9480         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9481         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9482         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9483         /* Input mixer2 */
9484         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9485         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9486         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9487         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9488         /* Input mixer3 */
9489         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9490         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9491         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9492         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9493
9494         { }
9495 };
9496
9497 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
9498         /*
9499          * Unmute ADC0-2 and set the default input to mic-in
9500          */
9501         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9502         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9503         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9504         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9505         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9506         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9507
9508         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9509          * mixer widget
9510          * Note: PASD motherboards uses the Line In 2 as the input for
9511          * front panel mic (mic 2)
9512          */
9513         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9514         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9515         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9516         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9517         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9518         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9519         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9520         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9521         
9522         /*
9523          * Set up output mixers (0x0c - 0x0e)
9524          */
9525         /* set vol=0 to output mixers */
9526         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9527         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9528         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9529
9530         /* set up input amps for analog loopback */
9531         /* Amp Indices: DAC = 0, mixer = 1 */
9532         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9533         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9534         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9535         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9536         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9537         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9538
9539         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9540         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9541         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9542
9543         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9544         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9545
9546         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9547         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9548
9549         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9550         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9551         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9552         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9553         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9554
9555         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9556         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9557         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9558         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9559         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9560         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9561
9562
9563         /* FIXME: use matrix-type input source selection */
9564         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9565         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9566         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9567         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9568         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9569         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9570         /* Input mixer2 */
9571         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9572         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9573         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9574         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9575         /* Input mixer3 */
9576         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9577         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9578         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9579         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9580
9581         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9582
9583         { }
9584 };
9585
9586 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
9587         /*
9588          * Unmute ADC0-2 and set the default input to mic-in
9589          */
9590         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9591         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9592         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9593         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9594         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9595         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9596
9597         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9598          * mixer widget
9599          * Note: PASD motherboards uses the Line In 2 as the input for front
9600          * panel mic (mic 2)
9601          */
9602         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9603         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9604         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9605         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9606         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9607         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9608         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9609         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
9610         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
9611         /*
9612          * Set up output mixers (0x0c - 0x0e)
9613          */
9614         /* set vol=0 to output mixers */
9615         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9616         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9617         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9618
9619         /* set up input amps for analog loopback */
9620         /* Amp Indices: DAC = 0, mixer = 1 */
9621         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9622         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9623         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9624         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9625         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9626         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9627
9628
9629         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
9630         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
9631         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
9632         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
9633         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
9634         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
9635         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
9636
9637         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9638         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
9639
9640         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9641         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9642
9643         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
9644         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9645         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9646         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
9647         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9648         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
9649
9650         /* FIXME: use matrix-type input source selection */
9651         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9652         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9653         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
9654         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
9655         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
9656         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
9657         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
9658         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
9659         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
9660         /* Input mixer2 */
9661         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9662         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9663         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9664         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9665         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9666         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
9667         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
9668         /* Input mixer3 */
9669         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9670         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9671         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9672         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9673         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
9674         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
9675         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
9676
9677         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9678
9679         { }
9680 };
9681
9682 #ifdef CONFIG_SND_HDA_POWER_SAVE
9683 #define alc262_loopbacks        alc880_loopbacks
9684 #endif
9685
9686 /* pcm configuration: identiacal with ALC880 */
9687 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
9688 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
9689 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
9690 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
9691
9692 /*
9693  * BIOS auto configuration
9694  */
9695 static int alc262_parse_auto_config(struct hda_codec *codec)
9696 {
9697         struct alc_spec *spec = codec->spec;
9698         int err;
9699         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
9700
9701         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9702                                            alc262_ignore);
9703         if (err < 0)
9704                 return err;
9705         if (!spec->autocfg.line_outs)
9706                 return 0; /* can't find valid BIOS pin config */
9707         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
9708         if (err < 0)
9709                 return err;
9710         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
9711         if (err < 0)
9712                 return err;
9713
9714         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
9715
9716         if (spec->autocfg.dig_out_pin)
9717                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
9718         if (spec->autocfg.dig_in_pin)
9719                 spec->dig_in_nid = ALC262_DIGIN_NID;
9720
9721         if (spec->kctl_alloc)
9722                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
9723
9724         spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs;
9725         spec->num_mux_defs = 1;
9726         spec->input_mux = &spec->private_imux;
9727
9728         err = alc_auto_add_mic_boost(codec);
9729         if (err < 0)
9730                 return err;
9731
9732         return 1;
9733 }
9734
9735 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
9736 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
9737 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
9738 #define alc262_auto_init_input_src      alc882_auto_init_input_src
9739
9740
9741 /* init callback for auto-configuration model -- overriding the default init */
9742 static void alc262_auto_init(struct hda_codec *codec)
9743 {
9744         struct alc_spec *spec = codec->spec;
9745         alc262_auto_init_multi_out(codec);
9746         alc262_auto_init_hp_out(codec);
9747         alc262_auto_init_analog_input(codec);
9748         alc262_auto_init_input_src(codec);
9749         if (spec->unsol_event)
9750                 alc_sku_automute(codec);
9751 }
9752
9753 /*
9754  * configuration and preset
9755  */
9756 static const char *alc262_models[ALC262_MODEL_LAST] = {
9757         [ALC262_BASIC]          = "basic",
9758         [ALC262_HIPPO]          = "hippo",
9759         [ALC262_HIPPO_1]        = "hippo_1",
9760         [ALC262_FUJITSU]        = "fujitsu",
9761         [ALC262_HP_BPC]         = "hp-bpc",
9762         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
9763         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
9764         [ALC262_HP_RP5700]      = "hp-rp5700",
9765         [ALC262_BENQ_ED8]       = "benq",
9766         [ALC262_BENQ_T31]       = "benq-t31",
9767         [ALC262_SONY_ASSAMD]    = "sony-assamd",
9768         [ALC262_ULTRA]          = "ultra",
9769         [ALC262_LENOVO_3000]    = "lenovo-3000",
9770         [ALC262_NEC]            = "nec",
9771         [ALC262_AUTO]           = "auto",
9772 };
9773
9774 static struct snd_pci_quirk alc262_cfg_tbl[] = {
9775         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
9776         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
9777         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
9778         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
9779         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
9780         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
9781         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
9782         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
9783         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
9784         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
9785         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
9786         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
9787         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
9788         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
9789         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
9790         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
9791         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
9792         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
9793         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
9794         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
9795         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
9796         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
9797                       ALC262_HP_TC_T5735),
9798         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
9799         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9800         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
9801         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9802         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
9803         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
9804         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
9805                       ALC262_SONY_ASSAMD),
9806         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
9807         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
9808         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
9809         SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
9810         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
9811         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
9812         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
9813         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
9814         {}
9815 };
9816
9817 static struct alc_config_preset alc262_presets[] = {
9818         [ALC262_BASIC] = {
9819                 .mixers = { alc262_base_mixer },
9820                 .init_verbs = { alc262_init_verbs },
9821                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9822                 .dac_nids = alc262_dac_nids,
9823                 .hp_nid = 0x03,
9824                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9825                 .channel_mode = alc262_modes,
9826                 .input_mux = &alc262_capture_source,
9827         },
9828         [ALC262_HIPPO] = {
9829                 .mixers = { alc262_base_mixer },
9830                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
9831                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9832                 .dac_nids = alc262_dac_nids,
9833                 .hp_nid = 0x03,
9834                 .dig_out_nid = ALC262_DIGOUT_NID,
9835                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9836                 .channel_mode = alc262_modes,
9837                 .input_mux = &alc262_capture_source,
9838                 .unsol_event = alc262_hippo_unsol_event,
9839                 .init_hook = alc262_hippo_automute,
9840         },
9841         [ALC262_HIPPO_1] = {
9842                 .mixers = { alc262_hippo1_mixer },
9843                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
9844                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9845                 .dac_nids = alc262_dac_nids,
9846                 .hp_nid = 0x02,
9847                 .dig_out_nid = ALC262_DIGOUT_NID,
9848                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9849                 .channel_mode = alc262_modes,
9850                 .input_mux = &alc262_capture_source,
9851                 .unsol_event = alc262_hippo1_unsol_event,
9852                 .init_hook = alc262_hippo1_automute,
9853         },
9854         [ALC262_FUJITSU] = {
9855                 .mixers = { alc262_fujitsu_mixer },
9856                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
9857                                 alc262_fujitsu_unsol_verbs },
9858                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9859                 .dac_nids = alc262_dac_nids,
9860                 .hp_nid = 0x03,
9861                 .dig_out_nid = ALC262_DIGOUT_NID,
9862                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9863                 .channel_mode = alc262_modes,
9864                 .input_mux = &alc262_fujitsu_capture_source,
9865                 .unsol_event = alc262_fujitsu_unsol_event,
9866                 .init_hook = alc262_fujitsu_init_hook,
9867         },
9868         [ALC262_HP_BPC] = {
9869                 .mixers = { alc262_HP_BPC_mixer },
9870                 .init_verbs = { alc262_HP_BPC_init_verbs },
9871                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9872                 .dac_nids = alc262_dac_nids,
9873                 .hp_nid = 0x03,
9874                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9875                 .channel_mode = alc262_modes,
9876                 .input_mux = &alc262_HP_capture_source,
9877                 .unsol_event = alc262_hp_bpc_unsol_event,
9878                 .init_hook = alc262_hp_bpc_automute,
9879         },
9880         [ALC262_HP_BPC_D7000_WF] = {
9881                 .mixers = { alc262_HP_BPC_WildWest_mixer },
9882                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
9883                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9884                 .dac_nids = alc262_dac_nids,
9885                 .hp_nid = 0x03,
9886                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9887                 .channel_mode = alc262_modes,
9888                 .input_mux = &alc262_HP_D7000_capture_source,
9889                 .unsol_event = alc262_hp_wildwest_unsol_event,
9890                 .init_hook = alc262_hp_wildwest_automute,
9891         },
9892         [ALC262_HP_BPC_D7000_WL] = {
9893                 .mixers = { alc262_HP_BPC_WildWest_mixer,
9894                             alc262_HP_BPC_WildWest_option_mixer },
9895                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
9896                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9897                 .dac_nids = alc262_dac_nids,
9898                 .hp_nid = 0x03,
9899                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9900                 .channel_mode = alc262_modes,
9901                 .input_mux = &alc262_HP_D7000_capture_source,
9902                 .unsol_event = alc262_hp_wildwest_unsol_event,
9903                 .init_hook = alc262_hp_wildwest_automute,
9904         },
9905         [ALC262_HP_TC_T5735] = {
9906                 .mixers = { alc262_hp_t5735_mixer },
9907                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
9908                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9909                 .dac_nids = alc262_dac_nids,
9910                 .hp_nid = 0x03,
9911                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9912                 .channel_mode = alc262_modes,
9913                 .input_mux = &alc262_capture_source,
9914                 .unsol_event = alc262_hp_t5735_unsol_event,
9915                 .init_hook = alc262_hp_t5735_init_hook,
9916         },
9917         [ALC262_HP_RP5700] = {
9918                 .mixers = { alc262_hp_rp5700_mixer },
9919                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
9920                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9921                 .dac_nids = alc262_dac_nids,
9922                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9923                 .channel_mode = alc262_modes,
9924                 .input_mux = &alc262_hp_rp5700_capture_source,
9925         },
9926         [ALC262_BENQ_ED8] = {
9927                 .mixers = { alc262_base_mixer },
9928                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
9929                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9930                 .dac_nids = alc262_dac_nids,
9931                 .hp_nid = 0x03,
9932                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9933                 .channel_mode = alc262_modes,
9934                 .input_mux = &alc262_capture_source,
9935         },
9936         [ALC262_SONY_ASSAMD] = {
9937                 .mixers = { alc262_sony_mixer },
9938                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
9939                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9940                 .dac_nids = alc262_dac_nids,
9941                 .hp_nid = 0x02,
9942                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9943                 .channel_mode = alc262_modes,
9944                 .input_mux = &alc262_capture_source,
9945                 .unsol_event = alc262_hippo_unsol_event,
9946                 .init_hook = alc262_hippo_automute,
9947         },
9948         [ALC262_BENQ_T31] = {
9949                 .mixers = { alc262_benq_t31_mixer },
9950                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
9951                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9952                 .dac_nids = alc262_dac_nids,
9953                 .hp_nid = 0x03,
9954                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9955                 .channel_mode = alc262_modes,
9956                 .input_mux = &alc262_capture_source,
9957                 .unsol_event = alc262_hippo_unsol_event,
9958                 .init_hook = alc262_hippo_automute,
9959         },      
9960         [ALC262_ULTRA] = {
9961                 .mixers = { alc262_ultra_mixer, alc262_ultra_capture_mixer },
9962                 .init_verbs = { alc262_ultra_verbs },
9963                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9964                 .dac_nids = alc262_dac_nids,
9965                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9966                 .channel_mode = alc262_modes,
9967                 .input_mux = &alc262_ultra_capture_source,
9968                 .adc_nids = alc262_adc_nids, /* ADC0 */
9969                 .capsrc_nids = alc262_capsrc_nids,
9970                 .num_adc_nids = 1, /* single ADC */
9971                 .unsol_event = alc262_ultra_unsol_event,
9972                 .init_hook = alc262_ultra_automute,
9973         },
9974         [ALC262_LENOVO_3000] = {
9975                 .mixers = { alc262_lenovo_3000_mixer },
9976                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
9977                                 alc262_lenovo_3000_unsol_verbs },
9978                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9979                 .dac_nids = alc262_dac_nids,
9980                 .hp_nid = 0x03,
9981                 .dig_out_nid = ALC262_DIGOUT_NID,
9982                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9983                 .channel_mode = alc262_modes,
9984                 .input_mux = &alc262_fujitsu_capture_source,
9985                 .unsol_event = alc262_lenovo_3000_unsol_event,
9986         },
9987         [ALC262_NEC] = {
9988                 .mixers = { alc262_nec_mixer },
9989                 .init_verbs = { alc262_nec_verbs },
9990                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9991                 .dac_nids = alc262_dac_nids,
9992                 .hp_nid = 0x03,
9993                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9994                 .channel_mode = alc262_modes,
9995                 .input_mux = &alc262_capture_source,
9996         },
9997 };
9998
9999 static int patch_alc262(struct hda_codec *codec)
10000 {
10001         struct alc_spec *spec;
10002         int board_config;
10003         int err;
10004
10005         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10006         if (spec == NULL)
10007                 return -ENOMEM;
10008
10009         codec->spec = spec;
10010 #if 0
10011         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
10012          * under-run
10013          */
10014         {
10015         int tmp;
10016         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10017         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
10018         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10019         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
10020         }
10021 #endif
10022
10023         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
10024
10025         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
10026                                                   alc262_models,
10027                                                   alc262_cfg_tbl);
10028
10029         if (board_config < 0) {
10030                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
10031                        "trying auto-probe from BIOS...\n");
10032                 board_config = ALC262_AUTO;
10033         }
10034
10035         if (board_config == ALC262_AUTO) {
10036                 /* automatic parse from the BIOS config */
10037                 err = alc262_parse_auto_config(codec);
10038                 if (err < 0) {
10039                         alc_free(codec);
10040                         return err;
10041                 } else if (!err) {
10042                         printk(KERN_INFO
10043                                "hda_codec: Cannot set up configuration "
10044                                "from BIOS.  Using base mode...\n");
10045                         board_config = ALC262_BASIC;
10046                 }
10047         }
10048
10049         if (board_config != ALC262_AUTO)
10050                 setup_preset(spec, &alc262_presets[board_config]);
10051
10052         spec->stream_name_analog = "ALC262 Analog";
10053         spec->stream_analog_playback = &alc262_pcm_analog_playback;
10054         spec->stream_analog_capture = &alc262_pcm_analog_capture;
10055                 
10056         spec->stream_name_digital = "ALC262 Digital";
10057         spec->stream_digital_playback = &alc262_pcm_digital_playback;
10058         spec->stream_digital_capture = &alc262_pcm_digital_capture;
10059
10060         if (!spec->adc_nids && spec->input_mux) {
10061                 /* check whether NID 0x07 is valid */
10062                 unsigned int wcap = get_wcaps(codec, 0x07);
10063
10064                 /* get type */
10065                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10066                 if (wcap != AC_WID_AUD_IN) {
10067                         spec->adc_nids = alc262_adc_nids_alt;
10068                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
10069                         spec->capsrc_nids = alc262_capsrc_nids_alt;
10070                         spec->mixers[spec->num_mixers] =
10071                                 alc262_capture_alt_mixer;
10072                         spec->num_mixers++;
10073                 } else {
10074                         spec->adc_nids = alc262_adc_nids;
10075                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
10076                         spec->capsrc_nids = alc262_capsrc_nids;
10077                         spec->mixers[spec->num_mixers] = alc262_capture_mixer;
10078                         spec->num_mixers++;
10079                 }
10080         }
10081
10082         spec->vmaster_nid = 0x0c;
10083
10084         codec->patch_ops = alc_patch_ops;
10085         if (board_config == ALC262_AUTO)
10086                 spec->init_hook = alc262_auto_init;
10087 #ifdef CONFIG_SND_HDA_POWER_SAVE
10088         if (!spec->loopback.amplist)
10089                 spec->loopback.amplist = alc262_loopbacks;
10090 #endif
10091                 
10092         return 0;
10093 }
10094
10095 /*
10096  *  ALC268 channel source setting (2 channel)
10097  */
10098 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
10099 #define alc268_modes            alc260_modes
10100         
10101 static hda_nid_t alc268_dac_nids[2] = {
10102         /* front, hp */
10103         0x02, 0x03
10104 };
10105
10106 static hda_nid_t alc268_adc_nids[2] = {
10107         /* ADC0-1 */
10108         0x08, 0x07
10109 };
10110
10111 static hda_nid_t alc268_adc_nids_alt[1] = {
10112         /* ADC0 */
10113         0x08
10114 };
10115
10116 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
10117
10118 static struct snd_kcontrol_new alc268_base_mixer[] = {
10119         /* output mixer control */
10120         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10121         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10122         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10123         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10124         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10125         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10126         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10127         { }
10128 };
10129
10130 /* bind Beep switches of both NID 0x0f and 0x10 */
10131 static struct hda_bind_ctls alc268_bind_beep_sw = {
10132         .ops = &snd_hda_bind_sw,
10133         .values = {
10134                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
10135                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
10136                 0
10137         },
10138 };
10139
10140 static struct snd_kcontrol_new alc268_beep_mixer[] = {
10141         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
10142         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
10143         { }
10144 };
10145
10146 static struct hda_verb alc268_eapd_verbs[] = {
10147         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10148         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10149         { }
10150 };
10151
10152 /* Toshiba specific */
10153 #define alc268_toshiba_automute alc262_hippo_automute
10154
10155 static struct hda_verb alc268_toshiba_verbs[] = {
10156         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10157         { } /* end */
10158 };
10159
10160 /* Acer specific */
10161 /* bind volumes of both NID 0x02 and 0x03 */
10162 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
10163         .ops = &snd_hda_bind_vol,
10164         .values = {
10165                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
10166                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
10167                 0
10168         },
10169 };
10170
10171 /* mute/unmute internal speaker according to the hp jack and mute state */
10172 static void alc268_acer_automute(struct hda_codec *codec, int force)
10173 {
10174         struct alc_spec *spec = codec->spec;
10175         unsigned int mute;
10176
10177         if (force || !spec->sense_updated) {
10178                 unsigned int present;
10179                 present = snd_hda_codec_read(codec, 0x14, 0,
10180                                          AC_VERB_GET_PIN_SENSE, 0);
10181                 spec->jack_present = (present & 0x80000000) != 0;
10182                 spec->sense_updated = 1;
10183         }
10184         if (spec->jack_present)
10185                 mute = HDA_AMP_MUTE; /* mute internal speaker */
10186         else /* unmute internal speaker if necessary */
10187                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10188         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10189                                  HDA_AMP_MUTE, mute);
10190 }
10191
10192
10193 /* bind hp and internal speaker mute (with plug check) */
10194 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
10195                                      struct snd_ctl_elem_value *ucontrol)
10196 {
10197         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10198         long *valp = ucontrol->value.integer.value;
10199         int change;
10200
10201         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
10202                                           HDA_AMP_MUTE,
10203                                           valp[0] ? 0 : HDA_AMP_MUTE);
10204         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
10205                                            HDA_AMP_MUTE,
10206                                            valp[1] ? 0 : HDA_AMP_MUTE);
10207         if (change)
10208                 alc268_acer_automute(codec, 0);
10209         return change;
10210 }
10211
10212 static struct snd_kcontrol_new alc268_acer_mixer[] = {
10213         /* output mixer control */
10214         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
10215         {
10216                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10217                 .name = "Master Playback Switch",
10218                 .info = snd_hda_mixer_amp_switch_info,
10219                 .get = snd_hda_mixer_amp_switch_get,
10220                 .put = alc268_acer_master_sw_put,
10221                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10222         },
10223         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10224         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
10225         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10226         { }
10227 };
10228
10229 static struct hda_verb alc268_acer_verbs[] = {
10230         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
10231         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10232         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10233         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10234         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10235         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10236
10237         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10238         { }
10239 };
10240
10241 /* unsolicited event for HP jack sensing */
10242 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
10243                                        unsigned int res)
10244 {
10245         if ((res >> 26) != ALC880_HP_EVENT)
10246                 return;
10247         alc268_toshiba_automute(codec);
10248 }
10249
10250 static void alc268_acer_unsol_event(struct hda_codec *codec,
10251                                        unsigned int res)
10252 {
10253         if ((res >> 26) != ALC880_HP_EVENT)
10254                 return;
10255         alc268_acer_automute(codec, 1);
10256 }
10257
10258 static void alc268_acer_init_hook(struct hda_codec *codec)
10259 {
10260         alc268_acer_automute(codec, 1);
10261 }
10262
10263 static struct snd_kcontrol_new alc268_dell_mixer[] = {
10264         /* output mixer control */
10265         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10266         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10267         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10268         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10269         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10270         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
10271         { }
10272 };
10273
10274 static struct hda_verb alc268_dell_verbs[] = {
10275         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10276         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10277         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10278         { }
10279 };
10280
10281 /* mute/unmute internal speaker according to the hp jack and mute state */
10282 static void alc268_dell_automute(struct hda_codec *codec)
10283 {
10284         unsigned int present;
10285         unsigned int mute;
10286
10287         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
10288         if (present & 0x80000000)
10289                 mute = HDA_AMP_MUTE;
10290         else
10291                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
10292         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10293                                  HDA_AMP_MUTE, mute);
10294 }
10295
10296 static void alc268_dell_unsol_event(struct hda_codec *codec,
10297                                     unsigned int res)
10298 {
10299         if ((res >> 26) != ALC880_HP_EVENT)
10300                 return;
10301         alc268_dell_automute(codec);
10302 }
10303
10304 #define alc268_dell_init_hook   alc268_dell_automute
10305
10306 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
10307         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10308         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10309         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10310         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10311         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10312         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
10313         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
10314         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10315         { }
10316 };
10317
10318 static struct hda_verb alc267_quanta_il1_verbs[] = {
10319         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10320         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
10321         { }
10322 };
10323
10324 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
10325 {
10326         unsigned int present;
10327
10328         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
10329                 & AC_PINSENSE_PRESENCE;
10330         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
10331                             present ? 0 : PIN_OUT);
10332 }
10333
10334 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
10335 {
10336         unsigned int present;
10337
10338         present = snd_hda_codec_read(codec, 0x18, 0,
10339                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10340         snd_hda_codec_write(codec, 0x23, 0,
10341                             AC_VERB_SET_CONNECT_SEL,
10342                             present ? 0x00 : 0x01);
10343 }
10344
10345 static void alc267_quanta_il1_automute(struct hda_codec *codec)
10346 {
10347         alc267_quanta_il1_hp_automute(codec);
10348         alc267_quanta_il1_mic_automute(codec);
10349 }
10350
10351 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
10352                                            unsigned int res)
10353 {
10354         switch (res >> 26) {
10355         case ALC880_HP_EVENT:
10356                 alc267_quanta_il1_hp_automute(codec);
10357                 break;
10358         case ALC880_MIC_EVENT:
10359                 alc267_quanta_il1_mic_automute(codec);
10360                 break;
10361         }
10362 }
10363
10364 /*
10365  * generic initialization of ADC, input mixers and output mixers
10366  */
10367 static struct hda_verb alc268_base_init_verbs[] = {
10368         /* Unmute DAC0-1 and set vol = 0 */
10369         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10370         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10371         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10372         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10373         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10374         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10375
10376         /*
10377          * Set up output mixers (0x0c - 0x0e)
10378          */
10379         /* set vol=0 to output mixers */
10380         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10381         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10382         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10383         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
10384
10385         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10386         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10387
10388         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10389         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10390         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10391         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10392         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10393         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10394         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10395         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10396
10397         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10398         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10399         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10400         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10401         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10402         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10403         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10404
10405         /* set PCBEEP vol = 0, mute connections */
10406         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10407         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10408         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10409
10410         /* Unmute Selector 23h,24h and set the default input to mic-in */
10411         
10412         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
10413         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10414         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
10415         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10416
10417         { }
10418 };
10419
10420 /*
10421  * generic initialization of ADC, input mixers and output mixers
10422  */
10423 static struct hda_verb alc268_volume_init_verbs[] = {
10424         /* set output DAC */
10425         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10426         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10427         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10428         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10429
10430         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10431         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10432         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10433         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10434         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10435
10436         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10437         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10438         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10439         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10440         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10441
10442         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10443         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10444         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10445         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10446
10447         /* set PCBEEP vol = 0, mute connections */
10448         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10449         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10450         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10451
10452         { }
10453 };
10454
10455 #define alc268_mux_enum_info alc_mux_enum_info
10456 #define alc268_mux_enum_get alc_mux_enum_get
10457 #define alc268_mux_enum_put alc_mux_enum_put
10458
10459 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
10460         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10461         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
10462         {
10463                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10464                 /* The multiple "Capture Source" controls confuse alsamixer
10465                  * So call somewhat different..
10466                  */
10467                 /* .name = "Capture Source", */
10468                 .name = "Input Source",
10469                 .count = 1,
10470                 .info = alc268_mux_enum_info,
10471                 .get = alc268_mux_enum_get,
10472                 .put = alc268_mux_enum_put,
10473         },
10474         { } /* end */
10475 };
10476
10477 static struct snd_kcontrol_new alc268_capture_mixer[] = {
10478         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10479         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
10480         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
10481         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
10482         {
10483                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10484                 /* The multiple "Capture Source" controls confuse alsamixer
10485                  * So call somewhat different..
10486                  */
10487                 /* .name = "Capture Source", */
10488                 .name = "Input Source",
10489                 .count = 2,
10490                 .info = alc268_mux_enum_info,
10491                 .get = alc268_mux_enum_get,
10492                 .put = alc268_mux_enum_put,
10493         },
10494         { } /* end */
10495 };
10496
10497 static struct hda_input_mux alc268_capture_source = {
10498         .num_items = 4,
10499         .items = {
10500                 { "Mic", 0x0 },
10501                 { "Front Mic", 0x1 },
10502                 { "Line", 0x2 },
10503                 { "CD", 0x3 },
10504         },
10505 };
10506
10507 static struct hda_input_mux alc268_acer_capture_source = {
10508         .num_items = 3,
10509         .items = {
10510                 { "Mic", 0x0 },
10511                 { "Internal Mic", 0x6 },
10512                 { "Line", 0x2 },
10513         },
10514 };
10515
10516 #ifdef CONFIG_SND_DEBUG
10517 static struct snd_kcontrol_new alc268_test_mixer[] = {
10518         /* Volume widgets */
10519         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10520         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10521         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
10522         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
10523         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
10524         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
10525         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
10526         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
10527         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
10528         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
10529         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
10530         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
10531         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
10532         /* The below appears problematic on some hardwares */
10533         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
10534         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
10535         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
10536         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
10537         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
10538
10539         /* Modes for retasking pin widgets */
10540         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
10541         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
10542         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
10543         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
10544
10545         /* Controls for GPIO pins, assuming they are configured as outputs */
10546         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
10547         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
10548         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
10549         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
10550
10551         /* Switches to allow the digital SPDIF output pin to be enabled.
10552          * The ALC268 does not have an SPDIF input.
10553          */
10554         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
10555
10556         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
10557          * this output to turn on an external amplifier.
10558          */
10559         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
10560         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
10561
10562         { } /* end */
10563 };
10564 #endif
10565
10566 /* create input playback/capture controls for the given pin */
10567 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
10568                                     const char *ctlname, int idx)
10569 {
10570         char name[32];
10571         int err;
10572
10573         sprintf(name, "%s Playback Volume", ctlname);
10574         if (nid == 0x14) {
10575                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
10576                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
10577                                                       HDA_OUTPUT));
10578                 if (err < 0)
10579                         return err;
10580         } else if (nid == 0x15) {
10581                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
10582                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
10583                                                       HDA_OUTPUT));
10584                 if (err < 0)
10585                         return err;
10586         } else
10587                 return -1;
10588         sprintf(name, "%s Playback Switch", ctlname);
10589         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
10590                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
10591         if (err < 0)
10592                 return err;
10593         return 0;
10594 }
10595
10596 /* add playback controls from the parsed DAC table */
10597 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
10598                                              const struct auto_pin_cfg *cfg)
10599 {
10600         hda_nid_t nid;
10601         int err;
10602
10603         spec->multiout.num_dacs = 2;    /* only use one dac */
10604         spec->multiout.dac_nids = spec->private_dac_nids;
10605         spec->multiout.dac_nids[0] = 2;
10606         spec->multiout.dac_nids[1] = 3;
10607
10608         nid = cfg->line_out_pins[0];
10609         if (nid)
10610                 alc268_new_analog_output(spec, nid, "Front", 0);        
10611
10612         nid = cfg->speaker_pins[0];
10613         if (nid == 0x1d) {
10614                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10615                                   "Speaker Playback Volume",
10616                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
10617                 if (err < 0)
10618                         return err;
10619         }
10620         nid = cfg->hp_pins[0];
10621         if (nid)
10622                 alc268_new_analog_output(spec, nid, "Headphone", 0);
10623
10624         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
10625         if (nid == 0x16) {
10626                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10627                                   "Mono Playback Switch",
10628                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
10629                 if (err < 0)
10630                         return err;
10631         }
10632         return 0;       
10633 }
10634
10635 /* create playback/capture controls for input pins */
10636 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
10637                                                 const struct auto_pin_cfg *cfg)
10638 {
10639         struct hda_input_mux *imux = &spec->private_imux;
10640         int i, idx1;
10641
10642         for (i = 0; i < AUTO_PIN_LAST; i++) {
10643                 switch(cfg->input_pins[i]) {
10644                 case 0x18:
10645                         idx1 = 0;       /* Mic 1 */
10646                         break;
10647                 case 0x19:
10648                         idx1 = 1;       /* Mic 2 */
10649                         break;
10650                 case 0x1a:
10651                         idx1 = 2;       /* Line In */
10652                         break;
10653                 case 0x1c:      
10654                         idx1 = 3;       /* CD */
10655                         break;
10656                 case 0x12:
10657                 case 0x13:
10658                         idx1 = 6;       /* digital mics */
10659                         break;
10660                 default:
10661                         continue;
10662                 }
10663                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
10664                 imux->items[imux->num_items].index = idx1;
10665                 imux->num_items++;      
10666         }
10667         return 0;
10668 }
10669
10670 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
10671 {
10672         struct alc_spec *spec = codec->spec;
10673         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
10674         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10675         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
10676         unsigned int    dac_vol1, dac_vol2;
10677
10678         if (speaker_nid) {
10679                 snd_hda_codec_write(codec, speaker_nid, 0,
10680                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
10681                 snd_hda_codec_write(codec, 0x0f, 0,
10682                                     AC_VERB_SET_AMP_GAIN_MUTE,
10683                                     AMP_IN_UNMUTE(1));
10684                 snd_hda_codec_write(codec, 0x10, 0,
10685                                     AC_VERB_SET_AMP_GAIN_MUTE,
10686                                     AMP_IN_UNMUTE(1));
10687         } else {
10688                 snd_hda_codec_write(codec, 0x0f, 0,
10689                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
10690                 snd_hda_codec_write(codec, 0x10, 0,
10691                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
10692         }
10693
10694         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
10695         if (line_nid == 0x14)   
10696                 dac_vol2 = AMP_OUT_ZERO;
10697         else if (line_nid == 0x15)
10698                 dac_vol1 = AMP_OUT_ZERO;
10699         if (hp_nid == 0x14)     
10700                 dac_vol2 = AMP_OUT_ZERO;
10701         else if (hp_nid == 0x15)
10702                 dac_vol1 = AMP_OUT_ZERO;
10703         if (line_nid != 0x16 || hp_nid != 0x16 ||
10704             spec->autocfg.line_out_pins[1] != 0x16 ||
10705             spec->autocfg.line_out_pins[2] != 0x16)
10706                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
10707
10708         snd_hda_codec_write(codec, 0x02, 0,
10709                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
10710         snd_hda_codec_write(codec, 0x03, 0,
10711                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
10712 }
10713
10714 /* pcm configuration: identiacal with ALC880 */
10715 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
10716 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
10717 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
10718 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
10719
10720 /*
10721  * BIOS auto configuration
10722  */
10723 static int alc268_parse_auto_config(struct hda_codec *codec)
10724 {
10725         struct alc_spec *spec = codec->spec;
10726         int err;
10727         static hda_nid_t alc268_ignore[] = { 0 };
10728
10729         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10730                                            alc268_ignore);
10731         if (err < 0)
10732                 return err;
10733         if (!spec->autocfg.line_outs)
10734                 return 0; /* can't find valid BIOS pin config */
10735
10736         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
10737         if (err < 0)
10738                 return err;
10739         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
10740         if (err < 0)
10741                 return err;
10742
10743         spec->multiout.max_channels = 2;
10744
10745         /* digital only support output */
10746         if (spec->autocfg.dig_out_pin)
10747                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
10748
10749         if (spec->kctl_alloc)
10750                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10751
10752         if (spec->autocfg.speaker_pins[0] != 0x1d)
10753                 spec->mixers[spec->num_mixers++] = alc268_beep_mixer;
10754
10755         spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs;
10756         spec->num_mux_defs = 1;
10757         spec->input_mux = &spec->private_imux;
10758
10759         err = alc_auto_add_mic_boost(codec);
10760         if (err < 0)
10761                 return err;
10762
10763         return 1;
10764 }
10765
10766 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
10767 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
10768 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
10769
10770 /* init callback for auto-configuration model -- overriding the default init */
10771 static void alc268_auto_init(struct hda_codec *codec)
10772 {
10773         struct alc_spec *spec = codec->spec;
10774         alc268_auto_init_multi_out(codec);
10775         alc268_auto_init_hp_out(codec);
10776         alc268_auto_init_mono_speaker_out(codec);
10777         alc268_auto_init_analog_input(codec);
10778         if (spec->unsol_event)
10779                 alc_sku_automute(codec);
10780 }
10781
10782 /*
10783  * configuration and preset
10784  */
10785 static const char *alc268_models[ALC268_MODEL_LAST] = {
10786         [ALC267_QUANTA_IL1]     = "quanta-il1",
10787         [ALC268_3ST]            = "3stack",
10788         [ALC268_TOSHIBA]        = "toshiba",
10789         [ALC268_ACER]           = "acer",
10790         [ALC268_DELL]           = "dell",
10791         [ALC268_ZEPTO]          = "zepto",
10792 #ifdef CONFIG_SND_DEBUG
10793         [ALC268_TEST]           = "test",
10794 #endif
10795         [ALC268_AUTO]           = "auto",
10796 };
10797
10798 static struct snd_pci_quirk alc268_cfg_tbl[] = {
10799         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
10800         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
10801         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
10802         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
10803         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
10804         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
10805         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
10806         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
10807         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
10808         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
10809         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
10810         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
10811         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
10812         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
10813         {}
10814 };
10815
10816 static struct alc_config_preset alc268_presets[] = {
10817         [ALC267_QUANTA_IL1] = {
10818                 .mixers = { alc267_quanta_il1_mixer },
10819                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10820                                 alc267_quanta_il1_verbs },
10821                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10822                 .dac_nids = alc268_dac_nids,
10823                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10824                 .adc_nids = alc268_adc_nids_alt,
10825                 .hp_nid = 0x03,
10826                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10827                 .channel_mode = alc268_modes,
10828                 .input_mux = &alc268_capture_source,
10829                 .unsol_event = alc267_quanta_il1_unsol_event,
10830                 .init_hook = alc267_quanta_il1_automute,
10831         },
10832         [ALC268_3ST] = {
10833                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10834                             alc268_beep_mixer },
10835                 .init_verbs = { alc268_base_init_verbs },
10836                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10837                 .dac_nids = alc268_dac_nids,
10838                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10839                 .adc_nids = alc268_adc_nids_alt,
10840                 .capsrc_nids = alc268_capsrc_nids,
10841                 .hp_nid = 0x03,
10842                 .dig_out_nid = ALC268_DIGOUT_NID,
10843                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10844                 .channel_mode = alc268_modes,
10845                 .input_mux = &alc268_capture_source,
10846         },
10847         [ALC268_TOSHIBA] = {
10848                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10849                             alc268_beep_mixer },
10850                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10851                                 alc268_toshiba_verbs },
10852                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10853                 .dac_nids = alc268_dac_nids,
10854                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10855                 .adc_nids = alc268_adc_nids_alt,
10856                 .capsrc_nids = alc268_capsrc_nids,
10857                 .hp_nid = 0x03,
10858                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10859                 .channel_mode = alc268_modes,
10860                 .input_mux = &alc268_capture_source,
10861                 .unsol_event = alc268_toshiba_unsol_event,
10862                 .init_hook = alc268_toshiba_automute,
10863         },
10864         [ALC268_ACER] = {
10865                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
10866                             alc268_beep_mixer },
10867                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10868                                 alc268_acer_verbs },
10869                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10870                 .dac_nids = alc268_dac_nids,
10871                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10872                 .adc_nids = alc268_adc_nids_alt,
10873                 .capsrc_nids = alc268_capsrc_nids,
10874                 .hp_nid = 0x02,
10875                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10876                 .channel_mode = alc268_modes,
10877                 .input_mux = &alc268_acer_capture_source,
10878                 .unsol_event = alc268_acer_unsol_event,
10879                 .init_hook = alc268_acer_init_hook,
10880         },
10881         [ALC268_DELL] = {
10882                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
10883                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10884                                 alc268_dell_verbs },
10885                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10886                 .dac_nids = alc268_dac_nids,
10887                 .hp_nid = 0x02,
10888                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10889                 .channel_mode = alc268_modes,
10890                 .unsol_event = alc268_dell_unsol_event,
10891                 .init_hook = alc268_dell_init_hook,
10892                 .input_mux = &alc268_capture_source,
10893         },
10894         [ALC268_ZEPTO] = {
10895                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10896                             alc268_beep_mixer },
10897                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10898                                 alc268_toshiba_verbs },
10899                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10900                 .dac_nids = alc268_dac_nids,
10901                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10902                 .adc_nids = alc268_adc_nids_alt,
10903                 .capsrc_nids = alc268_capsrc_nids,
10904                 .hp_nid = 0x03,
10905                 .dig_out_nid = ALC268_DIGOUT_NID,
10906                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10907                 .channel_mode = alc268_modes,
10908                 .input_mux = &alc268_capture_source,
10909                 .unsol_event = alc268_toshiba_unsol_event,
10910                 .init_hook = alc268_toshiba_automute
10911         },
10912 #ifdef CONFIG_SND_DEBUG
10913         [ALC268_TEST] = {
10914                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
10915                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10916                                 alc268_volume_init_verbs },
10917                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10918                 .dac_nids = alc268_dac_nids,
10919                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10920                 .adc_nids = alc268_adc_nids_alt,
10921                 .capsrc_nids = alc268_capsrc_nids,
10922                 .hp_nid = 0x03,
10923                 .dig_out_nid = ALC268_DIGOUT_NID,
10924                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10925                 .channel_mode = alc268_modes,
10926                 .input_mux = &alc268_capture_source,
10927         },
10928 #endif
10929 };
10930
10931 static int patch_alc268(struct hda_codec *codec)
10932 {
10933         struct alc_spec *spec;
10934         int board_config;
10935         int err;
10936
10937         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
10938         if (spec == NULL)
10939                 return -ENOMEM;
10940
10941         codec->spec = spec;
10942
10943         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
10944                                                   alc268_models,
10945                                                   alc268_cfg_tbl);
10946
10947         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
10948                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
10949                        "trying auto-probe from BIOS...\n");
10950                 board_config = ALC268_AUTO;
10951         }
10952
10953         if (board_config == ALC268_AUTO) {
10954                 /* automatic parse from the BIOS config */
10955                 err = alc268_parse_auto_config(codec);
10956                 if (err < 0) {
10957                         alc_free(codec);
10958                         return err;
10959                 } else if (!err) {
10960                         printk(KERN_INFO
10961                                "hda_codec: Cannot set up configuration "
10962                                "from BIOS.  Using base mode...\n");
10963                         board_config = ALC268_3ST;
10964                 }
10965         }
10966
10967         if (board_config != ALC268_AUTO)
10968                 setup_preset(spec, &alc268_presets[board_config]);
10969
10970         if (codec->vendor_id == 0x10ec0267) {
10971                 spec->stream_name_analog = "ALC267 Analog";
10972                 spec->stream_name_digital = "ALC267 Digital";
10973         } else {
10974                 spec->stream_name_analog = "ALC268 Analog";
10975                 spec->stream_name_digital = "ALC268 Digital";
10976         }
10977
10978         spec->stream_analog_playback = &alc268_pcm_analog_playback;
10979         spec->stream_analog_capture = &alc268_pcm_analog_capture;
10980         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
10981
10982         spec->stream_digital_playback = &alc268_pcm_digital_playback;
10983
10984         if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
10985                 /* override the amp caps for beep generator */
10986                 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
10987                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
10988                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
10989                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
10990                                           (0 << AC_AMPCAP_MUTE_SHIFT));
10991
10992         if (!spec->adc_nids && spec->input_mux) {
10993                 /* check whether NID 0x07 is valid */
10994                 unsigned int wcap = get_wcaps(codec, 0x07);
10995                 int i;
10996
10997                 /* get type */
10998                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10999                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
11000                         spec->adc_nids = alc268_adc_nids_alt;
11001                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
11002                         spec->mixers[spec->num_mixers] =
11003                                         alc268_capture_alt_mixer;
11004                         spec->num_mixers++;
11005                 } else {
11006                         spec->adc_nids = alc268_adc_nids;
11007                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
11008                         spec->mixers[spec->num_mixers] =
11009                                 alc268_capture_mixer;
11010                         spec->num_mixers++;
11011                 }
11012                 spec->capsrc_nids = alc268_capsrc_nids;
11013                 /* set default input source */
11014                 for (i = 0; i < spec->num_adc_nids; i++)
11015                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
11016                                 0, AC_VERB_SET_CONNECT_SEL,
11017                                 spec->input_mux->items[0].index);
11018         }
11019
11020         spec->vmaster_nid = 0x02;
11021
11022         codec->patch_ops = alc_patch_ops;
11023         if (board_config == ALC268_AUTO)
11024                 spec->init_hook = alc268_auto_init;
11025                 
11026         return 0;
11027 }
11028
11029 /*
11030  *  ALC269 channel source setting (2 channel)
11031  */
11032 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
11033
11034 #define alc269_dac_nids         alc260_dac_nids
11035
11036 static hda_nid_t alc269_adc_nids[1] = {
11037         /* ADC1 */
11038         0x08,
11039 };
11040
11041 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
11042         .num_items = 2,
11043         .items = {
11044                 { "i-Mic", 0x5 },
11045                 { "e-Mic", 0x0 },
11046         },
11047 };
11048
11049 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
11050         .num_items = 2,
11051         .items = {
11052                 { "i-Mic", 0x1 },
11053                 { "e-Mic", 0x0 },
11054         },
11055 };
11056
11057 #define alc269_modes            alc260_modes
11058 #define alc269_capture_source   alc880_lg_lw_capture_source
11059
11060 static struct snd_kcontrol_new alc269_base_mixer[] = {
11061         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11062         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11063         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11064         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11065         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11066         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11067         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11068         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
11069         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
11070         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11071         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11072         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
11073         { } /* end */
11074 };
11075
11076 /* bind volumes of both NID 0x0c and 0x0d */
11077 static struct hda_bind_ctls alc269_epc_bind_vol = {
11078         .ops = &snd_hda_bind_vol,
11079         .values = {
11080                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
11081                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
11082                 0
11083         },
11084 };
11085
11086 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
11087         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11088         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
11089         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11090         { } /* end */
11091 };
11092
11093 /* capture mixer elements */
11094 static struct snd_kcontrol_new alc269_capture_mixer[] = {
11095         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11096         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11097         {
11098                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11099                 /* The multiple "Capture Source" controls confuse alsamixer
11100                  * So call somewhat different..
11101                  */
11102                 /* .name = "Capture Source", */
11103                 .name = "Input Source",
11104                 .count = 1,
11105                 .info = alc_mux_enum_info,
11106                 .get = alc_mux_enum_get,
11107                 .put = alc_mux_enum_put,
11108         },
11109         { } /* end */
11110 };
11111
11112 /* capture mixer elements */
11113 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
11114         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11115         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11116         { } /* end */
11117 };
11118
11119 /*
11120  * generic initialization of ADC, input mixers and output mixers
11121  */
11122 static struct hda_verb alc269_init_verbs[] = {
11123         /*
11124          * Unmute ADC0 and set the default input to mic-in
11125          */
11126         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11127
11128         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
11129          * analog-loopback mixer widget
11130          * Note: PASD motherboards uses the Line In 2 as the input for
11131          * front panel mic (mic 2)
11132          */
11133         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11134         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11135         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11136         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11137         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11138         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11139
11140         /*
11141          * Set up output mixers (0x0c - 0x0e)
11142          */
11143         /* set vol=0 to output mixers */
11144         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11145         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11146
11147         /* set up input amps for analog loopback */
11148         /* Amp Indices: DAC = 0, mixer = 1 */
11149         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11150         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11151         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11152         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11153         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11154         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11155
11156         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11157         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11158         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11159         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11160         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11161         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11162         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11163
11164         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11165         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11166         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11167         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11168         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11169         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11170         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11171
11172         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
11173         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11174
11175         /* FIXME: use matrix-type input source selection */
11176         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
11177         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11178         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11179         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11180         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11181         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11182
11183         /* set EAPD */
11184         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11185         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
11186         { }
11187 };
11188
11189 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
11190         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11191         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
11192         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
11193         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
11194         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11195         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11196         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11197         {}
11198 };
11199
11200 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
11201         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11202         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
11203         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
11204         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
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 /* toggle speaker-output according to the hp-jack state */
11211 static void alc269_speaker_automute(struct hda_codec *codec)
11212 {
11213         unsigned int present;
11214         unsigned int bits;
11215
11216         present = snd_hda_codec_read(codec, 0x15, 0,
11217                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11218         bits = present ? AMP_IN_MUTE(0) : 0;
11219         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
11220                                  AMP_IN_MUTE(0), bits);
11221         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
11222                                  AMP_IN_MUTE(0), bits);
11223 }
11224
11225 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
11226 {
11227         unsigned int present;
11228
11229         present = snd_hda_codec_read(codec, 0x18, 0, AC_VERB_GET_PIN_SENSE, 0)
11230                 & AC_PINSENSE_PRESENCE;
11231         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
11232                             present ? 0 : 5);
11233 }
11234
11235 static void alc269_eeepc_amic_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, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11242                             present ? AMP_IN_UNMUTE(0) : AMP_IN_MUTE(0));
11243         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11244                             present ? AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1));
11245 }
11246
11247 /* unsolicited event for HP jack sensing */
11248 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
11249                                           unsigned int res)
11250 {
11251         if ((res >> 26) == ALC880_HP_EVENT)
11252                 alc269_speaker_automute(codec);
11253
11254         if ((res >> 26) == ALC880_MIC_EVENT)
11255                 alc269_eeepc_dmic_automute(codec);
11256 }
11257
11258 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
11259 {
11260         alc269_speaker_automute(codec);
11261         alc269_eeepc_dmic_automute(codec);
11262 }
11263
11264 /* unsolicited event for HP jack sensing */
11265 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
11266                                           unsigned int res)
11267 {
11268         if ((res >> 26) == ALC880_HP_EVENT)
11269                 alc269_speaker_automute(codec);
11270
11271         if ((res >> 26) == ALC880_MIC_EVENT)
11272                 alc269_eeepc_amic_automute(codec);
11273 }
11274
11275 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
11276 {
11277         alc269_speaker_automute(codec);
11278         alc269_eeepc_amic_automute(codec);
11279 }
11280
11281 /* add playback controls from the parsed DAC table */
11282 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
11283                                              const struct auto_pin_cfg *cfg)
11284 {
11285         hda_nid_t nid;
11286         int err;
11287
11288         spec->multiout.num_dacs = 1;    /* only use one dac */
11289         spec->multiout.dac_nids = spec->private_dac_nids;
11290         spec->multiout.dac_nids[0] = 2;
11291
11292         nid = cfg->line_out_pins[0];
11293         if (nid) {
11294                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
11295                                   "Front Playback Volume",
11296                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
11297                 if (err < 0)
11298                         return err;
11299                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11300                                   "Front Playback Switch",
11301                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
11302                 if (err < 0)
11303                         return err;
11304         }
11305
11306         nid = cfg->speaker_pins[0];
11307         if (nid) {
11308                 if (!cfg->line_out_pins[0]) {
11309                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11310                                           "Speaker Playback Volume",
11311                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
11312                                                               HDA_OUTPUT));
11313                         if (err < 0)
11314                                 return err;
11315                 }
11316                 if (nid == 0x16) {
11317                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11318                                           "Speaker Playback Switch",
11319                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
11320                                                               HDA_OUTPUT));
11321                         if (err < 0)
11322                                 return err;
11323                 } else {
11324                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11325                                           "Speaker Playback Switch",
11326                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
11327                                                               HDA_OUTPUT));
11328                         if (err < 0)
11329                                 return err;
11330                 }
11331         }
11332         nid = cfg->hp_pins[0];
11333         if (nid) {
11334                 /* spec->multiout.hp_nid = 2; */
11335                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
11336                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11337                                           "Headphone Playback Volume",
11338                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
11339                                                               HDA_OUTPUT));
11340                         if (err < 0)
11341                                 return err;
11342                 }
11343                 if (nid == 0x16) {
11344                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11345                                           "Headphone Playback Switch",
11346                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
11347                                                               HDA_OUTPUT));
11348                         if (err < 0)
11349                                 return err;
11350                 } else {
11351                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11352                                           "Headphone Playback Switch",
11353                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
11354                                                               HDA_OUTPUT));
11355                         if (err < 0)
11356                                 return err;
11357                 }
11358         }
11359         return 0;
11360 }
11361
11362 #define alc269_auto_create_analog_input_ctls \
11363         alc880_auto_create_analog_input_ctls
11364
11365 #ifdef CONFIG_SND_HDA_POWER_SAVE
11366 #define alc269_loopbacks        alc880_loopbacks
11367 #endif
11368
11369 /* pcm configuration: identiacal with ALC880 */
11370 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
11371 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
11372 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
11373 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
11374
11375 /*
11376  * BIOS auto configuration
11377  */
11378 static int alc269_parse_auto_config(struct hda_codec *codec)
11379 {
11380         struct alc_spec *spec = codec->spec;
11381         int err;
11382         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
11383
11384         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11385                                            alc269_ignore);
11386         if (err < 0)
11387                 return err;
11388
11389         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
11390         if (err < 0)
11391                 return err;
11392         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
11393         if (err < 0)
11394                 return err;
11395
11396         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11397
11398         if (spec->autocfg.dig_out_pin)
11399                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
11400
11401         if (spec->kctl_alloc)
11402                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
11403
11404         spec->init_verbs[spec->num_init_verbs++] = alc269_init_verbs;
11405         spec->num_mux_defs = 1;
11406         spec->input_mux = &spec->private_imux;
11407
11408         err = alc_auto_add_mic_boost(codec);
11409         if (err < 0)
11410                 return err;
11411
11412         spec->mixers[spec->num_mixers] = alc269_capture_mixer;
11413         spec->num_mixers++;
11414
11415         return 1;
11416 }
11417
11418 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
11419 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
11420 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
11421
11422
11423 /* init callback for auto-configuration model -- overriding the default init */
11424 static void alc269_auto_init(struct hda_codec *codec)
11425 {
11426         struct alc_spec *spec = codec->spec;
11427         alc269_auto_init_multi_out(codec);
11428         alc269_auto_init_hp_out(codec);
11429         alc269_auto_init_analog_input(codec);
11430         if (spec->unsol_event)
11431                 alc_sku_automute(codec);
11432 }
11433
11434 /*
11435  * configuration and preset
11436  */
11437 static const char *alc269_models[ALC269_MODEL_LAST] = {
11438         [ALC269_BASIC]          = "basic",
11439 };
11440
11441 static struct snd_pci_quirk alc269_cfg_tbl[] = {
11442         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
11443                       ALC269_ASUS_EEEPC_P703),
11444         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
11445                       ALC269_ASUS_EEEPC_P901),
11446         {}
11447 };
11448
11449 static struct alc_config_preset alc269_presets[] = {
11450         [ALC269_BASIC] = {
11451                 .mixers = { alc269_base_mixer, alc269_capture_mixer },
11452                 .init_verbs = { alc269_init_verbs },
11453                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
11454                 .dac_nids = alc269_dac_nids,
11455                 .hp_nid = 0x03,
11456                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
11457                 .channel_mode = alc269_modes,
11458                 .input_mux = &alc269_capture_source,
11459         },
11460         [ALC269_ASUS_EEEPC_P703] = {
11461                 .mixers = { alc269_eeepc_mixer, alc269_epc_capture_mixer },
11462                 .init_verbs = { alc269_init_verbs,
11463                                 alc269_eeepc_amic_init_verbs },
11464                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
11465                 .dac_nids = alc269_dac_nids,
11466                 .hp_nid = 0x03,
11467                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
11468                 .channel_mode = alc269_modes,
11469                 .input_mux = &alc269_eeepc_amic_capture_source,
11470                 .unsol_event = alc269_eeepc_amic_unsol_event,
11471                 .init_hook = alc269_eeepc_amic_inithook,
11472         },
11473         [ALC269_ASUS_EEEPC_P901] = {
11474                 .mixers = { alc269_eeepc_mixer, alc269_epc_capture_mixer},
11475                 .init_verbs = { alc269_init_verbs,
11476                                 alc269_eeepc_dmic_init_verbs },
11477                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
11478                 .dac_nids = alc269_dac_nids,
11479                 .hp_nid = 0x03,
11480                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
11481                 .channel_mode = alc269_modes,
11482                 .input_mux = &alc269_eeepc_dmic_capture_source,
11483                 .unsol_event = alc269_eeepc_dmic_unsol_event,
11484                 .init_hook = alc269_eeepc_dmic_inithook,
11485         },
11486 };
11487
11488 static int patch_alc269(struct hda_codec *codec)
11489 {
11490         struct alc_spec *spec;
11491         int board_config;
11492         int err;
11493
11494         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11495         if (spec == NULL)
11496                 return -ENOMEM;
11497
11498         codec->spec = spec;
11499
11500         alc_fix_pll_init(codec, 0x20, 0x04, 15);
11501
11502         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
11503                                                   alc269_models,
11504                                                   alc269_cfg_tbl);
11505
11506         if (board_config < 0) {
11507                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
11508                        "trying auto-probe from BIOS...\n");
11509                 board_config = ALC269_AUTO;
11510         }
11511
11512         if (board_config == ALC269_AUTO) {
11513                 /* automatic parse from the BIOS config */
11514                 err = alc269_parse_auto_config(codec);
11515                 if (err < 0) {
11516                         alc_free(codec);
11517                         return err;
11518                 } else if (!err) {
11519                         printk(KERN_INFO
11520                                "hda_codec: Cannot set up configuration "
11521                                "from BIOS.  Using base mode...\n");
11522                         board_config = ALC269_BASIC;
11523                 }
11524         }
11525
11526         if (board_config != ALC269_AUTO)
11527                 setup_preset(spec, &alc269_presets[board_config]);
11528
11529         spec->stream_name_analog = "ALC269 Analog";
11530         spec->stream_analog_playback = &alc269_pcm_analog_playback;
11531         spec->stream_analog_capture = &alc269_pcm_analog_capture;
11532
11533         spec->stream_name_digital = "ALC269 Digital";
11534         spec->stream_digital_playback = &alc269_pcm_digital_playback;
11535         spec->stream_digital_capture = &alc269_pcm_digital_capture;
11536
11537         spec->adc_nids = alc269_adc_nids;
11538         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
11539
11540         codec->patch_ops = alc_patch_ops;
11541         if (board_config == ALC269_AUTO)
11542                 spec->init_hook = alc269_auto_init;
11543 #ifdef CONFIG_SND_HDA_POWER_SAVE
11544         if (!spec->loopback.amplist)
11545                 spec->loopback.amplist = alc269_loopbacks;
11546 #endif
11547
11548         return 0;
11549 }
11550
11551 /*
11552  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
11553  */
11554
11555 /*
11556  * set the path ways for 2 channel output
11557  * need to set the codec line out and mic 1 pin widgets to inputs
11558  */
11559 static struct hda_verb alc861_threestack_ch2_init[] = {
11560         /* set pin widget 1Ah (line in) for input */
11561         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11562         /* set pin widget 18h (mic1/2) for input, for mic also enable
11563          * the vref
11564          */
11565         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11566
11567         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
11568 #if 0
11569         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
11570         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
11571 #endif
11572         { } /* end */
11573 };
11574 /*
11575  * 6ch mode
11576  * need to set the codec line out and mic 1 pin widgets to outputs
11577  */
11578 static struct hda_verb alc861_threestack_ch6_init[] = {
11579         /* set pin widget 1Ah (line in) for output (Back Surround)*/
11580         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11581         /* set pin widget 18h (mic1) for output (CLFE)*/
11582         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11583
11584         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
11585         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
11586
11587         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
11588 #if 0
11589         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
11590         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
11591 #endif
11592         { } /* end */
11593 };
11594
11595 static struct hda_channel_mode alc861_threestack_modes[2] = {
11596         { 2, alc861_threestack_ch2_init },
11597         { 6, alc861_threestack_ch6_init },
11598 };
11599 /* Set mic1 as input and unmute the mixer */
11600 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
11601         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11602         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
11603         { } /* end */
11604 };
11605 /* Set mic1 as output and mute mixer */
11606 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
11607         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11608         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
11609         { } /* end */
11610 };
11611
11612 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
11613         { 2, alc861_uniwill_m31_ch2_init },
11614         { 4, alc861_uniwill_m31_ch4_init },
11615 };
11616
11617 /* Set mic1 and line-in as input and unmute the mixer */
11618 static struct hda_verb alc861_asus_ch2_init[] = {
11619         /* set pin widget 1Ah (line in) for input */
11620         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11621         /* set pin widget 18h (mic1/2) for input, for mic also enable
11622          * the vref
11623          */
11624         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11625
11626         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
11627 #if 0
11628         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
11629         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
11630 #endif
11631         { } /* end */
11632 };
11633 /* Set mic1 nad line-in as output and mute mixer */
11634 static struct hda_verb alc861_asus_ch6_init[] = {
11635         /* set pin widget 1Ah (line in) for output (Back Surround)*/
11636         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11637         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
11638         /* set pin widget 18h (mic1) for output (CLFE)*/
11639         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11640         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
11641         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
11642         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
11643
11644         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
11645 #if 0
11646         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
11647         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
11648 #endif
11649         { } /* end */
11650 };
11651
11652 static struct hda_channel_mode alc861_asus_modes[2] = {
11653         { 2, alc861_asus_ch2_init },
11654         { 6, alc861_asus_ch6_init },
11655 };
11656
11657 /* patch-ALC861 */
11658
11659 static struct snd_kcontrol_new alc861_base_mixer[] = {
11660         /* output mixer control */
11661         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11662         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11663         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11664         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11665         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
11666
11667         /*Input mixer control */
11668         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11669            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11670         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11671         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11672         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11673         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11674         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11675         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11676         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11677         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11678
11679         /* Capture mixer control */
11680         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11681         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11682         {
11683                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11684                 .name = "Capture Source",
11685                 .count = 1,
11686                 .info = alc_mux_enum_info,
11687                 .get = alc_mux_enum_get,
11688                 .put = alc_mux_enum_put,
11689         },
11690         { } /* end */
11691 };
11692
11693 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
11694         /* output mixer control */
11695         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11696         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11697         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11698         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11699         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
11700
11701         /* Input mixer control */
11702         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11703            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11704         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11705         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11706         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11707         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11708         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11709         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11710         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11711         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11712
11713         /* Capture mixer control */
11714         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11715         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11716         {
11717                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11718                 .name = "Capture Source",
11719                 .count = 1,
11720                 .info = alc_mux_enum_info,
11721                 .get = alc_mux_enum_get,
11722                 .put = alc_mux_enum_put,
11723         },
11724         {
11725                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11726                 .name = "Channel Mode",
11727                 .info = alc_ch_mode_info,
11728                 .get = alc_ch_mode_get,
11729                 .put = alc_ch_mode_put,
11730                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
11731         },
11732         { } /* end */
11733 };
11734
11735 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
11736         /* output mixer control */
11737         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11738         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11739         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11740         
11741         /*Capture mixer control */
11742         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11743         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11744         {
11745                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11746                 .name = "Capture Source",
11747                 .count = 1,
11748                 .info = alc_mux_enum_info,
11749                 .get = alc_mux_enum_get,
11750                 .put = alc_mux_enum_put,
11751         },
11752
11753         { } /* end */
11754 };
11755
11756 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
11757         /* output mixer control */
11758         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11759         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11760         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11761         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11762         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
11763
11764         /* Input mixer control */
11765         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11766            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
11767         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11768         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11769         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11770         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11771         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11772         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11773         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11774         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
11775
11776         /* Capture mixer control */
11777         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11778         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11779         {
11780                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11781                 .name = "Capture Source",
11782                 .count = 1,
11783                 .info = alc_mux_enum_info,
11784                 .get = alc_mux_enum_get,
11785                 .put = alc_mux_enum_put,
11786         },
11787         {
11788                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11789                 .name = "Channel Mode",
11790                 .info = alc_ch_mode_info,
11791                 .get = alc_ch_mode_get,
11792                 .put = alc_ch_mode_put,
11793                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
11794         },
11795         { } /* end */
11796 };
11797
11798 static struct snd_kcontrol_new alc861_asus_mixer[] = {
11799         /* output mixer control */
11800         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
11801         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
11802         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
11803         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
11804         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
11805
11806         /* Input mixer control */
11807         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
11808         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11809         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11810         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11811         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
11812         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
11813         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
11814         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
11815         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
11816         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
11817
11818         /* Capture mixer control */
11819         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
11820         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
11821         {
11822                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11823                 .name = "Capture Source",
11824                 .count = 1,
11825                 .info = alc_mux_enum_info,
11826                 .get = alc_mux_enum_get,
11827                 .put = alc_mux_enum_put,
11828         },
11829         {
11830                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11831                 .name = "Channel Mode",
11832                 .info = alc_ch_mode_info,
11833                 .get = alc_ch_mode_get,
11834                 .put = alc_ch_mode_put,
11835                 .private_value = ARRAY_SIZE(alc861_asus_modes),
11836         },
11837         { }
11838 };
11839
11840 /* additional mixer */
11841 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
11842         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
11843         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
11844         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
11845         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
11846         { }
11847 };
11848
11849 /*
11850  * generic initialization of ADC, input mixers and output mixers
11851  */
11852 static struct hda_verb alc861_base_init_verbs[] = {
11853         /*
11854          * Unmute ADC0 and set the default input to mic-in
11855          */
11856         /* port-A for surround (rear panel) */
11857         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11858         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
11859         /* port-B for mic-in (rear panel) with vref */
11860         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11861         /* port-C for line-in (rear panel) */
11862         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11863         /* port-D for Front */
11864         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11865         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11866         /* port-E for HP out (front panel) */
11867         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
11868         /* route front PCM to HP */
11869         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11870         /* port-F for mic-in (front panel) with vref */
11871         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11872         /* port-G for CLFE (rear panel) */
11873         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11874         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11875         /* port-H for side (rear panel) */
11876         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11877         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
11878         /* CD-in */
11879         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11880         /* route front mic to ADC1*/
11881         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11882         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11883         
11884         /* Unmute DAC0~3 & spdif out*/
11885         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11886         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11887         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11888         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11889         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11890         
11891         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11892         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11893         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11894         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11895         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11896         
11897         /* Unmute Stereo Mixer 15 */
11898         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11899         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11900         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11901         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
11902
11903         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11904         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11905         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11906         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11907         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11908         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11909         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11910         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11911         /* hp used DAC 3 (Front) */
11912         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11913         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11914
11915         { }
11916 };
11917
11918 static struct hda_verb alc861_threestack_init_verbs[] = {
11919         /*
11920          * Unmute ADC0 and set the default input to mic-in
11921          */
11922         /* port-A for surround (rear panel) */
11923         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11924         /* port-B for mic-in (rear panel) with vref */
11925         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11926         /* port-C for line-in (rear panel) */
11927         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11928         /* port-D for Front */
11929         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11930         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11931         /* port-E for HP out (front panel) */
11932         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
11933         /* route front PCM to HP */
11934         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11935         /* port-F for mic-in (front panel) with vref */
11936         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11937         /* port-G for CLFE (rear panel) */
11938         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11939         /* port-H for side (rear panel) */
11940         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11941         /* CD-in */
11942         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11943         /* route front mic to ADC1*/
11944         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11945         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11946         /* Unmute DAC0~3 & spdif out*/
11947         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11948         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11949         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11950         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11951         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11952         
11953         /* Unmute Mixer 14 (mic) 1c (Line in)*/
11954         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11955         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11956         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11957         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11958         
11959         /* Unmute Stereo Mixer 15 */
11960         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11961         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11962         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11963         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
11964
11965         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11966         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11967         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11968         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11969         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11970         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11971         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11972         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11973         /* hp used DAC 3 (Front) */
11974         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
11975         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11976         { }
11977 };
11978
11979 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
11980         /*
11981          * Unmute ADC0 and set the default input to mic-in
11982          */
11983         /* port-A for surround (rear panel) */
11984         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11985         /* port-B for mic-in (rear panel) with vref */
11986         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11987         /* port-C for line-in (rear panel) */
11988         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
11989         /* port-D for Front */
11990         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
11991         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
11992         /* port-E for HP out (front panel) */
11993         /* this has to be set to VREF80 */
11994         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11995         /* route front PCM to HP */
11996         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
11997         /* port-F for mic-in (front panel) with vref */
11998         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
11999         /* port-G for CLFE (rear panel) */
12000         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12001         /* port-H for side (rear panel) */
12002         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12003         /* CD-in */
12004         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12005         /* route front mic to ADC1*/
12006         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12007         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12008         /* Unmute DAC0~3 & spdif out*/
12009         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12010         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12011         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12012         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12013         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12014         
12015         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12016         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12017         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12018         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12019         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12020         
12021         /* Unmute Stereo Mixer 15 */
12022         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12023         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12024         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12025         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12026
12027         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12028         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12029         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12030         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12031         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12032         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12033         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12034         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12035         /* hp used DAC 3 (Front) */
12036         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12037         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12038         { }
12039 };
12040
12041 static struct hda_verb alc861_asus_init_verbs[] = {
12042         /*
12043          * Unmute ADC0 and set the default input to mic-in
12044          */
12045         /* port-A for surround (rear panel)
12046          * according to codec#0 this is the HP jack
12047          */
12048         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
12049         /* route front PCM to HP */
12050         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
12051         /* port-B for mic-in (rear panel) with vref */
12052         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12053         /* port-C for line-in (rear panel) */
12054         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12055         /* port-D for Front */
12056         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12057         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
12058         /* port-E for HP out (front panel) */
12059         /* this has to be set to VREF80 */
12060         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12061         /* route front PCM to HP */
12062         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
12063         /* port-F for mic-in (front panel) with vref */
12064         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12065         /* port-G for CLFE (rear panel) */
12066         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12067         /* port-H for side (rear panel) */
12068         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12069         /* CD-in */
12070         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12071         /* route front mic to ADC1*/
12072         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
12073         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12074         /* Unmute DAC0~3 & spdif out*/
12075         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12076         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12077         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12078         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12079         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12080         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12081         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12082         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12083         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12084         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12085         
12086         /* Unmute Stereo Mixer 15 */
12087         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12088         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12089         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12090         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
12091
12092         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12093         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12094         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12095         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12096         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12097         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12098         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12099         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12100         /* hp used DAC 3 (Front) */
12101         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12102         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12103         { }
12104 };
12105
12106 /* additional init verbs for ASUS laptops */
12107 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
12108         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
12109         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
12110         { }
12111 };
12112
12113 /*
12114  * generic initialization of ADC, input mixers and output mixers
12115  */
12116 static struct hda_verb alc861_auto_init_verbs[] = {
12117         /*
12118          * Unmute ADC0 and set the default input to mic-in
12119          */
12120         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
12121         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12122         
12123         /* Unmute DAC0~3 & spdif out*/
12124         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12125         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12126         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12127         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12128         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12129         
12130         /* Unmute Mixer 14 (mic) 1c (Line in)*/
12131         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12132         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12133         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12134         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12135         
12136         /* Unmute Stereo Mixer 15 */
12137         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12138         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12139         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12140         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
12141
12142         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12143         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12144         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12145         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12146         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12147         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12148         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12149         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12150
12151         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12152         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12153         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12154         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12155         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12156         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12157         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12158         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
12159
12160         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
12161
12162         { }
12163 };
12164
12165 static struct hda_verb alc861_toshiba_init_verbs[] = {
12166         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12167
12168         { }
12169 };
12170
12171 /* toggle speaker-output according to the hp-jack state */
12172 static void alc861_toshiba_automute(struct hda_codec *codec)
12173 {
12174         unsigned int present;
12175
12176         present = snd_hda_codec_read(codec, 0x0f, 0,
12177                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12178         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
12179                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
12180         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
12181                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
12182 }
12183
12184 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
12185                                        unsigned int res)
12186 {
12187         if ((res >> 26) == ALC880_HP_EVENT)
12188                 alc861_toshiba_automute(codec);
12189 }
12190
12191 /* pcm configuration: identiacal with ALC880 */
12192 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
12193 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
12194 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
12195 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
12196
12197
12198 #define ALC861_DIGOUT_NID       0x07
12199
12200 static struct hda_channel_mode alc861_8ch_modes[1] = {
12201         { 8, NULL }
12202 };
12203
12204 static hda_nid_t alc861_dac_nids[4] = {
12205         /* front, surround, clfe, side */
12206         0x03, 0x06, 0x05, 0x04
12207 };
12208
12209 static hda_nid_t alc660_dac_nids[3] = {
12210         /* front, clfe, surround */
12211         0x03, 0x05, 0x06
12212 };
12213
12214 static hda_nid_t alc861_adc_nids[1] = {
12215         /* ADC0-2 */
12216         0x08,
12217 };
12218
12219 static struct hda_input_mux alc861_capture_source = {
12220         .num_items = 5,
12221         .items = {
12222                 { "Mic", 0x0 },
12223                 { "Front Mic", 0x3 },
12224                 { "Line", 0x1 },
12225                 { "CD", 0x4 },
12226                 { "Mixer", 0x5 },
12227         },
12228 };
12229
12230 /* fill in the dac_nids table from the parsed pin configuration */
12231 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
12232                                      const struct auto_pin_cfg *cfg)
12233 {
12234         int i;
12235         hda_nid_t nid;
12236
12237         spec->multiout.dac_nids = spec->private_dac_nids;
12238         for (i = 0; i < cfg->line_outs; i++) {
12239                 nid = cfg->line_out_pins[i];
12240                 if (nid) {
12241                         if (i >= ARRAY_SIZE(alc861_dac_nids))
12242                                 continue;
12243                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
12244                 }
12245         }
12246         spec->multiout.num_dacs = cfg->line_outs;
12247         return 0;
12248 }
12249
12250 /* add playback controls from the parsed DAC table */
12251 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
12252                                              const struct auto_pin_cfg *cfg)
12253 {
12254         char name[32];
12255         static const char *chname[4] = {
12256                 "Front", "Surround", NULL /*CLFE*/, "Side"
12257         };
12258         hda_nid_t nid;
12259         int i, idx, err;
12260
12261         for (i = 0; i < cfg->line_outs; i++) {
12262                 nid = spec->multiout.dac_nids[i];
12263                 if (!nid)
12264                         continue;
12265                 if (nid == 0x05) {
12266                         /* Center/LFE */
12267                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12268                                           "Center Playback Switch",
12269                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
12270                                                               HDA_OUTPUT));
12271                         if (err < 0)
12272                                 return err;
12273                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12274                                           "LFE Playback Switch",
12275                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12276                                                               HDA_OUTPUT));
12277                         if (err < 0)
12278                                 return err;
12279                 } else {
12280                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
12281                              idx++)
12282                                 if (nid == alc861_dac_nids[idx])
12283                                         break;
12284                         sprintf(name, "%s Playback Switch", chname[idx]);
12285                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
12286                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12287                                                               HDA_OUTPUT));
12288                         if (err < 0)
12289                                 return err;
12290                 }
12291         }
12292         return 0;
12293 }
12294
12295 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
12296 {
12297         int err;
12298         hda_nid_t nid;
12299
12300         if (!pin)
12301                 return 0;
12302
12303         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
12304                 nid = 0x03;
12305                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12306                                   "Headphone Playback Switch",
12307                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12308                 if (err < 0)
12309                         return err;
12310                 spec->multiout.hp_nid = nid;
12311         }
12312         return 0;
12313 }
12314
12315 /* create playback/capture controls for input pins */
12316 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
12317                                                 const struct auto_pin_cfg *cfg)
12318 {
12319         struct hda_input_mux *imux = &spec->private_imux;
12320         int i, err, idx, idx1;
12321
12322         for (i = 0; i < AUTO_PIN_LAST; i++) {
12323                 switch (cfg->input_pins[i]) {
12324                 case 0x0c:
12325                         idx1 = 1;
12326                         idx = 2;        /* Line In */
12327                         break;
12328                 case 0x0f:
12329                         idx1 = 2;
12330                         idx = 2;        /* Line In */
12331                         break;
12332                 case 0x0d:
12333                         idx1 = 0;
12334                         idx = 1;        /* Mic In */
12335                         break;
12336                 case 0x10:
12337                         idx1 = 3;
12338                         idx = 1;        /* Mic In */
12339                         break;
12340                 case 0x11:
12341                         idx1 = 4;
12342                         idx = 0;        /* CD */
12343                         break;
12344                 default:
12345                         continue;
12346                 }
12347
12348                 err = new_analog_input(spec, cfg->input_pins[i],
12349                                        auto_pin_cfg_labels[i], idx, 0x15);
12350                 if (err < 0)
12351                         return err;
12352
12353                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
12354                 imux->items[imux->num_items].index = idx1;
12355                 imux->num_items++;
12356         }
12357         return 0;
12358 }
12359
12360 static struct snd_kcontrol_new alc861_capture_mixer[] = {
12361         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12362         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12363
12364         {
12365                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12366                 /* The multiple "Capture Source" controls confuse alsamixer
12367                  * So call somewhat different..
12368                  */
12369                 /* .name = "Capture Source", */
12370                 .name = "Input Source",
12371                 .count = 1,
12372                 .info = alc_mux_enum_info,
12373                 .get = alc_mux_enum_get,
12374                 .put = alc_mux_enum_put,
12375         },
12376         { } /* end */
12377 };
12378
12379 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
12380                                               hda_nid_t nid,
12381                                               int pin_type, int dac_idx)
12382 {
12383         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
12384                             pin_type);
12385         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12386                             AMP_OUT_UNMUTE);
12387 }
12388
12389 static void alc861_auto_init_multi_out(struct hda_codec *codec)
12390 {
12391         struct alc_spec *spec = codec->spec;
12392         int i;
12393
12394         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
12395         for (i = 0; i < spec->autocfg.line_outs; i++) {
12396                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
12397                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
12398                 if (nid)
12399                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
12400                                                           spec->multiout.dac_nids[i]);
12401         }
12402 }
12403
12404 static void alc861_auto_init_hp_out(struct hda_codec *codec)
12405 {
12406         struct alc_spec *spec = codec->spec;
12407         hda_nid_t pin;
12408
12409         pin = spec->autocfg.hp_pins[0];
12410         if (pin) /* connect to front */
12411                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
12412                                                   spec->multiout.dac_nids[0]);
12413         pin = spec->autocfg.speaker_pins[0];
12414         if (pin)
12415                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
12416 }
12417
12418 static void alc861_auto_init_analog_input(struct hda_codec *codec)
12419 {
12420         struct alc_spec *spec = codec->spec;
12421         int i;
12422
12423         for (i = 0; i < AUTO_PIN_LAST; i++) {
12424                 hda_nid_t nid = spec->autocfg.input_pins[i];
12425                 if (nid >= 0x0c && nid <= 0x11) {
12426                         snd_hda_codec_write(codec, nid, 0,
12427                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
12428                                             i <= AUTO_PIN_FRONT_MIC ?
12429                                             PIN_VREF80 : PIN_IN);
12430                 }
12431         }
12432 }
12433
12434 /* parse the BIOS configuration and set up the alc_spec */
12435 /* return 1 if successful, 0 if the proper config is not found,
12436  * or a negative error code
12437  */
12438 static int alc861_parse_auto_config(struct hda_codec *codec)
12439 {
12440         struct alc_spec *spec = codec->spec;
12441         int err;
12442         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
12443
12444         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12445                                            alc861_ignore);
12446         if (err < 0)
12447                 return err;
12448         if (!spec->autocfg.line_outs)
12449                 return 0; /* can't find valid BIOS pin config */
12450
12451         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
12452         if (err < 0)
12453                 return err;
12454         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
12455         if (err < 0)
12456                 return err;
12457         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
12458         if (err < 0)
12459                 return err;
12460         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
12461         if (err < 0)
12462                 return err;
12463
12464         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12465
12466         if (spec->autocfg.dig_out_pin)
12467                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
12468
12469         if (spec->kctl_alloc)
12470                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
12471
12472         spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs;
12473
12474         spec->num_mux_defs = 1;
12475         spec->input_mux = &spec->private_imux;
12476
12477         spec->adc_nids = alc861_adc_nids;
12478         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
12479         spec->mixers[spec->num_mixers] = alc861_capture_mixer;
12480         spec->num_mixers++;
12481
12482         return 1;
12483 }
12484
12485 /* additional initialization for auto-configuration model */
12486 static void alc861_auto_init(struct hda_codec *codec)
12487 {
12488         struct alc_spec *spec = codec->spec;
12489         alc861_auto_init_multi_out(codec);
12490         alc861_auto_init_hp_out(codec);
12491         alc861_auto_init_analog_input(codec);
12492         if (spec->unsol_event)
12493                 alc_sku_automute(codec);
12494 }
12495
12496 #ifdef CONFIG_SND_HDA_POWER_SAVE
12497 static struct hda_amp_list alc861_loopbacks[] = {
12498         { 0x15, HDA_INPUT, 0 },
12499         { 0x15, HDA_INPUT, 1 },
12500         { 0x15, HDA_INPUT, 2 },
12501         { 0x15, HDA_INPUT, 3 },
12502         { } /* end */
12503 };
12504 #endif
12505
12506
12507 /*
12508  * configuration and preset
12509  */
12510 static const char *alc861_models[ALC861_MODEL_LAST] = {
12511         [ALC861_3ST]            = "3stack",
12512         [ALC660_3ST]            = "3stack-660",
12513         [ALC861_3ST_DIG]        = "3stack-dig",
12514         [ALC861_6ST_DIG]        = "6stack-dig",
12515         [ALC861_UNIWILL_M31]    = "uniwill-m31",
12516         [ALC861_TOSHIBA]        = "toshiba",
12517         [ALC861_ASUS]           = "asus",
12518         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
12519         [ALC861_AUTO]           = "auto",
12520 };
12521
12522 static struct snd_pci_quirk alc861_cfg_tbl[] = {
12523         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
12524         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
12525         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
12526         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
12527         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
12528         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
12529         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
12530         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
12531          *        Any other models that need this preset?
12532          */
12533         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
12534         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
12535         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
12536         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
12537         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
12538         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
12539         /* FIXME: the below seems conflict */
12540         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
12541         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
12542         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
12543         {}
12544 };
12545
12546 static struct alc_config_preset alc861_presets[] = {
12547         [ALC861_3ST] = {
12548                 .mixers = { alc861_3ST_mixer },
12549                 .init_verbs = { alc861_threestack_init_verbs },
12550                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12551                 .dac_nids = alc861_dac_nids,
12552                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
12553                 .channel_mode = alc861_threestack_modes,
12554                 .need_dac_fix = 1,
12555                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12556                 .adc_nids = alc861_adc_nids,
12557                 .input_mux = &alc861_capture_source,
12558         },
12559         [ALC861_3ST_DIG] = {
12560                 .mixers = { alc861_base_mixer },
12561                 .init_verbs = { alc861_threestack_init_verbs },
12562                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12563                 .dac_nids = alc861_dac_nids,
12564                 .dig_out_nid = ALC861_DIGOUT_NID,
12565                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
12566                 .channel_mode = alc861_threestack_modes,
12567                 .need_dac_fix = 1,
12568                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12569                 .adc_nids = alc861_adc_nids,
12570                 .input_mux = &alc861_capture_source,
12571         },
12572         [ALC861_6ST_DIG] = {
12573                 .mixers = { alc861_base_mixer },
12574                 .init_verbs = { alc861_base_init_verbs },
12575                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12576                 .dac_nids = alc861_dac_nids,
12577                 .dig_out_nid = ALC861_DIGOUT_NID,
12578                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
12579                 .channel_mode = alc861_8ch_modes,
12580                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12581                 .adc_nids = alc861_adc_nids,
12582                 .input_mux = &alc861_capture_source,
12583         },
12584         [ALC660_3ST] = {
12585                 .mixers = { alc861_3ST_mixer },
12586                 .init_verbs = { alc861_threestack_init_verbs },
12587                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
12588                 .dac_nids = alc660_dac_nids,
12589                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
12590                 .channel_mode = alc861_threestack_modes,
12591                 .need_dac_fix = 1,
12592                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12593                 .adc_nids = alc861_adc_nids,
12594                 .input_mux = &alc861_capture_source,
12595         },
12596         [ALC861_UNIWILL_M31] = {
12597                 .mixers = { alc861_uniwill_m31_mixer },
12598                 .init_verbs = { alc861_uniwill_m31_init_verbs },
12599                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12600                 .dac_nids = alc861_dac_nids,
12601                 .dig_out_nid = ALC861_DIGOUT_NID,
12602                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
12603                 .channel_mode = alc861_uniwill_m31_modes,
12604                 .need_dac_fix = 1,
12605                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12606                 .adc_nids = alc861_adc_nids,
12607                 .input_mux = &alc861_capture_source,
12608         },
12609         [ALC861_TOSHIBA] = {
12610                 .mixers = { alc861_toshiba_mixer },
12611                 .init_verbs = { alc861_base_init_verbs,
12612                                 alc861_toshiba_init_verbs },
12613                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12614                 .dac_nids = alc861_dac_nids,
12615                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
12616                 .channel_mode = alc883_3ST_2ch_modes,
12617                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12618                 .adc_nids = alc861_adc_nids,
12619                 .input_mux = &alc861_capture_source,
12620                 .unsol_event = alc861_toshiba_unsol_event,
12621                 .init_hook = alc861_toshiba_automute,
12622         },
12623         [ALC861_ASUS] = {
12624                 .mixers = { alc861_asus_mixer },
12625                 .init_verbs = { alc861_asus_init_verbs },
12626                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
12627                 .dac_nids = alc861_dac_nids,
12628                 .dig_out_nid = ALC861_DIGOUT_NID,
12629                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
12630                 .channel_mode = alc861_asus_modes,
12631                 .need_dac_fix = 1,
12632                 .hp_nid = 0x06,
12633                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12634                 .adc_nids = alc861_adc_nids,
12635                 .input_mux = &alc861_capture_source,
12636         },
12637         [ALC861_ASUS_LAPTOP] = {
12638                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
12639                 .init_verbs = { alc861_asus_init_verbs,
12640                                 alc861_asus_laptop_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(alc883_3ST_2ch_modes),
12645                 .channel_mode = alc883_3ST_2ch_modes,
12646                 .need_dac_fix = 1,
12647                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
12648                 .adc_nids = alc861_adc_nids,
12649                 .input_mux = &alc861_capture_source,
12650         },
12651 };
12652
12653
12654 static int patch_alc861(struct hda_codec *codec)
12655 {
12656         struct alc_spec *spec;
12657         int board_config;
12658         int err;
12659
12660         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12661         if (spec == NULL)
12662                 return -ENOMEM;
12663
12664         codec->spec = spec;
12665
12666         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
12667                                                   alc861_models,
12668                                                   alc861_cfg_tbl);
12669
12670         if (board_config < 0) {
12671                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
12672                        "trying auto-probe from BIOS...\n");
12673                 board_config = ALC861_AUTO;
12674         }
12675
12676         if (board_config == ALC861_AUTO) {
12677                 /* automatic parse from the BIOS config */
12678                 err = alc861_parse_auto_config(codec);
12679                 if (err < 0) {
12680                         alc_free(codec);
12681                         return err;
12682                 } else if (!err) {
12683                         printk(KERN_INFO
12684                                "hda_codec: Cannot set up configuration "
12685                                "from BIOS.  Using base mode...\n");
12686                    board_config = ALC861_3ST_DIG;
12687                 }
12688         }
12689
12690         if (board_config != ALC861_AUTO)
12691                 setup_preset(spec, &alc861_presets[board_config]);
12692
12693         spec->stream_name_analog = "ALC861 Analog";
12694         spec->stream_analog_playback = &alc861_pcm_analog_playback;
12695         spec->stream_analog_capture = &alc861_pcm_analog_capture;
12696
12697         spec->stream_name_digital = "ALC861 Digital";
12698         spec->stream_digital_playback = &alc861_pcm_digital_playback;
12699         spec->stream_digital_capture = &alc861_pcm_digital_capture;
12700
12701         spec->vmaster_nid = 0x03;
12702
12703         codec->patch_ops = alc_patch_ops;
12704         if (board_config == ALC861_AUTO)
12705                 spec->init_hook = alc861_auto_init;
12706 #ifdef CONFIG_SND_HDA_POWER_SAVE
12707         if (!spec->loopback.amplist)
12708                 spec->loopback.amplist = alc861_loopbacks;
12709 #endif
12710                 
12711         return 0;
12712 }
12713
12714 /*
12715  * ALC861-VD support
12716  *
12717  * Based on ALC882
12718  *
12719  * In addition, an independent DAC
12720  */
12721 #define ALC861VD_DIGOUT_NID     0x06
12722
12723 static hda_nid_t alc861vd_dac_nids[4] = {
12724         /* front, surr, clfe, side surr */
12725         0x02, 0x03, 0x04, 0x05
12726 };
12727
12728 /* dac_nids for ALC660vd are in a different order - according to
12729  * Realtek's driver.
12730  * This should probably tesult in a different mixer for 6stack models
12731  * of ALC660vd codecs, but for now there is only 3stack mixer
12732  * - and it is the same as in 861vd.
12733  * adc_nids in ALC660vd are (is) the same as in 861vd
12734  */
12735 static hda_nid_t alc660vd_dac_nids[3] = {
12736         /* front, rear, clfe, rear_surr */
12737         0x02, 0x04, 0x03
12738 };
12739
12740 static hda_nid_t alc861vd_adc_nids[1] = {
12741         /* ADC0 */
12742         0x09,
12743 };
12744
12745 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
12746
12747 /* input MUX */
12748 /* FIXME: should be a matrix-type input source selection */
12749 static struct hda_input_mux alc861vd_capture_source = {
12750         .num_items = 4,
12751         .items = {
12752                 { "Mic", 0x0 },
12753                 { "Front Mic", 0x1 },
12754                 { "Line", 0x2 },
12755                 { "CD", 0x4 },
12756         },
12757 };
12758
12759 static struct hda_input_mux alc861vd_dallas_capture_source = {
12760         .num_items = 2,
12761         .items = {
12762                 { "Ext Mic", 0x0 },
12763                 { "Int Mic", 0x1 },
12764         },
12765 };
12766
12767 static struct hda_input_mux alc861vd_hp_capture_source = {
12768         .num_items = 2,
12769         .items = {
12770                 { "Front Mic", 0x0 },
12771                 { "ATAPI Mic", 0x1 },
12772         },
12773 };
12774
12775 #define alc861vd_mux_enum_info alc_mux_enum_info
12776 #define alc861vd_mux_enum_get alc_mux_enum_get
12777 /* ALC861VD has the ALC882-type input selection (but has only one ADC) */
12778 #define alc861vd_mux_enum_put alc882_mux_enum_put
12779
12780 /*
12781  * 2ch mode
12782  */
12783 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
12784         { 2, NULL }
12785 };
12786
12787 /*
12788  * 6ch mode
12789  */
12790 static struct hda_verb alc861vd_6stack_ch6_init[] = {
12791         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12792         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12793         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12794         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12795         { } /* end */
12796 };
12797
12798 /*
12799  * 8ch mode
12800  */
12801 static struct hda_verb alc861vd_6stack_ch8_init[] = {
12802         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12803         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12804         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12805         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12806         { } /* end */
12807 };
12808
12809 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
12810         { 6, alc861vd_6stack_ch6_init },
12811         { 8, alc861vd_6stack_ch8_init },
12812 };
12813
12814 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
12815         {
12816                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12817                 .name = "Channel Mode",
12818                 .info = alc_ch_mode_info,
12819                 .get = alc_ch_mode_get,
12820                 .put = alc_ch_mode_put,
12821         },
12822         { } /* end */
12823 };
12824
12825 static struct snd_kcontrol_new alc861vd_capture_mixer[] = {
12826         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
12827         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
12828
12829         {
12830                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12831                 /* The multiple "Capture Source" controls confuse alsamixer
12832                  * So call somewhat different..
12833                  */
12834                 /* .name = "Capture Source", */
12835                 .name = "Input Source",
12836                 .count = 1,
12837                 .info = alc861vd_mux_enum_info,
12838                 .get = alc861vd_mux_enum_get,
12839                 .put = alc861vd_mux_enum_put,
12840         },
12841         { } /* end */
12842 };
12843
12844 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
12845  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
12846  */
12847 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
12848         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12849         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12850
12851         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12852         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
12853
12854         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
12855                                 HDA_OUTPUT),
12856         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
12857                                 HDA_OUTPUT),
12858         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
12859         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
12860
12861         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
12862         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
12863
12864         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12865
12866         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12867         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12868         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12869
12870         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12871         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12872         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12873
12874         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12875         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12876
12877         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12878         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12879
12880         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
12881         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
12882
12883         { } /* end */
12884 };
12885
12886 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
12887         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12888         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12889
12890         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12891
12892         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12893         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12894         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12895
12896         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12897         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12898         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12899
12900         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12901         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12902
12903         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12904         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12905
12906         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
12907         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
12908
12909         { } /* end */
12910 };
12911
12912 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
12913         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12914         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
12915         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12916
12917         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12918
12919         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12920         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12921         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12922
12923         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12924         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12925         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12926
12927         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12928         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12929
12930         { } /* end */
12931 };
12932
12933 /* Pin assignment: Speaker=0x14, HP = 0x15,
12934  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
12935  */
12936 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
12937         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12938         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
12939         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12940         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
12941         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
12942         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12943         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12944         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
12945         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12946         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12947         HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
12948         HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
12949         { } /* end */
12950 };
12951
12952 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
12953  *                 Front Mic=0x18, ATAPI Mic = 0x19,
12954  */
12955 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
12956         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12957         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
12958         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12959         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
12960         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12961         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12962         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12963         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12964         
12965         { } /* end */
12966 };
12967
12968 /*
12969  * generic initialization of ADC, input mixers and output mixers
12970  */
12971 static struct hda_verb alc861vd_volume_init_verbs[] = {
12972         /*
12973          * Unmute ADC0 and set the default input to mic-in
12974          */
12975         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
12976         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12977
12978         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
12979          * the analog-loopback mixer widget
12980          */
12981         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12982         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12983         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12984         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12985         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12986         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12987
12988         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
12989         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12990         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12991         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12992         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
12993
12994         /*
12995          * Set up output mixers (0x02 - 0x05)
12996          */
12997         /* set vol=0 to output mixers */
12998         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12999         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13000         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13001         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13002
13003         /* set up input amps for analog loopback */
13004         /* Amp Indices: DAC = 0, mixer = 1 */
13005         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13006         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13007         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13008         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13009         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13010         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13011         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13012         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13013
13014         { }
13015 };
13016
13017 /*
13018  * 3-stack pin configuration:
13019  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
13020  */
13021 static struct hda_verb alc861vd_3stack_init_verbs[] = {
13022         /*
13023          * Set pin mode and muting
13024          */
13025         /* set front pin widgets 0x14 for output */
13026         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13027         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13028         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13029
13030         /* Mic (rear) pin: input vref at 80% */
13031         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13032         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13033         /* Front Mic pin: input vref at 80% */
13034         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13035         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13036         /* Line In pin: input */
13037         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13038         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13039         /* Line-2 In: Headphone output (output 0 - 0x0c) */
13040         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13041         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13042         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13043         /* CD pin widget for input */
13044         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13045
13046         { }
13047 };
13048
13049 /*
13050  * 6-stack pin configuration:
13051  */
13052 static struct hda_verb alc861vd_6stack_init_verbs[] = {
13053         /*
13054          * Set pin mode and muting
13055          */
13056         /* set front pin widgets 0x14 for output */
13057         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13058         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13059         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13060
13061         /* Rear Pin: output 1 (0x0d) */
13062         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13063         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13064         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13065         /* CLFE Pin: output 2 (0x0e) */
13066         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13067         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13068         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
13069         /* Side Pin: output 3 (0x0f) */
13070         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13071         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13072         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
13073
13074         /* Mic (rear) pin: input vref at 80% */
13075         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13076         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13077         /* Front Mic pin: input vref at 80% */
13078         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13079         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13080         /* Line In pin: input */
13081         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13082         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13083         /* Line-2 In: Headphone output (output 0 - 0x0c) */
13084         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13085         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13086         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
13087         /* CD pin widget for input */
13088         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13089
13090         { }
13091 };
13092
13093 static struct hda_verb alc861vd_eapd_verbs[] = {
13094         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13095         { }
13096 };
13097
13098 static struct hda_verb alc660vd_eapd_verbs[] = {
13099         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13100         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
13101         { }
13102 };
13103
13104 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
13105         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13106         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13107         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
13108         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13109         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT}, 
13110         {}
13111 };
13112
13113 /* toggle speaker-output according to the hp-jack state */
13114 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
13115 {
13116         unsigned int present;
13117         unsigned char bits;
13118
13119         present = snd_hda_codec_read(codec, 0x1b, 0,
13120                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13121         bits = present ? HDA_AMP_MUTE : 0;
13122         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
13123                                  HDA_AMP_MUTE, bits);
13124 }
13125
13126 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
13127 {
13128         unsigned int present;
13129         unsigned char bits;
13130
13131         present = snd_hda_codec_read(codec, 0x18, 0,
13132                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13133         bits = present ? HDA_AMP_MUTE : 0;
13134         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
13135                                  HDA_AMP_MUTE, bits);
13136 }
13137
13138 static void alc861vd_lenovo_automute(struct hda_codec *codec)
13139 {
13140         alc861vd_lenovo_hp_automute(codec);
13141         alc861vd_lenovo_mic_automute(codec);
13142 }
13143
13144 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
13145                                         unsigned int res)
13146 {
13147         switch (res >> 26) {
13148         case ALC880_HP_EVENT:
13149                 alc861vd_lenovo_hp_automute(codec);
13150                 break;
13151         case ALC880_MIC_EVENT:
13152                 alc861vd_lenovo_mic_automute(codec);
13153                 break;
13154         }
13155 }
13156
13157 static struct hda_verb alc861vd_dallas_verbs[] = {
13158         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13159         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13160         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13161         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13162
13163         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13164         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13165         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13166         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13167         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13168         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13169         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13170         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13171         
13172         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13173         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13174         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13175         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13176         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13177         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13178         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13179         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13180
13181         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
13182         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13183         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
13184         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13185         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13186         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13187         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13188         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13189
13190         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13191         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13192         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13193         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13194
13195         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13196         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},  
13197         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13198
13199         { } /* end */
13200 };
13201
13202 /* toggle speaker-output according to the hp-jack state */
13203 static void alc861vd_dallas_automute(struct hda_codec *codec)
13204 {
13205         unsigned int present;
13206
13207         present = snd_hda_codec_read(codec, 0x15, 0,
13208                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13209         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
13210                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
13211 }
13212
13213 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
13214 {
13215         if ((res >> 26) == ALC880_HP_EVENT)
13216                 alc861vd_dallas_automute(codec);
13217 }
13218
13219 #ifdef CONFIG_SND_HDA_POWER_SAVE
13220 #define alc861vd_loopbacks      alc880_loopbacks
13221 #endif
13222
13223 /* pcm configuration: identiacal with ALC880 */
13224 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
13225 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
13226 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
13227 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
13228
13229 /*
13230  * configuration and preset
13231  */
13232 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
13233         [ALC660VD_3ST]          = "3stack-660",
13234         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
13235         [ALC861VD_3ST]          = "3stack",
13236         [ALC861VD_3ST_DIG]      = "3stack-digout",
13237         [ALC861VD_6ST_DIG]      = "6stack-digout",
13238         [ALC861VD_LENOVO]       = "lenovo",
13239         [ALC861VD_DALLAS]       = "dallas",
13240         [ALC861VD_HP]           = "hp",
13241         [ALC861VD_AUTO]         = "auto",
13242 };
13243
13244 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
13245         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
13246         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
13247         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
13248         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
13249         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC861VD_LENOVO),
13250         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
13251         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
13252         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
13253         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
13254         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
13255         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
13256         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
13257         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
13258         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
13259         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
13260         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 N200", ALC861VD_LENOVO),
13261         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
13262         {}
13263 };
13264
13265 static struct alc_config_preset alc861vd_presets[] = {
13266         [ALC660VD_3ST] = {
13267                 .mixers = { alc861vd_3st_mixer },
13268                 .init_verbs = { alc861vd_volume_init_verbs,
13269                                  alc861vd_3stack_init_verbs },
13270                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
13271                 .dac_nids = alc660vd_dac_nids,
13272                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13273                 .channel_mode = alc861vd_3stack_2ch_modes,
13274                 .input_mux = &alc861vd_capture_source,
13275         },
13276         [ALC660VD_3ST_DIG] = {
13277                 .mixers = { alc861vd_3st_mixer },
13278                 .init_verbs = { alc861vd_volume_init_verbs,
13279                                  alc861vd_3stack_init_verbs },
13280                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
13281                 .dac_nids = alc660vd_dac_nids,
13282                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13283                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13284                 .channel_mode = alc861vd_3stack_2ch_modes,
13285                 .input_mux = &alc861vd_capture_source,
13286         },
13287         [ALC861VD_3ST] = {
13288                 .mixers = { alc861vd_3st_mixer },
13289                 .init_verbs = { alc861vd_volume_init_verbs,
13290                                  alc861vd_3stack_init_verbs },
13291                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13292                 .dac_nids = alc861vd_dac_nids,
13293                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13294                 .channel_mode = alc861vd_3stack_2ch_modes,
13295                 .input_mux = &alc861vd_capture_source,
13296         },
13297         [ALC861VD_3ST_DIG] = {
13298                 .mixers = { alc861vd_3st_mixer },
13299                 .init_verbs = { alc861vd_volume_init_verbs,
13300                                  alc861vd_3stack_init_verbs },
13301                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13302                 .dac_nids = alc861vd_dac_nids,
13303                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13304                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13305                 .channel_mode = alc861vd_3stack_2ch_modes,
13306                 .input_mux = &alc861vd_capture_source,
13307         },
13308         [ALC861VD_6ST_DIG] = {
13309                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
13310                 .init_verbs = { alc861vd_volume_init_verbs,
13311                                 alc861vd_6stack_init_verbs },
13312                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13313                 .dac_nids = alc861vd_dac_nids,
13314                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13315                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
13316                 .channel_mode = alc861vd_6stack_modes,
13317                 .input_mux = &alc861vd_capture_source,
13318         },
13319         [ALC861VD_LENOVO] = {
13320                 .mixers = { alc861vd_lenovo_mixer },
13321                 .init_verbs = { alc861vd_volume_init_verbs,
13322                                 alc861vd_3stack_init_verbs,
13323                                 alc861vd_eapd_verbs,
13324                                 alc861vd_lenovo_unsol_verbs },
13325                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
13326                 .dac_nids = alc660vd_dac_nids,
13327                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13328                 .channel_mode = alc861vd_3stack_2ch_modes,
13329                 .input_mux = &alc861vd_capture_source,
13330                 .unsol_event = alc861vd_lenovo_unsol_event,
13331                 .init_hook = alc861vd_lenovo_automute,
13332         },
13333         [ALC861VD_DALLAS] = {
13334                 .mixers = { alc861vd_dallas_mixer },
13335                 .init_verbs = { alc861vd_dallas_verbs },
13336                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13337                 .dac_nids = alc861vd_dac_nids,
13338                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13339                 .channel_mode = alc861vd_3stack_2ch_modes,
13340                 .input_mux = &alc861vd_dallas_capture_source,
13341                 .unsol_event = alc861vd_dallas_unsol_event,
13342                 .init_hook = alc861vd_dallas_automute,
13343         },
13344         [ALC861VD_HP] = {
13345                 .mixers = { alc861vd_hp_mixer },
13346                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
13347                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
13348                 .dac_nids = alc861vd_dac_nids,
13349                 .dig_out_nid = ALC861VD_DIGOUT_NID,
13350                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
13351                 .channel_mode = alc861vd_3stack_2ch_modes,
13352                 .input_mux = &alc861vd_hp_capture_source,
13353                 .unsol_event = alc861vd_dallas_unsol_event,
13354                 .init_hook = alc861vd_dallas_automute,
13355         },              
13356 };
13357
13358 /*
13359  * BIOS auto configuration
13360  */
13361 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
13362                                 hda_nid_t nid, int pin_type, int dac_idx)
13363 {
13364         alc_set_pin_output(codec, nid, pin_type);
13365 }
13366
13367 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
13368 {
13369         struct alc_spec *spec = codec->spec;
13370         int i;
13371
13372         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
13373         for (i = 0; i <= HDA_SIDE; i++) {
13374                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13375                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13376                 if (nid)
13377                         alc861vd_auto_set_output_and_unmute(codec, nid,
13378                                                             pin_type, i);
13379         }
13380 }
13381
13382
13383 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
13384 {
13385         struct alc_spec *spec = codec->spec;
13386         hda_nid_t pin;
13387
13388         pin = spec->autocfg.hp_pins[0];
13389         if (pin) /* connect to front and  use dac 0 */
13390                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
13391         pin = spec->autocfg.speaker_pins[0];
13392         if (pin)
13393                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13394 }
13395
13396 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
13397 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
13398
13399 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
13400 {
13401         struct alc_spec *spec = codec->spec;
13402         int i;
13403
13404         for (i = 0; i < AUTO_PIN_LAST; i++) {
13405                 hda_nid_t nid = spec->autocfg.input_pins[i];
13406                 if (alc861vd_is_input_pin(nid)) {
13407                         snd_hda_codec_write(codec, nid, 0,
13408                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
13409                                         i <= AUTO_PIN_FRONT_MIC ?
13410                                                         PIN_VREF80 : PIN_IN);
13411                         if (nid != ALC861VD_PIN_CD_NID)
13412                                 snd_hda_codec_write(codec, nid, 0,
13413                                                 AC_VERB_SET_AMP_GAIN_MUTE,
13414                                                 AMP_OUT_MUTE);
13415                 }
13416         }
13417 }
13418
13419 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
13420
13421 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
13422 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
13423
13424 /* add playback controls from the parsed DAC table */
13425 /* Based on ALC880 version. But ALC861VD has separate,
13426  * different NIDs for mute/unmute switch and volume control */
13427 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
13428                                              const struct auto_pin_cfg *cfg)
13429 {
13430         char name[32];
13431         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
13432         hda_nid_t nid_v, nid_s;
13433         int i, err;
13434
13435         for (i = 0; i < cfg->line_outs; i++) {
13436                 if (!spec->multiout.dac_nids[i])
13437                         continue;
13438                 nid_v = alc861vd_idx_to_mixer_vol(
13439                                 alc880_dac_to_idx(
13440                                         spec->multiout.dac_nids[i]));
13441                 nid_s = alc861vd_idx_to_mixer_switch(
13442                                 alc880_dac_to_idx(
13443                                         spec->multiout.dac_nids[i]));
13444
13445                 if (i == 2) {
13446                         /* Center/LFE */
13447                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13448                                           "Center Playback Volume",
13449                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
13450                                                               HDA_OUTPUT));
13451                         if (err < 0)
13452                                 return err;
13453                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13454                                           "LFE Playback Volume",
13455                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
13456                                                               HDA_OUTPUT));
13457                         if (err < 0)
13458                                 return err;
13459                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13460                                           "Center Playback Switch",
13461                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
13462                                                               HDA_INPUT));
13463                         if (err < 0)
13464                                 return err;
13465                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13466                                           "LFE Playback Switch",
13467                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
13468                                                               HDA_INPUT));
13469                         if (err < 0)
13470                                 return err;
13471                 } else {
13472                         sprintf(name, "%s Playback Volume", chname[i]);
13473                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
13474                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
13475                                                               HDA_OUTPUT));
13476                         if (err < 0)
13477                                 return err;
13478                         sprintf(name, "%s Playback Switch", chname[i]);
13479                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13480                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
13481                                                               HDA_INPUT));
13482                         if (err < 0)
13483                                 return err;
13484                 }
13485         }
13486         return 0;
13487 }
13488
13489 /* add playback controls for speaker and HP outputs */
13490 /* Based on ALC880 version. But ALC861VD has separate,
13491  * different NIDs for mute/unmute switch and volume control */
13492 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
13493                                         hda_nid_t pin, const char *pfx)
13494 {
13495         hda_nid_t nid_v, nid_s;
13496         int err;
13497         char name[32];
13498
13499         if (!pin)
13500                 return 0;
13501
13502         if (alc880_is_fixed_pin(pin)) {
13503                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
13504                 /* specify the DAC as the extra output */
13505                 if (!spec->multiout.hp_nid)
13506                         spec->multiout.hp_nid = nid_v;
13507                 else
13508                         spec->multiout.extra_out_nid[0] = nid_v;
13509                 /* control HP volume/switch on the output mixer amp */
13510                 nid_v = alc861vd_idx_to_mixer_vol(
13511                                 alc880_fixed_pin_idx(pin));
13512                 nid_s = alc861vd_idx_to_mixer_switch(
13513                                 alc880_fixed_pin_idx(pin));
13514
13515                 sprintf(name, "%s Playback Volume", pfx);
13516                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
13517                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
13518                 if (err < 0)
13519                         return err;
13520                 sprintf(name, "%s Playback Switch", pfx);
13521                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13522                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
13523                 if (err < 0)
13524                         return err;
13525         } else if (alc880_is_multi_pin(pin)) {
13526                 /* set manual connection */
13527                 /* we have only a switch on HP-out PIN */
13528                 sprintf(name, "%s Playback Switch", pfx);
13529                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
13530                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
13531                 if (err < 0)
13532                         return err;
13533         }
13534         return 0;
13535 }
13536
13537 /* parse the BIOS configuration and set up the alc_spec
13538  * return 1 if successful, 0 if the proper config is not found,
13539  * or a negative error code
13540  * Based on ALC880 version - had to change it to override
13541  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
13542 static int alc861vd_parse_auto_config(struct hda_codec *codec)
13543 {
13544         struct alc_spec *spec = codec->spec;
13545         int err;
13546         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
13547
13548         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13549                                            alc861vd_ignore);
13550         if (err < 0)
13551                 return err;
13552         if (!spec->autocfg.line_outs)
13553                 return 0; /* can't find valid BIOS pin config */
13554
13555         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
13556         if (err < 0)
13557                 return err;
13558         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
13559         if (err < 0)
13560                 return err;
13561         err = alc861vd_auto_create_extra_out(spec,
13562                                              spec->autocfg.speaker_pins[0],
13563                                              "Speaker");
13564         if (err < 0)
13565                 return err;
13566         err = alc861vd_auto_create_extra_out(spec,
13567                                              spec->autocfg.hp_pins[0],
13568                                              "Headphone");
13569         if (err < 0)
13570                 return err;
13571         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
13572         if (err < 0)
13573                 return err;
13574
13575         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13576
13577         if (spec->autocfg.dig_out_pin)
13578                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
13579
13580         if (spec->kctl_alloc)
13581                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
13582
13583         spec->init_verbs[spec->num_init_verbs++]
13584                 = alc861vd_volume_init_verbs;
13585
13586         spec->num_mux_defs = 1;
13587         spec->input_mux = &spec->private_imux;
13588
13589         err = alc_auto_add_mic_boost(codec);
13590         if (err < 0)
13591                 return err;
13592
13593         return 1;
13594 }
13595
13596 /* additional initialization for auto-configuration model */
13597 static void alc861vd_auto_init(struct hda_codec *codec)
13598 {
13599         struct alc_spec *spec = codec->spec;
13600         alc861vd_auto_init_multi_out(codec);
13601         alc861vd_auto_init_hp_out(codec);
13602         alc861vd_auto_init_analog_input(codec);
13603         alc861vd_auto_init_input_src(codec);
13604         if (spec->unsol_event)
13605                 alc_sku_automute(codec);
13606 }
13607
13608 static int patch_alc861vd(struct hda_codec *codec)
13609 {
13610         struct alc_spec *spec;
13611         int err, board_config;
13612
13613         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13614         if (spec == NULL)
13615                 return -ENOMEM;
13616
13617         codec->spec = spec;
13618
13619         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
13620                                                   alc861vd_models,
13621                                                   alc861vd_cfg_tbl);
13622
13623         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
13624                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
13625                         "ALC861VD, trying auto-probe from BIOS...\n");
13626                 board_config = ALC861VD_AUTO;
13627         }
13628
13629         if (board_config == ALC861VD_AUTO) {
13630                 /* automatic parse from the BIOS config */
13631                 err = alc861vd_parse_auto_config(codec);
13632                 if (err < 0) {
13633                         alc_free(codec);
13634                         return err;
13635                 } else if (!err) {
13636                         printk(KERN_INFO
13637                                "hda_codec: Cannot set up configuration "
13638                                "from BIOS.  Using base mode...\n");
13639                         board_config = ALC861VD_3ST;
13640                 }
13641         }
13642
13643         if (board_config != ALC861VD_AUTO)
13644                 setup_preset(spec, &alc861vd_presets[board_config]);
13645
13646         if (codec->vendor_id == 0x10ec0660) {
13647                 spec->stream_name_analog = "ALC660-VD Analog";
13648                 spec->stream_name_digital = "ALC660-VD Digital";
13649                 /* always turn on EAPD */
13650                 spec->init_verbs[spec->num_init_verbs++] = alc660vd_eapd_verbs;
13651         } else {
13652                 spec->stream_name_analog = "ALC861VD Analog";
13653                 spec->stream_name_digital = "ALC861VD Digital";
13654         }
13655
13656         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
13657         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
13658
13659         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
13660         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
13661
13662         spec->adc_nids = alc861vd_adc_nids;
13663         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
13664         spec->capsrc_nids = alc861vd_capsrc_nids;
13665
13666         spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
13667         spec->num_mixers++;
13668
13669         spec->vmaster_nid = 0x02;
13670
13671         codec->patch_ops = alc_patch_ops;
13672
13673         if (board_config == ALC861VD_AUTO)
13674                 spec->init_hook = alc861vd_auto_init;
13675 #ifdef CONFIG_SND_HDA_POWER_SAVE
13676         if (!spec->loopback.amplist)
13677                 spec->loopback.amplist = alc861vd_loopbacks;
13678 #endif
13679
13680         return 0;
13681 }
13682
13683 /*
13684  * ALC662 support
13685  *
13686  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
13687  * configuration.  Each pin widget can choose any input DACs and a mixer.
13688  * Each ADC is connected from a mixer of all inputs.  This makes possible
13689  * 6-channel independent captures.
13690  *
13691  * In addition, an independent DAC for the multi-playback (not used in this
13692  * driver yet).
13693  */
13694 #define ALC662_DIGOUT_NID       0x06
13695 #define ALC662_DIGIN_NID        0x0a
13696
13697 static hda_nid_t alc662_dac_nids[4] = {
13698         /* front, rear, clfe, rear_surr */
13699         0x02, 0x03, 0x04
13700 };
13701
13702 static hda_nid_t alc662_adc_nids[1] = {
13703         /* ADC1-2 */
13704         0x09,
13705 };
13706
13707 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
13708
13709 /* input MUX */
13710 /* FIXME: should be a matrix-type input source selection */
13711 static struct hda_input_mux alc662_capture_source = {
13712         .num_items = 4,
13713         .items = {
13714                 { "Mic", 0x0 },
13715                 { "Front Mic", 0x1 },
13716                 { "Line", 0x2 },
13717                 { "CD", 0x4 },
13718         },
13719 };
13720
13721 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
13722         .num_items = 2,
13723         .items = {
13724                 { "Mic", 0x1 },
13725                 { "Line", 0x2 },
13726         },
13727 };
13728
13729 static struct hda_input_mux alc662_eeepc_capture_source = {
13730         .num_items = 2,
13731         .items = {
13732                 { "i-Mic", 0x1 },
13733                 { "e-Mic", 0x0 },
13734         },
13735 };
13736
13737 static struct hda_input_mux alc663_capture_source = {
13738         .num_items = 3,
13739         .items = {
13740                 { "Mic", 0x0 },
13741                 { "Front Mic", 0x1 },
13742                 { "Line", 0x2 },
13743         },
13744 };
13745
13746 static struct hda_input_mux alc663_m51va_capture_source = {
13747         .num_items = 2,
13748         .items = {
13749                 { "Ext-Mic", 0x0 },
13750                 { "D-Mic", 0x9 },
13751         },
13752 };
13753
13754 #define alc662_mux_enum_info alc_mux_enum_info
13755 #define alc662_mux_enum_get alc_mux_enum_get
13756 #define alc662_mux_enum_put alc882_mux_enum_put
13757
13758 /*
13759  * 2ch mode
13760  */
13761 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
13762         { 2, NULL }
13763 };
13764
13765 /*
13766  * 2ch mode
13767  */
13768 static struct hda_verb alc662_3ST_ch2_init[] = {
13769         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
13770         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
13771         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
13772         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
13773         { } /* end */
13774 };
13775
13776 /*
13777  * 6ch mode
13778  */
13779 static struct hda_verb alc662_3ST_ch6_init[] = {
13780         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13781         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
13782         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
13783         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13784         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
13785         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
13786         { } /* end */
13787 };
13788
13789 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
13790         { 2, alc662_3ST_ch2_init },
13791         { 6, alc662_3ST_ch6_init },
13792 };
13793
13794 /*
13795  * 2ch mode
13796  */
13797 static struct hda_verb alc662_sixstack_ch6_init[] = {
13798         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13799         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13800         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13801         { } /* end */
13802 };
13803
13804 /*
13805  * 6ch mode
13806  */
13807 static struct hda_verb alc662_sixstack_ch8_init[] = {
13808         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13809         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13810         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13811         { } /* end */
13812 };
13813
13814 static struct hda_channel_mode alc662_5stack_modes[2] = {
13815         { 2, alc662_sixstack_ch6_init },
13816         { 6, alc662_sixstack_ch8_init },
13817 };
13818
13819 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
13820  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
13821  */
13822
13823 static struct snd_kcontrol_new alc662_base_mixer[] = {
13824         /* output mixer control */
13825         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
13826         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
13827         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
13828         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
13829         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13830         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13831         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
13832         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
13833         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13834
13835         /*Input mixer control */
13836         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
13837         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
13838         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
13839         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
13840         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
13841         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
13842         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
13843         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
13844         { } /* end */
13845 };
13846
13847 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
13848         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13849         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
13850         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13851         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13852         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13853         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13854         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13855         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13856         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13857         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13858         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13859         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13860         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13861         { } /* end */
13862 };
13863
13864 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
13865         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13866         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
13867         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13868         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
13869         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13870         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13871         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
13872         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
13873         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13874         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
13875         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
13876         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13877         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13878         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13879         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13880         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13881         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13882         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
13883         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
13884         { } /* end */
13885 };
13886
13887 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
13888         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13889         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
13890         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13891         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
13892         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13893         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13894         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13895         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13896         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13897         { } /* end */
13898 };
13899
13900 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
13901         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13902
13903         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13904         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13905
13906         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
13907         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13908         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13909
13910         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
13911         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13912         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13913         { } /* end */
13914 };
13915
13916 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
13917         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13918         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13919         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13920         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
13921         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
13922         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
13923         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
13924         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
13925         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13926         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
13927         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13928         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13929         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13930         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13931         { } /* end */
13932 };
13933
13934 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
13935         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13936         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13937         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
13938         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13939         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13940         HDA_CODEC_MUTE("DMic Playback Switch", 0x23, 0x9, HDA_INPUT),
13941         { } /* end */
13942 };
13943
13944 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
13945         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13946         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13947         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13948         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13949         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
13950
13951         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13952         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13953         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13954         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13955         { } /* end */
13956 };
13957
13958 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
13959         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13960         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
13961         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
13962
13963         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13964         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13965         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13966         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13967         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
13968         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
13969         { } /* end */
13970 };
13971
13972 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
13973         {
13974                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13975                 .name = "Channel Mode",
13976                 .info = alc_ch_mode_info,
13977                 .get = alc_ch_mode_get,
13978                 .put = alc_ch_mode_put,
13979         },
13980         { } /* end */
13981 };
13982
13983 static struct hda_verb alc662_init_verbs[] = {
13984         /* ADC: mute amp left and right */
13985         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13986         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
13987         /* Front mixer: unmute input/output amp left and right (volume = 0) */
13988
13989         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13990         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13991         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13992         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13993         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13994
13995         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13996         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13997         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13998         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13999         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14000         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14001
14002         /* Front Pin: output 0 (0x0c) */
14003         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14004         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14005
14006         /* Rear Pin: output 1 (0x0d) */
14007         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14008         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14009
14010         /* CLFE Pin: output 2 (0x0e) */
14011         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14012         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14013
14014         /* Mic (rear) pin: input vref at 80% */
14015         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14016         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14017         /* Front Mic pin: input vref at 80% */
14018         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14019         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14020         /* Line In pin: input */
14021         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14022         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14023         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14024         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14025         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14026         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14027         /* CD pin widget for input */
14028         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14029
14030         /* FIXME: use matrix-type input source selection */
14031         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
14032         /* Input mixer */
14033         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14034         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14035         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14036         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14037
14038         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14039         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14040         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14041         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14042
14043         /* always trun on EAPD */
14044         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14045         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
14046
14047         { }
14048 };
14049
14050 static struct hda_verb alc662_sue_init_verbs[] = {
14051         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
14052         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
14053         {}
14054 };
14055
14056 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
14057         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14058         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14059         {}
14060 };
14061
14062 /* Set Unsolicited Event*/
14063 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
14064         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14065         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14066         {}
14067 };
14068
14069 /*
14070  * generic initialization of ADC, input mixers and output mixers
14071  */
14072 static struct hda_verb alc662_auto_init_verbs[] = {
14073         /*
14074          * Unmute ADC and set the default input to mic-in
14075          */
14076         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14077         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14078
14079         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
14080          * mixer widget
14081          * Note: PASD motherboards uses the Line In 2 as the input for front
14082          * panel mic (mic 2)
14083          */
14084         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14085         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14086         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14087         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14088         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14089         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14090
14091         /*
14092          * Set up output mixers (0x0c - 0x0f)
14093          */
14094         /* set vol=0 to output mixers */
14095         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14096         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14097         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14098
14099         /* set up input amps for analog loopback */
14100         /* Amp Indices: DAC = 0, mixer = 1 */
14101         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14102         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14103         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14104         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14105         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14106         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14107
14108
14109         /* FIXME: use matrix-type input source selection */
14110         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
14111         /* Input mixer */
14112         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14113         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14114         { }
14115 };
14116
14117 /* additional verbs for ALC663 */
14118 static struct hda_verb alc663_auto_init_verbs[] = {
14119         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14120         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14121         { }
14122 };
14123
14124 static struct hda_verb alc663_m51va_init_verbs[] = {
14125         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14126         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14127         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
14128
14129         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
14130
14131         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14132         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14133         {}
14134 };
14135
14136 static struct hda_verb alc663_g71v_init_verbs[] = {
14137         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14138         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
14139         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
14140
14141         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14142         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14143         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
14144
14145         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
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_g50v_init_verbs[] = {
14152         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14153         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14154         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
14155
14156         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14157         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14158         {}
14159 };
14160
14161 /* capture mixer elements */
14162 static struct snd_kcontrol_new alc662_capture_mixer[] = {
14163         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
14164         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
14165         {
14166                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14167                 /* The multiple "Capture Source" controls confuse alsamixer
14168                  * So call somewhat different..
14169                  */
14170                 /* .name = "Capture Source", */
14171                 .name = "Input Source",
14172                 .count = 1,
14173                 .info = alc662_mux_enum_info,
14174                 .get = alc662_mux_enum_get,
14175                 .put = alc662_mux_enum_put,
14176         },
14177         { } /* end */
14178 };
14179
14180 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
14181 {
14182         unsigned int present;
14183         unsigned char bits;
14184
14185         present = snd_hda_codec_read(codec, 0x14, 0,
14186                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14187         bits = present ? HDA_AMP_MUTE : 0;
14188         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
14189                                  HDA_AMP_MUTE, bits);
14190 }
14191
14192 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
14193 {
14194         unsigned int present;
14195         unsigned char bits;
14196
14197         present = snd_hda_codec_read(codec, 0x1b, 0,
14198                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14199         bits = present ? HDA_AMP_MUTE : 0;
14200         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
14201                                  HDA_AMP_MUTE, bits);
14202         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14203                                  HDA_AMP_MUTE, bits);
14204 }
14205
14206 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
14207                                            unsigned int res)
14208 {
14209         if ((res >> 26) == ALC880_HP_EVENT)
14210                 alc662_lenovo_101e_all_automute(codec);
14211         if ((res >> 26) == ALC880_FRONT_EVENT)
14212                 alc662_lenovo_101e_ispeaker_automute(codec);
14213 }
14214
14215 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
14216 {
14217         unsigned int present;
14218
14219         present = snd_hda_codec_read(codec, 0x18, 0,
14220                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14221         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14222                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14223         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14224                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14225         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14226                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
14227         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14228                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
14229 }
14230
14231 /* unsolicited event for HP jack sensing */
14232 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
14233                                      unsigned int res)
14234 {
14235         if ((res >> 26) == ALC880_HP_EVENT)
14236                 alc262_hippo1_automute( codec );
14237
14238         if ((res >> 26) == ALC880_MIC_EVENT)
14239                 alc662_eeepc_mic_automute(codec);
14240 }
14241
14242 static void alc662_eeepc_inithook(struct hda_codec *codec)
14243 {
14244         alc262_hippo1_automute( codec );
14245         alc662_eeepc_mic_automute(codec);
14246 }
14247
14248 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
14249 {
14250         unsigned int mute;
14251         unsigned int present;
14252
14253         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
14254         present = snd_hda_codec_read(codec, 0x14, 0,
14255                                      AC_VERB_GET_PIN_SENSE, 0);
14256         present = (present & 0x80000000) != 0;
14257         if (present) {
14258                 /* mute internal speaker */
14259                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
14260                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
14261         } else {
14262                 /* unmute internal speaker if necessary */
14263                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
14264                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
14265                                          HDA_AMP_MUTE, mute);
14266         }
14267 }
14268
14269 /* unsolicited event for HP jack sensing */
14270 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
14271                                           unsigned int res)
14272 {
14273         if ((res >> 26) == ALC880_HP_EVENT)
14274                 alc662_eeepc_ep20_automute(codec);
14275 }
14276
14277 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
14278 {
14279         alc662_eeepc_ep20_automute(codec);
14280 }
14281
14282 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
14283 {
14284         unsigned int present;
14285         unsigned char bits;
14286
14287         present = snd_hda_codec_read(codec, 0x21, 0,
14288                                      AC_VERB_GET_PIN_SENSE, 0)
14289                 & AC_PINSENSE_PRESENCE;
14290         bits = present ? HDA_AMP_MUTE : 0;
14291         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14292                                  HDA_AMP_MUTE, bits);
14293 }
14294
14295 static void alc663_m51va_mic_automute(struct hda_codec *codec)
14296 {
14297         unsigned int present;
14298
14299         present = snd_hda_codec_read(codec, 0x18, 0,
14300                                      AC_VERB_GET_PIN_SENSE, 0)
14301                 & AC_PINSENSE_PRESENCE;
14302         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14303                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14304         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14305                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
14306         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14307                             0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
14308         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14309                             0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
14310 }
14311
14312 static void alc663_m51va_unsol_event(struct hda_codec *codec,
14313                                            unsigned int res)
14314 {
14315         switch (res >> 26) {
14316         case ALC880_HP_EVENT:
14317                 alc663_m51va_speaker_automute(codec);
14318                 break;
14319         case ALC880_MIC_EVENT:
14320                 alc663_m51va_mic_automute(codec);
14321                 break;
14322         }
14323 }
14324
14325 static void alc663_m51va_inithook(struct hda_codec *codec)
14326 {
14327         alc663_m51va_speaker_automute(codec);
14328         alc663_m51va_mic_automute(codec);
14329 }
14330
14331 static void alc663_g71v_hp_automute(struct hda_codec *codec)
14332 {
14333         unsigned int present;
14334         unsigned char bits;
14335
14336         present = snd_hda_codec_read(codec, 0x21, 0,
14337                                      AC_VERB_GET_PIN_SENSE, 0)
14338                 & AC_PINSENSE_PRESENCE;
14339         bits = present ? HDA_AMP_MUTE : 0;
14340         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
14341                                  HDA_AMP_MUTE, bits);
14342         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14343                                  HDA_AMP_MUTE, bits);
14344 }
14345
14346 static void alc663_g71v_front_automute(struct hda_codec *codec)
14347 {
14348         unsigned int present;
14349         unsigned char bits;
14350
14351         present = snd_hda_codec_read(codec, 0x15, 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, 0x14, HDA_OUTPUT, 0,
14356                                  HDA_AMP_MUTE, bits);
14357 }
14358
14359 static void alc663_g71v_unsol_event(struct hda_codec *codec,
14360                                            unsigned int res)
14361 {
14362         switch (res >> 26) {
14363         case ALC880_HP_EVENT:
14364                 alc663_g71v_hp_automute(codec);
14365                 break;
14366         case ALC880_FRONT_EVENT:
14367                 alc663_g71v_front_automute(codec);
14368                 break;
14369         case ALC880_MIC_EVENT:
14370                 alc662_eeepc_mic_automute(codec);
14371                 break;
14372         }
14373 }
14374
14375 static void alc663_g71v_inithook(struct hda_codec *codec)
14376 {
14377         alc663_g71v_front_automute(codec);
14378         alc663_g71v_hp_automute(codec);
14379         alc662_eeepc_mic_automute(codec);
14380 }
14381
14382 static void alc663_g50v_unsol_event(struct hda_codec *codec,
14383                                            unsigned int res)
14384 {
14385         switch (res >> 26) {
14386         case ALC880_HP_EVENT:
14387                 alc663_m51va_speaker_automute(codec);
14388                 break;
14389         case ALC880_MIC_EVENT:
14390                 alc662_eeepc_mic_automute(codec);
14391                 break;
14392         }
14393 }
14394
14395 static void alc663_g50v_inithook(struct hda_codec *codec)
14396 {
14397         alc663_m51va_speaker_automute(codec);
14398         alc662_eeepc_mic_automute(codec);
14399 }
14400
14401 #ifdef CONFIG_SND_HDA_POWER_SAVE
14402 #define alc662_loopbacks        alc880_loopbacks
14403 #endif
14404
14405
14406 /* pcm configuration: identiacal with ALC880 */
14407 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
14408 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
14409 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
14410 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
14411
14412 /*
14413  * configuration and preset
14414  */
14415 static const char *alc662_models[ALC662_MODEL_LAST] = {
14416         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
14417         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
14418         [ALC662_3ST_6ch]        = "3stack-6ch",
14419         [ALC662_5ST_DIG]        = "6stack-dig",
14420         [ALC662_LENOVO_101E]    = "lenovo-101e",
14421         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
14422         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
14423         [ALC663_ASUS_M51VA] = "m51va",
14424         [ALC663_ASUS_G71V] = "g71v",
14425         [ALC663_ASUS_H13] = "h13",
14426         [ALC663_ASUS_G50V] = "g50v",
14427         [ALC662_AUTO]           = "auto",
14428 };
14429
14430 static struct snd_pci_quirk alc662_cfg_tbl[] = {
14431         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS G71V", ALC663_ASUS_G71V),
14432         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
14433         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS M51VA", ALC663_ASUS_G50V),
14434         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
14435         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
14436         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
14437         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
14438         SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13),
14439         SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13),
14440         SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13),
14441         {}
14442 };
14443
14444 static struct alc_config_preset alc662_presets[] = {
14445         [ALC662_3ST_2ch_DIG] = {
14446                 .mixers = { alc662_3ST_2ch_mixer, alc662_capture_mixer },
14447                 .init_verbs = { alc662_init_verbs },
14448                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14449                 .dac_nids = alc662_dac_nids,
14450                 .dig_out_nid = ALC662_DIGOUT_NID,
14451                 .dig_in_nid = ALC662_DIGIN_NID,
14452                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14453                 .channel_mode = alc662_3ST_2ch_modes,
14454                 .input_mux = &alc662_capture_source,
14455         },
14456         [ALC662_3ST_6ch_DIG] = {
14457                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
14458                             alc662_capture_mixer },
14459                 .init_verbs = { alc662_init_verbs },
14460                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14461                 .dac_nids = alc662_dac_nids,
14462                 .dig_out_nid = ALC662_DIGOUT_NID,
14463                 .dig_in_nid = ALC662_DIGIN_NID,
14464                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
14465                 .channel_mode = alc662_3ST_6ch_modes,
14466                 .need_dac_fix = 1,
14467                 .input_mux = &alc662_capture_source,
14468         },
14469         [ALC662_3ST_6ch] = {
14470                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
14471                             alc662_capture_mixer },
14472                 .init_verbs = { alc662_init_verbs },
14473                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14474                 .dac_nids = alc662_dac_nids,
14475                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
14476                 .channel_mode = alc662_3ST_6ch_modes,
14477                 .need_dac_fix = 1,
14478                 .input_mux = &alc662_capture_source,
14479         },
14480         [ALC662_5ST_DIG] = {
14481                 .mixers = { alc662_base_mixer, alc662_chmode_mixer,
14482                             alc662_capture_mixer },
14483                 .init_verbs = { alc662_init_verbs },
14484                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14485                 .dac_nids = alc662_dac_nids,
14486                 .dig_out_nid = ALC662_DIGOUT_NID,
14487                 .dig_in_nid = ALC662_DIGIN_NID,
14488                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
14489                 .channel_mode = alc662_5stack_modes,
14490                 .input_mux = &alc662_capture_source,
14491         },
14492         [ALC662_LENOVO_101E] = {
14493                 .mixers = { alc662_lenovo_101e_mixer, alc662_capture_mixer },
14494                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
14495                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14496                 .dac_nids = alc662_dac_nids,
14497                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14498                 .channel_mode = alc662_3ST_2ch_modes,
14499                 .input_mux = &alc662_lenovo_101e_capture_source,
14500                 .unsol_event = alc662_lenovo_101e_unsol_event,
14501                 .init_hook = alc662_lenovo_101e_all_automute,
14502         },
14503         [ALC662_ASUS_EEEPC_P701] = {
14504                 .mixers = { alc662_eeepc_p701_mixer, alc662_capture_mixer },
14505                 .init_verbs = { alc662_init_verbs,
14506                                 alc662_eeepc_sue_init_verbs },
14507                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14508                 .dac_nids = alc662_dac_nids,
14509                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14510                 .channel_mode = alc662_3ST_2ch_modes,
14511                 .input_mux = &alc662_eeepc_capture_source,
14512                 .unsol_event = alc662_eeepc_unsol_event,
14513                 .init_hook = alc662_eeepc_inithook,
14514         },
14515         [ALC662_ASUS_EEEPC_EP20] = {
14516                 .mixers = { alc662_eeepc_ep20_mixer, alc662_capture_mixer,
14517                             alc662_chmode_mixer },
14518                 .init_verbs = { alc662_init_verbs,
14519                                 alc662_eeepc_ep20_sue_init_verbs },
14520                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14521                 .dac_nids = alc662_dac_nids,
14522                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
14523                 .channel_mode = alc662_3ST_6ch_modes,
14524                 .input_mux = &alc662_lenovo_101e_capture_source,
14525                 .unsol_event = alc662_eeepc_ep20_unsol_event,
14526                 .init_hook = alc662_eeepc_ep20_inithook,
14527         },
14528         [ALC663_ASUS_M51VA] = {
14529                 .mixers = { alc663_m51va_mixer, alc662_capture_mixer},
14530                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
14531                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14532                 .dac_nids = alc662_dac_nids,
14533                 .dig_out_nid = ALC662_DIGOUT_NID,
14534                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14535                 .channel_mode = alc662_3ST_2ch_modes,
14536                 .input_mux = &alc663_m51va_capture_source,
14537                 .unsol_event = alc663_m51va_unsol_event,
14538                 .init_hook = alc663_m51va_inithook,
14539         },
14540         [ALC663_ASUS_G71V] = {
14541                 .mixers = { alc663_g71v_mixer, alc662_capture_mixer},
14542                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
14543                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14544                 .dac_nids = alc662_dac_nids,
14545                 .dig_out_nid = ALC662_DIGOUT_NID,
14546                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14547                 .channel_mode = alc662_3ST_2ch_modes,
14548                 .input_mux = &alc662_eeepc_capture_source,
14549                 .unsol_event = alc663_g71v_unsol_event,
14550                 .init_hook = alc663_g71v_inithook,
14551         },
14552         [ALC663_ASUS_H13] = {
14553                 .mixers = { alc663_m51va_mixer, alc662_capture_mixer},
14554                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
14555                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14556                 .dac_nids = alc662_dac_nids,
14557                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
14558                 .channel_mode = alc662_3ST_2ch_modes,
14559                 .input_mux = &alc663_m51va_capture_source,
14560                 .unsol_event = alc663_m51va_unsol_event,
14561                 .init_hook = alc663_m51va_inithook,
14562         },
14563         [ALC663_ASUS_G50V] = {
14564                 .mixers = { alc663_g50v_mixer, alc662_capture_mixer},
14565                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
14566                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
14567                 .dac_nids = alc662_dac_nids,
14568                 .dig_out_nid = ALC662_DIGOUT_NID,
14569                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
14570                 .channel_mode = alc662_3ST_6ch_modes,
14571                 .input_mux = &alc663_capture_source,
14572                 .unsol_event = alc663_g50v_unsol_event,
14573                 .init_hook = alc663_g50v_inithook,
14574         },
14575 };
14576
14577
14578 /*
14579  * BIOS auto configuration
14580  */
14581
14582 /* add playback controls from the parsed DAC table */
14583 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
14584                                              const struct auto_pin_cfg *cfg)
14585 {
14586         char name[32];
14587         static const char *chname[4] = {
14588                 "Front", "Surround", NULL /*CLFE*/, "Side"
14589         };
14590         hda_nid_t nid;
14591         int i, err;
14592
14593         for (i = 0; i < cfg->line_outs; i++) {
14594                 if (!spec->multiout.dac_nids[i])
14595                         continue;
14596                 nid = alc880_idx_to_dac(i);
14597                 if (i == 2) {
14598                         /* Center/LFE */
14599                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14600                                           "Center Playback Volume",
14601                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
14602                                                               HDA_OUTPUT));
14603                         if (err < 0)
14604                                 return err;
14605                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14606                                           "LFE Playback Volume",
14607                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
14608                                                               HDA_OUTPUT));
14609                         if (err < 0)
14610                                 return err;
14611                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14612                                           "Center Playback Switch",
14613                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
14614                                                               HDA_INPUT));
14615                         if (err < 0)
14616                                 return err;
14617                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14618                                           "LFE Playback Switch",
14619                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
14620                                                               HDA_INPUT));
14621                         if (err < 0)
14622                                 return err;
14623                 } else {
14624                         sprintf(name, "%s Playback Volume", chname[i]);
14625                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14626                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
14627                                                               HDA_OUTPUT));
14628                         if (err < 0)
14629                                 return err;
14630                         sprintf(name, "%s Playback Switch", chname[i]);
14631                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14632                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
14633                                                               HDA_INPUT));
14634                         if (err < 0)
14635                                 return err;
14636                 }
14637         }
14638         return 0;
14639 }
14640
14641 /* add playback controls for speaker and HP outputs */
14642 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
14643                                         const char *pfx)
14644 {
14645         hda_nid_t nid;
14646         int err;
14647         char name[32];
14648
14649         if (!pin)
14650                 return 0;
14651
14652         if (pin == 0x17) {
14653                 /* ALC663 has a mono output pin on 0x17 */
14654                 sprintf(name, "%s Playback Switch", pfx);
14655                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14656                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
14657                 return err;
14658         }
14659
14660         if (alc880_is_fixed_pin(pin)) {
14661                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14662                 /* printk("DAC nid=%x\n",nid); */
14663                 /* specify the DAC as the extra output */
14664                 if (!spec->multiout.hp_nid)
14665                         spec->multiout.hp_nid = nid;
14666                 else
14667                         spec->multiout.extra_out_nid[0] = nid;
14668                 /* control HP volume/switch on the output mixer amp */
14669                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14670                 sprintf(name, "%s Playback Volume", pfx);
14671                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14672                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
14673                 if (err < 0)
14674                         return err;
14675                 sprintf(name, "%s Playback Switch", pfx);
14676                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14677                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
14678                 if (err < 0)
14679                         return err;
14680         } else if (alc880_is_multi_pin(pin)) {
14681                 /* set manual connection */
14682                 /* we have only a switch on HP-out PIN */
14683                 sprintf(name, "%s Playback Switch", pfx);
14684                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14685                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
14686                 if (err < 0)
14687                         return err;
14688         }
14689         return 0;
14690 }
14691
14692 /* create playback/capture controls for input pins */
14693 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
14694                                                 const struct auto_pin_cfg *cfg)
14695 {
14696         struct hda_input_mux *imux = &spec->private_imux;
14697         int i, err, idx;
14698
14699         for (i = 0; i < AUTO_PIN_LAST; i++) {
14700                 if (alc880_is_input_pin(cfg->input_pins[i])) {
14701                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
14702                         err = new_analog_input(spec, cfg->input_pins[i],
14703                                                auto_pin_cfg_labels[i],
14704                                                idx, 0x0b);
14705                         if (err < 0)
14706                                 return err;
14707                         imux->items[imux->num_items].label =
14708                                 auto_pin_cfg_labels[i];
14709                         imux->items[imux->num_items].index =
14710                                 alc880_input_pin_idx(cfg->input_pins[i]);
14711                         imux->num_items++;
14712                 }
14713         }
14714         return 0;
14715 }
14716
14717 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
14718                                               hda_nid_t nid, int pin_type,
14719                                               int dac_idx)
14720 {
14721         alc_set_pin_output(codec, nid, pin_type);
14722         /* need the manual connection? */
14723         if (alc880_is_multi_pin(nid)) {
14724                 struct alc_spec *spec = codec->spec;
14725                 int idx = alc880_multi_pin_idx(nid);
14726                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
14727                                     AC_VERB_SET_CONNECT_SEL,
14728                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
14729         }
14730 }
14731
14732 static void alc662_auto_init_multi_out(struct hda_codec *codec)
14733 {
14734         struct alc_spec *spec = codec->spec;
14735         int i;
14736
14737         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
14738         for (i = 0; i <= HDA_SIDE; i++) {
14739                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14740                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14741                 if (nid)
14742                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
14743                                                           i);
14744         }
14745 }
14746
14747 static void alc662_auto_init_hp_out(struct hda_codec *codec)
14748 {
14749         struct alc_spec *spec = codec->spec;
14750         hda_nid_t pin;
14751
14752         pin = spec->autocfg.hp_pins[0];
14753         if (pin) /* connect to front */
14754                 /* use dac 0 */
14755                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
14756         pin = spec->autocfg.speaker_pins[0];
14757         if (pin)
14758                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14759 }
14760
14761 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
14762 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
14763
14764 static void alc662_auto_init_analog_input(struct hda_codec *codec)
14765 {
14766         struct alc_spec *spec = codec->spec;
14767         int i;
14768
14769         for (i = 0; i < AUTO_PIN_LAST; i++) {
14770                 hda_nid_t nid = spec->autocfg.input_pins[i];
14771                 if (alc662_is_input_pin(nid)) {
14772                         snd_hda_codec_write(codec, nid, 0,
14773                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
14774                                             (i <= AUTO_PIN_FRONT_MIC ?
14775                                              PIN_VREF80 : PIN_IN));
14776                         if (nid != ALC662_PIN_CD_NID)
14777                                 snd_hda_codec_write(codec, nid, 0,
14778                                                     AC_VERB_SET_AMP_GAIN_MUTE,
14779                                                     AMP_OUT_MUTE);
14780                 }
14781         }
14782 }
14783
14784 #define alc662_auto_init_input_src      alc882_auto_init_input_src
14785
14786 static int alc662_parse_auto_config(struct hda_codec *codec)
14787 {
14788         struct alc_spec *spec = codec->spec;
14789         int err;
14790         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
14791
14792         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14793                                            alc662_ignore);
14794         if (err < 0)
14795                 return err;
14796         if (!spec->autocfg.line_outs)
14797                 return 0; /* can't find valid BIOS pin config */
14798
14799         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
14800         if (err < 0)
14801                 return err;
14802         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
14803         if (err < 0)
14804                 return err;
14805         err = alc662_auto_create_extra_out(spec,
14806                                            spec->autocfg.speaker_pins[0],
14807                                            "Speaker");
14808         if (err < 0)
14809                 return err;
14810         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
14811                                            "Headphone");
14812         if (err < 0)
14813                 return err;
14814         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
14815         if (err < 0)
14816                 return err;
14817
14818         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14819
14820         if (spec->autocfg.dig_out_pin)
14821                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
14822
14823         if (spec->kctl_alloc)
14824                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
14825
14826         spec->num_mux_defs = 1;
14827         spec->input_mux = &spec->private_imux;
14828         
14829         spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs;
14830         if (codec->vendor_id == 0x10ec0663)
14831                 spec->init_verbs[spec->num_init_verbs++] =
14832                         alc663_auto_init_verbs;
14833
14834         err = alc_auto_add_mic_boost(codec);
14835         if (err < 0)
14836                 return err;
14837
14838         spec->mixers[spec->num_mixers] = alc662_capture_mixer;
14839         spec->num_mixers++;
14840         return 1;
14841 }
14842
14843 /* additional initialization for auto-configuration model */
14844 static void alc662_auto_init(struct hda_codec *codec)
14845 {
14846         struct alc_spec *spec = codec->spec;
14847         alc662_auto_init_multi_out(codec);
14848         alc662_auto_init_hp_out(codec);
14849         alc662_auto_init_analog_input(codec);
14850         alc662_auto_init_input_src(codec);
14851         if (spec->unsol_event)
14852                 alc_sku_automute(codec);
14853 }
14854
14855 static int patch_alc662(struct hda_codec *codec)
14856 {
14857         struct alc_spec *spec;
14858         int err, board_config;
14859
14860         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14861         if (!spec)
14862                 return -ENOMEM;
14863
14864         codec->spec = spec;
14865
14866         alc_fix_pll_init(codec, 0x20, 0x04, 15);
14867
14868         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
14869                                                   alc662_models,
14870                                                   alc662_cfg_tbl);
14871         if (board_config < 0) {
14872                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
14873                        "trying auto-probe from BIOS...\n");
14874                 board_config = ALC662_AUTO;
14875         }
14876
14877         if (board_config == ALC662_AUTO) {
14878                 /* automatic parse from the BIOS config */
14879                 err = alc662_parse_auto_config(codec);
14880                 if (err < 0) {
14881                         alc_free(codec);
14882                         return err;
14883                 } else if (!err) {
14884                         printk(KERN_INFO
14885                                "hda_codec: Cannot set up configuration "
14886                                "from BIOS.  Using base mode...\n");
14887                         board_config = ALC662_3ST_2ch_DIG;
14888                 }
14889         }
14890
14891         if (board_config != ALC662_AUTO)
14892                 setup_preset(spec, &alc662_presets[board_config]);
14893
14894         if (codec->vendor_id == 0x10ec0663) {
14895                 spec->stream_name_analog = "ALC663 Analog";
14896                 spec->stream_name_digital = "ALC663 Digital";
14897         } else {
14898                 spec->stream_name_analog = "ALC662 Analog";
14899                 spec->stream_name_digital = "ALC662 Digital";
14900         }
14901
14902         spec->stream_analog_playback = &alc662_pcm_analog_playback;
14903         spec->stream_analog_capture = &alc662_pcm_analog_capture;
14904
14905         spec->stream_digital_playback = &alc662_pcm_digital_playback;
14906         spec->stream_digital_capture = &alc662_pcm_digital_capture;
14907
14908         spec->adc_nids = alc662_adc_nids;
14909         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
14910         spec->capsrc_nids = alc662_capsrc_nids;
14911
14912         spec->vmaster_nid = 0x02;
14913
14914         codec->patch_ops = alc_patch_ops;
14915         if (board_config == ALC662_AUTO)
14916                 spec->init_hook = alc662_auto_init;
14917 #ifdef CONFIG_SND_HDA_POWER_SAVE
14918         if (!spec->loopback.amplist)
14919                 spec->loopback.amplist = alc662_loopbacks;
14920 #endif
14921
14922         return 0;
14923 }
14924
14925 /*
14926  * patch entries
14927  */
14928 struct hda_codec_preset snd_hda_preset_realtek[] = {
14929         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
14930         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
14931         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
14932         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
14933         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
14934         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
14935           .patch = patch_alc861 },
14936         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
14937         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
14938         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
14939         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
14940           .patch = patch_alc883 },
14941         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
14942           .patch = patch_alc662 },
14943         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
14944         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
14945         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
14946         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
14947         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
14948           .patch = patch_alc882 }, /* should be patch_alc883() in future */
14949         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
14950         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
14951         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
14952         {} /* terminator */
14953 };