]> git.karo-electronics.de Git - mv-sheeva.git/blob - sound/pci/hda/patch_realtek.c
[ALSA] hda-codec - Initial support of the Mitac 8252D (based on ALC883)
[mv-sheeva.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 <sound/driver.h>
27 #include <linux/init.h>
28 #include <linux/delay.h>
29 #include <linux/slab.h>
30 #include <linux/pci.h>
31 #include <sound/core.h>
32 #include "hda_codec.h"
33 #include "hda_local.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 #ifdef CONFIG_SND_DEBUG
64         ALC880_TEST,
65 #endif
66         ALC880_AUTO,
67         ALC880_MODEL_LAST /* last tag */
68 };
69
70 /* ALC260 models */
71 enum {
72         ALC260_BASIC,
73         ALC260_HP,
74         ALC260_HP_3013,
75         ALC260_FUJITSU_S702X,
76         ALC260_ACER,
77         ALC260_WILL,
78         ALC260_REPLACER_672V,
79 #ifdef CONFIG_SND_DEBUG
80         ALC260_TEST,
81 #endif
82         ALC260_AUTO,
83         ALC260_MODEL_LAST /* last tag */
84 };
85
86 /* ALC262 models */
87 enum {
88         ALC262_BASIC,
89         ALC262_HIPPO,
90         ALC262_HIPPO_1,
91         ALC262_FUJITSU,
92         ALC262_HP_BPC,
93         ALC262_HP_BPC_D7000_WL,
94         ALC262_HP_BPC_D7000_WF,
95         ALC262_HP_TC_T5735,
96         ALC262_BENQ_ED8,
97         ALC262_SONY_ASSAMD,
98         ALC262_BENQ_T31,
99         ALC262_ULTRA,
100         ALC262_AUTO,
101         ALC262_MODEL_LAST /* last tag */
102 };
103
104 /* ALC268 models */
105 enum {
106         ALC268_3ST,
107         ALC268_TOSHIBA,
108         ALC268_ACER,
109         ALC268_AUTO,
110         ALC268_MODEL_LAST /* last tag */
111 };
112
113 /* ALC269 models */
114 enum {
115         ALC269_BASIC,
116         ALC269_AUTO,
117         ALC269_MODEL_LAST /* last tag */
118 };
119
120 /* ALC861 models */
121 enum {
122         ALC861_3ST,
123         ALC660_3ST,
124         ALC861_3ST_DIG,
125         ALC861_6ST_DIG,
126         ALC861_UNIWILL_M31,
127         ALC861_TOSHIBA,
128         ALC861_ASUS,
129         ALC861_ASUS_LAPTOP,
130         ALC861_AUTO,
131         ALC861_MODEL_LAST,
132 };
133
134 /* ALC861-VD models */
135 enum {
136         ALC660VD_3ST,
137         ALC660VD_3ST_DIG,
138         ALC861VD_3ST,
139         ALC861VD_3ST_DIG,
140         ALC861VD_6ST_DIG,
141         ALC861VD_LENOVO,
142         ALC861VD_DALLAS,
143         ALC861VD_HP,
144         ALC861VD_AUTO,
145         ALC861VD_MODEL_LAST,
146 };
147
148 /* ALC662 models */
149 enum {
150         ALC662_3ST_2ch_DIG,
151         ALC662_3ST_6ch_DIG,
152         ALC662_3ST_6ch,
153         ALC662_5ST_DIG,
154         ALC662_LENOVO_101E,
155         ALC662_ASUS_EEEPC_P701,
156         ALC662_AUTO,
157         ALC662_MODEL_LAST,
158 };
159
160 /* ALC882 models */
161 enum {
162         ALC882_3ST_DIG,
163         ALC882_6ST_DIG,
164         ALC882_ARIMA,
165         ALC882_W2JC,
166         ALC882_TARGA,
167         ALC882_ASUS_A7J,
168         ALC882_ASUS_A7M,
169         ALC885_MACPRO,
170         ALC885_MBP3,
171         ALC885_IMAC24,
172         ALC882_AUTO,
173         ALC882_MODEL_LAST,
174 };
175
176 /* ALC883 models */
177 enum {
178         ALC883_3ST_2ch_DIG,
179         ALC883_3ST_6ch_DIG,
180         ALC883_3ST_6ch,
181         ALC883_6ST_DIG,
182         ALC883_TARGA_DIG,
183         ALC883_TARGA_2ch_DIG,
184         ALC883_ACER,
185         ALC883_ACER_ASPIRE,
186         ALC883_MEDION,
187         ALC883_MEDION_MD2,      
188         ALC883_LAPTOP_EAPD,
189         ALC883_LENOVO_101E_2ch,
190         ALC883_LENOVO_NB0763,
191         ALC888_LENOVO_MS7195_DIG,
192         ALC883_HAIER_W66,               
193         ALC888_6ST_HP,
194         ALC888_3ST_HP,
195         ALC883_MITAC,
196         ALC883_AUTO,
197         ALC883_MODEL_LAST,
198 };
199
200 /* for GPIO Poll */
201 #define GPIO_MASK       0x03
202
203 struct alc_spec {
204         /* codec parameterization */
205         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
206         unsigned int num_mixers;
207
208         const struct hda_verb *init_verbs[5];   /* initialization verbs
209                                                  * don't forget NULL
210                                                  * termination!
211                                                  */
212         unsigned int num_init_verbs;
213
214         char *stream_name_analog;       /* analog PCM stream */
215         struct hda_pcm_stream *stream_analog_playback;
216         struct hda_pcm_stream *stream_analog_capture;
217
218         char *stream_name_digital;      /* digital PCM stream */
219         struct hda_pcm_stream *stream_digital_playback;
220         struct hda_pcm_stream *stream_digital_capture;
221
222         /* playback */
223         struct hda_multi_out multiout;  /* playback set-up
224                                          * max_channels, dacs must be set
225                                          * dig_out_nid and hp_nid are optional
226                                          */
227
228         /* capture */
229         unsigned int num_adc_nids;
230         hda_nid_t *adc_nids;
231         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
232
233         /* capture source */
234         unsigned int num_mux_defs;
235         const struct hda_input_mux *input_mux;
236         unsigned int cur_mux[3];
237
238         /* channel model */
239         const struct hda_channel_mode *channel_mode;
240         int num_channel_mode;
241         int need_dac_fix;
242
243         /* PCM information */
244         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
245
246         /* dynamic controls, init_verbs and input_mux */
247         struct auto_pin_cfg autocfg;
248         unsigned int num_kctl_alloc, num_kctl_used;
249         struct snd_kcontrol_new *kctl_alloc;
250         struct hda_input_mux private_imux;
251         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
252
253         /* hooks */
254         void (*init_hook)(struct hda_codec *codec);
255         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
256
257         /* for pin sensing */
258         unsigned int sense_updated: 1;
259         unsigned int jack_present: 1;
260
261 #ifdef CONFIG_SND_HDA_POWER_SAVE
262         struct hda_loopback_check loopback;
263 #endif
264 };
265
266 /*
267  * configuration template - to be copied to the spec instance
268  */
269 struct alc_config_preset {
270         struct snd_kcontrol_new *mixers[5]; /* should be identical size
271                                              * with spec
272                                              */
273         const struct hda_verb *init_verbs[5];
274         unsigned int num_dacs;
275         hda_nid_t *dac_nids;
276         hda_nid_t dig_out_nid;          /* optional */
277         hda_nid_t hp_nid;               /* optional */
278         unsigned int num_adc_nids;
279         hda_nid_t *adc_nids;
280         hda_nid_t dig_in_nid;
281         unsigned int num_channel_mode;
282         const struct hda_channel_mode *channel_mode;
283         int need_dac_fix;
284         unsigned int num_mux_defs;
285         const struct hda_input_mux *input_mux;
286         void (*unsol_event)(struct hda_codec *, unsigned int);
287         void (*init_hook)(struct hda_codec *);
288 #ifdef CONFIG_SND_HDA_POWER_SAVE
289         struct hda_amp_list *loopbacks;
290 #endif
291 };
292
293
294 /*
295  * input MUX handling
296  */
297 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
298                              struct snd_ctl_elem_info *uinfo)
299 {
300         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
301         struct alc_spec *spec = codec->spec;
302         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
303         if (mux_idx >= spec->num_mux_defs)
304                 mux_idx = 0;
305         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
306 }
307
308 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
309                             struct snd_ctl_elem_value *ucontrol)
310 {
311         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
312         struct alc_spec *spec = codec->spec;
313         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
314
315         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
316         return 0;
317 }
318
319 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
320                             struct snd_ctl_elem_value *ucontrol)
321 {
322         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
323         struct alc_spec *spec = codec->spec;
324         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
325         unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
326         return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
327                                      spec->adc_nids[adc_idx],
328                                      &spec->cur_mux[adc_idx]);
329 }
330
331
332 /*
333  * channel mode setting
334  */
335 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
336                             struct snd_ctl_elem_info *uinfo)
337 {
338         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
339         struct alc_spec *spec = codec->spec;
340         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
341                                     spec->num_channel_mode);
342 }
343
344 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
345                            struct snd_ctl_elem_value *ucontrol)
346 {
347         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
348         struct alc_spec *spec = codec->spec;
349         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
350                                    spec->num_channel_mode,
351                                    spec->multiout.max_channels);
352 }
353
354 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
355                            struct snd_ctl_elem_value *ucontrol)
356 {
357         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
358         struct alc_spec *spec = codec->spec;
359         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
360                                       spec->num_channel_mode,
361                                       &spec->multiout.max_channels);
362         if (err >= 0 && spec->need_dac_fix)
363                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
364         return err;
365 }
366
367 /*
368  * Control the mode of pin widget settings via the mixer.  "pc" is used
369  * instead of "%" to avoid consequences of accidently treating the % as 
370  * being part of a format specifier.  Maximum allowed length of a value is
371  * 63 characters plus NULL terminator.
372  *
373  * Note: some retasking pin complexes seem to ignore requests for input
374  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
375  * are requested.  Therefore order this list so that this behaviour will not
376  * cause problems when mixer clients move through the enum sequentially.
377  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
378  * March 2006.
379  */
380 static char *alc_pin_mode_names[] = {
381         "Mic 50pc bias", "Mic 80pc bias",
382         "Line in", "Line out", "Headphone out",
383 };
384 static unsigned char alc_pin_mode_values[] = {
385         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
386 };
387 /* The control can present all 5 options, or it can limit the options based
388  * in the pin being assumed to be exclusively an input or an output pin.  In
389  * addition, "input" pins may or may not process the mic bias option
390  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
391  * accept requests for bias as of chip versions up to March 2006) and/or
392  * wiring in the computer.
393  */
394 #define ALC_PIN_DIR_IN              0x00
395 #define ALC_PIN_DIR_OUT             0x01
396 #define ALC_PIN_DIR_INOUT           0x02
397 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
398 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
399
400 /* Info about the pin modes supported by the different pin direction modes. 
401  * For each direction the minimum and maximum values are given.
402  */
403 static signed char alc_pin_mode_dir_info[5][2] = {
404         { 0, 2 },    /* ALC_PIN_DIR_IN */
405         { 3, 4 },    /* ALC_PIN_DIR_OUT */
406         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
407         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
408         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
409 };
410 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
411 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
412 #define alc_pin_mode_n_items(_dir) \
413         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
414
415 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
416                              struct snd_ctl_elem_info *uinfo)
417 {
418         unsigned int item_num = uinfo->value.enumerated.item;
419         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
420
421         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
422         uinfo->count = 1;
423         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
424
425         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
426                 item_num = alc_pin_mode_min(dir);
427         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
428         return 0;
429 }
430
431 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
432                             struct snd_ctl_elem_value *ucontrol)
433 {
434         unsigned int i;
435         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
436         hda_nid_t nid = kcontrol->private_value & 0xffff;
437         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
438         long *valp = ucontrol->value.integer.value;
439         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
440                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
441                                                  0x00);
442
443         /* Find enumerated value for current pinctl setting */
444         i = alc_pin_mode_min(dir);
445         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
446                 i++;
447         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
448         return 0;
449 }
450
451 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
452                             struct snd_ctl_elem_value *ucontrol)
453 {
454         signed int change;
455         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
456         hda_nid_t nid = kcontrol->private_value & 0xffff;
457         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
458         long val = *ucontrol->value.integer.value;
459         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
460                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
461                                                  0x00);
462
463         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
464                 val = alc_pin_mode_min(dir);
465
466         change = pinctl != alc_pin_mode_values[val];
467         if (change) {
468                 /* Set pin mode to that requested */
469                 snd_hda_codec_write_cache(codec, nid, 0,
470                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
471                                           alc_pin_mode_values[val]);
472
473                 /* Also enable the retasking pin's input/output as required 
474                  * for the requested pin mode.  Enum values of 2 or less are
475                  * input modes.
476                  *
477                  * Dynamically switching the input/output buffers probably
478                  * reduces noise slightly (particularly on input) so we'll
479                  * do it.  However, having both input and output buffers
480                  * enabled simultaneously doesn't seem to be problematic if
481                  * this turns out to be necessary in the future.
482                  */
483                 if (val <= 2) {
484                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
485                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
486                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
487                                                  HDA_AMP_MUTE, 0);
488                 } else {
489                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
490                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
491                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
492                                                  HDA_AMP_MUTE, 0);
493                 }
494         }
495         return change;
496 }
497
498 #define ALC_PIN_MODE(xname, nid, dir) \
499         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
500           .info = alc_pin_mode_info, \
501           .get = alc_pin_mode_get, \
502           .put = alc_pin_mode_put, \
503           .private_value = nid | (dir<<16) }
504
505 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
506  * together using a mask with more than one bit set.  This control is
507  * currently used only by the ALC260 test model.  At this stage they are not
508  * needed for any "production" models.
509  */
510 #ifdef CONFIG_SND_DEBUG
511 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
512
513 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
514                              struct snd_ctl_elem_value *ucontrol)
515 {
516         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
517         hda_nid_t nid = kcontrol->private_value & 0xffff;
518         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
519         long *valp = ucontrol->value.integer.value;
520         unsigned int val = snd_hda_codec_read(codec, nid, 0,
521                                               AC_VERB_GET_GPIO_DATA, 0x00);
522
523         *valp = (val & mask) != 0;
524         return 0;
525 }
526 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
527                              struct snd_ctl_elem_value *ucontrol)
528 {
529         signed int change;
530         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
531         hda_nid_t nid = kcontrol->private_value & 0xffff;
532         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
533         long val = *ucontrol->value.integer.value;
534         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
535                                                     AC_VERB_GET_GPIO_DATA,
536                                                     0x00);
537
538         /* Set/unset the masked GPIO bit(s) as needed */
539         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
540         if (val == 0)
541                 gpio_data &= ~mask;
542         else
543                 gpio_data |= mask;
544         snd_hda_codec_write_cache(codec, nid, 0,
545                                   AC_VERB_SET_GPIO_DATA, gpio_data);
546
547         return change;
548 }
549 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
550         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
551           .info = alc_gpio_data_info, \
552           .get = alc_gpio_data_get, \
553           .put = alc_gpio_data_put, \
554           .private_value = nid | (mask<<16) }
555 #endif   /* CONFIG_SND_DEBUG */
556
557 /* A switch control to allow the enabling of the digital IO pins on the
558  * ALC260.  This is incredibly simplistic; the intention of this control is
559  * to provide something in the test model allowing digital outputs to be
560  * identified if present.  If models are found which can utilise these
561  * outputs a more complete mixer control can be devised for those models if
562  * necessary.
563  */
564 #ifdef CONFIG_SND_DEBUG
565 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
566
567 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
568                               struct snd_ctl_elem_value *ucontrol)
569 {
570         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
571         hda_nid_t nid = kcontrol->private_value & 0xffff;
572         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
573         long *valp = ucontrol->value.integer.value;
574         unsigned int val = snd_hda_codec_read(codec, nid, 0,
575                                               AC_VERB_GET_DIGI_CONVERT, 0x00);
576
577         *valp = (val & mask) != 0;
578         return 0;
579 }
580 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
581                               struct snd_ctl_elem_value *ucontrol)
582 {
583         signed int change;
584         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
585         hda_nid_t nid = kcontrol->private_value & 0xffff;
586         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
587         long val = *ucontrol->value.integer.value;
588         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
589                                                     AC_VERB_GET_DIGI_CONVERT,
590                                                     0x00);
591
592         /* Set/unset the masked control bit(s) as needed */
593         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
594         if (val==0)
595                 ctrl_data &= ~mask;
596         else
597                 ctrl_data |= mask;
598         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
599                                   ctrl_data);
600
601         return change;
602 }
603 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
604         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
605           .info = alc_spdif_ctrl_info, \
606           .get = alc_spdif_ctrl_get, \
607           .put = alc_spdif_ctrl_put, \
608           .private_value = nid | (mask<<16) }
609 #endif   /* CONFIG_SND_DEBUG */
610
611 /*
612  * set up from the preset table
613  */
614 static void setup_preset(struct alc_spec *spec,
615                          const struct alc_config_preset *preset)
616 {
617         int i;
618
619         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
620                 spec->mixers[spec->num_mixers++] = preset->mixers[i];
621         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
622              i++)
623                 spec->init_verbs[spec->num_init_verbs++] =
624                         preset->init_verbs[i];
625         
626         spec->channel_mode = preset->channel_mode;
627         spec->num_channel_mode = preset->num_channel_mode;
628         spec->need_dac_fix = preset->need_dac_fix;
629
630         spec->multiout.max_channels = spec->channel_mode[0].channels;
631
632         spec->multiout.num_dacs = preset->num_dacs;
633         spec->multiout.dac_nids = preset->dac_nids;
634         spec->multiout.dig_out_nid = preset->dig_out_nid;
635         spec->multiout.hp_nid = preset->hp_nid;
636         
637         spec->num_mux_defs = preset->num_mux_defs;
638         if (!spec->num_mux_defs)
639                 spec->num_mux_defs = 1;
640         spec->input_mux = preset->input_mux;
641
642         spec->num_adc_nids = preset->num_adc_nids;
643         spec->adc_nids = preset->adc_nids;
644         spec->dig_in_nid = preset->dig_in_nid;
645
646         spec->unsol_event = preset->unsol_event;
647         spec->init_hook = preset->init_hook;
648 #ifdef CONFIG_SND_HDA_POWER_SAVE
649         spec->loopback.amplist = preset->loopbacks;
650 #endif
651 }
652
653 /* Enable GPIO mask and set output */
654 static struct hda_verb alc_gpio1_init_verbs[] = {
655         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
656         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
657         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
658         { }
659 };
660
661 static struct hda_verb alc_gpio2_init_verbs[] = {
662         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
663         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
664         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
665         { }
666 };
667
668 static struct hda_verb alc_gpio3_init_verbs[] = {
669         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
670         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
671         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
672         { }
673 };
674
675 static void alc_sku_automute(struct hda_codec *codec)
676 {
677         struct alc_spec *spec = codec->spec;
678         unsigned int mute;
679         unsigned int present;
680         unsigned int hp_nid = spec->autocfg.hp_pins[0];
681         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
682
683         /* need to execute and sync at first */
684         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
685         present = snd_hda_codec_read(codec, hp_nid, 0,
686                                      AC_VERB_GET_PIN_SENSE, 0);
687         spec->jack_present = (present & 0x80000000) != 0;
688         if (spec->jack_present) {
689                 /* mute internal speaker */
690                 snd_hda_codec_amp_stereo(codec, sp_nid, HDA_OUTPUT, 0,
691                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
692         } else {
693                 /* unmute internal speaker if necessary */
694                 mute = snd_hda_codec_amp_read(codec, hp_nid, 0, HDA_OUTPUT, 0);
695                 snd_hda_codec_amp_stereo(codec, sp_nid, HDA_OUTPUT, 0,
696                                          HDA_AMP_MUTE, mute);
697         }
698 }
699
700 /* unsolicited event for HP jack sensing */
701 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
702 {
703         if (codec->vendor_id == 0x10ec0880)
704                 res >>= 28;
705         else
706                 res >>= 26;
707         if (res != ALC880_HP_EVENT)
708                 return;
709
710         alc_sku_automute(codec);
711 }
712
713 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
714  *      31 ~ 16 :       Manufacture ID
715  *      15 ~ 8  :       SKU ID
716  *      7  ~ 0  :       Assembly ID
717  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
718  */
719 static void alc_subsystem_id(struct hda_codec *codec,
720                              unsigned int porta, unsigned int porte,
721                              unsigned int portd)
722 {
723         unsigned int ass, tmp, i;
724         unsigned nid;
725         struct alc_spec *spec = codec->spec;
726
727         ass = codec->subsystem_id & 0xffff;
728         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
729                 goto do_sku;
730
731         /*      
732          * 31~30        : port conetcivity
733          * 29~21        : reserve
734          * 20           : PCBEEP input
735          * 19~16        : Check sum (15:1)
736          * 15~1         : Custom
737          * 0            : override
738         */
739         nid = 0x1d;
740         if (codec->vendor_id == 0x10ec0260)
741                 nid = 0x17;
742         ass = snd_hda_codec_read(codec, nid, 0,
743                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
744         if (!(ass & 1) && !(ass & 0x100000))
745                 return;
746         if ((ass >> 30) != 1)   /* no physical connection */
747                 return;
748
749         /* check sum */
750         tmp = 0;
751         for (i = 1; i < 16; i++) {
752                 if ((ass >> i) && 1)
753                         tmp++;
754         }
755         if (((ass >> 16) & 0xf) != tmp)
756                 return;
757 do_sku:
758         /*
759          * 0 : override
760          * 1 :  Swap Jack
761          * 2 : 0 --> Desktop, 1 --> Laptop
762          * 3~5 : External Amplifier control
763          * 7~6 : Reserved
764         */
765         tmp = (ass & 0x38) >> 3;        /* external Amp control */
766         switch (tmp) {
767         case 1:
768                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
769                 break;
770         case 3:
771                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
772                 break;
773         case 7:
774                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
775                 break;
776         case 5: /* set EAPD output high */
777                 switch (codec->vendor_id) {
778                 case 0x10ec0260:
779                         snd_hda_codec_write(codec, 0x0f, 0,
780                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
781                         snd_hda_codec_write(codec, 0x10, 0,
782                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
783                         break;
784                 case 0x10ec0262:
785                 case 0x10ec0267:
786                 case 0x10ec0268:
787                 case 0x10ec0269:
788                 case 0x10ec0862:
789                 case 0x10ec0662:        
790                         snd_hda_codec_write(codec, 0x14, 0,
791                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
792                         snd_hda_codec_write(codec, 0x15, 0,
793                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
794                         break;
795                 }
796                 switch (codec->vendor_id) {
797                 case 0x10ec0260:
798                         snd_hda_codec_write(codec, 0x1a, 0,
799                                             AC_VERB_SET_COEF_INDEX, 7);
800                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
801                                                  AC_VERB_GET_PROC_COEF, 0);
802                         snd_hda_codec_write(codec, 0x1a, 0,
803                                             AC_VERB_SET_COEF_INDEX, 7);
804                         snd_hda_codec_write(codec, 0x1a, 0,
805                                             AC_VERB_SET_PROC_COEF,
806                                             tmp | 0x2010);
807                         break;
808                 case 0x10ec0262:
809                 case 0x10ec0880:
810                 case 0x10ec0882:
811                 case 0x10ec0883:
812                 case 0x10ec0885:
813                 case 0x10ec0888:
814                         snd_hda_codec_write(codec, 0x20, 0,
815                                             AC_VERB_SET_COEF_INDEX, 7);
816                         tmp = snd_hda_codec_read(codec, 0x20, 0,
817                                                  AC_VERB_GET_PROC_COEF, 0);
818                         snd_hda_codec_write(codec, 0x20, 0,
819                                             AC_VERB_SET_COEF_INDEX, 7); 
820                         snd_hda_codec_write(codec, 0x20, 0,
821                                             AC_VERB_SET_PROC_COEF,
822                                             tmp | 0x2010);
823                         break;
824                 case 0x10ec0267:
825                 case 0x10ec0268:
826                         snd_hda_codec_write(codec, 0x20, 0,
827                                             AC_VERB_SET_COEF_INDEX, 7);
828                         tmp = snd_hda_codec_read(codec, 0x20, 0,
829                                                  AC_VERB_GET_PROC_COEF, 0);
830                         snd_hda_codec_write(codec, 0x20, 0,
831                                             AC_VERB_SET_COEF_INDEX, 7); 
832                         snd_hda_codec_write(codec, 0x20, 0,
833                                             AC_VERB_SET_PROC_COEF,
834                                             tmp | 0x3000);
835                         break;
836                 }
837         default:
838                 break;
839         }
840         
841         /* is laptop and enable the function "Mute internal speaker
842          * when the external headphone out jack is plugged"
843          */
844         if (!(ass & 0x4) || !(ass & 0x8000))
845                 return;
846         /*
847          * 10~8 : Jack location
848          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
849          * 14~13: Resvered
850          * 15   : 1 --> enable the function "Mute internal speaker
851          *              when the external headphone out jack is plugged"
852          */
853         if (!spec->autocfg.speaker_pins[0]) {
854                 if (spec->multiout.dac_nids[0])
855                         spec->autocfg.speaker_pins[0] =
856                                 spec->multiout.dac_nids[0];
857                 else
858                         return;
859         }
860
861         if (!spec->autocfg.hp_pins[0]) {
862                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
863                 if (tmp == 0)
864                         spec->autocfg.hp_pins[0] = porta;
865                 else if (tmp == 1)
866                         spec->autocfg.hp_pins[0] = porte;
867                 else if (tmp == 2)
868                         spec->autocfg.hp_pins[0] = portd;
869                 else
870                         return;
871         }
872
873         snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
874                             AC_VERB_SET_UNSOLICITED_ENABLE,
875                             AC_USRSP_EN | ALC880_HP_EVENT);
876         spec->unsol_event = alc_sku_unsol_event;
877         spec->init_hook = alc_sku_automute;     
878 }
879
880 /*
881  * Fix-up pin default configurations
882  */
883
884 struct alc_pincfg {
885         hda_nid_t nid;
886         u32 val;
887 };
888
889 static void alc_fix_pincfg(struct hda_codec *codec,
890                            const struct snd_pci_quirk *quirk,
891                            const struct alc_pincfg **pinfix)
892 {
893         const struct alc_pincfg *cfg;
894
895         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
896         if (!quirk)
897                 return;
898
899         cfg = pinfix[quirk->value];
900         for (; cfg->nid; cfg++) {
901                 int i;
902                 u32 val = cfg->val;
903                 for (i = 0; i < 4; i++) {
904                         snd_hda_codec_write(codec, cfg->nid, 0,
905                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
906                                     val & 0xff);
907                         val >>= 8;
908                 }
909         }
910 }
911
912 /*
913  * ALC880 3-stack model
914  *
915  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
916  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
917  *                 F-Mic = 0x1b, HP = 0x19
918  */
919
920 static hda_nid_t alc880_dac_nids[4] = {
921         /* front, rear, clfe, rear_surr */
922         0x02, 0x05, 0x04, 0x03
923 };
924
925 static hda_nid_t alc880_adc_nids[3] = {
926         /* ADC0-2 */
927         0x07, 0x08, 0x09,
928 };
929
930 /* The datasheet says the node 0x07 is connected from inputs,
931  * but it shows zero connection in the real implementation on some devices.
932  * Note: this is a 915GAV bug, fixed on 915GLV
933  */
934 static hda_nid_t alc880_adc_nids_alt[2] = {
935         /* ADC1-2 */
936         0x08, 0x09,
937 };
938
939 #define ALC880_DIGOUT_NID       0x06
940 #define ALC880_DIGIN_NID        0x0a
941
942 static struct hda_input_mux alc880_capture_source = {
943         .num_items = 4,
944         .items = {
945                 { "Mic", 0x0 },
946                 { "Front Mic", 0x3 },
947                 { "Line", 0x2 },
948                 { "CD", 0x4 },
949         },
950 };
951
952 /* channel source setting (2/6 channel selection for 3-stack) */
953 /* 2ch mode */
954 static struct hda_verb alc880_threestack_ch2_init[] = {
955         /* set line-in to input, mute it */
956         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
957         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
958         /* set mic-in to input vref 80%, mute it */
959         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
960         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
961         { } /* end */
962 };
963
964 /* 6ch mode */
965 static struct hda_verb alc880_threestack_ch6_init[] = {
966         /* set line-in to output, unmute it */
967         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
968         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
969         /* set mic-in to output, unmute it */
970         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
971         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
972         { } /* end */
973 };
974
975 static struct hda_channel_mode alc880_threestack_modes[2] = {
976         { 2, alc880_threestack_ch2_init },
977         { 6, alc880_threestack_ch6_init },
978 };
979
980 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
981         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
982         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
983         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
984         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
985         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
986         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
987         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
988         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
989         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
990         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
991         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
992         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
993         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
994         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
995         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
996         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
997         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
998         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
999         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1000         {
1001                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1002                 .name = "Channel Mode",
1003                 .info = alc_ch_mode_info,
1004                 .get = alc_ch_mode_get,
1005                 .put = alc_ch_mode_put,
1006         },
1007         { } /* end */
1008 };
1009
1010 /* capture mixer elements */
1011 static struct snd_kcontrol_new alc880_capture_mixer[] = {
1012         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
1013         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
1014         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
1015         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
1016         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
1017         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
1018         {
1019                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1020                 /* The multiple "Capture Source" controls confuse alsamixer
1021                  * So call somewhat different..
1022                  * FIXME: the controls appear in the "playback" view!
1023                  */
1024                 /* .name = "Capture Source", */
1025                 .name = "Input Source",
1026                 .count = 3,
1027                 .info = alc_mux_enum_info,
1028                 .get = alc_mux_enum_get,
1029                 .put = alc_mux_enum_put,
1030         },
1031         { } /* end */
1032 };
1033
1034 /* capture mixer elements (in case NID 0x07 not available) */
1035 static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
1036         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1037         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1038         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
1039         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
1040         {
1041                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1042                 /* The multiple "Capture Source" controls confuse alsamixer
1043                  * So call somewhat different..
1044                  * FIXME: the controls appear in the "playback" view!
1045                  */
1046                 /* .name = "Capture Source", */
1047                 .name = "Input Source",
1048                 .count = 2,
1049                 .info = alc_mux_enum_info,
1050                 .get = alc_mux_enum_get,
1051                 .put = alc_mux_enum_put,
1052         },
1053         { } /* end */
1054 };
1055
1056
1057
1058 /*
1059  * ALC880 5-stack model
1060  *
1061  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1062  *      Side = 0x02 (0xd)
1063  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1064  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1065  */
1066
1067 /* additional mixers to alc880_three_stack_mixer */
1068 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1069         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1070         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1071         { } /* end */
1072 };
1073
1074 /* channel source setting (6/8 channel selection for 5-stack) */
1075 /* 6ch mode */
1076 static struct hda_verb alc880_fivestack_ch6_init[] = {
1077         /* set line-in to input, mute it */
1078         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1079         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1080         { } /* end */
1081 };
1082
1083 /* 8ch mode */
1084 static struct hda_verb alc880_fivestack_ch8_init[] = {
1085         /* set line-in to output, unmute it */
1086         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1087         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1088         { } /* end */
1089 };
1090
1091 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1092         { 6, alc880_fivestack_ch6_init },
1093         { 8, alc880_fivestack_ch8_init },
1094 };
1095
1096
1097 /*
1098  * ALC880 6-stack model
1099  *
1100  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1101  *      Side = 0x05 (0x0f)
1102  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1103  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1104  */
1105
1106 static hda_nid_t alc880_6st_dac_nids[4] = {
1107         /* front, rear, clfe, rear_surr */
1108         0x02, 0x03, 0x04, 0x05
1109 };
1110
1111 static struct hda_input_mux alc880_6stack_capture_source = {
1112         .num_items = 4,
1113         .items = {
1114                 { "Mic", 0x0 },
1115                 { "Front Mic", 0x1 },
1116                 { "Line", 0x2 },
1117                 { "CD", 0x4 },
1118         },
1119 };
1120
1121 /* fixed 8-channels */
1122 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1123         { 8, NULL },
1124 };
1125
1126 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1127         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1128         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1129         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1130         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1131         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1132         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1133         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1134         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1135         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1136         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1137         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1138         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1139         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1140         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1141         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1142         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1143         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1144         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1145         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1146         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1147         {
1148                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1149                 .name = "Channel Mode",
1150                 .info = alc_ch_mode_info,
1151                 .get = alc_ch_mode_get,
1152                 .put = alc_ch_mode_put,
1153         },
1154         { } /* end */
1155 };
1156
1157
1158 /*
1159  * ALC880 W810 model
1160  *
1161  * W810 has rear IO for:
1162  * Front (DAC 02)
1163  * Surround (DAC 03)
1164  * Center/LFE (DAC 04)
1165  * Digital out (06)
1166  *
1167  * The system also has a pair of internal speakers, and a headphone jack.
1168  * These are both connected to Line2 on the codec, hence to DAC 02.
1169  * 
1170  * There is a variable resistor to control the speaker or headphone
1171  * volume. This is a hardware-only device without a software API.
1172  *
1173  * Plugging headphones in will disable the internal speakers. This is
1174  * implemented in hardware, not via the driver using jack sense. In
1175  * a similar fashion, plugging into the rear socket marked "front" will
1176  * disable both the speakers and headphones.
1177  *
1178  * For input, there's a microphone jack, and an "audio in" jack.
1179  * These may not do anything useful with this driver yet, because I
1180  * haven't setup any initialization verbs for these yet...
1181  */
1182
1183 static hda_nid_t alc880_w810_dac_nids[3] = {
1184         /* front, rear/surround, clfe */
1185         0x02, 0x03, 0x04
1186 };
1187
1188 /* fixed 6 channels */
1189 static struct hda_channel_mode alc880_w810_modes[1] = {
1190         { 6, NULL }
1191 };
1192
1193 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1194 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1195         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1196         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1197         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1198         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1199         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1200         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1201         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1202         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1203         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1204         { } /* end */
1205 };
1206
1207
1208 /*
1209  * Z710V model
1210  *
1211  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1212  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1213  *                 Line = 0x1a
1214  */
1215
1216 static hda_nid_t alc880_z71v_dac_nids[1] = {
1217         0x02
1218 };
1219 #define ALC880_Z71V_HP_DAC      0x03
1220
1221 /* fixed 2 channels */
1222 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1223         { 2, NULL }
1224 };
1225
1226 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1227         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1228         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1229         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1230         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1231         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1232         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1233         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1234         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1235         { } /* end */
1236 };
1237
1238
1239 /* FIXME! */
1240 /*
1241  * ALC880 F1734 model
1242  *
1243  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1244  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1245  */
1246
1247 static hda_nid_t alc880_f1734_dac_nids[1] = {
1248         0x03
1249 };
1250 #define ALC880_F1734_HP_DAC     0x02
1251
1252 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1253         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1254         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1255         HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1256         HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1257         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1258         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1259         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1260         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1261         { } /* end */
1262 };
1263
1264
1265 /* FIXME! */
1266 /*
1267  * ALC880 ASUS model
1268  *
1269  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1270  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1271  *  Mic = 0x18, Line = 0x1a
1272  */
1273
1274 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1275 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1276
1277 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1278         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1279         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1280         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1281         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1282         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1283         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1284         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1285         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1286         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1287         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1288         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1289         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1290         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1291         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1292         {
1293                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1294                 .name = "Channel Mode",
1295                 .info = alc_ch_mode_info,
1296                 .get = alc_ch_mode_get,
1297                 .put = alc_ch_mode_put,
1298         },
1299         { } /* end */
1300 };
1301
1302 /* FIXME! */
1303 /*
1304  * ALC880 ASUS W1V model
1305  *
1306  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1307  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1308  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1309  */
1310
1311 /* additional mixers to alc880_asus_mixer */
1312 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1313         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1314         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1315         { } /* end */
1316 };
1317
1318 /* additional mixers to alc880_asus_mixer */
1319 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1320         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1321         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1322         { } /* end */
1323 };
1324
1325 /* TCL S700 */
1326 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1327         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1328         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1329         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1330         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1331         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1332         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1333         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1334         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1335         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1336         {
1337                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1338                 /* The multiple "Capture Source" controls confuse alsamixer
1339                  * So call somewhat different..
1340                  * FIXME: the controls appear in the "playback" view!
1341                  */
1342                 /* .name = "Capture Source", */
1343                 .name = "Input Source",
1344                 .count = 1,
1345                 .info = alc_mux_enum_info,
1346                 .get = alc_mux_enum_get,
1347                 .put = alc_mux_enum_put,
1348         },
1349         { } /* end */
1350 };
1351
1352 /* Uniwill */
1353 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1354         HDA_CODEC_VOLUME("HPhone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1355         HDA_BIND_MUTE("HPhone Playback Switch", 0x0c, 2, HDA_INPUT),
1356         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1357         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
1358         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1359         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1360         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1361         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 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("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1365         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1366         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1367         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1368         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1369         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1370         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1371         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1372         {
1373                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1374                 .name = "Channel Mode",
1375                 .info = alc_ch_mode_info,
1376                 .get = alc_ch_mode_get,
1377                 .put = alc_ch_mode_put,
1378         },
1379         { } /* end */
1380 };
1381
1382 static struct snd_kcontrol_new alc880_fujitsu_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("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1390         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1391         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1392         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1393         { } /* end */
1394 };
1395
1396 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1397         HDA_CODEC_VOLUME("HPhone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1398         HDA_BIND_MUTE("HPhone Playback Switch", 0x0c, 2, HDA_INPUT),
1399         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1400         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
1401         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1402         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1403         { } /* end */
1404 };
1405
1406 /*
1407  * build control elements
1408  */
1409 static int alc_build_controls(struct hda_codec *codec)
1410 {
1411         struct alc_spec *spec = codec->spec;
1412         int err;
1413         int i;
1414
1415         for (i = 0; i < spec->num_mixers; i++) {
1416                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1417                 if (err < 0)
1418                         return err;
1419         }
1420
1421         if (spec->multiout.dig_out_nid) {
1422                 err = snd_hda_create_spdif_out_ctls(codec,
1423                                                     spec->multiout.dig_out_nid);
1424                 if (err < 0)
1425                         return err;
1426         }
1427         if (spec->dig_in_nid) {
1428                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1429                 if (err < 0)
1430                         return err;
1431         }
1432         return 0;
1433 }
1434
1435
1436 /*
1437  * initialize the codec volumes, etc
1438  */
1439
1440 /*
1441  * generic initialization of ADC, input mixers and output mixers
1442  */
1443 static struct hda_verb alc880_volume_init_verbs[] = {
1444         /*
1445          * Unmute ADC0-2 and set the default input to mic-in
1446          */
1447         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
1448         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1449         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
1450         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1451         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1452         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1453
1454         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1455          * mixer widget
1456          * Note: PASD motherboards uses the Line In 2 as the input for front
1457          * panel mic (mic 2)
1458          */
1459         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
1460         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1461         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1462         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1463         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1464         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1465         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1466         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1467
1468         /*
1469          * Set up output mixers (0x0c - 0x0f)
1470          */
1471         /* set vol=0 to output mixers */
1472         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1473         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1474         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1475         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1476         /* set up input amps for analog loopback */
1477         /* Amp Indices: DAC = 0, mixer = 1 */
1478         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1479         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1480         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1481         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1482         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1483         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1484         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1485         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1486
1487         { }
1488 };
1489
1490 /*
1491  * 3-stack pin configuration:
1492  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
1493  */
1494 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
1495         /*
1496          * preset connection lists of input pins
1497          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1498          */
1499         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1500         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1501         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1502
1503         /*
1504          * Set pin mode and muting
1505          */
1506         /* set front pin widgets 0x14 for output */
1507         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1508         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1509         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1510         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1511         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1512         /* Mic2 (as headphone out) for HP output */
1513         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1514         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1515         /* Line In pin widget for input */
1516         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1517         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1518         /* Line2 (as front mic) pin widget for input and vref at 80% */
1519         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1520         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1521         /* CD pin widget for input */
1522         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1523
1524         { }
1525 };
1526
1527 /*
1528  * 5-stack pin configuration:
1529  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
1530  * line-in/side = 0x1a, f-mic = 0x1b
1531  */
1532 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
1533         /*
1534          * preset connection lists of input pins
1535          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1536          */
1537         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1538         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1539
1540         /*
1541          * Set pin mode and muting
1542          */
1543         /* set pin widgets 0x14-0x17 for output */
1544         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1545         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1546         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1547         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1548         /* unmute pins for output (no gain on this amp) */
1549         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1550         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1551         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1552         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1553
1554         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1555         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1556         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1557         /* Mic2 (as headphone out) for HP output */
1558         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1559         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1560         /* Line In pin widget for input */
1561         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1562         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1563         /* Line2 (as front mic) pin widget for input and vref at 80% */
1564         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1565         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1566         /* CD pin widget for input */
1567         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1568
1569         { }
1570 };
1571
1572 /*
1573  * W810 pin configuration:
1574  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
1575  */
1576 static struct hda_verb alc880_pin_w810_init_verbs[] = {
1577         /* hphone/speaker input selector: front DAC */
1578         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1579
1580         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1581         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1582         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1583         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1584         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1585         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1586
1587         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1588         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1589
1590         { }
1591 };
1592
1593 /*
1594  * Z71V pin configuration:
1595  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
1596  */
1597 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
1598         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1599         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1600         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1601         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1602
1603         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1604         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1605         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1606         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1607
1608         { }
1609 };
1610
1611 /*
1612  * 6-stack pin configuration:
1613  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
1614  * f-mic = 0x19, line = 0x1a, HP = 0x1b
1615  */
1616 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1617         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1618
1619         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1620         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1621         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1622         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1623         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1624         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1625         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1626         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1627
1628         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1629         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1630         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1631         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1632         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1633         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1634         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1635         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1636         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1637         
1638         { }
1639 };
1640
1641 /*
1642  * Uniwill pin configuration:
1643  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
1644  * line = 0x1a
1645  */
1646 static struct hda_verb alc880_uniwill_init_verbs[] = {
1647         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1648
1649         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1650         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1651         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1652         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1653         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1654         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1655         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1656         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1657         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1658         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1659         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1660         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1661         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1662         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1663
1664         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1665         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1666         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1667         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1668         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1669         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1670         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
1671         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
1672         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1673
1674         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1675         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
1676
1677         { }
1678 };
1679
1680 /*
1681 * Uniwill P53
1682 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19, 
1683  */
1684 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
1685         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1686
1687         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1688         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1689         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1690         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1691         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1692         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1693         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1694         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1695         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1696         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1697         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1698         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1699
1700         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1701         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1702         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1703         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1704         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1705         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1706
1707         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1708         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
1709
1710         { }
1711 };
1712
1713 static struct hda_verb alc880_beep_init_verbs[] = {
1714         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
1715         { }
1716 };
1717
1718 /* toggle speaker-output according to the hp-jack state */
1719 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
1720 {
1721         unsigned int present;
1722         unsigned char bits;
1723
1724         present = snd_hda_codec_read(codec, 0x14, 0,
1725                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1726         bits = present ? HDA_AMP_MUTE : 0;
1727         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1728                                  HDA_AMP_MUTE, bits);
1729         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
1730                                  HDA_AMP_MUTE, bits);
1731 }
1732
1733 /* auto-toggle front mic */
1734 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
1735 {
1736         unsigned int present;
1737         unsigned char bits;
1738
1739         present = snd_hda_codec_read(codec, 0x18, 0,
1740                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1741         bits = present ? HDA_AMP_MUTE : 0;
1742         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
1743 }
1744
1745 static void alc880_uniwill_automute(struct hda_codec *codec)
1746 {
1747         alc880_uniwill_hp_automute(codec);
1748         alc880_uniwill_mic_automute(codec);
1749 }
1750
1751 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
1752                                        unsigned int res)
1753 {
1754         /* Looks like the unsol event is incompatible with the standard
1755          * definition.  4bit tag is placed at 28 bit!
1756          */
1757         switch (res >> 28) {
1758         case ALC880_HP_EVENT:
1759                 alc880_uniwill_hp_automute(codec);
1760                 break;
1761         case ALC880_MIC_EVENT:
1762                 alc880_uniwill_mic_automute(codec);
1763                 break;
1764         }
1765 }
1766
1767 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
1768 {
1769         unsigned int present;
1770         unsigned char bits;
1771
1772         present = snd_hda_codec_read(codec, 0x14, 0,
1773                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1774         bits = present ? HDA_AMP_MUTE : 0;
1775         snd_hda_codec_amp_stereo(codec, 0x15, HDA_INPUT, 0, HDA_AMP_MUTE, bits);
1776 }
1777
1778 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
1779 {
1780         unsigned int present;
1781         
1782         present = snd_hda_codec_read(codec, 0x21, 0,
1783                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
1784         present &= HDA_AMP_VOLMASK;
1785         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
1786                                  HDA_AMP_VOLMASK, present);
1787         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
1788                                  HDA_AMP_VOLMASK, present);
1789 }
1790
1791 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
1792                                            unsigned int res)
1793 {
1794         /* Looks like the unsol event is incompatible with the standard
1795          * definition.  4bit tag is placed at 28 bit!
1796          */
1797         if ((res >> 28) == ALC880_HP_EVENT)
1798                 alc880_uniwill_p53_hp_automute(codec);
1799         if ((res >> 28) == ALC880_DCVOL_EVENT)
1800                 alc880_uniwill_p53_dcvol_automute(codec);
1801 }
1802
1803 /* FIXME! */
1804 /*
1805  * F1734 pin configuration:
1806  * HP = 0x14, speaker-out = 0x15, mic = 0x18
1807  */
1808 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1809         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1810         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1811         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1812         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1813
1814         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1815         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1816         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1817         {0x15, 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_OUT},
1824         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1825         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
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 /* FIXME! */
1833 /*
1834  * ASUS pin configuration:
1835  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
1836  */
1837 static struct hda_verb alc880_pin_asus_init_verbs[] = {
1838         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1839         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1840         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1841         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1842
1843         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1844         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1845         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1846         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1847         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1848         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1849         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1850         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1851
1852         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1853         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1854         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1855         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1856         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1857         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1858         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1859         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1860         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1861         
1862         { }
1863 };
1864
1865 /* Enable GPIO mask and set output */
1866 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
1867 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
1868
1869 /* Clevo m520g init */
1870 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
1871         /* headphone output */
1872         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
1873         /* line-out */
1874         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1875         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1876         /* Line-in */
1877         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1878         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1879         /* CD */
1880         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1881         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1882         /* Mic1 (rear panel) */
1883         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1884         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1885         /* Mic2 (front panel) */
1886         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1887         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1888         /* headphone */
1889         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1890         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1891         /* change to EAPD mode */
1892         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1893         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
1894
1895         { }
1896 };
1897
1898 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
1899         /* change to EAPD mode */
1900         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1901         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
1902
1903         /* Headphone output */
1904         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1905         /* Front output*/
1906         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1907         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1908
1909         /* Line In pin widget for input */
1910         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1911         /* CD pin widget for input */
1912         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1913         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1914         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1915
1916         /* change to EAPD mode */
1917         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1918         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
1919
1920         { }
1921 };
1922
1923 /*
1924  * LG m1 express dual
1925  *
1926  * Pin assignment:
1927  *   Rear Line-In/Out (blue): 0x14
1928  *   Build-in Mic-In: 0x15
1929  *   Speaker-out: 0x17
1930  *   HP-Out (green): 0x1b
1931  *   Mic-In/Out (red): 0x19
1932  *   SPDIF-Out: 0x1e
1933  */
1934
1935 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
1936 static hda_nid_t alc880_lg_dac_nids[3] = {
1937         0x05, 0x02, 0x03
1938 };
1939
1940 /* seems analog CD is not working */
1941 static struct hda_input_mux alc880_lg_capture_source = {
1942         .num_items = 3,
1943         .items = {
1944                 { "Mic", 0x1 },
1945                 { "Line", 0x5 },
1946                 { "Internal Mic", 0x6 },
1947         },
1948 };
1949
1950 /* 2,4,6 channel modes */
1951 static struct hda_verb alc880_lg_ch2_init[] = {
1952         /* set line-in and mic-in to input */
1953         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1954         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1955         { }
1956 };
1957
1958 static struct hda_verb alc880_lg_ch4_init[] = {
1959         /* set line-in to out and mic-in to input */
1960         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1961         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1962         { }
1963 };
1964
1965 static struct hda_verb alc880_lg_ch6_init[] = {
1966         /* set line-in and mic-in to output */
1967         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1968         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1969         { }
1970 };
1971
1972 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
1973         { 2, alc880_lg_ch2_init },
1974         { 4, alc880_lg_ch4_init },
1975         { 6, alc880_lg_ch6_init },
1976 };
1977
1978 static struct snd_kcontrol_new alc880_lg_mixer[] = {
1979         /* FIXME: it's not really "master" but front channels */
1980         HDA_CODEC_VOLUME("Master Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1981         HDA_BIND_MUTE("Master Playback Switch", 0x0f, 2, HDA_INPUT),
1982         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1983         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
1984         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1985         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
1986         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
1987         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
1988         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1989         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1990         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
1991         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
1992         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
1993         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
1994         {
1995                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1996                 .name = "Channel Mode",
1997                 .info = alc_ch_mode_info,
1998                 .get = alc_ch_mode_get,
1999                 .put = alc_ch_mode_put,
2000         },
2001         { } /* end */
2002 };
2003
2004 static struct hda_verb alc880_lg_init_verbs[] = {
2005         /* set capture source to mic-in */
2006         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2007         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2008         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2009         /* mute all amp mixer inputs */
2010         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2011         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2012         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2013         /* line-in to input */
2014         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2015         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2016         /* built-in mic */
2017         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2018         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2019         /* speaker-out */
2020         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2021         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2022         /* mic-in to input */
2023         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2024         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2025         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2026         /* HP-out */
2027         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2028         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2029         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2030         /* jack sense */
2031         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2032         { }
2033 };
2034
2035 /* toggle speaker-output according to the hp-jack state */
2036 static void alc880_lg_automute(struct hda_codec *codec)
2037 {
2038         unsigned int present;
2039         unsigned char bits;
2040
2041         present = snd_hda_codec_read(codec, 0x1b, 0,
2042                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2043         bits = present ? HDA_AMP_MUTE : 0;
2044         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2045                                  HDA_AMP_MUTE, bits);
2046 }
2047
2048 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2049 {
2050         /* Looks like the unsol event is incompatible with the standard
2051          * definition.  4bit tag is placed at 28 bit!
2052          */
2053         if ((res >> 28) == 0x01)
2054                 alc880_lg_automute(codec);
2055 }
2056
2057 /*
2058  * LG LW20
2059  *
2060  * Pin assignment:
2061  *   Speaker-out: 0x14
2062  *   Mic-In: 0x18
2063  *   Built-in Mic-In: 0x19
2064  *   Line-In: 0x1b
2065  *   HP-Out: 0x1a
2066  *   SPDIF-Out: 0x1e
2067  */
2068
2069 static struct hda_input_mux alc880_lg_lw_capture_source = {
2070         .num_items = 3,
2071         .items = {
2072                 { "Mic", 0x0 },
2073                 { "Internal Mic", 0x1 },
2074                 { "Line In", 0x2 },
2075         },
2076 };
2077
2078 #define alc880_lg_lw_modes alc880_threestack_modes
2079
2080 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2081         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2082         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2083         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2084         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2085         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2086         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2087         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2088         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2089         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2090         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2091         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2092         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2093         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2094         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2095         {
2096                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2097                 .name = "Channel Mode",
2098                 .info = alc_ch_mode_info,
2099                 .get = alc_ch_mode_get,
2100                 .put = alc_ch_mode_put,
2101         },
2102         { } /* end */
2103 };
2104
2105 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2106         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2107         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2108         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2109
2110         /* set capture source to mic-in */
2111         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2112         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2113         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2114         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2115         /* speaker-out */
2116         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2117         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2118         /* HP-out */
2119         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2120         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2121         /* mic-in to input */
2122         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2123         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2124         /* built-in mic */
2125         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2126         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2127         /* jack sense */
2128         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2129         { }
2130 };
2131
2132 /* toggle speaker-output according to the hp-jack state */
2133 static void alc880_lg_lw_automute(struct hda_codec *codec)
2134 {
2135         unsigned int present;
2136         unsigned char bits;
2137
2138         present = snd_hda_codec_read(codec, 0x1b, 0,
2139                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2140         bits = present ? HDA_AMP_MUTE : 0;
2141         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2142                                  HDA_AMP_MUTE, bits);
2143 }
2144
2145 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2146 {
2147         /* Looks like the unsol event is incompatible with the standard
2148          * definition.  4bit tag is placed at 28 bit!
2149          */
2150         if ((res >> 28) == 0x01)
2151                 alc880_lg_lw_automute(codec);
2152 }
2153
2154 #ifdef CONFIG_SND_HDA_POWER_SAVE
2155 static struct hda_amp_list alc880_loopbacks[] = {
2156         { 0x0b, HDA_INPUT, 0 },
2157         { 0x0b, HDA_INPUT, 1 },
2158         { 0x0b, HDA_INPUT, 2 },
2159         { 0x0b, HDA_INPUT, 3 },
2160         { 0x0b, HDA_INPUT, 4 },
2161         { } /* end */
2162 };
2163
2164 static struct hda_amp_list alc880_lg_loopbacks[] = {
2165         { 0x0b, HDA_INPUT, 1 },
2166         { 0x0b, HDA_INPUT, 6 },
2167         { 0x0b, HDA_INPUT, 7 },
2168         { } /* end */
2169 };
2170 #endif
2171
2172 /*
2173  * Common callbacks
2174  */
2175
2176 static int alc_init(struct hda_codec *codec)
2177 {
2178         struct alc_spec *spec = codec->spec;
2179         unsigned int i;
2180
2181         for (i = 0; i < spec->num_init_verbs; i++)
2182                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2183
2184         if (spec->init_hook)
2185                 spec->init_hook(codec);
2186
2187         return 0;
2188 }
2189
2190 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2191 {
2192         struct alc_spec *spec = codec->spec;
2193
2194         if (spec->unsol_event)
2195                 spec->unsol_event(codec, res);
2196 }
2197
2198 #ifdef CONFIG_SND_HDA_POWER_SAVE
2199 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2200 {
2201         struct alc_spec *spec = codec->spec;
2202         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2203 }
2204 #endif
2205
2206 /*
2207  * Analog playback callbacks
2208  */
2209 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2210                                     struct hda_codec *codec,
2211                                     struct snd_pcm_substream *substream)
2212 {
2213         struct alc_spec *spec = codec->spec;
2214         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
2215 }
2216
2217 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2218                                        struct hda_codec *codec,
2219                                        unsigned int stream_tag,
2220                                        unsigned int format,
2221                                        struct snd_pcm_substream *substream)
2222 {
2223         struct alc_spec *spec = codec->spec;
2224         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2225                                                 stream_tag, format, substream);
2226 }
2227
2228 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2229                                        struct hda_codec *codec,
2230                                        struct snd_pcm_substream *substream)
2231 {
2232         struct alc_spec *spec = codec->spec;
2233         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2234 }
2235
2236 /*
2237  * Digital out
2238  */
2239 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2240                                         struct hda_codec *codec,
2241                                         struct snd_pcm_substream *substream)
2242 {
2243         struct alc_spec *spec = codec->spec;
2244         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2245 }
2246
2247 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2248                                            struct hda_codec *codec,
2249                                            unsigned int stream_tag,
2250                                            unsigned int format,
2251                                            struct snd_pcm_substream *substream)
2252 {
2253         struct alc_spec *spec = codec->spec;
2254         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2255                                              stream_tag, format, substream);
2256 }
2257
2258 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2259                                          struct hda_codec *codec,
2260                                          struct snd_pcm_substream *substream)
2261 {
2262         struct alc_spec *spec = codec->spec;
2263         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2264 }
2265
2266 /*
2267  * Analog capture
2268  */
2269 static int alc880_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2270                                       struct hda_codec *codec,
2271                                       unsigned int stream_tag,
2272                                       unsigned int format,
2273                                       struct snd_pcm_substream *substream)
2274 {
2275         struct alc_spec *spec = codec->spec;
2276
2277         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
2278                                    stream_tag, 0, format);
2279         return 0;
2280 }
2281
2282 static int alc880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2283                                       struct hda_codec *codec,
2284                                       struct snd_pcm_substream *substream)
2285 {
2286         struct alc_spec *spec = codec->spec;
2287
2288         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
2289                                    0, 0, 0);
2290         return 0;
2291 }
2292
2293
2294 /*
2295  */
2296 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2297         .substreams = 1,
2298         .channels_min = 2,
2299         .channels_max = 8,
2300         /* NID is set in alc_build_pcms */
2301         .ops = {
2302                 .open = alc880_playback_pcm_open,
2303                 .prepare = alc880_playback_pcm_prepare,
2304                 .cleanup = alc880_playback_pcm_cleanup
2305         },
2306 };
2307
2308 static struct hda_pcm_stream alc880_pcm_analog_capture = {
2309         .substreams = 2,
2310         .channels_min = 2,
2311         .channels_max = 2,
2312         /* NID is set in alc_build_pcms */
2313         .ops = {
2314                 .prepare = alc880_capture_pcm_prepare,
2315                 .cleanup = alc880_capture_pcm_cleanup
2316         },
2317 };
2318
2319 static struct hda_pcm_stream alc880_pcm_digital_playback = {
2320         .substreams = 1,
2321         .channels_min = 2,
2322         .channels_max = 2,
2323         /* NID is set in alc_build_pcms */
2324         .ops = {
2325                 .open = alc880_dig_playback_pcm_open,
2326                 .close = alc880_dig_playback_pcm_close,
2327                 .prepare = alc880_dig_playback_pcm_prepare
2328         },
2329 };
2330
2331 static struct hda_pcm_stream alc880_pcm_digital_capture = {
2332         .substreams = 1,
2333         .channels_min = 2,
2334         .channels_max = 2,
2335         /* NID is set in alc_build_pcms */
2336 };
2337
2338 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2339 static struct hda_pcm_stream alc_pcm_null_playback = {
2340         .substreams = 0,
2341         .channels_min = 0,
2342         .channels_max = 0,
2343 };
2344
2345 static int alc_build_pcms(struct hda_codec *codec)
2346 {
2347         struct alc_spec *spec = codec->spec;
2348         struct hda_pcm *info = spec->pcm_rec;
2349         int i;
2350
2351         codec->num_pcms = 1;
2352         codec->pcm_info = info;
2353
2354         info->name = spec->stream_name_analog;
2355         if (spec->stream_analog_playback) {
2356                 snd_assert(spec->multiout.dac_nids, return -EINVAL);
2357                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
2358                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2359         }
2360         if (spec->stream_analog_capture) {
2361                 snd_assert(spec->adc_nids, return -EINVAL);
2362                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2363                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2364         }
2365
2366         if (spec->channel_mode) {
2367                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2368                 for (i = 0; i < spec->num_channel_mode; i++) {
2369                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2370                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2371                         }
2372                 }
2373         }
2374
2375         /* SPDIF for stream index #1 */
2376         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2377                 codec->num_pcms = 2;
2378                 info = spec->pcm_rec + 1;
2379                 info->name = spec->stream_name_digital;
2380                 if (spec->multiout.dig_out_nid &&
2381                     spec->stream_digital_playback) {
2382                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
2383                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2384                 }
2385                 if (spec->dig_in_nid &&
2386                     spec->stream_digital_capture) {
2387                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
2388                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2389                 }
2390         }
2391
2392         /* If the use of more than one ADC is requested for the current
2393          * model, configure a second analog capture-only PCM.
2394          */
2395         /* Additional Analaog capture for index #2 */
2396         if (spec->num_adc_nids > 1 && spec->stream_analog_capture &&
2397             spec->adc_nids) {
2398                 codec->num_pcms = 3;
2399                 info = spec->pcm_rec + 2;
2400                 info->name = spec->stream_name_analog;
2401                 /* No playback stream for second PCM */
2402                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = alc_pcm_null_playback;
2403                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2404                 if (spec->stream_analog_capture) {
2405                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2406                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[1];
2407                 }
2408         }
2409
2410         return 0;
2411 }
2412
2413 static void alc_free(struct hda_codec *codec)
2414 {
2415         struct alc_spec *spec = codec->spec;
2416         unsigned int i;
2417
2418         if (!spec)
2419                 return;
2420
2421         if (spec->kctl_alloc) {
2422                 for (i = 0; i < spec->num_kctl_used; i++)
2423                         kfree(spec->kctl_alloc[i].name);
2424                 kfree(spec->kctl_alloc);
2425         }
2426         kfree(spec);
2427 }
2428
2429 /*
2430  */
2431 static struct hda_codec_ops alc_patch_ops = {
2432         .build_controls = alc_build_controls,
2433         .build_pcms = alc_build_pcms,
2434         .init = alc_init,
2435         .free = alc_free,
2436         .unsol_event = alc_unsol_event,
2437 #ifdef CONFIG_SND_HDA_POWER_SAVE
2438         .check_power_status = alc_check_power_status,
2439 #endif
2440 };
2441
2442
2443 /*
2444  * Test configuration for debugging
2445  *
2446  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
2447  * enum controls.
2448  */
2449 #ifdef CONFIG_SND_DEBUG
2450 static hda_nid_t alc880_test_dac_nids[4] = {
2451         0x02, 0x03, 0x04, 0x05
2452 };
2453
2454 static struct hda_input_mux alc880_test_capture_source = {
2455         .num_items = 7,
2456         .items = {
2457                 { "In-1", 0x0 },
2458                 { "In-2", 0x1 },
2459                 { "In-3", 0x2 },
2460                 { "In-4", 0x3 },
2461                 { "CD", 0x4 },
2462                 { "Front", 0x5 },
2463                 { "Surround", 0x6 },
2464         },
2465 };
2466
2467 static struct hda_channel_mode alc880_test_modes[4] = {
2468         { 2, NULL },
2469         { 4, NULL },
2470         { 6, NULL },
2471         { 8, NULL },
2472 };
2473
2474 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
2475                                  struct snd_ctl_elem_info *uinfo)
2476 {
2477         static char *texts[] = {
2478                 "N/A", "Line Out", "HP Out",
2479                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
2480         };
2481         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2482         uinfo->count = 1;
2483         uinfo->value.enumerated.items = 8;
2484         if (uinfo->value.enumerated.item >= 8)
2485                 uinfo->value.enumerated.item = 7;
2486         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2487         return 0;
2488 }
2489
2490 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
2491                                 struct snd_ctl_elem_value *ucontrol)
2492 {
2493         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2494         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2495         unsigned int pin_ctl, item = 0;
2496
2497         pin_ctl = snd_hda_codec_read(codec, nid, 0,
2498                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2499         if (pin_ctl & AC_PINCTL_OUT_EN) {
2500                 if (pin_ctl & AC_PINCTL_HP_EN)
2501                         item = 2;
2502                 else
2503                         item = 1;
2504         } else if (pin_ctl & AC_PINCTL_IN_EN) {
2505                 switch (pin_ctl & AC_PINCTL_VREFEN) {
2506                 case AC_PINCTL_VREF_HIZ: item = 3; break;
2507                 case AC_PINCTL_VREF_50:  item = 4; break;
2508                 case AC_PINCTL_VREF_GRD: item = 5; break;
2509                 case AC_PINCTL_VREF_80:  item = 6; break;
2510                 case AC_PINCTL_VREF_100: item = 7; break;
2511                 }
2512         }
2513         ucontrol->value.enumerated.item[0] = item;
2514         return 0;
2515 }
2516
2517 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
2518                                 struct snd_ctl_elem_value *ucontrol)
2519 {
2520         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2521         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2522         static unsigned int ctls[] = {
2523                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
2524                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
2525                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
2526                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
2527                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
2528                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
2529         };
2530         unsigned int old_ctl, new_ctl;
2531
2532         old_ctl = snd_hda_codec_read(codec, nid, 0,
2533                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2534         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
2535         if (old_ctl != new_ctl) {
2536                 int val;
2537                 snd_hda_codec_write_cache(codec, nid, 0,
2538                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
2539                                           new_ctl);
2540                 val = ucontrol->value.enumerated.item[0] >= 3 ?
2541                         HDA_AMP_MUTE : 0;
2542                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
2543                                          HDA_AMP_MUTE, val);
2544                 return 1;
2545         }
2546         return 0;
2547 }
2548
2549 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
2550                                  struct snd_ctl_elem_info *uinfo)
2551 {
2552         static char *texts[] = {
2553                 "Front", "Surround", "CLFE", "Side"
2554         };
2555         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2556         uinfo->count = 1;
2557         uinfo->value.enumerated.items = 4;
2558         if (uinfo->value.enumerated.item >= 4)
2559                 uinfo->value.enumerated.item = 3;
2560         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2561         return 0;
2562 }
2563
2564 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
2565                                 struct snd_ctl_elem_value *ucontrol)
2566 {
2567         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2568         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2569         unsigned int sel;
2570
2571         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
2572         ucontrol->value.enumerated.item[0] = sel & 3;
2573         return 0;
2574 }
2575
2576 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
2577                                 struct snd_ctl_elem_value *ucontrol)
2578 {
2579         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2580         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2581         unsigned int sel;
2582
2583         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
2584         if (ucontrol->value.enumerated.item[0] != sel) {
2585                 sel = ucontrol->value.enumerated.item[0] & 3;
2586                 snd_hda_codec_write_cache(codec, nid, 0,
2587                                           AC_VERB_SET_CONNECT_SEL, sel);
2588                 return 1;
2589         }
2590         return 0;
2591 }
2592
2593 #define PIN_CTL_TEST(xname,nid) {                       \
2594                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2595                         .name = xname,                 \
2596                         .info = alc_test_pin_ctl_info, \
2597                         .get = alc_test_pin_ctl_get,   \
2598                         .put = alc_test_pin_ctl_put,   \
2599                         .private_value = nid           \
2600                         }
2601
2602 #define PIN_SRC_TEST(xname,nid) {                       \
2603                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2604                         .name = xname,                 \
2605                         .info = alc_test_pin_src_info, \
2606                         .get = alc_test_pin_src_get,   \
2607                         .put = alc_test_pin_src_put,   \
2608                         .private_value = nid           \
2609                         }
2610
2611 static struct snd_kcontrol_new alc880_test_mixer[] = {
2612         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2613         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2614         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
2615         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2616         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2617         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2618         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
2619         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2620         PIN_CTL_TEST("Front Pin Mode", 0x14),
2621         PIN_CTL_TEST("Surround Pin Mode", 0x15),
2622         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
2623         PIN_CTL_TEST("Side Pin Mode", 0x17),
2624         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
2625         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
2626         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
2627         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
2628         PIN_SRC_TEST("In-1 Pin Source", 0x18),
2629         PIN_SRC_TEST("In-2 Pin Source", 0x19),
2630         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
2631         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
2632         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
2633         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
2634         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
2635         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
2636         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
2637         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
2638         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
2639         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
2640         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
2641         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
2642         {
2643                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2644                 .name = "Channel Mode",
2645                 .info = alc_ch_mode_info,
2646                 .get = alc_ch_mode_get,
2647                 .put = alc_ch_mode_put,
2648         },
2649         { } /* end */
2650 };
2651
2652 static struct hda_verb alc880_test_init_verbs[] = {
2653         /* Unmute inputs of 0x0c - 0x0f */
2654         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2655         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2656         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2657         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2658         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2659         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2660         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2661         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2662         /* Vol output for 0x0c-0x0f */
2663         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2664         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2665         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2666         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2667         /* Set output pins 0x14-0x17 */
2668         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2669         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2670         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2671         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2672         /* Unmute output pins 0x14-0x17 */
2673         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2674         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2675         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2676         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2677         /* Set input pins 0x18-0x1c */
2678         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2679         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2680         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2681         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2682         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2683         /* Mute input pins 0x18-0x1b */
2684         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2685         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2686         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2687         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2688         /* ADC set up */
2689         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2690         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2691         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2692         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2693         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2694         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2695         /* Analog input/passthru */
2696         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2697         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2698         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2699         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2700         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2701         { }
2702 };
2703 #endif
2704
2705 /*
2706  */
2707
2708 static const char *alc880_models[ALC880_MODEL_LAST] = {
2709         [ALC880_3ST]            = "3stack",
2710         [ALC880_TCL_S700]       = "tcl",
2711         [ALC880_3ST_DIG]        = "3stack-digout",
2712         [ALC880_CLEVO]          = "clevo",
2713         [ALC880_5ST]            = "5stack",
2714         [ALC880_5ST_DIG]        = "5stack-digout",
2715         [ALC880_W810]           = "w810",
2716         [ALC880_Z71V]           = "z71v",
2717         [ALC880_6ST]            = "6stack",
2718         [ALC880_6ST_DIG]        = "6stack-digout",
2719         [ALC880_ASUS]           = "asus",
2720         [ALC880_ASUS_W1V]       = "asus-w1v",
2721         [ALC880_ASUS_DIG]       = "asus-dig",
2722         [ALC880_ASUS_DIG2]      = "asus-dig2",
2723         [ALC880_UNIWILL_DIG]    = "uniwill",
2724         [ALC880_UNIWILL_P53]    = "uniwill-p53",
2725         [ALC880_FUJITSU]        = "fujitsu",
2726         [ALC880_F1734]          = "F1734",
2727         [ALC880_LG]             = "lg",
2728         [ALC880_LG_LW]          = "lg-lw",
2729 #ifdef CONFIG_SND_DEBUG
2730         [ALC880_TEST]           = "test",
2731 #endif
2732         [ALC880_AUTO]           = "auto",
2733 };
2734
2735 static struct snd_pci_quirk alc880_cfg_tbl[] = {
2736         /* Broken BIOS configuration */
2737         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG),
2738         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
2739
2740         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
2741         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
2742         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
2743         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
2744         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
2745         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
2746         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
2747         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
2748         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
2749
2750         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
2751         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
2752
2753         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
2754         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
2755         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
2756         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
2757         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
2758         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
2759         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
2760         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
2761         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
2762         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
2763         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS", ALC880_ASUS),
2764         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
2765         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
2766         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
2767         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS),
2768
2769         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
2770         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
2771         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
2772         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
2773         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
2774         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
2775         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
2776         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
2777         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
2778         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
2779         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
2780         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
2781         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
2782         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
2783         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
2784         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
2785         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
2786         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
2787
2788         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
2789         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
2790         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
2791         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
2792
2793         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
2794         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
2795         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
2796         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
2797
2798         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
2799         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
2800         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
2801         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
2802
2803         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
2804         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
2805         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
2806         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
2807         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
2808         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
2809         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
2810         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
2811         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
2812         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
2813         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST),
2814
2815         {}
2816 };
2817
2818 /*
2819  * ALC880 codec presets
2820  */
2821 static struct alc_config_preset alc880_presets[] = {
2822         [ALC880_3ST] = {
2823                 .mixers = { alc880_three_stack_mixer },
2824                 .init_verbs = { alc880_volume_init_verbs,
2825                                 alc880_pin_3stack_init_verbs },
2826                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2827                 .dac_nids = alc880_dac_nids,
2828                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2829                 .channel_mode = alc880_threestack_modes,
2830                 .need_dac_fix = 1,
2831                 .input_mux = &alc880_capture_source,
2832         },
2833         [ALC880_3ST_DIG] = {
2834                 .mixers = { alc880_three_stack_mixer },
2835                 .init_verbs = { alc880_volume_init_verbs,
2836                                 alc880_pin_3stack_init_verbs },
2837                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2838                 .dac_nids = alc880_dac_nids,
2839                 .dig_out_nid = ALC880_DIGOUT_NID,
2840                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2841                 .channel_mode = alc880_threestack_modes,
2842                 .need_dac_fix = 1,
2843                 .input_mux = &alc880_capture_source,
2844         },
2845         [ALC880_TCL_S700] = {
2846                 .mixers = { alc880_tcl_s700_mixer },
2847                 .init_verbs = { alc880_volume_init_verbs,
2848                                 alc880_pin_tcl_S700_init_verbs,
2849                                 alc880_gpio2_init_verbs },
2850                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2851                 .dac_nids = alc880_dac_nids,
2852                 .hp_nid = 0x03,
2853                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2854                 .channel_mode = alc880_2_jack_modes,
2855                 .input_mux = &alc880_capture_source,
2856         },
2857         [ALC880_5ST] = {
2858                 .mixers = { alc880_three_stack_mixer,
2859                             alc880_five_stack_mixer},
2860                 .init_verbs = { alc880_volume_init_verbs,
2861                                 alc880_pin_5stack_init_verbs },
2862                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2863                 .dac_nids = alc880_dac_nids,
2864                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
2865                 .channel_mode = alc880_fivestack_modes,
2866                 .input_mux = &alc880_capture_source,
2867         },
2868         [ALC880_5ST_DIG] = {
2869                 .mixers = { alc880_three_stack_mixer,
2870                             alc880_five_stack_mixer },
2871                 .init_verbs = { alc880_volume_init_verbs,
2872                                 alc880_pin_5stack_init_verbs },
2873                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2874                 .dac_nids = alc880_dac_nids,
2875                 .dig_out_nid = ALC880_DIGOUT_NID,
2876                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
2877                 .channel_mode = alc880_fivestack_modes,
2878                 .input_mux = &alc880_capture_source,
2879         },
2880         [ALC880_6ST] = {
2881                 .mixers = { alc880_six_stack_mixer },
2882                 .init_verbs = { alc880_volume_init_verbs,
2883                                 alc880_pin_6stack_init_verbs },
2884                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
2885                 .dac_nids = alc880_6st_dac_nids,
2886                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
2887                 .channel_mode = alc880_sixstack_modes,
2888                 .input_mux = &alc880_6stack_capture_source,
2889         },
2890         [ALC880_6ST_DIG] = {
2891                 .mixers = { alc880_six_stack_mixer },
2892                 .init_verbs = { alc880_volume_init_verbs,
2893                                 alc880_pin_6stack_init_verbs },
2894                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
2895                 .dac_nids = alc880_6st_dac_nids,
2896                 .dig_out_nid = ALC880_DIGOUT_NID,
2897                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
2898                 .channel_mode = alc880_sixstack_modes,
2899                 .input_mux = &alc880_6stack_capture_source,
2900         },
2901         [ALC880_W810] = {
2902                 .mixers = { alc880_w810_base_mixer },
2903                 .init_verbs = { alc880_volume_init_verbs,
2904                                 alc880_pin_w810_init_verbs,
2905                                 alc880_gpio2_init_verbs },
2906                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
2907                 .dac_nids = alc880_w810_dac_nids,
2908                 .dig_out_nid = ALC880_DIGOUT_NID,
2909                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
2910                 .channel_mode = alc880_w810_modes,
2911                 .input_mux = &alc880_capture_source,
2912         },
2913         [ALC880_Z71V] = {
2914                 .mixers = { alc880_z71v_mixer },
2915                 .init_verbs = { alc880_volume_init_verbs,
2916                                 alc880_pin_z71v_init_verbs },
2917                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
2918                 .dac_nids = alc880_z71v_dac_nids,
2919                 .dig_out_nid = ALC880_DIGOUT_NID,
2920                 .hp_nid = 0x03,
2921                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2922                 .channel_mode = alc880_2_jack_modes,
2923                 .input_mux = &alc880_capture_source,
2924         },
2925         [ALC880_F1734] = {
2926                 .mixers = { alc880_f1734_mixer },
2927                 .init_verbs = { alc880_volume_init_verbs,
2928                                 alc880_pin_f1734_init_verbs },
2929                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
2930                 .dac_nids = alc880_f1734_dac_nids,
2931                 .hp_nid = 0x02,
2932                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2933                 .channel_mode = alc880_2_jack_modes,
2934                 .input_mux = &alc880_capture_source,
2935         },
2936         [ALC880_ASUS] = {
2937                 .mixers = { alc880_asus_mixer },
2938                 .init_verbs = { alc880_volume_init_verbs,
2939                                 alc880_pin_asus_init_verbs,
2940                                 alc880_gpio1_init_verbs },
2941                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2942                 .dac_nids = alc880_asus_dac_nids,
2943                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2944                 .channel_mode = alc880_asus_modes,
2945                 .need_dac_fix = 1,
2946                 .input_mux = &alc880_capture_source,
2947         },
2948         [ALC880_ASUS_DIG] = {
2949                 .mixers = { alc880_asus_mixer },
2950                 .init_verbs = { alc880_volume_init_verbs,
2951                                 alc880_pin_asus_init_verbs,
2952                                 alc880_gpio1_init_verbs },
2953                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2954                 .dac_nids = alc880_asus_dac_nids,
2955                 .dig_out_nid = ALC880_DIGOUT_NID,
2956                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2957                 .channel_mode = alc880_asus_modes,
2958                 .need_dac_fix = 1,
2959                 .input_mux = &alc880_capture_source,
2960         },
2961         [ALC880_ASUS_DIG2] = {
2962                 .mixers = { alc880_asus_mixer },
2963                 .init_verbs = { alc880_volume_init_verbs,
2964                                 alc880_pin_asus_init_verbs,
2965                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
2966                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2967                 .dac_nids = alc880_asus_dac_nids,
2968                 .dig_out_nid = ALC880_DIGOUT_NID,
2969                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2970                 .channel_mode = alc880_asus_modes,
2971                 .need_dac_fix = 1,
2972                 .input_mux = &alc880_capture_source,
2973         },
2974         [ALC880_ASUS_W1V] = {
2975                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
2976                 .init_verbs = { alc880_volume_init_verbs,
2977                                 alc880_pin_asus_init_verbs,
2978                                 alc880_gpio1_init_verbs },
2979                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2980                 .dac_nids = alc880_asus_dac_nids,
2981                 .dig_out_nid = ALC880_DIGOUT_NID,
2982                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2983                 .channel_mode = alc880_asus_modes,
2984                 .need_dac_fix = 1,
2985                 .input_mux = &alc880_capture_source,
2986         },
2987         [ALC880_UNIWILL_DIG] = {
2988                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
2989                 .init_verbs = { alc880_volume_init_verbs,
2990                                 alc880_pin_asus_init_verbs },
2991                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2992                 .dac_nids = alc880_asus_dac_nids,
2993                 .dig_out_nid = ALC880_DIGOUT_NID,
2994                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2995                 .channel_mode = alc880_asus_modes,
2996                 .need_dac_fix = 1,
2997                 .input_mux = &alc880_capture_source,
2998         },
2999         [ALC880_UNIWILL] = {
3000                 .mixers = { alc880_uniwill_mixer },
3001                 .init_verbs = { alc880_volume_init_verbs,
3002                                 alc880_uniwill_init_verbs },
3003                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3004                 .dac_nids = alc880_asus_dac_nids,
3005                 .dig_out_nid = ALC880_DIGOUT_NID,
3006                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3007                 .channel_mode = alc880_threestack_modes,
3008                 .need_dac_fix = 1,
3009                 .input_mux = &alc880_capture_source,
3010                 .unsol_event = alc880_uniwill_unsol_event,
3011                 .init_hook = alc880_uniwill_automute,
3012         },
3013         [ALC880_UNIWILL_P53] = {
3014                 .mixers = { alc880_uniwill_p53_mixer },
3015                 .init_verbs = { alc880_volume_init_verbs,
3016                                 alc880_uniwill_p53_init_verbs },
3017                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3018                 .dac_nids = alc880_asus_dac_nids,
3019                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3020                 .channel_mode = alc880_threestack_modes,
3021                 .input_mux = &alc880_capture_source,
3022                 .unsol_event = alc880_uniwill_p53_unsol_event,
3023                 .init_hook = alc880_uniwill_p53_hp_automute,
3024         },
3025         [ALC880_FUJITSU] = {
3026                 .mixers = { alc880_fujitsu_mixer,
3027                             alc880_pcbeep_mixer, },
3028                 .init_verbs = { alc880_volume_init_verbs,
3029                                 alc880_uniwill_p53_init_verbs,
3030                                 alc880_beep_init_verbs },
3031                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3032                 .dac_nids = alc880_dac_nids,
3033                 .dig_out_nid = ALC880_DIGOUT_NID,
3034                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3035                 .channel_mode = alc880_2_jack_modes,
3036                 .input_mux = &alc880_capture_source,
3037                 .unsol_event = alc880_uniwill_p53_unsol_event,
3038                 .init_hook = alc880_uniwill_p53_hp_automute,
3039         },
3040         [ALC880_CLEVO] = {
3041                 .mixers = { alc880_three_stack_mixer },
3042                 .init_verbs = { alc880_volume_init_verbs,
3043                                 alc880_pin_clevo_init_verbs },
3044                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3045                 .dac_nids = alc880_dac_nids,
3046                 .hp_nid = 0x03,
3047                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3048                 .channel_mode = alc880_threestack_modes,
3049                 .need_dac_fix = 1,
3050                 .input_mux = &alc880_capture_source,
3051         },
3052         [ALC880_LG] = {
3053                 .mixers = { alc880_lg_mixer },
3054                 .init_verbs = { alc880_volume_init_verbs,
3055                                 alc880_lg_init_verbs },
3056                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3057                 .dac_nids = alc880_lg_dac_nids,
3058                 .dig_out_nid = ALC880_DIGOUT_NID,
3059                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3060                 .channel_mode = alc880_lg_ch_modes,
3061                 .need_dac_fix = 1,
3062                 .input_mux = &alc880_lg_capture_source,
3063                 .unsol_event = alc880_lg_unsol_event,
3064                 .init_hook = alc880_lg_automute,
3065 #ifdef CONFIG_SND_HDA_POWER_SAVE
3066                 .loopbacks = alc880_lg_loopbacks,
3067 #endif
3068         },
3069         [ALC880_LG_LW] = {
3070                 .mixers = { alc880_lg_lw_mixer },
3071                 .init_verbs = { alc880_volume_init_verbs,
3072                                 alc880_lg_lw_init_verbs },
3073                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3074                 .dac_nids = alc880_dac_nids,
3075                 .dig_out_nid = ALC880_DIGOUT_NID,
3076                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3077                 .channel_mode = alc880_lg_lw_modes,
3078                 .input_mux = &alc880_lg_lw_capture_source,
3079                 .unsol_event = alc880_lg_lw_unsol_event,
3080                 .init_hook = alc880_lg_lw_automute,
3081         },
3082 #ifdef CONFIG_SND_DEBUG
3083         [ALC880_TEST] = {
3084                 .mixers = { alc880_test_mixer },
3085                 .init_verbs = { alc880_test_init_verbs },
3086                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3087                 .dac_nids = alc880_test_dac_nids,
3088                 .dig_out_nid = ALC880_DIGOUT_NID,
3089                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3090                 .channel_mode = alc880_test_modes,
3091                 .input_mux = &alc880_test_capture_source,
3092         },
3093 #endif
3094 };
3095
3096 /*
3097  * Automatic parse of I/O pins from the BIOS configuration
3098  */
3099
3100 #define NUM_CONTROL_ALLOC       32
3101 #define NUM_VERB_ALLOC          32
3102
3103 enum {
3104         ALC_CTL_WIDGET_VOL,
3105         ALC_CTL_WIDGET_MUTE,
3106         ALC_CTL_BIND_MUTE,
3107 };
3108 static struct snd_kcontrol_new alc880_control_templates[] = {
3109         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3110         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3111         HDA_BIND_MUTE(NULL, 0, 0, 0),
3112 };
3113
3114 /* add dynamic controls */
3115 static int add_control(struct alc_spec *spec, int type, const char *name,
3116                        unsigned long val)
3117 {
3118         struct snd_kcontrol_new *knew;
3119
3120         if (spec->num_kctl_used >= spec->num_kctl_alloc) {
3121                 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
3122
3123                 /* array + terminator */
3124                 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
3125                 if (!knew)
3126                         return -ENOMEM;
3127                 if (spec->kctl_alloc) {
3128                         memcpy(knew, spec->kctl_alloc,
3129                                sizeof(*knew) * spec->num_kctl_alloc);
3130                         kfree(spec->kctl_alloc);
3131                 }
3132                 spec->kctl_alloc = knew;
3133                 spec->num_kctl_alloc = num;
3134         }
3135
3136         knew = &spec->kctl_alloc[spec->num_kctl_used];
3137         *knew = alc880_control_templates[type];
3138         knew->name = kstrdup(name, GFP_KERNEL);
3139         if (!knew->name)
3140                 return -ENOMEM;
3141         knew->private_value = val;
3142         spec->num_kctl_used++;
3143         return 0;
3144 }
3145
3146 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3147 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3148 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3149 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3150 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3151 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3152 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3153 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3154 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3155 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3156 #define ALC880_PIN_CD_NID               0x1c
3157
3158 /* fill in the dac_nids table from the parsed pin configuration */
3159 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3160                                      const struct auto_pin_cfg *cfg)
3161 {
3162         hda_nid_t nid;
3163         int assigned[4];
3164         int i, j;
3165
3166         memset(assigned, 0, sizeof(assigned));
3167         spec->multiout.dac_nids = spec->private_dac_nids;
3168
3169         /* check the pins hardwired to audio widget */
3170         for (i = 0; i < cfg->line_outs; i++) {
3171                 nid = cfg->line_out_pins[i];
3172                 if (alc880_is_fixed_pin(nid)) {
3173                         int idx = alc880_fixed_pin_idx(nid);
3174                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3175                         assigned[idx] = 1;
3176                 }
3177         }
3178         /* left pins can be connect to any audio widget */
3179         for (i = 0; i < cfg->line_outs; i++) {
3180                 nid = cfg->line_out_pins[i];
3181                 if (alc880_is_fixed_pin(nid))
3182                         continue;
3183                 /* search for an empty channel */
3184                 for (j = 0; j < cfg->line_outs; j++) {
3185                         if (!assigned[j]) {
3186                                 spec->multiout.dac_nids[i] =
3187                                         alc880_idx_to_dac(j);
3188                                 assigned[j] = 1;
3189                                 break;
3190                         }
3191                 }
3192         }
3193         spec->multiout.num_dacs = cfg->line_outs;
3194         return 0;
3195 }
3196
3197 /* add playback controls from the parsed DAC table */
3198 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
3199                                              const struct auto_pin_cfg *cfg)
3200 {
3201         char name[32];
3202         static const char *chname[4] = {
3203                 "Front", "Surround", NULL /*CLFE*/, "Side"
3204         };
3205         hda_nid_t nid;
3206         int i, err;
3207
3208         for (i = 0; i < cfg->line_outs; i++) {
3209                 if (!spec->multiout.dac_nids[i])
3210                         continue;
3211                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3212                 if (i == 2) {
3213                         /* Center/LFE */
3214                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3215                                           "Center Playback Volume",
3216                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3217                                                               HDA_OUTPUT));
3218                         if (err < 0)
3219                                 return err;
3220                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3221                                           "LFE Playback Volume",
3222                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3223                                                               HDA_OUTPUT));
3224                         if (err < 0)
3225                                 return err;
3226                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3227                                           "Center Playback Switch",
3228                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
3229                                                               HDA_INPUT));
3230                         if (err < 0)
3231                                 return err;
3232                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3233                                           "LFE Playback Switch",
3234                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
3235                                                               HDA_INPUT));
3236                         if (err < 0)
3237                                 return err;
3238                 } else {
3239                         sprintf(name, "%s Playback Volume", chname[i]);
3240                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3241                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3242                                                               HDA_OUTPUT));
3243                         if (err < 0)
3244                                 return err;
3245                         sprintf(name, "%s Playback Switch", chname[i]);
3246                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3247                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
3248                                                               HDA_INPUT));
3249                         if (err < 0)
3250                                 return err;
3251                 }
3252         }
3253         return 0;
3254 }
3255
3256 /* add playback controls for speaker and HP outputs */
3257 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
3258                                         const char *pfx)
3259 {
3260         hda_nid_t nid;
3261         int err;
3262         char name[32];
3263
3264         if (!pin)
3265                 return 0;
3266
3267         if (alc880_is_fixed_pin(pin)) {
3268                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
3269                 /* specify the DAC as the extra output */
3270                 if (!spec->multiout.hp_nid)
3271                         spec->multiout.hp_nid = nid;
3272                 else
3273                         spec->multiout.extra_out_nid[0] = nid;
3274                 /* control HP volume/switch on the output mixer amp */
3275                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
3276                 sprintf(name, "%s Playback Volume", pfx);
3277                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3278                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3279                 if (err < 0)
3280                         return err;
3281                 sprintf(name, "%s Playback Switch", pfx);
3282                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3283                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
3284                 if (err < 0)
3285                         return err;
3286         } else if (alc880_is_multi_pin(pin)) {
3287                 /* set manual connection */
3288                 /* we have only a switch on HP-out PIN */
3289                 sprintf(name, "%s Playback Switch", pfx);
3290                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3291                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3292                 if (err < 0)
3293                         return err;
3294         }
3295         return 0;
3296 }
3297
3298 /* create input playback/capture controls for the given pin */
3299 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
3300                             const char *ctlname,
3301                             int idx, hda_nid_t mix_nid)
3302 {
3303         char name[32];
3304         int err;
3305
3306         sprintf(name, "%s Playback Volume", ctlname);
3307         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3308                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3309         if (err < 0)
3310                 return err;
3311         sprintf(name, "%s Playback Switch", ctlname);
3312         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3313                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3314         if (err < 0)
3315                 return err;
3316         return 0;
3317 }
3318
3319 /* create playback/capture controls for input pins */
3320 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3321                                                 const struct auto_pin_cfg *cfg)
3322 {
3323         struct hda_input_mux *imux = &spec->private_imux;
3324         int i, err, idx;
3325
3326         for (i = 0; i < AUTO_PIN_LAST; i++) {
3327                 if (alc880_is_input_pin(cfg->input_pins[i])) {
3328                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
3329                         err = new_analog_input(spec, cfg->input_pins[i],
3330                                                auto_pin_cfg_labels[i],
3331                                                idx, 0x0b);
3332                         if (err < 0)
3333                                 return err;
3334                         imux->items[imux->num_items].label =
3335                                 auto_pin_cfg_labels[i];
3336                         imux->items[imux->num_items].index =
3337                                 alc880_input_pin_idx(cfg->input_pins[i]);
3338                         imux->num_items++;
3339                 }
3340         }
3341         return 0;
3342 }
3343
3344 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3345                                               hda_nid_t nid, int pin_type,
3346                                               int dac_idx)
3347 {
3348         /* set as output */
3349         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3350                             pin_type);
3351         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3352                             AMP_OUT_UNMUTE);
3353         /* need the manual connection? */
3354         if (alc880_is_multi_pin(nid)) {
3355                 struct alc_spec *spec = codec->spec;
3356                 int idx = alc880_multi_pin_idx(nid);
3357                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
3358                                     AC_VERB_SET_CONNECT_SEL,
3359                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
3360         }
3361 }
3362
3363 static int get_pin_type(int line_out_type)
3364 {
3365         if (line_out_type == AUTO_PIN_HP_OUT)
3366                 return PIN_HP;
3367         else
3368                 return PIN_OUT;
3369 }
3370
3371 static void alc880_auto_init_multi_out(struct hda_codec *codec)
3372 {
3373         struct alc_spec *spec = codec->spec;
3374         int i;
3375         
3376         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
3377         for (i = 0; i < spec->autocfg.line_outs; i++) {
3378                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3379                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3380                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
3381         }
3382 }
3383
3384 static void alc880_auto_init_extra_out(struct hda_codec *codec)
3385 {
3386         struct alc_spec *spec = codec->spec;
3387         hda_nid_t pin;
3388
3389         pin = spec->autocfg.speaker_pins[0];
3390         if (pin) /* connect to front */
3391                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
3392         pin = spec->autocfg.hp_pins[0];
3393         if (pin) /* connect to front */
3394                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3395 }
3396
3397 static void alc880_auto_init_analog_input(struct hda_codec *codec)
3398 {
3399         struct alc_spec *spec = codec->spec;
3400         int i;
3401
3402         for (i = 0; i < AUTO_PIN_LAST; i++) {
3403                 hda_nid_t nid = spec->autocfg.input_pins[i];
3404                 if (alc880_is_input_pin(nid)) {
3405                         snd_hda_codec_write(codec, nid, 0,
3406                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
3407                                             i <= AUTO_PIN_FRONT_MIC ?
3408                                             PIN_VREF80 : PIN_IN);
3409                         if (nid != ALC880_PIN_CD_NID)
3410                                 snd_hda_codec_write(codec, nid, 0,
3411                                                     AC_VERB_SET_AMP_GAIN_MUTE,
3412                                                     AMP_OUT_MUTE);
3413                 }
3414         }
3415 }
3416
3417 /* parse the BIOS configuration and set up the alc_spec */
3418 /* return 1 if successful, 0 if the proper config is not found,
3419  * or a negative error code
3420  */
3421 static int alc880_parse_auto_config(struct hda_codec *codec)
3422 {
3423         struct alc_spec *spec = codec->spec;
3424         int err;
3425         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3426
3427         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3428                                            alc880_ignore);
3429         if (err < 0)
3430                 return err;
3431         if (!spec->autocfg.line_outs)
3432                 return 0; /* can't find valid BIOS pin config */
3433
3434         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
3435         if (err < 0)
3436                 return err;
3437         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
3438         if (err < 0)
3439                 return err;
3440         err = alc880_auto_create_extra_out(spec,
3441                                            spec->autocfg.speaker_pins[0],
3442                                            "Speaker");
3443         if (err < 0)
3444                 return err;
3445         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
3446                                            "Headphone");
3447         if (err < 0)
3448                 return err;
3449         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
3450         if (err < 0)
3451                 return err;
3452
3453         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3454
3455         if (spec->autocfg.dig_out_pin)
3456                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
3457         if (spec->autocfg.dig_in_pin)
3458                 spec->dig_in_nid = ALC880_DIGIN_NID;
3459
3460         if (spec->kctl_alloc)
3461                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3462
3463         spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
3464
3465         spec->num_mux_defs = 1;
3466         spec->input_mux = &spec->private_imux;
3467
3468         return 1;
3469 }
3470
3471 /* additional initialization for auto-configuration model */
3472 static void alc880_auto_init(struct hda_codec *codec)
3473 {
3474         alc880_auto_init_multi_out(codec);
3475         alc880_auto_init_extra_out(codec);
3476         alc880_auto_init_analog_input(codec);
3477 }
3478
3479 /*
3480  * OK, here we have finally the patch for ALC880
3481  */
3482
3483 static int patch_alc880(struct hda_codec *codec)
3484 {
3485         struct alc_spec *spec;
3486         int board_config;
3487         int err;
3488
3489         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3490         if (spec == NULL)
3491                 return -ENOMEM;
3492
3493         codec->spec = spec;
3494
3495         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
3496                                                   alc880_models,
3497                                                   alc880_cfg_tbl);
3498         if (board_config < 0) {
3499                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
3500                        "trying auto-probe from BIOS...\n");
3501                 board_config = ALC880_AUTO;
3502         }
3503
3504         if (board_config == ALC880_AUTO) {
3505                 /* automatic parse from the BIOS config */
3506                 err = alc880_parse_auto_config(codec);
3507                 if (err < 0) {
3508                         alc_free(codec);
3509                         return err;
3510                 } else if (!err) {
3511                         printk(KERN_INFO
3512                                "hda_codec: Cannot set up configuration "
3513                                "from BIOS.  Using 3-stack mode...\n");
3514                         board_config = ALC880_3ST;
3515                 }
3516         }
3517
3518         if (board_config != ALC880_AUTO)
3519                 setup_preset(spec, &alc880_presets[board_config]);
3520
3521         spec->stream_name_analog = "ALC880 Analog";
3522         spec->stream_analog_playback = &alc880_pcm_analog_playback;
3523         spec->stream_analog_capture = &alc880_pcm_analog_capture;
3524
3525         spec->stream_name_digital = "ALC880 Digital";
3526         spec->stream_digital_playback = &alc880_pcm_digital_playback;
3527         spec->stream_digital_capture = &alc880_pcm_digital_capture;
3528
3529         if (!spec->adc_nids && spec->input_mux) {
3530                 /* check whether NID 0x07 is valid */
3531                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
3532                 /* get type */
3533                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3534                 if (wcap != AC_WID_AUD_IN) {
3535                         spec->adc_nids = alc880_adc_nids_alt;
3536                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
3537                         spec->mixers[spec->num_mixers] =
3538                                 alc880_capture_alt_mixer;
3539                         spec->num_mixers++;
3540                 } else {
3541                         spec->adc_nids = alc880_adc_nids;
3542                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
3543                         spec->mixers[spec->num_mixers] = alc880_capture_mixer;
3544                         spec->num_mixers++;
3545                 }
3546         }
3547
3548         codec->patch_ops = alc_patch_ops;
3549         if (board_config == ALC880_AUTO)
3550                 spec->init_hook = alc880_auto_init;
3551 #ifdef CONFIG_SND_HDA_POWER_SAVE
3552         if (!spec->loopback.amplist)
3553                 spec->loopback.amplist = alc880_loopbacks;
3554 #endif
3555
3556         return 0;
3557 }
3558
3559
3560 /*
3561  * ALC260 support
3562  */
3563
3564 static hda_nid_t alc260_dac_nids[1] = {
3565         /* front */
3566         0x02,
3567 };
3568
3569 static hda_nid_t alc260_adc_nids[1] = {
3570         /* ADC0 */
3571         0x04,
3572 };
3573
3574 static hda_nid_t alc260_adc_nids_alt[1] = {
3575         /* ADC1 */
3576         0x05,
3577 };
3578
3579 static hda_nid_t alc260_hp_adc_nids[2] = {
3580         /* ADC1, 0 */
3581         0x05, 0x04
3582 };
3583
3584 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
3585  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
3586  */
3587 static hda_nid_t alc260_dual_adc_nids[2] = {
3588         /* ADC0, ADC1 */
3589         0x04, 0x05
3590 };
3591
3592 #define ALC260_DIGOUT_NID       0x03
3593 #define ALC260_DIGIN_NID        0x06
3594
3595 static struct hda_input_mux alc260_capture_source = {
3596         .num_items = 4,
3597         .items = {
3598                 { "Mic", 0x0 },
3599                 { "Front Mic", 0x1 },
3600                 { "Line", 0x2 },
3601                 { "CD", 0x4 },
3602         },
3603 };
3604
3605 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
3606  * headphone jack and the internal CD lines since these are the only pins at
3607  * which audio can appear.  For flexibility, also allow the option of
3608  * recording the mixer output on the second ADC (ADC0 doesn't have a
3609  * connection to the mixer output).
3610  */
3611 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
3612         {
3613                 .num_items = 3,
3614                 .items = {
3615                         { "Mic/Line", 0x0 },
3616                         { "CD", 0x4 },
3617                         { "Headphone", 0x2 },
3618                 },
3619         },
3620         {
3621                 .num_items = 4,
3622                 .items = {
3623                         { "Mic/Line", 0x0 },
3624                         { "CD", 0x4 },
3625                         { "Headphone", 0x2 },
3626                         { "Mixer", 0x5 },
3627                 },
3628         },
3629
3630 };
3631
3632 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
3633  * the Fujitsu S702x, but jacks are marked differently.
3634  */
3635 static struct hda_input_mux alc260_acer_capture_sources[2] = {
3636         {
3637                 .num_items = 4,
3638                 .items = {
3639                         { "Mic", 0x0 },
3640                         { "Line", 0x2 },
3641                         { "CD", 0x4 },
3642                         { "Headphone", 0x5 },
3643                 },
3644         },
3645         {
3646                 .num_items = 5,
3647                 .items = {
3648                         { "Mic", 0x0 },
3649                         { "Line", 0x2 },
3650                         { "CD", 0x4 },
3651                         { "Headphone", 0x6 },
3652                         { "Mixer", 0x5 },
3653                 },
3654         },
3655 };
3656 /*
3657  * This is just place-holder, so there's something for alc_build_pcms to look
3658  * at when it calculates the maximum number of channels. ALC260 has no mixer
3659  * element which allows changing the channel mode, so the verb list is
3660  * never used.
3661  */
3662 static struct hda_channel_mode alc260_modes[1] = {
3663         { 2, NULL },
3664 };
3665
3666
3667 /* Mixer combinations
3668  *
3669  * basic: base_output + input + pc_beep + capture
3670  * HP: base_output + input + capture_alt
3671  * HP_3013: hp_3013 + input + capture
3672  * fujitsu: fujitsu + capture
3673  * acer: acer + capture
3674  */
3675
3676 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
3677         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3678         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
3679         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3680         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
3681         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3682         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
3683         { } /* end */
3684 };
3685
3686 static struct snd_kcontrol_new alc260_input_mixer[] = {
3687         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3688         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3689         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3690         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3691         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3692         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3693         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
3694         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
3695         { } /* end */
3696 };
3697
3698 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
3699         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
3700         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
3701         { } /* end */
3702 };
3703
3704 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
3705         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3706         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
3707         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
3708         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
3709         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3710         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
3711         HDA_CODEC_VOLUME_MONO("iSpeaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3712         HDA_CODEC_MUTE_MONO("iSpeaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
3713         { } /* end */
3714 };
3715
3716 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12, 
3717  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
3718  */
3719 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
3720         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3721         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
3722         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3723         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3724         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3725         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
3726         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
3727         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
3728         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3729         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3730         HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3731         HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x09, 2, HDA_INPUT),
3732         { } /* end */
3733 };
3734
3735 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
3736  * versions of the ALC260 don't act on requests to enable mic bias from NID
3737  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
3738  * datasheet doesn't mention this restriction.  At this stage it's not clear
3739  * whether this behaviour is intentional or is a hardware bug in chip
3740  * revisions available in early 2006.  Therefore for now allow the
3741  * "Headphone Jack Mode" control to span all choices, but if it turns out
3742  * that the lack of mic bias for this NID is intentional we could change the
3743  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
3744  *
3745  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
3746  * don't appear to make the mic bias available from the "line" jack, even
3747  * though the NID used for this jack (0x14) can supply it.  The theory is
3748  * that perhaps Acer have included blocking capacitors between the ALC260
3749  * and the output jack.  If this turns out to be the case for all such
3750  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
3751  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
3752  *
3753  * The C20x Tablet series have a mono internal speaker which is controlled
3754  * via the chip's Mono sum widget and pin complex, so include the necessary
3755  * controls for such models.  On models without a "mono speaker" the control
3756  * won't do anything.
3757  */
3758 static struct snd_kcontrol_new alc260_acer_mixer[] = {
3759         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3760         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
3761         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
3762         HDA_CODEC_VOLUME_MONO("Mono Speaker Playback Volume", 0x0a, 1, 0x0,
3763                               HDA_OUTPUT),
3764         HDA_BIND_MUTE_MONO("Mono Speaker Playback Switch", 0x0a, 1, 2,
3765                            HDA_INPUT),
3766         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3767         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3768         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3769         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3770         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3771         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3772         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3773         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3774         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3775         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3776         { } /* end */
3777 };
3778
3779 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
3780  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
3781  */
3782 static struct snd_kcontrol_new alc260_will_mixer[] = {
3783         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3784         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
3785         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3786         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3787         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3788         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3789         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3790         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3791         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3792         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3793         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3794         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3795         { } /* end */
3796 };
3797
3798 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
3799  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
3800  */
3801 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
3802         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3803         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
3804         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3805         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3806         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3807         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
3808         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
3809         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3810         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3811         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3812         { } /* end */
3813 };
3814
3815 /* capture mixer elements */
3816 static struct snd_kcontrol_new alc260_capture_mixer[] = {
3817         HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
3818         HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
3819         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
3820         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),
3821         {
3822                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3823                 /* The multiple "Capture Source" controls confuse alsamixer
3824                  * So call somewhat different..
3825                  * FIXME: the controls appear in the "playback" view!
3826                  */
3827                 /* .name = "Capture Source", */
3828                 .name = "Input Source",
3829                 .count = 2,
3830                 .info = alc_mux_enum_info,
3831                 .get = alc_mux_enum_get,
3832                 .put = alc_mux_enum_put,
3833         },
3834         { } /* end */
3835 };
3836
3837 static struct snd_kcontrol_new alc260_capture_alt_mixer[] = {
3838         HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
3839         HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
3840         {
3841                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3842                 /* The multiple "Capture Source" controls confuse alsamixer
3843                  * So call somewhat different..
3844                  * FIXME: the controls appear in the "playback" view!
3845                  */
3846                 /* .name = "Capture Source", */
3847                 .name = "Input Source",
3848                 .count = 1,
3849                 .info = alc_mux_enum_info,
3850                 .get = alc_mux_enum_get,
3851                 .put = alc_mux_enum_put,
3852         },
3853         { } /* end */
3854 };
3855
3856 /*
3857  * initialization verbs
3858  */
3859 static struct hda_verb alc260_init_verbs[] = {
3860         /* Line In pin widget for input */
3861         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3862         /* CD pin widget for input */
3863         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3864         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3865         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3866         /* Mic2 (front panel) pin widget for input and vref at 80% */
3867         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3868         /* LINE-2 is used for line-out in rear */
3869         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3870         /* select line-out */
3871         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
3872         /* LINE-OUT pin */
3873         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3874         /* enable HP */
3875         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3876         /* enable Mono */
3877         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3878         /* mute capture amp left and right */
3879         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3880         /* set connection select to line in (default select for this ADC) */
3881         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3882         /* mute capture amp left and right */
3883         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3884         /* set connection select to line in (default select for this ADC) */
3885         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
3886         /* set vol=0 Line-Out mixer amp left and right */
3887         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3888         /* unmute pin widget amp left and right (no gain on this amp) */
3889         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3890         /* set vol=0 HP mixer amp left and right */
3891         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3892         /* unmute pin widget amp left and right (no gain on this amp) */
3893         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3894         /* set vol=0 Mono mixer amp left and right */
3895         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3896         /* unmute pin widget amp left and right (no gain on this amp) */
3897         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3898         /* unmute LINE-2 out pin */
3899         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3900         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
3901          * Line In 2 = 0x03
3902          */
3903         /* mute analog inputs */
3904         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3905         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3906         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3907         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3908         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3909         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3910         /* mute Front out path */
3911         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3912         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3913         /* mute Headphone out path */
3914         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3915         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3916         /* mute Mono out path */
3917         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3918         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3919         { }
3920 };
3921
3922 #if 0 /* should be identical with alc260_init_verbs? */
3923 static struct hda_verb alc260_hp_init_verbs[] = {
3924         /* Headphone and output */
3925         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
3926         /* mono output */
3927         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3928         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3929         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3930         /* Mic2 (front panel) pin widget for input and vref at 80% */
3931         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3932         /* Line In pin widget for input */
3933         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3934         /* Line-2 pin widget for output */
3935         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3936         /* CD pin widget for input */
3937         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3938         /* unmute amp left and right */
3939         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
3940         /* set connection select to line in (default select for this ADC) */
3941         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3942         /* unmute Line-Out mixer amp left and right (volume = 0) */
3943         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3944         /* mute pin widget amp left and right (no gain on this amp) */
3945         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3946         /* unmute HP mixer amp left and right (volume = 0) */
3947         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3948         /* mute pin widget amp left and right (no gain on this amp) */
3949         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3950         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
3951          * Line In 2 = 0x03
3952          */
3953         /* mute analog inputs */
3954         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3955         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3956         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3957         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3958         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3959         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3960         /* Unmute Front out path */
3961         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3962         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3963         /* Unmute Headphone out path */
3964         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3965         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3966         /* Unmute Mono out path */
3967         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3968         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3969         { }
3970 };
3971 #endif
3972
3973 static struct hda_verb alc260_hp_3013_init_verbs[] = {
3974         /* Line out and output */
3975         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3976         /* mono output */
3977         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3978         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3979         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3980         /* Mic2 (front panel) pin widget for input and vref at 80% */
3981         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3982         /* Line In pin widget for input */
3983         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3984         /* Headphone pin widget for output */
3985         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
3986         /* CD pin widget for input */
3987         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3988         /* unmute amp left and right */
3989         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
3990         /* set connection select to line in (default select for this ADC) */
3991         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3992         /* unmute Line-Out mixer amp left and right (volume = 0) */
3993         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3994         /* mute pin widget amp left and right (no gain on this amp) */
3995         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3996         /* unmute HP mixer amp left and right (volume = 0) */
3997         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3998         /* mute pin widget amp left and right (no gain on this amp) */
3999         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4000         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4001          * Line In 2 = 0x03
4002          */
4003         /* mute analog inputs */
4004         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4005         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4006         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4007         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4008         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4009         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4010         /* Unmute Front out path */
4011         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4012         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4013         /* Unmute Headphone out path */
4014         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4015         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4016         /* Unmute Mono out path */
4017         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4018         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4019         { }
4020 };
4021
4022 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4023  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4024  * audio = 0x16, internal speaker = 0x10.
4025  */
4026 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4027         /* Disable all GPIOs */
4028         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4029         /* Internal speaker is connected to headphone pin */
4030         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4031         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4032         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4033         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4034         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4035         /* Ensure all other unused pins are disabled and muted. */
4036         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4037         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4038         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4039         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4040         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4041         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4042         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4043         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4044
4045         /* Disable digital (SPDIF) pins */
4046         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4047         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4048
4049         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus 
4050          * when acting as an output.
4051          */
4052         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4053
4054         /* Start with output sum widgets muted and their output gains at min */
4055         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4056         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4057         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4058         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4059         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4060         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4061         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4062         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4063         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4064
4065         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
4066         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4067         /* Unmute Line1 pin widget output buffer since it starts as an output.
4068          * If the pin mode is changed by the user the pin mode control will
4069          * take care of enabling the pin's input/output buffers as needed.
4070          * Therefore there's no need to enable the input buffer at this
4071          * stage.
4072          */
4073         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4074         /* Unmute input buffer of pin widget used for Line-in (no equiv 
4075          * mixer ctrl)
4076          */
4077         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4078
4079         /* Mute capture amp left and right */
4080         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4081         /* Set ADC connection select to match default mixer setting - line 
4082          * in (on mic1 pin)
4083          */
4084         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4085
4086         /* Do the same for the second ADC: mute capture input amp and
4087          * set ADC connection to line in (on mic1 pin)
4088          */
4089         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4090         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4091
4092         /* Mute all inputs to mixer widget (even unconnected ones) */
4093         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4094         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4095         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4096         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4097         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4098         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4099         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4100         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4101
4102         { }
4103 };
4104
4105 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
4106  * similar laptops (adapted from Fujitsu init verbs).
4107  */
4108 static struct hda_verb alc260_acer_init_verbs[] = {
4109         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
4110          * the headphone jack.  Turn this on and rely on the standard mute
4111          * methods whenever the user wants to turn these outputs off.
4112          */
4113         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4114         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4115         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
4116         /* Internal speaker/Headphone jack is connected to Line-out pin */
4117         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4118         /* Internal microphone/Mic jack is connected to Mic1 pin */
4119         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
4120         /* Line In jack is connected to Line1 pin */
4121         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4122         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
4123         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4124         /* Ensure all other unused pins are disabled and muted. */
4125         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4126         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4127         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4128         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4129         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4130         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4131         /* Disable digital (SPDIF) pins */
4132         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4133         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4134
4135         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum 
4136          * bus when acting as outputs.
4137          */
4138         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4139         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4140
4141         /* Start with output sum widgets muted and their output gains at min */
4142         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4143         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4144         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4145         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4146         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4147         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4148         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4149         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4150         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4151
4152         /* Unmute Line-out pin widget amp left and right
4153          * (no equiv mixer ctrl)
4154          */
4155         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4156         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
4157         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4158         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
4159          * inputs. If the pin mode is changed by the user the pin mode control
4160          * will take care of enabling the pin's input/output buffers as needed.
4161          * Therefore there's no need to enable the input buffer at this
4162          * stage.
4163          */
4164         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4165         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4166
4167         /* Mute capture amp left and right */
4168         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4169         /* Set ADC connection select to match default mixer setting - mic
4170          * (on mic1 pin)
4171          */
4172         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4173
4174         /* Do similar with the second ADC: mute capture input amp and
4175          * set ADC connection to mic to match ALSA's default state.
4176          */
4177         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4178         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4179
4180         /* Mute all inputs to mixer widget (even unconnected ones) */
4181         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4182         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4183         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4184         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4185         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4186         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4187         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4188         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4189
4190         { }
4191 };
4192
4193 static struct hda_verb alc260_will_verbs[] = {
4194         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4195         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
4196         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
4197         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4198         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4199         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
4200         {}
4201 };
4202
4203 static struct hda_verb alc260_replacer_672v_verbs[] = {
4204         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4205         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
4206         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
4207
4208         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
4209         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4210         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4211
4212         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4213         {}
4214 };
4215
4216 /* toggle speaker-output according to the hp-jack state */
4217 static void alc260_replacer_672v_automute(struct hda_codec *codec)
4218 {
4219         unsigned int present;
4220
4221         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
4222         present = snd_hda_codec_read(codec, 0x0f, 0,
4223                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
4224         if (present) {
4225                 snd_hda_codec_write_cache(codec, 0x01, 0,
4226                                           AC_VERB_SET_GPIO_DATA, 1);
4227                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4228                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4229                                           PIN_HP);
4230         } else {
4231                 snd_hda_codec_write_cache(codec, 0x01, 0,
4232                                           AC_VERB_SET_GPIO_DATA, 0);
4233                 snd_hda_codec_write_cache(codec, 0x0f, 0,
4234                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4235                                           PIN_OUT);
4236         }
4237 }
4238
4239 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
4240                                        unsigned int res)
4241 {
4242         if ((res >> 26) == ALC880_HP_EVENT)
4243                 alc260_replacer_672v_automute(codec);
4244 }
4245
4246 /* Test configuration for debugging, modelled after the ALC880 test
4247  * configuration.
4248  */
4249 #ifdef CONFIG_SND_DEBUG
4250 static hda_nid_t alc260_test_dac_nids[1] = {
4251         0x02,
4252 };
4253 static hda_nid_t alc260_test_adc_nids[2] = {
4254         0x04, 0x05,
4255 };
4256 /* For testing the ALC260, each input MUX needs its own definition since
4257  * the signal assignments are different.  This assumes that the first ADC 
4258  * is NID 0x04.
4259  */
4260 static struct hda_input_mux alc260_test_capture_sources[2] = {
4261         {
4262                 .num_items = 7,
4263                 .items = {
4264                         { "MIC1 pin", 0x0 },
4265                         { "MIC2 pin", 0x1 },
4266                         { "LINE1 pin", 0x2 },
4267                         { "LINE2 pin", 0x3 },
4268                         { "CD pin", 0x4 },
4269                         { "LINE-OUT pin", 0x5 },
4270                         { "HP-OUT pin", 0x6 },
4271                 },
4272         },
4273         {
4274                 .num_items = 8,
4275                 .items = {
4276                         { "MIC1 pin", 0x0 },
4277                         { "MIC2 pin", 0x1 },
4278                         { "LINE1 pin", 0x2 },
4279                         { "LINE2 pin", 0x3 },
4280                         { "CD pin", 0x4 },
4281                         { "Mixer", 0x5 },
4282                         { "LINE-OUT pin", 0x6 },
4283                         { "HP-OUT pin", 0x7 },
4284                 },
4285         },
4286 };
4287 static struct snd_kcontrol_new alc260_test_mixer[] = {
4288         /* Output driver widgets */
4289         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4290         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4291         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4292         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
4293         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4294         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
4295
4296         /* Modes for retasking pin widgets
4297          * Note: the ALC260 doesn't seem to act on requests to enable mic
4298          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
4299          * mention this restriction.  At this stage it's not clear whether
4300          * this behaviour is intentional or is a hardware bug in chip
4301          * revisions available at least up until early 2006.  Therefore for
4302          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
4303          * choices, but if it turns out that the lack of mic bias for these
4304          * NIDs is intentional we could change their modes from
4305          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4306          */
4307         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
4308         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
4309         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
4310         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
4311         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
4312         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
4313
4314         /* Loopback mixer controls */
4315         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
4316         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
4317         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
4318         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
4319         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
4320         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
4321         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
4322         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
4323         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4324         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4325         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4326         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4327         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
4328         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
4329         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
4330         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
4331
4332         /* Controls for GPIO pins, assuming they are configured as outputs */
4333         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
4334         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
4335         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
4336         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
4337
4338         /* Switches to allow the digital IO pins to be enabled.  The datasheet
4339          * is ambigious as to which NID is which; testing on laptops which
4340          * make this output available should provide clarification. 
4341          */
4342         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
4343         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
4344
4345         { } /* end */
4346 };
4347 static struct hda_verb alc260_test_init_verbs[] = {
4348         /* Enable all GPIOs as outputs with an initial value of 0 */
4349         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
4350         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4351         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
4352
4353         /* Enable retasking pins as output, initially without power amp */
4354         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4355         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4356         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4357         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4358         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4359         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4360
4361         /* Disable digital (SPDIF) pins initially, but users can enable
4362          * them via a mixer switch.  In the case of SPDIF-out, this initverb
4363          * payload also sets the generation to 0, output to be in "consumer"
4364          * PCM format, copyright asserted, no pre-emphasis and no validity
4365          * control.
4366          */
4367         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4368         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4369
4370         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the 
4371          * OUT1 sum bus when acting as an output.
4372          */
4373         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4374         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
4375         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4376         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
4377
4378         /* Start with output sum widgets muted and their output gains at min */
4379         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4380         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4381         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4382         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4383         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4384         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4385         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4386         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4387         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4388
4389         /* Unmute retasking pin widget output buffers since the default
4390          * state appears to be output.  As the pin mode is changed by the
4391          * user the pin mode control will take care of enabling the pin's
4392          * input/output buffers as needed.
4393          */
4394         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4395         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4396         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4397         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4398         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4399         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4400         /* Also unmute the mono-out pin widget */
4401         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4402
4403         /* Mute capture amp left and right */
4404         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4405         /* Set ADC connection select to match default mixer setting (mic1
4406          * pin)
4407          */
4408         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4409
4410         /* Do the same for the second ADC: mute capture input amp and
4411          * set ADC connection to mic1 pin
4412          */
4413         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4414         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4415
4416         /* Mute all inputs to mixer widget (even unconnected ones) */
4417         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4418         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4419         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4420         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4421         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4422         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4423         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4424         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4425
4426         { }
4427 };
4428 #endif
4429
4430 static struct hda_pcm_stream alc260_pcm_analog_playback = {
4431         .substreams = 1,
4432         .channels_min = 2,
4433         .channels_max = 2,
4434 };
4435
4436 static struct hda_pcm_stream alc260_pcm_analog_capture = {
4437         .substreams = 1,
4438         .channels_min = 2,
4439         .channels_max = 2,
4440 };
4441
4442 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
4443 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
4444
4445 /*
4446  * for BIOS auto-configuration
4447  */
4448
4449 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
4450                                         const char *pfx)
4451 {
4452         hda_nid_t nid_vol;
4453         unsigned long vol_val, sw_val;
4454         char name[32];
4455         int err;
4456
4457         if (nid >= 0x0f && nid < 0x11) {
4458                 nid_vol = nid - 0x7;
4459                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4460                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4461         } else if (nid == 0x11) {
4462                 nid_vol = nid - 0x7;
4463                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
4464                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
4465         } else if (nid >= 0x12 && nid <= 0x15) {
4466                 nid_vol = 0x08;
4467                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4468                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4469         } else
4470                 return 0; /* N/A */
4471         
4472         snprintf(name, sizeof(name), "%s Playback Volume", pfx);
4473         err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
4474         if (err < 0)
4475                 return err;
4476         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
4477         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
4478         if (err < 0)
4479                 return err;
4480         return 1;
4481 }
4482
4483 /* add playback controls from the parsed DAC table */
4484 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
4485                                              const struct auto_pin_cfg *cfg)
4486 {
4487         hda_nid_t nid;
4488         int err;
4489
4490         spec->multiout.num_dacs = 1;
4491         spec->multiout.dac_nids = spec->private_dac_nids;
4492         spec->multiout.dac_nids[0] = 0x02;
4493
4494         nid = cfg->line_out_pins[0];
4495         if (nid) {
4496                 err = alc260_add_playback_controls(spec, nid, "Front");
4497                 if (err < 0)
4498                         return err;
4499         }
4500
4501         nid = cfg->speaker_pins[0];
4502         if (nid) {
4503                 err = alc260_add_playback_controls(spec, nid, "Speaker");
4504                 if (err < 0)
4505                         return err;
4506         }
4507
4508         nid = cfg->hp_pins[0];
4509         if (nid) {
4510                 err = alc260_add_playback_controls(spec, nid, "Headphone");
4511                 if (err < 0)
4512                         return err;
4513         }
4514         return 0;
4515 }
4516
4517 /* create playback/capture controls for input pins */
4518 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
4519                                                 const struct auto_pin_cfg *cfg)
4520 {
4521         struct hda_input_mux *imux = &spec->private_imux;
4522         int i, err, idx;
4523
4524         for (i = 0; i < AUTO_PIN_LAST; i++) {
4525                 if (cfg->input_pins[i] >= 0x12) {
4526                         idx = cfg->input_pins[i] - 0x12;
4527                         err = new_analog_input(spec, cfg->input_pins[i],
4528                                                auto_pin_cfg_labels[i], idx,
4529                                                0x07);
4530                         if (err < 0)
4531                                 return err;
4532                         imux->items[imux->num_items].label =
4533                                 auto_pin_cfg_labels[i];
4534                         imux->items[imux->num_items].index = idx;
4535                         imux->num_items++;
4536                 }
4537                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
4538                         idx = cfg->input_pins[i] - 0x09;
4539                         err = new_analog_input(spec, cfg->input_pins[i],
4540                                                auto_pin_cfg_labels[i], idx,
4541                                                0x07);
4542                         if (err < 0)
4543                                 return err;
4544                         imux->items[imux->num_items].label =
4545                                 auto_pin_cfg_labels[i];
4546                         imux->items[imux->num_items].index = idx;
4547                         imux->num_items++;
4548                 }
4549         }
4550         return 0;
4551 }
4552
4553 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
4554                                               hda_nid_t nid, int pin_type,
4555                                               int sel_idx)
4556 {
4557         /* set as output */
4558         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4559                             pin_type);
4560         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4561                             AMP_OUT_UNMUTE);
4562         /* need the manual connection? */
4563         if (nid >= 0x12) {
4564                 int idx = nid - 0x12;
4565                 snd_hda_codec_write(codec, idx + 0x0b, 0,
4566                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
4567         }
4568 }
4569
4570 static void alc260_auto_init_multi_out(struct hda_codec *codec)
4571 {
4572         struct alc_spec *spec = codec->spec;
4573         hda_nid_t nid;
4574
4575         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
4576         nid = spec->autocfg.line_out_pins[0];
4577         if (nid) {
4578                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4579                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
4580         }
4581         
4582         nid = spec->autocfg.speaker_pins[0];
4583         if (nid)
4584                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
4585
4586         nid = spec->autocfg.hp_pins[0];
4587         if (nid)
4588                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
4589 }
4590
4591 #define ALC260_PIN_CD_NID               0x16
4592 static void alc260_auto_init_analog_input(struct hda_codec *codec)
4593 {
4594         struct alc_spec *spec = codec->spec;
4595         int i;
4596
4597         for (i = 0; i < AUTO_PIN_LAST; i++) {
4598                 hda_nid_t nid = spec->autocfg.input_pins[i];
4599                 if (nid >= 0x12) {
4600                         snd_hda_codec_write(codec, nid, 0,
4601                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
4602                                             i <= AUTO_PIN_FRONT_MIC ?
4603                                             PIN_VREF80 : PIN_IN);
4604                         if (nid != ALC260_PIN_CD_NID)
4605                                 snd_hda_codec_write(codec, nid, 0,
4606                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4607                                                     AMP_OUT_MUTE);
4608                 }
4609         }
4610 }
4611
4612 /*
4613  * generic initialization of ADC, input mixers and output mixers
4614  */
4615 static struct hda_verb alc260_volume_init_verbs[] = {
4616         /*
4617          * Unmute ADC0-1 and set the default input to mic-in
4618          */
4619         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4620         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4621         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4622         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4623         
4624         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4625          * mixer widget
4626          * Note: PASD motherboards uses the Line In 2 as the input for
4627          * front panel mic (mic 2)
4628          */
4629         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
4630         /* mute analog inputs */
4631         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4632         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4633         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4634         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4635         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4636
4637         /*
4638          * Set up output mixers (0x08 - 0x0a)
4639          */
4640         /* set vol=0 to output mixers */
4641         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4642         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4643         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4644         /* set up input amps for analog loopback */
4645         /* Amp Indices: DAC = 0, mixer = 1 */
4646         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4647         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4648         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4649         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4650         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4651         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4652         
4653         { }
4654 };
4655
4656 static int alc260_parse_auto_config(struct hda_codec *codec)
4657 {
4658         struct alc_spec *spec = codec->spec;
4659         unsigned int wcap;
4660         int err;
4661         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
4662
4663         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4664                                            alc260_ignore);
4665         if (err < 0)
4666                 return err;
4667         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
4668         if (err < 0)
4669                 return err;
4670         if (!spec->kctl_alloc)
4671                 return 0; /* can't find valid BIOS pin config */
4672         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
4673         if (err < 0)
4674                 return err;
4675
4676         spec->multiout.max_channels = 2;
4677
4678         if (spec->autocfg.dig_out_pin)
4679                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
4680         if (spec->kctl_alloc)
4681                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
4682
4683         spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs;
4684
4685         spec->num_mux_defs = 1;
4686         spec->input_mux = &spec->private_imux;
4687
4688         /* check whether NID 0x04 is valid */
4689         wcap = get_wcaps(codec, 0x04);
4690         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
4691         if (wcap != AC_WID_AUD_IN) {
4692                 spec->adc_nids = alc260_adc_nids_alt;
4693                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
4694                 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
4695         } else {
4696                 spec->adc_nids = alc260_adc_nids;
4697                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
4698                 spec->mixers[spec->num_mixers] = alc260_capture_mixer;
4699         }
4700         spec->num_mixers++;
4701
4702         return 1;
4703 }
4704
4705 /* additional initialization for auto-configuration model */
4706 static void alc260_auto_init(struct hda_codec *codec)
4707 {
4708         alc260_auto_init_multi_out(codec);
4709         alc260_auto_init_analog_input(codec);
4710 }
4711
4712 #ifdef CONFIG_SND_HDA_POWER_SAVE
4713 static struct hda_amp_list alc260_loopbacks[] = {
4714         { 0x07, HDA_INPUT, 0 },
4715         { 0x07, HDA_INPUT, 1 },
4716         { 0x07, HDA_INPUT, 2 },
4717         { 0x07, HDA_INPUT, 3 },
4718         { 0x07, HDA_INPUT, 4 },
4719         { } /* end */
4720 };
4721 #endif
4722
4723 /*
4724  * ALC260 configurations
4725  */
4726 static const char *alc260_models[ALC260_MODEL_LAST] = {
4727         [ALC260_BASIC]          = "basic",
4728         [ALC260_HP]             = "hp",
4729         [ALC260_HP_3013]        = "hp-3013",
4730         [ALC260_FUJITSU_S702X]  = "fujitsu",
4731         [ALC260_ACER]           = "acer",
4732         [ALC260_WILL]           = "will",
4733         [ALC260_REPLACER_672V]  = "replacer",
4734 #ifdef CONFIG_SND_DEBUG
4735         [ALC260_TEST]           = "test",
4736 #endif
4737         [ALC260_AUTO]           = "auto",
4738 };
4739
4740 static struct snd_pci_quirk alc260_cfg_tbl[] = {
4741         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
4742         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
4743         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
4744         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
4745         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
4746         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP),
4747         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_3013),
4748         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
4749         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
4750         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
4751         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
4752         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
4753         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
4754         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
4755         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
4756         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
4757         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
4758         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
4759         {}
4760 };
4761
4762 static struct alc_config_preset alc260_presets[] = {
4763         [ALC260_BASIC] = {
4764                 .mixers = { alc260_base_output_mixer,
4765                             alc260_input_mixer,
4766                             alc260_pc_beep_mixer,
4767                             alc260_capture_mixer },
4768                 .init_verbs = { alc260_init_verbs },
4769                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4770                 .dac_nids = alc260_dac_nids,
4771                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4772                 .adc_nids = alc260_adc_nids,
4773                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4774                 .channel_mode = alc260_modes,
4775                 .input_mux = &alc260_capture_source,
4776         },
4777         [ALC260_HP] = {
4778                 .mixers = { alc260_base_output_mixer,
4779                             alc260_input_mixer,
4780                             alc260_capture_alt_mixer },
4781                 .init_verbs = { alc260_init_verbs },
4782                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4783                 .dac_nids = alc260_dac_nids,
4784                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
4785                 .adc_nids = alc260_hp_adc_nids,
4786                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4787                 .channel_mode = alc260_modes,
4788                 .input_mux = &alc260_capture_source,
4789         },
4790         [ALC260_HP_3013] = {
4791                 .mixers = { alc260_hp_3013_mixer,
4792                             alc260_input_mixer,
4793                             alc260_capture_alt_mixer },
4794                 .init_verbs = { alc260_hp_3013_init_verbs },
4795                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4796                 .dac_nids = alc260_dac_nids,
4797                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
4798                 .adc_nids = alc260_hp_adc_nids,
4799                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4800                 .channel_mode = alc260_modes,
4801                 .input_mux = &alc260_capture_source,
4802         },
4803         [ALC260_FUJITSU_S702X] = {
4804                 .mixers = { alc260_fujitsu_mixer,
4805                             alc260_capture_mixer },
4806                 .init_verbs = { alc260_fujitsu_init_verbs },
4807                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4808                 .dac_nids = alc260_dac_nids,
4809                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
4810                 .adc_nids = alc260_dual_adc_nids,
4811                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4812                 .channel_mode = alc260_modes,
4813                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
4814                 .input_mux = alc260_fujitsu_capture_sources,
4815         },
4816         [ALC260_ACER] = {
4817                 .mixers = { alc260_acer_mixer,
4818                             alc260_capture_mixer },
4819                 .init_verbs = { alc260_acer_init_verbs },
4820                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4821                 .dac_nids = alc260_dac_nids,
4822                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
4823                 .adc_nids = alc260_dual_adc_nids,
4824                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4825                 .channel_mode = alc260_modes,
4826                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
4827                 .input_mux = alc260_acer_capture_sources,
4828         },
4829         [ALC260_WILL] = {
4830                 .mixers = { alc260_will_mixer,
4831                             alc260_capture_mixer },
4832                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
4833                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4834                 .dac_nids = alc260_dac_nids,
4835                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4836                 .adc_nids = alc260_adc_nids,
4837                 .dig_out_nid = ALC260_DIGOUT_NID,
4838                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4839                 .channel_mode = alc260_modes,
4840                 .input_mux = &alc260_capture_source,
4841         },
4842         [ALC260_REPLACER_672V] = {
4843                 .mixers = { alc260_replacer_672v_mixer,
4844                             alc260_capture_mixer },
4845                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
4846                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4847                 .dac_nids = alc260_dac_nids,
4848                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4849                 .adc_nids = alc260_adc_nids,
4850                 .dig_out_nid = ALC260_DIGOUT_NID,
4851                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4852                 .channel_mode = alc260_modes,
4853                 .input_mux = &alc260_capture_source,
4854                 .unsol_event = alc260_replacer_672v_unsol_event,
4855                 .init_hook = alc260_replacer_672v_automute,
4856         },
4857 #ifdef CONFIG_SND_DEBUG
4858         [ALC260_TEST] = {
4859                 .mixers = { alc260_test_mixer,
4860                             alc260_capture_mixer },
4861                 .init_verbs = { alc260_test_init_verbs },
4862                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
4863                 .dac_nids = alc260_test_dac_nids,
4864                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
4865                 .adc_nids = alc260_test_adc_nids,
4866                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4867                 .channel_mode = alc260_modes,
4868                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
4869                 .input_mux = alc260_test_capture_sources,
4870         },
4871 #endif
4872 };
4873
4874 static int patch_alc260(struct hda_codec *codec)
4875 {
4876         struct alc_spec *spec;
4877         int err, board_config;
4878
4879         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4880         if (spec == NULL)
4881                 return -ENOMEM;
4882
4883         codec->spec = spec;
4884
4885         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
4886                                                   alc260_models,
4887                                                   alc260_cfg_tbl);
4888         if (board_config < 0) {
4889                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
4890                            "trying auto-probe from BIOS...\n");
4891                 board_config = ALC260_AUTO;
4892         }
4893
4894         if (board_config == ALC260_AUTO) {
4895                 /* automatic parse from the BIOS config */
4896                 err = alc260_parse_auto_config(codec);
4897                 if (err < 0) {
4898                         alc_free(codec);
4899                         return err;
4900                 } else if (!err) {
4901                         printk(KERN_INFO
4902                                "hda_codec: Cannot set up configuration "
4903                                "from BIOS.  Using base mode...\n");
4904                         board_config = ALC260_BASIC;
4905                 }
4906         }
4907
4908         if (board_config != ALC260_AUTO)
4909                 setup_preset(spec, &alc260_presets[board_config]);
4910
4911         spec->stream_name_analog = "ALC260 Analog";
4912         spec->stream_analog_playback = &alc260_pcm_analog_playback;
4913         spec->stream_analog_capture = &alc260_pcm_analog_capture;
4914
4915         spec->stream_name_digital = "ALC260 Digital";
4916         spec->stream_digital_playback = &alc260_pcm_digital_playback;
4917         spec->stream_digital_capture = &alc260_pcm_digital_capture;
4918
4919         codec->patch_ops = alc_patch_ops;
4920         if (board_config == ALC260_AUTO)
4921                 spec->init_hook = alc260_auto_init;
4922 #ifdef CONFIG_SND_HDA_POWER_SAVE
4923         if (!spec->loopback.amplist)
4924                 spec->loopback.amplist = alc260_loopbacks;
4925 #endif
4926
4927         return 0;
4928 }
4929
4930
4931 /*
4932  * ALC882 support
4933  *
4934  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4935  * configuration.  Each pin widget can choose any input DACs and a mixer.
4936  * Each ADC is connected from a mixer of all inputs.  This makes possible
4937  * 6-channel independent captures.
4938  *
4939  * In addition, an independent DAC for the multi-playback (not used in this
4940  * driver yet).
4941  */
4942 #define ALC882_DIGOUT_NID       0x06
4943 #define ALC882_DIGIN_NID        0x0a
4944
4945 static struct hda_channel_mode alc882_ch_modes[1] = {
4946         { 8, NULL }
4947 };
4948
4949 static hda_nid_t alc882_dac_nids[4] = {
4950         /* front, rear, clfe, rear_surr */
4951         0x02, 0x03, 0x04, 0x05
4952 };
4953
4954 /* identical with ALC880 */
4955 #define alc882_adc_nids         alc880_adc_nids
4956 #define alc882_adc_nids_alt     alc880_adc_nids_alt
4957
4958 /* input MUX */
4959 /* FIXME: should be a matrix-type input source selection */
4960
4961 static struct hda_input_mux alc882_capture_source = {
4962         .num_items = 4,
4963         .items = {
4964                 { "Mic", 0x0 },
4965                 { "Front Mic", 0x1 },
4966                 { "Line", 0x2 },
4967                 { "CD", 0x4 },
4968         },
4969 };
4970 #define alc882_mux_enum_info alc_mux_enum_info
4971 #define alc882_mux_enum_get alc_mux_enum_get
4972
4973 static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol,
4974                                struct snd_ctl_elem_value *ucontrol)
4975 {
4976         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4977         struct alc_spec *spec = codec->spec;
4978         const struct hda_input_mux *imux = spec->input_mux;
4979         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
4980         static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
4981         hda_nid_t nid = capture_mixers[adc_idx];
4982         unsigned int *cur_val = &spec->cur_mux[adc_idx];
4983         unsigned int i, idx;
4984
4985         idx = ucontrol->value.enumerated.item[0];
4986         if (idx >= imux->num_items)
4987                 idx = imux->num_items - 1;
4988         if (*cur_val == idx)
4989                 return 0;
4990         for (i = 0; i < imux->num_items; i++) {
4991                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
4992                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
4993                                          imux->items[i].index,
4994                                          HDA_AMP_MUTE, v);
4995         }
4996         *cur_val = idx;
4997         return 1;
4998 }
4999
5000 /*
5001  * 2ch mode
5002  */
5003 static struct hda_verb alc882_3ST_ch2_init[] = {
5004         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5005         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5006         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5007         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5008         { } /* end */
5009 };
5010
5011 /*
5012  * 6ch mode
5013  */
5014 static struct hda_verb alc882_3ST_ch6_init[] = {
5015         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5016         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5017         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5018         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5019         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5020         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5021         { } /* end */
5022 };
5023
5024 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5025         { 2, alc882_3ST_ch2_init },
5026         { 6, alc882_3ST_ch6_init },
5027 };
5028
5029 /*
5030  * 6ch mode
5031  */
5032 static struct hda_verb alc882_sixstack_ch6_init[] = {
5033         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5034         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5035         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5036         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5037         { } /* end */
5038 };
5039
5040 /*
5041  * 8ch mode
5042  */
5043 static struct hda_verb alc882_sixstack_ch8_init[] = {
5044         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5045         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5046         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5047         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5048         { } /* end */
5049 };
5050
5051 static struct hda_channel_mode alc882_sixstack_modes[2] = {
5052         { 6, alc882_sixstack_ch6_init },
5053         { 8, alc882_sixstack_ch8_init },
5054 };
5055
5056 /*
5057  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
5058  */
5059
5060 /*
5061  * 2ch mode
5062  */
5063 static struct hda_verb alc885_mbp_ch2_init[] = {
5064         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5065         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5066         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5067         { } /* end */
5068 };
5069
5070 /*
5071  * 6ch mode
5072  */
5073 static struct hda_verb alc885_mbp_ch6_init[] = {
5074         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5075         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5076         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5077         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5078         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5079         { } /* end */
5080 };
5081
5082 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
5083         { 2, alc885_mbp_ch2_init },
5084         { 6, alc885_mbp_ch6_init },
5085 };
5086
5087
5088 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
5089  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
5090  */
5091 static struct snd_kcontrol_new alc882_base_mixer[] = {
5092         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5093         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5094         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5095         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5096         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5097         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5098         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5099         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5100         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
5101         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
5102         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5103         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5104         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5105         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5106         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5107         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5108         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5109         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5110         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5111         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5112         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5113         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5114         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5115         { } /* end */
5116 };
5117
5118 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
5119         HDA_CODEC_VOLUME("Master Volume", 0x0c, 0x00, HDA_OUTPUT),
5120         HDA_BIND_MUTE   ("Master Switch", 0x0c, 0x02, HDA_INPUT),
5121         HDA_CODEC_MUTE  ("Speaker Switch", 0x14, 0x00, HDA_OUTPUT),
5122         HDA_CODEC_VOLUME("Line Out Volume", 0x0d,0x00, HDA_OUTPUT),
5123         HDA_CODEC_VOLUME("Line In Playback Volume", 0x0b, 0x02, HDA_INPUT),
5124         HDA_CODEC_MUTE  ("Line In Playback Switch", 0x0b, 0x02, HDA_INPUT),
5125         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
5126         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
5127         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0x00, HDA_INPUT),
5128         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
5129         { } /* end */
5130 };
5131 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
5132         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5133         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5134         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5135         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5136         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5137         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5138         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5139         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5140         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5141         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5142         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5143         { } /* end */
5144 };
5145
5146 static struct snd_kcontrol_new alc882_targa_mixer[] = {
5147         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5148         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5149         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5150         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5151         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5152         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5153         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5154         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5155         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5156         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5157         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5158         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5159         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5160         { } /* end */
5161 };
5162
5163 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
5164  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
5165  */
5166 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
5167         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5168         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5169         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5170         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
5171         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5172         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5173         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5174         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5175         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
5176         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
5177         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5178         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5179         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5180         { } /* end */
5181 };
5182
5183 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
5184         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5185         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5186         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5187         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5188         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5189         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5190         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5191         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5192         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5193         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5194         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5195         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5196         { } /* end */
5197 };
5198
5199 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
5200         {
5201                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5202                 .name = "Channel Mode",
5203                 .info = alc_ch_mode_info,
5204                 .get = alc_ch_mode_get,
5205                 .put = alc_ch_mode_put,
5206         },
5207         { } /* end */
5208 };
5209
5210 static struct hda_verb alc882_init_verbs[] = {
5211         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5212         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5213         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5214         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5215         /* Rear mixer */
5216         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5217         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5218         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5219         /* CLFE mixer */
5220         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5221         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5222         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5223         /* Side mixer */
5224         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5225         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5226         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5227
5228         /* Front Pin: output 0 (0x0c) */
5229         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5230         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5231         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5232         /* Rear Pin: output 1 (0x0d) */
5233         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5234         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5235         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5236         /* CLFE Pin: output 2 (0x0e) */
5237         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5238         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5239         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
5240         /* Side Pin: output 3 (0x0f) */
5241         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5242         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5243         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
5244         /* Mic (rear) pin: input vref at 80% */
5245         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5246         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5247         /* Front Mic pin: input vref at 80% */
5248         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5249         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5250         /* Line In pin: input */
5251         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5252         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5253         /* Line-2 In: Headphone output (output 0 - 0x0c) */
5254         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5255         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5256         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
5257         /* CD pin widget for input */
5258         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5259
5260         /* FIXME: use matrix-type input source selection */
5261         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5262         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5263         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5264         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5265         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5266         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5267         /* Input mixer2 */
5268         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5269         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5270         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5271         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5272         /* Input mixer3 */
5273         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5274         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5275         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5276         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5277         /* ADC1: mute amp left and right */
5278         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5279         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5280         /* ADC2: mute amp left and right */
5281         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5282         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5283         /* ADC3: mute amp left and right */
5284         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5285         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5286
5287         { }
5288 };
5289
5290 static struct hda_verb alc882_eapd_verbs[] = {
5291         /* change to EAPD mode */
5292         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5293         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
5294         { }
5295 };
5296
5297 /* Mac Pro test */
5298 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
5299         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5300         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5301         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
5302         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
5303         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
5304         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
5305         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
5306         { } /* end */
5307 };
5308
5309 static struct hda_verb alc882_macpro_init_verbs[] = {
5310         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5311         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5312         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5313         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5314         /* Front Pin: output 0 (0x0c) */
5315         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5316         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5317         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5318         /* Front Mic pin: input vref at 80% */
5319         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5320         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5321         /* Speaker:  output */
5322         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5323         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5324         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
5325         /* Headphone output (output 0 - 0x0c) */
5326         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5327         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5328         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5329
5330         /* FIXME: use matrix-type input source selection */
5331         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5332         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5333         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5334         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5335         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5336         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5337         /* Input mixer2 */
5338         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5339         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5340         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5341         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5342         /* Input mixer3 */
5343         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5344         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5345         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5346         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5347         /* ADC1: mute amp left and right */
5348         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5349         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5350         /* ADC2: mute amp left and right */
5351         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5352         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5353         /* ADC3: mute amp left and right */
5354         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5355         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5356
5357         { }
5358 };
5359
5360 /* Macbook Pro rev3 */
5361 static struct hda_verb alc885_mbp3_init_verbs[] = {
5362         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5363         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5364         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5365         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5366         /* Rear mixer */
5367         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5368         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5369         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5370         /* Front Pin: output 0 (0x0c) */
5371         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5372         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5373         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5374         /* HP Pin: output 0 (0x0d) */
5375         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
5376         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5377         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5378         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5379         /* Mic (rear) pin: input vref at 80% */
5380         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5381         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5382         /* Front Mic pin: input vref at 80% */
5383         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5384         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5385         /* Line In pin: use output 1 when in LineOut mode */
5386         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5387         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5388         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
5389
5390         /* FIXME: use matrix-type input source selection */
5391         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5392         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5393         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5394         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5395         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5396         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5397         /* Input mixer2 */
5398         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5399         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5400         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5401         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5402         /* Input mixer3 */
5403         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5404         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5405         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5406         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5407         /* ADC1: mute amp left and right */
5408         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5409         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5410         /* ADC2: mute amp left and right */
5411         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5412         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5413         /* ADC3: mute amp left and right */
5414         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5415         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5416
5417         { }
5418 };
5419
5420 /* iMac 24 mixer. */
5421 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
5422         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
5423         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
5424         { } /* end */
5425 };
5426
5427 /* iMac 24 init verbs. */
5428 static struct hda_verb alc885_imac24_init_verbs[] = {
5429         /* Internal speakers: output 0 (0x0c) */
5430         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5431         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5432         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5433         /* Internal speakers: output 0 (0x0c) */
5434         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5435         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5436         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
5437         /* Headphone: output 0 (0x0c) */
5438         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5439         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5440         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
5441         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5442         /* Front Mic: input vref at 80% */
5443         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5444         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5445         { }
5446 };
5447
5448 /* Toggle speaker-output according to the hp-jack state */
5449 static void alc885_imac24_automute(struct hda_codec *codec)
5450 {
5451         unsigned int present;
5452
5453         present = snd_hda_codec_read(codec, 0x14, 0,
5454                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5455         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
5456                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5457         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
5458                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5459 }
5460
5461 /* Processes unsolicited events. */
5462 static void alc885_imac24_unsol_event(struct hda_codec *codec,
5463                                       unsigned int res)
5464 {
5465         /* Headphone insertion or removal. */
5466         if ((res >> 26) == ALC880_HP_EVENT)
5467                 alc885_imac24_automute(codec);
5468 }
5469
5470 static void alc885_mbp3_automute(struct hda_codec *codec)
5471 {
5472         unsigned int present;
5473
5474         present = snd_hda_codec_read(codec, 0x15, 0,
5475                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5476         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
5477                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5478         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
5479                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
5480
5481 }
5482 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
5483                                     unsigned int res)
5484 {
5485         /* Headphone insertion or removal. */
5486         if ((res >> 26) == ALC880_HP_EVENT)
5487                 alc885_mbp3_automute(codec);
5488 }
5489
5490
5491 static struct hda_verb alc882_targa_verbs[] = {
5492         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5493         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5494
5495         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5496         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5497         
5498         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5499         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5500         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5501
5502         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5503         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5504         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
5505         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
5506         { } /* end */
5507 };
5508
5509 /* toggle speaker-output according to the hp-jack state */
5510 static void alc882_targa_automute(struct hda_codec *codec)
5511 {
5512         unsigned int present;
5513  
5514         present = snd_hda_codec_read(codec, 0x14, 0,
5515                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5516         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
5517                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
5518         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
5519                                   present ? 1 : 3);
5520 }
5521
5522 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
5523 {
5524         /* Looks like the unsol event is incompatible with the standard
5525          * definition.  4bit tag is placed at 26 bit!
5526          */
5527         if (((res >> 26) == ALC880_HP_EVENT)) {
5528                 alc882_targa_automute(codec);
5529         }
5530 }
5531
5532 static struct hda_verb alc882_asus_a7j_verbs[] = {
5533         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5534         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5535
5536         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5537         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5538         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5539         
5540         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5541         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5542         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5543
5544         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5545         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5546         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5547         { } /* end */
5548 };
5549
5550 static struct hda_verb alc882_asus_a7m_verbs[] = {
5551         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5552         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5553
5554         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5555         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5556         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5557         
5558         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5559         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5560         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5561
5562         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5563         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5564         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5565         { } /* end */
5566 };
5567
5568 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5569 {
5570         unsigned int gpiostate, gpiomask, gpiodir;
5571
5572         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5573                                        AC_VERB_GET_GPIO_DATA, 0);
5574
5575         if (!muted)
5576                 gpiostate |= (1 << pin);
5577         else
5578                 gpiostate &= ~(1 << pin);
5579
5580         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5581                                       AC_VERB_GET_GPIO_MASK, 0);
5582         gpiomask |= (1 << pin);
5583
5584         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5585                                      AC_VERB_GET_GPIO_DIRECTION, 0);
5586         gpiodir |= (1 << pin);
5587
5588
5589         snd_hda_codec_write(codec, codec->afg, 0,
5590                             AC_VERB_SET_GPIO_MASK, gpiomask);
5591         snd_hda_codec_write(codec, codec->afg, 0,
5592                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5593
5594         msleep(1);
5595
5596         snd_hda_codec_write(codec, codec->afg, 0,
5597                             AC_VERB_SET_GPIO_DATA, gpiostate);
5598 }
5599
5600 /* set up GPIO at initialization */
5601 static void alc885_macpro_init_hook(struct hda_codec *codec)
5602 {
5603         alc882_gpio_mute(codec, 0, 0);
5604         alc882_gpio_mute(codec, 1, 0);
5605 }
5606
5607 /* set up GPIO and update auto-muting at initialization */
5608 static void alc885_imac24_init_hook(struct hda_codec *codec)
5609 {
5610         alc885_macpro_init_hook(codec);
5611         alc885_imac24_automute(codec);
5612 }
5613
5614 /*
5615  * generic initialization of ADC, input mixers and output mixers
5616  */
5617 static struct hda_verb alc882_auto_init_verbs[] = {
5618         /*
5619          * Unmute ADC0-2 and set the default input to mic-in
5620          */
5621         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5622         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5623         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5624         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5625         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5626         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5627
5628         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5629          * mixer widget
5630          * Note: PASD motherboards uses the Line In 2 as the input for
5631          * front panel mic (mic 2)
5632          */
5633         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5634         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5635         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5636         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5637         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5638         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5639
5640         /*
5641          * Set up output mixers (0x0c - 0x0f)
5642          */
5643         /* set vol=0 to output mixers */
5644         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5645         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5646         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5647         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5648         /* set up input amps for analog loopback */
5649         /* Amp Indices: DAC = 0, mixer = 1 */
5650         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5651         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5652         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5653         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5654         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5655         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5656         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5657         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5658         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5659         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5660
5661         /* FIXME: use matrix-type input source selection */
5662         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5663         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5664         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5665         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5666         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5667         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5668         /* Input mixer2 */
5669         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5670         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5671         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5672         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5673         /* Input mixer3 */
5674         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5675         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5676         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5677         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5678
5679         { }
5680 };
5681
5682 /* capture mixer elements */
5683 static struct snd_kcontrol_new alc882_capture_alt_mixer[] = {
5684         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5685         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5686         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5687         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5688         {
5689                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5690                 /* The multiple "Capture Source" controls confuse alsamixer
5691                  * So call somewhat different..
5692                  * FIXME: the controls appear in the "playback" view!
5693                  */
5694                 /* .name = "Capture Source", */
5695                 .name = "Input Source",
5696                 .count = 2,
5697                 .info = alc882_mux_enum_info,
5698                 .get = alc882_mux_enum_get,
5699                 .put = alc882_mux_enum_put,
5700         },
5701         { } /* end */
5702 };
5703
5704 static struct snd_kcontrol_new alc882_capture_mixer[] = {
5705         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
5706         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
5707         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
5708         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
5709         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
5710         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
5711         {
5712                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5713                 /* The multiple "Capture Source" controls confuse alsamixer
5714                  * So call somewhat different..
5715                  * FIXME: the controls appear in the "playback" view!
5716                  */
5717                 /* .name = "Capture Source", */
5718                 .name = "Input Source",
5719                 .count = 3,
5720                 .info = alc882_mux_enum_info,
5721                 .get = alc882_mux_enum_get,
5722                 .put = alc882_mux_enum_put,
5723         },
5724         { } /* end */
5725 };
5726
5727 #ifdef CONFIG_SND_HDA_POWER_SAVE
5728 #define alc882_loopbacks        alc880_loopbacks
5729 #endif
5730
5731 /* pcm configuration: identiacal with ALC880 */
5732 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
5733 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
5734 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
5735 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
5736
5737 /*
5738  * configuration and preset
5739  */
5740 static const char *alc882_models[ALC882_MODEL_LAST] = {
5741         [ALC882_3ST_DIG]        = "3stack-dig",
5742         [ALC882_6ST_DIG]        = "6stack-dig",
5743         [ALC882_ARIMA]          = "arima",
5744         [ALC882_W2JC]           = "w2jc",
5745         [ALC882_TARGA]          = "targa",
5746         [ALC882_ASUS_A7J]       = "asus-a7j",
5747         [ALC882_ASUS_A7M]       = "asus-a7m",
5748         [ALC885_MACPRO]         = "macpro",
5749         [ALC885_MBP3]           = "mbp3",
5750         [ALC885_IMAC24]         = "imac24",
5751         [ALC882_AUTO]           = "auto",
5752 };
5753
5754 static struct snd_pci_quirk alc882_cfg_tbl[] = {
5755         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
5756         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
5757         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
5758         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
5759         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
5760         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
5761         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
5762         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
5763         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
5764         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
5765         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
5766         {}
5767 };
5768
5769 static struct alc_config_preset alc882_presets[] = {
5770         [ALC882_3ST_DIG] = {
5771                 .mixers = { alc882_base_mixer },
5772                 .init_verbs = { alc882_init_verbs },
5773                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5774                 .dac_nids = alc882_dac_nids,
5775                 .dig_out_nid = ALC882_DIGOUT_NID,
5776                 .dig_in_nid = ALC882_DIGIN_NID,
5777                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
5778                 .channel_mode = alc882_ch_modes,
5779                 .need_dac_fix = 1,
5780                 .input_mux = &alc882_capture_source,
5781         },
5782         [ALC882_6ST_DIG] = {
5783                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
5784                 .init_verbs = { alc882_init_verbs },
5785                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5786                 .dac_nids = alc882_dac_nids,
5787                 .dig_out_nid = ALC882_DIGOUT_NID,
5788                 .dig_in_nid = ALC882_DIGIN_NID,
5789                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
5790                 .channel_mode = alc882_sixstack_modes,
5791                 .input_mux = &alc882_capture_source,
5792         },
5793         [ALC882_ARIMA] = {
5794                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
5795                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
5796                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5797                 .dac_nids = alc882_dac_nids,
5798                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
5799                 .channel_mode = alc882_sixstack_modes,
5800                 .input_mux = &alc882_capture_source,
5801         },
5802         [ALC882_W2JC] = {
5803                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
5804                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
5805                                 alc880_gpio1_init_verbs },
5806                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5807                 .dac_nids = alc882_dac_nids,
5808                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
5809                 .channel_mode = alc880_threestack_modes,
5810                 .need_dac_fix = 1,
5811                 .input_mux = &alc882_capture_source,
5812                 .dig_out_nid = ALC882_DIGOUT_NID,
5813         },
5814         [ALC885_MBP3] = {
5815                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
5816                 .init_verbs = { alc885_mbp3_init_verbs,
5817                                 alc880_gpio1_init_verbs },
5818                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5819                 .dac_nids = alc882_dac_nids,
5820                 .channel_mode = alc885_mbp_6ch_modes,
5821                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
5822                 .input_mux = &alc882_capture_source,
5823                 .dig_out_nid = ALC882_DIGOUT_NID,
5824                 .dig_in_nid = ALC882_DIGIN_NID,
5825                 .unsol_event = alc885_mbp3_unsol_event,
5826                 .init_hook = alc885_mbp3_automute,
5827         },
5828         [ALC885_MACPRO] = {
5829                 .mixers = { alc882_macpro_mixer },
5830                 .init_verbs = { alc882_macpro_init_verbs },
5831                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5832                 .dac_nids = alc882_dac_nids,
5833                 .dig_out_nid = ALC882_DIGOUT_NID,
5834                 .dig_in_nid = ALC882_DIGIN_NID,
5835                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
5836                 .channel_mode = alc882_ch_modes,
5837                 .input_mux = &alc882_capture_source,
5838                 .init_hook = alc885_macpro_init_hook,
5839         },
5840         [ALC885_IMAC24] = {
5841                 .mixers = { alc885_imac24_mixer },
5842                 .init_verbs = { alc885_imac24_init_verbs },
5843                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5844                 .dac_nids = alc882_dac_nids,
5845                 .dig_out_nid = ALC882_DIGOUT_NID,
5846                 .dig_in_nid = ALC882_DIGIN_NID,
5847                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
5848                 .channel_mode = alc882_ch_modes,
5849                 .input_mux = &alc882_capture_source,
5850                 .unsol_event = alc885_imac24_unsol_event,
5851                 .init_hook = alc885_imac24_init_hook,
5852         },
5853         [ALC882_TARGA] = {
5854                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer,
5855                             alc882_capture_mixer },
5856                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
5857                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5858                 .dac_nids = alc882_dac_nids,
5859                 .dig_out_nid = ALC882_DIGOUT_NID,
5860                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
5861                 .adc_nids = alc882_adc_nids,
5862                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
5863                 .channel_mode = alc882_3ST_6ch_modes,
5864                 .need_dac_fix = 1,
5865                 .input_mux = &alc882_capture_source,
5866                 .unsol_event = alc882_targa_unsol_event,
5867                 .init_hook = alc882_targa_automute,
5868         },
5869         [ALC882_ASUS_A7J] = {
5870                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer,
5871                             alc882_capture_mixer },
5872                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
5873                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5874                 .dac_nids = alc882_dac_nids,
5875                 .dig_out_nid = ALC882_DIGOUT_NID,
5876                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
5877                 .adc_nids = alc882_adc_nids,
5878                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
5879                 .channel_mode = alc882_3ST_6ch_modes,
5880                 .need_dac_fix = 1,
5881                 .input_mux = &alc882_capture_source,
5882         },      
5883         [ALC882_ASUS_A7M] = {
5884                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
5885                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
5886                                 alc880_gpio1_init_verbs,
5887                                 alc882_asus_a7m_verbs },
5888                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5889                 .dac_nids = alc882_dac_nids,
5890                 .dig_out_nid = ALC882_DIGOUT_NID,
5891                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
5892                 .channel_mode = alc880_threestack_modes,
5893                 .need_dac_fix = 1,
5894                 .input_mux = &alc882_capture_source,
5895         },      
5896 };
5897
5898
5899 /*
5900  * Pin config fixes
5901  */
5902 enum { 
5903         PINFIX_ABIT_AW9D_MAX
5904 };
5905
5906 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
5907         { 0x15, 0x01080104 }, /* side */
5908         { 0x16, 0x01011012 }, /* rear */
5909         { 0x17, 0x01016011 }, /* clfe */
5910         { }
5911 };
5912
5913 static const struct alc_pincfg *alc882_pin_fixes[] = {
5914         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
5915 };
5916
5917 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
5918         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
5919         {}
5920 };
5921
5922 /*
5923  * BIOS auto configuration
5924  */
5925 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
5926                                               hda_nid_t nid, int pin_type,
5927                                               int dac_idx)
5928 {
5929         /* set as output */
5930         struct alc_spec *spec = codec->spec;
5931         int idx;
5932
5933         if (spec->multiout.dac_nids[dac_idx] == 0x25)
5934                 idx = 4;
5935         else
5936                 idx = spec->multiout.dac_nids[dac_idx] - 2;
5937
5938         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5939                             pin_type);
5940         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5941                             AMP_OUT_UNMUTE);
5942         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
5943
5944 }
5945
5946 static void alc882_auto_init_multi_out(struct hda_codec *codec)
5947 {
5948         struct alc_spec *spec = codec->spec;
5949         int i;
5950
5951         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
5952         for (i = 0; i <= HDA_SIDE; i++) {
5953                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
5954                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5955                 if (nid)
5956                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
5957                                                           i);
5958         }
5959 }
5960
5961 static void alc882_auto_init_hp_out(struct hda_codec *codec)
5962 {
5963         struct alc_spec *spec = codec->spec;
5964         hda_nid_t pin;
5965
5966         pin = spec->autocfg.hp_pins[0];
5967         if (pin) /* connect to front */
5968                 /* use dac 0 */
5969                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
5970 }
5971
5972 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
5973 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
5974
5975 static void alc882_auto_init_analog_input(struct hda_codec *codec)
5976 {
5977         struct alc_spec *spec = codec->spec;
5978         int i;
5979
5980         for (i = 0; i < AUTO_PIN_LAST; i++) {
5981                 hda_nid_t nid = spec->autocfg.input_pins[i];
5982                 if (alc882_is_input_pin(nid)) {
5983                         snd_hda_codec_write(codec, nid, 0,
5984                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5985                                             i <= AUTO_PIN_FRONT_MIC ?
5986                                             PIN_VREF80 : PIN_IN);
5987                         if (nid != ALC882_PIN_CD_NID)
5988                                 snd_hda_codec_write(codec, nid, 0,
5989                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5990                                                     AMP_OUT_MUTE);
5991                 }
5992         }
5993 }
5994
5995 /* add mic boosts if needed */
5996 static int alc_auto_add_mic_boost(struct hda_codec *codec)
5997 {
5998         struct alc_spec *spec = codec->spec;
5999         int err;
6000         hda_nid_t nid;
6001
6002         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6003         if (nid) {
6004                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6005                                   "Mic Boost",
6006                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6007                 if (err < 0)
6008                         return err;
6009         }
6010         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6011         if (nid) {
6012                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6013                                   "Front Mic Boost",
6014                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6015                 if (err < 0)
6016                         return err;
6017         }
6018         return 0;
6019 }
6020
6021 /* almost identical with ALC880 parser... */
6022 static int alc882_parse_auto_config(struct hda_codec *codec)
6023 {
6024         struct alc_spec *spec = codec->spec;
6025         int err = alc880_parse_auto_config(codec);
6026
6027         if (err < 0)
6028                 return err;
6029         else if (!err)
6030                 return 0; /* no config found */
6031
6032         err = alc_auto_add_mic_boost(codec);
6033         if (err < 0)
6034                 return err;
6035
6036         /* hack - override the init verbs */
6037         spec->init_verbs[0] = alc882_auto_init_verbs;
6038
6039         return 1; /* config found */
6040 }
6041
6042 /* additional initialization for auto-configuration model */
6043 static void alc882_auto_init(struct hda_codec *codec)
6044 {
6045         alc882_auto_init_multi_out(codec);
6046         alc882_auto_init_hp_out(codec);
6047         alc882_auto_init_analog_input(codec);
6048 }
6049
6050 static int patch_alc882(struct hda_codec *codec)
6051 {
6052         struct alc_spec *spec;
6053         int err, board_config;
6054
6055         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6056         if (spec == NULL)
6057                 return -ENOMEM;
6058
6059         codec->spec = spec;
6060
6061         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
6062                                                   alc882_models,
6063                                                   alc882_cfg_tbl);
6064
6065         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
6066                 /* Pick up systems that don't supply PCI SSID */
6067                 switch (codec->subsystem_id) {
6068                 case 0x106b0c00: /* Mac Pro */
6069                         board_config = ALC885_MACPRO;
6070                         break;
6071                 case 0x106b1000: /* iMac 24 */
6072                         board_config = ALC885_IMAC24;
6073                         break;
6074                 case 0x106b2c00: /* Macbook Pro rev3 */
6075                         board_config = ALC885_MBP3;
6076                         break;
6077                 default:
6078                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
6079                                          "trying auto-probe from BIOS...\n");
6080                         board_config = ALC882_AUTO;
6081                 }
6082         }
6083
6084         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
6085
6086         if (board_config == ALC882_AUTO) {
6087                 /* automatic parse from the BIOS config */
6088                 err = alc882_parse_auto_config(codec);
6089                 if (err < 0) {
6090                         alc_free(codec);
6091                         return err;
6092                 } else if (!err) {
6093                         printk(KERN_INFO
6094                                "hda_codec: Cannot set up configuration "
6095                                "from BIOS.  Using base mode...\n");
6096                         board_config = ALC882_3ST_DIG;
6097                 }
6098         }
6099
6100         if (board_config != ALC882_AUTO)
6101                 setup_preset(spec, &alc882_presets[board_config]);
6102
6103         spec->stream_name_analog = "ALC882 Analog";
6104         spec->stream_analog_playback = &alc882_pcm_analog_playback;
6105         spec->stream_analog_capture = &alc882_pcm_analog_capture;
6106
6107         spec->stream_name_digital = "ALC882 Digital";
6108         spec->stream_digital_playback = &alc882_pcm_digital_playback;
6109         spec->stream_digital_capture = &alc882_pcm_digital_capture;
6110
6111         if (!spec->adc_nids && spec->input_mux) {
6112                 /* check whether NID 0x07 is valid */
6113                 unsigned int wcap = get_wcaps(codec, 0x07);
6114                 /* get type */
6115                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
6116                 if (wcap != AC_WID_AUD_IN) {
6117                         spec->adc_nids = alc882_adc_nids_alt;
6118                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
6119                         spec->mixers[spec->num_mixers] =
6120                                 alc882_capture_alt_mixer;
6121                         spec->num_mixers++;
6122                 } else {
6123                         spec->adc_nids = alc882_adc_nids;
6124                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
6125                         spec->mixers[spec->num_mixers] = alc882_capture_mixer;
6126                         spec->num_mixers++;
6127                 }
6128         }
6129
6130         codec->patch_ops = alc_patch_ops;
6131         if (board_config == ALC882_AUTO)
6132                 spec->init_hook = alc882_auto_init;
6133 #ifdef CONFIG_SND_HDA_POWER_SAVE
6134         if (!spec->loopback.amplist)
6135                 spec->loopback.amplist = alc882_loopbacks;
6136 #endif
6137
6138         return 0;
6139 }
6140
6141 /*
6142  * ALC883 support
6143  *
6144  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
6145  * configuration.  Each pin widget can choose any input DACs and a mixer.
6146  * Each ADC is connected from a mixer of all inputs.  This makes possible
6147  * 6-channel independent captures.
6148  *
6149  * In addition, an independent DAC for the multi-playback (not used in this
6150  * driver yet).
6151  */
6152 #define ALC883_DIGOUT_NID       0x06
6153 #define ALC883_DIGIN_NID        0x0a
6154
6155 static hda_nid_t alc883_dac_nids[4] = {
6156         /* front, rear, clfe, rear_surr */
6157         0x02, 0x04, 0x03, 0x05
6158 };
6159
6160 static hda_nid_t alc883_adc_nids[2] = {
6161         /* ADC1-2 */
6162         0x08, 0x09,
6163 };
6164
6165 /* input MUX */
6166 /* FIXME: should be a matrix-type input source selection */
6167
6168 static struct hda_input_mux alc883_capture_source = {
6169         .num_items = 4,
6170         .items = {
6171                 { "Mic", 0x0 },
6172                 { "Front Mic", 0x1 },
6173                 { "Line", 0x2 },
6174                 { "CD", 0x4 },
6175         },
6176 };
6177
6178 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6179         .num_items = 2,
6180         .items = {
6181                 { "Mic", 0x1 },
6182                 { "Line", 0x2 },
6183         },
6184 };
6185
6186 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6187         .num_items = 4,
6188         .items = {
6189                 { "Mic", 0x0 },
6190                 { "iMic", 0x1 },
6191                 { "Line", 0x2 },
6192                 { "CD", 0x4 },
6193         },
6194 };
6195
6196 #define alc883_mux_enum_info alc_mux_enum_info
6197 #define alc883_mux_enum_get alc_mux_enum_get
6198
6199 static int alc883_mux_enum_put(struct snd_kcontrol *kcontrol,
6200                                struct snd_ctl_elem_value *ucontrol)
6201 {
6202         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6203         struct alc_spec *spec = codec->spec;
6204         const struct hda_input_mux *imux = spec->input_mux;
6205         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
6206         static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
6207         hda_nid_t nid = capture_mixers[adc_idx];
6208         unsigned int *cur_val = &spec->cur_mux[adc_idx];
6209         unsigned int i, idx;
6210
6211         idx = ucontrol->value.enumerated.item[0];
6212         if (idx >= imux->num_items)
6213                 idx = imux->num_items - 1;
6214         if (*cur_val == idx)
6215                 return 0;
6216         for (i = 0; i < imux->num_items; i++) {
6217                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
6218                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
6219                                          imux->items[i].index,
6220                                          HDA_AMP_MUTE, v);
6221         }
6222         *cur_val = idx;
6223         return 1;
6224 }
6225
6226 /*
6227  * 2ch mode
6228  */
6229 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6230         { 2, NULL }
6231 };
6232
6233 /*
6234  * 2ch mode
6235  */
6236 static struct hda_verb alc883_3ST_ch2_init[] = {
6237         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6238         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6239         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6240         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6241         { } /* end */
6242 };
6243
6244 /*
6245  * 4ch mode
6246  */
6247 static struct hda_verb alc883_3ST_ch4_init[] = {
6248         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6249         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6250         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6251         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6252         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6253         { } /* end */
6254 };
6255
6256 /*
6257  * 6ch mode
6258  */
6259 static struct hda_verb alc883_3ST_ch6_init[] = {
6260         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6261         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6262         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6263         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6264         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6265         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6266         { } /* end */
6267 };
6268
6269 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
6270         { 2, alc883_3ST_ch2_init },
6271         { 4, alc883_3ST_ch4_init },
6272         { 6, alc883_3ST_ch6_init },
6273 };
6274
6275 /*
6276  * 6ch mode
6277  */
6278 static struct hda_verb alc883_sixstack_ch6_init[] = {
6279         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6280         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6281         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6282         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6283         { } /* end */
6284 };
6285
6286 /*
6287  * 8ch mode
6288  */
6289 static struct hda_verb alc883_sixstack_ch8_init[] = {
6290         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6291         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6292         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6293         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6294         { } /* end */
6295 };
6296
6297 static struct hda_channel_mode alc883_sixstack_modes[2] = {
6298         { 6, alc883_sixstack_ch6_init },
6299         { 8, alc883_sixstack_ch8_init },
6300 };
6301
6302 static struct hda_verb alc883_medion_eapd_verbs[] = {
6303         /* eanable EAPD on medion laptop */
6304         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6305         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
6306         { }
6307 };
6308
6309 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6310  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6311  */
6312
6313 static struct snd_kcontrol_new alc883_base_mixer[] = {
6314         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6315         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6316         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6317         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6318         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6319         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6320         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6321         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6322         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6323         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6324         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6325         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6326         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6327         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6328         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6329         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6330         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6331         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6332         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6333         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6334         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6335         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6336         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6337         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6338         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6339         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6340         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6341         {
6342                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6343                 /* .name = "Capture Source", */
6344                 .name = "Input Source",
6345                 .count = 2,
6346                 .info = alc883_mux_enum_info,
6347                 .get = alc883_mux_enum_get,
6348                 .put = alc883_mux_enum_put,
6349         },
6350         { } /* end */
6351 };
6352
6353 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
6354         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6355         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6356         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6357         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6358         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6359         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6360         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6361         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6362         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6363         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6364         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6365         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6366         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6367         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6368         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6369         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6370         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6371         {
6372                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6373                 /* .name = "Capture Source", */
6374                 .name = "Input Source",
6375                 .count = 2,
6376                 .info = alc883_mux_enum_info,
6377                 .get = alc883_mux_enum_get,
6378                 .put = alc883_mux_enum_put,
6379         },
6380         { } /* end */
6381 };
6382
6383 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
6384         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6385         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6386         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6387         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6388         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6389         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6390         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6391         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6392         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6393         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6394         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6395         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6396         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6397         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6398         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6399         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6400         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6401         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6402         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6403         {
6404                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6405                 /* .name = "Capture Source", */
6406                 .name = "Input Source",
6407                 .count = 2,
6408                 .info = alc883_mux_enum_info,
6409                 .get = alc883_mux_enum_get,
6410                 .put = alc883_mux_enum_put,
6411         },
6412         { } /* end */
6413 };
6414
6415 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
6416         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6417         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6418         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6419         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6420         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6421         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6422         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6423         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6424         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6425         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6426         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6427         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6428         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6429         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6430         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6431         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6432         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6433         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6434         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6435         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6436         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6437         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6438         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6439         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6440         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6441         {
6442                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6443                 /* .name = "Capture Source", */
6444                 .name = "Input Source",
6445                 .count = 2,
6446                 .info = alc883_mux_enum_info,
6447                 .get = alc883_mux_enum_get,
6448                 .put = alc883_mux_enum_put,
6449         },
6450         { } /* end */
6451 };
6452
6453 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
6454         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6455         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6456         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6457         HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6458         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6459         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6460         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x16, 1, 0x0, HDA_OUTPUT),
6461         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
6462         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6463         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6464         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6465         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6466         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6467         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6468         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6469         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6470         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6471         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6472         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6473         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6474         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6475         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6476         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6477
6478         {
6479                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6480                 /* .name = "Capture Source", */
6481                 .name = "Input Source",
6482                 .count = 1,
6483                 .info = alc883_mux_enum_info,
6484                 .get = alc883_mux_enum_get,
6485                 .put = alc883_mux_enum_put,
6486         },
6487         { } /* end */
6488 };
6489
6490 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
6491         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6492         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6493         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6494         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6495         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6496         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6497         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6498         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6499         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6500         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6501         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6502         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6503         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6504         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6505         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6506         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6507         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6508         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6509         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6510         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6511         {
6512                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6513                 /* .name = "Capture Source", */
6514                 .name = "Input Source",
6515                 .count = 2,
6516                 .info = alc883_mux_enum_info,
6517                 .get = alc883_mux_enum_get,
6518                 .put = alc883_mux_enum_put,
6519         },
6520         { } /* end */
6521 };
6522
6523 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
6524         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6525         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6526         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6527         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6528         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6529         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6530         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6531         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6532         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6533         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6534         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6535         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6536         {
6537                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6538                 /* .name = "Capture Source", */
6539                 .name = "Input Source",
6540                 .count = 2,
6541                 .info = alc883_mux_enum_info,
6542                 .get = alc883_mux_enum_get,
6543                 .put = alc883_mux_enum_put,
6544         },
6545         { } /* end */
6546 };
6547
6548 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
6549         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6550         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6551         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6552         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
6553         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6554         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6555         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6556         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6557         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6558         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6559         {
6560                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6561                 /* .name = "Capture Source", */
6562                 .name = "Input Source",
6563                 .count = 1,
6564                 .info = alc883_mux_enum_info,
6565                 .get = alc883_mux_enum_get,
6566                 .put = alc883_mux_enum_put,
6567         },
6568         { } /* end */
6569 };
6570
6571 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
6572         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6573         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
6574         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6575         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6576         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6577         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6578         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6579         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6580         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6581         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6582         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6583         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6584         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6585         {
6586                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6587                 /* .name = "Capture Source", */
6588                 .name = "Input Source",
6589                 .count = 2,
6590                 .info = alc883_mux_enum_info,
6591                 .get = alc883_mux_enum_get,
6592                 .put = alc883_mux_enum_put,
6593         },
6594         { } /* end */
6595 };
6596
6597 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
6598         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6599         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6600         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6601         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6602         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6603         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6604         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6605         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6606         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6607         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6608         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6609         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6610         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6611         {
6612                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6613                 /* .name = "Capture Source", */
6614                 .name = "Input Source",
6615                 .count = 2,
6616                 .info = alc883_mux_enum_info,
6617                 .get = alc883_mux_enum_get,
6618                 .put = alc883_mux_enum_put,
6619         },
6620         { } /* end */
6621 };      
6622
6623 static struct snd_kcontrol_new alc888_6st_hp_mixer[] = {
6624         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6625         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6626         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6627         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6628         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6629         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6630         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6631         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6632         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6633         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6634         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6635         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6636         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6637         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6638         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6639         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6640         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6641         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6642         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6643         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6644         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6645         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6646         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6647         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6648         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6649         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6650         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6651         {
6652                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6653                 /* .name = "Capture Source", */
6654                 .name = "Input Source",
6655                 .count = 2,
6656                 .info = alc883_mux_enum_info,
6657                 .get = alc883_mux_enum_get,
6658                 .put = alc883_mux_enum_put,
6659         },
6660         { } /* end */
6661 };
6662
6663 static struct snd_kcontrol_new alc888_3st_hp_mixer[] = {
6664         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6665         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6666         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6667         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6668         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6669         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6670         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6671         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6672         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6673         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6674         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6675         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6676         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6677         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6678         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6679         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6680         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6681         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6682         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6683         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6684         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6685         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6686         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6687         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6688         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6689         {
6690                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6691                 /* .name = "Capture Source", */
6692                 .name = "Input Source",
6693                 .count = 2,
6694                 .info = alc883_mux_enum_info,
6695                 .get = alc883_mux_enum_get,
6696                 .put = alc883_mux_enum_put,
6697         },
6698         { } /* end */
6699 };
6700
6701 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
6702         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6703         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6704         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6705         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6706         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6707         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6708         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6709         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6710         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6711         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6712         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6713         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6714         {
6715                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6716                 /* .name = "Capture Source", */
6717                 .name = "Input Source",
6718                 .count = 2,
6719                 .info = alc883_mux_enum_info,
6720                 .get = alc883_mux_enum_get,
6721                 .put = alc883_mux_enum_put,
6722         },
6723         { } /* end */
6724 };
6725
6726 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
6727         {
6728                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6729                 .name = "Channel Mode",
6730                 .info = alc_ch_mode_info,
6731                 .get = alc_ch_mode_get,
6732                 .put = alc_ch_mode_put,
6733         },
6734         { } /* end */
6735 };
6736
6737 static struct hda_verb alc883_init_verbs[] = {
6738         /* ADC1: mute amp left and right */
6739         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6740         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6741         /* ADC2: mute amp left and right */
6742         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6743         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6744         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6745         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6746         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6747         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6748         /* Rear mixer */
6749         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6750         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6751         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6752         /* CLFE mixer */
6753         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6754         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6755         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6756         /* Side mixer */
6757         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6758         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6759         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6760
6761         /* mute analog input loopbacks */
6762         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6763         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6764         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6765         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6766         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6767
6768         /* Front Pin: output 0 (0x0c) */
6769         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6770         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6771         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6772         /* Rear Pin: output 1 (0x0d) */
6773         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6774         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6775         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6776         /* CLFE Pin: output 2 (0x0e) */
6777         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6778         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6779         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
6780         /* Side Pin: output 3 (0x0f) */
6781         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6782         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6783         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
6784         /* Mic (rear) pin: input vref at 80% */
6785         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6786         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6787         /* Front Mic pin: input vref at 80% */
6788         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6789         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6790         /* Line In pin: input */
6791         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6792         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6793         /* Line-2 In: Headphone output (output 0 - 0x0c) */
6794         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6795         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6796         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6797         /* CD pin widget for input */
6798         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6799
6800         /* FIXME: use matrix-type input source selection */
6801         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6802         /* Input mixer2 */
6803         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6804         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6805         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6806         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6807         /* Input mixer3 */
6808         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6809         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6810         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6811         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6812         { }
6813 };
6814
6815 /* toggle speaker-output according to the hp-jack state */
6816 static void alc883_mitac_hp_automute(struct hda_codec *codec)
6817 {
6818         unsigned int present;
6819
6820         present = snd_hda_codec_read(codec, 0x15, 0,
6821                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6822         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
6823                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6824         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
6825                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6826 }
6827
6828 /* auto-toggle front mic */
6829 /*
6830 static void alc883_mitac_mic_automute(struct hda_codec *codec)
6831 {
6832         unsigned int present;
6833         unsigned char bits;
6834
6835         present = snd_hda_codec_read(codec, 0x18, 0,
6836                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6837         bits = present ? HDA_AMP_MUTE : 0;
6838         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
6839 }
6840 */
6841
6842 static void alc883_mitac_automute(struct hda_codec *codec)
6843 {
6844         alc883_mitac_hp_automute(codec);
6845         /* alc883_mitac_mic_automute(codec); */
6846 }
6847
6848 static void alc883_mitac_unsol_event(struct hda_codec *codec,
6849                                            unsigned int res)
6850 {
6851         switch (res >> 26) {
6852         case ALC880_HP_EVENT:
6853                 alc883_mitac_hp_automute(codec);
6854                 break;
6855         case ALC880_MIC_EVENT:
6856                 /* alc883_mitac_mic_automute(codec); */
6857                 break;
6858         }
6859 }
6860
6861 static struct hda_verb alc883_mitac_verbs[] = {
6862         /* HP */
6863         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6864         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6865         /* Subwoofer */
6866         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
6867         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6868
6869         /* enable unsolicited event */
6870         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6871         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
6872
6873         { } /* end */
6874 };
6875
6876 static struct hda_verb alc883_tagra_verbs[] = {
6877         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6878         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6879
6880         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6881         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6882         
6883         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6884         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6885         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6886
6887         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6888         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6889         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6890         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6891
6892         { } /* end */
6893 };
6894
6895 static struct hda_verb alc883_lenovo_101e_verbs[] = {
6896         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6897         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
6898         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
6899         { } /* end */
6900 };
6901
6902 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
6903         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6904         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6905         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6906         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6907         { } /* end */
6908 };
6909
6910 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
6911         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6912         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6913         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6914         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
6915         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
6916         { } /* end */
6917 };
6918
6919 static struct hda_verb alc883_haier_w66_verbs[] = {
6920         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6921         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6922
6923         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6924
6925         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6926         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6927         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6928         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6929         { } /* end */
6930 };
6931
6932 static struct hda_verb alc888_6st_hp_verbs[] = {
6933         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
6934         {0x15, AC_VERB_SET_CONNECT_SEL, 0x02},  /* Rear : output 2 (0x0e) */
6935         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* CLFE : output 1 (0x0d) */
6936         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},  /* Side : output 3 (0x0f) */
6937         { }
6938 };
6939
6940 static struct hda_verb alc888_3st_hp_verbs[] = {
6941         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
6942         {0x18, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
6943         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
6944         { }
6945 };
6946
6947 static struct hda_verb alc888_3st_hp_2ch_init[] = {
6948         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6949         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6950         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6951         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6952         { }
6953 };
6954
6955 static struct hda_verb alc888_3st_hp_6ch_init[] = {
6956         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6957         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6958         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6959         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6960         { }
6961 };
6962
6963 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
6964         { 2, alc888_3st_hp_2ch_init },
6965         { 6, alc888_3st_hp_6ch_init },
6966 };
6967
6968 /* toggle front-jack and RCA according to the hp-jack state */
6969 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
6970 {
6971         unsigned int present;
6972  
6973         present = snd_hda_codec_read(codec, 0x1b, 0,
6974                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6975         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
6976                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6977         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6978                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6979 }
6980
6981 /* toggle RCA according to the front-jack state */
6982 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
6983 {
6984         unsigned int present;
6985  
6986         present = snd_hda_codec_read(codec, 0x14, 0,
6987                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6988         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6989                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6990 }
6991
6992 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
6993                                              unsigned int res)
6994 {
6995         if ((res >> 26) == ALC880_HP_EVENT)
6996                 alc888_lenovo_ms7195_front_automute(codec);
6997         if ((res >> 26) == ALC880_FRONT_EVENT)
6998                 alc888_lenovo_ms7195_rca_automute(codec);
6999 }
7000
7001 static struct hda_verb alc883_medion_md2_verbs[] = {
7002         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7003         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7004
7005         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7006
7007         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7008         { } /* end */
7009 };
7010
7011 /* toggle speaker-output according to the hp-jack state */
7012 static void alc883_medion_md2_automute(struct hda_codec *codec)
7013 {
7014         unsigned int present;
7015  
7016         present = snd_hda_codec_read(codec, 0x14, 0,
7017                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7018         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7019                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7020 }
7021
7022 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
7023                                           unsigned int res)
7024 {
7025         if ((res >> 26) == ALC880_HP_EVENT)
7026                 alc883_medion_md2_automute(codec);
7027 }
7028
7029 /* toggle speaker-output according to the hp-jack state */
7030 static void alc883_tagra_automute(struct hda_codec *codec)
7031 {
7032         unsigned int present;
7033         unsigned char bits;
7034
7035         present = snd_hda_codec_read(codec, 0x14, 0,
7036                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7037         bits = present ? HDA_AMP_MUTE : 0;
7038         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
7039                                  HDA_AMP_MUTE, bits);
7040         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7041                                   present ? 1 : 3);
7042 }
7043
7044 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
7045 {
7046         if ((res >> 26) == ALC880_HP_EVENT)
7047                 alc883_tagra_automute(codec);
7048 }
7049
7050 static void alc883_haier_w66_automute(struct hda_codec *codec)
7051 {
7052         unsigned int present;
7053         unsigned char bits;
7054
7055         present = snd_hda_codec_read(codec, 0x1b, 0,
7056                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7057         bits = present ? 0x80 : 0;
7058         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7059                                  0x80, bits);
7060 }
7061
7062 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
7063                                          unsigned int res)
7064 {
7065         if ((res >> 26) == ALC880_HP_EVENT)
7066                 alc883_haier_w66_automute(codec);
7067 }
7068
7069 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
7070 {
7071         unsigned int present;
7072         unsigned char bits;
7073
7074         present = snd_hda_codec_read(codec, 0x14, 0,
7075                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7076         bits = present ? HDA_AMP_MUTE : 0;
7077         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7078                                  HDA_AMP_MUTE, bits);
7079 }
7080
7081 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
7082 {
7083         unsigned int present;
7084         unsigned char bits;
7085
7086         present = snd_hda_codec_read(codec, 0x1b, 0,
7087                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7088         bits = present ? HDA_AMP_MUTE : 0;
7089         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7090                                  HDA_AMP_MUTE, bits);
7091         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7092                                  HDA_AMP_MUTE, bits);
7093 }
7094
7095 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
7096                                            unsigned int res)
7097 {
7098         if ((res >> 26) == ALC880_HP_EVENT)
7099                 alc883_lenovo_101e_all_automute(codec);
7100         if ((res >> 26) == ALC880_FRONT_EVENT)
7101                 alc883_lenovo_101e_ispeaker_automute(codec);
7102 }
7103
7104 /* toggle speaker-output according to the hp-jack state */
7105 static void alc883_acer_aspire_automute(struct hda_codec *codec)
7106 {
7107         unsigned int present;
7108  
7109         present = snd_hda_codec_read(codec, 0x14, 0,
7110                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7111         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7112                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7113         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
7114                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7115 }
7116
7117 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
7118                                            unsigned int res)
7119 {
7120         if ((res >> 26) == ALC880_HP_EVENT)
7121                 alc883_acer_aspire_automute(codec);
7122 }
7123
7124 static struct hda_verb alc883_acer_eapd_verbs[] = {
7125         /* HP Pin: output 0 (0x0c) */
7126         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7127         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7128         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7129         /* Front Pin: output 0 (0x0c) */
7130         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7131         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7132         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7133         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
7134         /* eanable EAPD on medion laptop */
7135         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7136         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
7137         /* enable unsolicited event */
7138         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7139         { }
7140 };
7141
7142 /*
7143  * generic initialization of ADC, input mixers and output mixers
7144  */
7145 static struct hda_verb alc883_auto_init_verbs[] = {
7146         /*
7147          * Unmute ADC0-2 and set the default input to mic-in
7148          */
7149         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7150         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7151         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7152         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7153
7154         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7155          * mixer widget
7156          * Note: PASD motherboards uses the Line In 2 as the input for
7157          * front panel mic (mic 2)
7158          */
7159         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7160         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7161         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7162         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7163         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7164         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7165
7166         /*
7167          * Set up output mixers (0x0c - 0x0f)
7168          */
7169         /* set vol=0 to output mixers */
7170         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7171         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7172         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7173         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7174         /* set up input amps for analog loopback */
7175         /* Amp Indices: DAC = 0, mixer = 1 */
7176         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7177         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7178         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7179         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7180         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7181         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7182         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7183         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7184         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7185         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7186
7187         /* FIXME: use matrix-type input source selection */
7188         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7189         /* Input mixer1 */
7190         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7191         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7192         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7193         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
7194         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7195         /* Input mixer2 */
7196         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7197         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7198         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7199         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
7200         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7201
7202         { }
7203 };
7204
7205 /* capture mixer elements */
7206 static struct snd_kcontrol_new alc883_capture_mixer[] = {
7207         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
7208         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
7209         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
7210         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
7211         {
7212                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7213                 /* The multiple "Capture Source" controls confuse alsamixer
7214                  * So call somewhat different..
7215                  * FIXME: the controls appear in the "playback" view!
7216                  */
7217                 /* .name = "Capture Source", */
7218                 .name = "Input Source",
7219                 .count = 2,
7220                 .info = alc882_mux_enum_info,
7221                 .get = alc882_mux_enum_get,
7222                 .put = alc882_mux_enum_put,
7223         },
7224         { } /* end */
7225 };
7226
7227 #ifdef CONFIG_SND_HDA_POWER_SAVE
7228 #define alc883_loopbacks        alc880_loopbacks
7229 #endif
7230
7231 /* pcm configuration: identiacal with ALC880 */
7232 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
7233 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
7234 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
7235 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
7236
7237 /*
7238  * configuration and preset
7239  */
7240 static const char *alc883_models[ALC883_MODEL_LAST] = {
7241         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
7242         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
7243         [ALC883_3ST_6ch]        = "3stack-6ch",
7244         [ALC883_6ST_DIG]        = "6stack-dig",
7245         [ALC883_TARGA_DIG]      = "targa-dig",
7246         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
7247         [ALC883_ACER]           = "acer",
7248         [ALC883_ACER_ASPIRE]    = "acer-aspire",
7249         [ALC883_MEDION]         = "medion",
7250         [ALC883_MEDION_MD2]     = "medion-md2",
7251         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
7252         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
7253         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
7254         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
7255         [ALC883_HAIER_W66]      = "haier-w66",
7256         [ALC888_6ST_HP]         = "6stack-hp",
7257         [ALC888_3ST_HP]         = "3stack-hp",
7258         [ALC883_MITAC]          = "mitac",
7259         [ALC883_AUTO]           = "auto",
7260 };
7261
7262 static struct snd_pci_quirk alc883_cfg_tbl[] = {
7263         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
7264         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
7265         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
7266         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
7267         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
7268         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
7269         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
7270         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
7271         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
7272         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
7273         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
7274         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
7275         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
7276         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
7277         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
7278         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
7279         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
7280         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
7281         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
7282         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
7283         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
7284         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
7285         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
7286         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
7287         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
7288         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
7289         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
7290         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
7291         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER),
7292         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
7293         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
7294         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
7295         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
7296         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
7297         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
7298         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7299         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7300         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC888_6ST_HP),
7301         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
7302         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
7303         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
7304         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
7305         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7306         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
7307         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
7308         {}
7309 };
7310
7311 static struct alc_config_preset alc883_presets[] = {
7312         [ALC883_3ST_2ch_DIG] = {
7313                 .mixers = { alc883_3ST_2ch_mixer },
7314                 .init_verbs = { alc883_init_verbs },
7315                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7316                 .dac_nids = alc883_dac_nids,
7317                 .dig_out_nid = ALC883_DIGOUT_NID,
7318                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7319                 .adc_nids = alc883_adc_nids,
7320                 .dig_in_nid = ALC883_DIGIN_NID,
7321                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7322                 .channel_mode = alc883_3ST_2ch_modes,
7323                 .input_mux = &alc883_capture_source,
7324         },
7325         [ALC883_3ST_6ch_DIG] = {
7326                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7327                 .init_verbs = { alc883_init_verbs },
7328                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7329                 .dac_nids = alc883_dac_nids,
7330                 .dig_out_nid = ALC883_DIGOUT_NID,
7331                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7332                 .adc_nids = alc883_adc_nids,
7333                 .dig_in_nid = ALC883_DIGIN_NID,
7334                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7335                 .channel_mode = alc883_3ST_6ch_modes,
7336                 .need_dac_fix = 1,
7337                 .input_mux = &alc883_capture_source,
7338         },
7339         [ALC883_3ST_6ch] = {
7340                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7341                 .init_verbs = { alc883_init_verbs },
7342                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7343                 .dac_nids = alc883_dac_nids,
7344                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7345                 .adc_nids = alc883_adc_nids,
7346                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7347                 .channel_mode = alc883_3ST_6ch_modes,
7348                 .need_dac_fix = 1,
7349                 .input_mux = &alc883_capture_source,
7350         },
7351         [ALC883_6ST_DIG] = {
7352                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
7353                 .init_verbs = { alc883_init_verbs },
7354                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7355                 .dac_nids = alc883_dac_nids,
7356                 .dig_out_nid = ALC883_DIGOUT_NID,
7357                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7358                 .adc_nids = alc883_adc_nids,
7359                 .dig_in_nid = ALC883_DIGIN_NID,
7360                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7361                 .channel_mode = alc883_sixstack_modes,
7362                 .input_mux = &alc883_capture_source,
7363         },
7364         [ALC883_TARGA_DIG] = {
7365                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
7366                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
7367                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7368                 .dac_nids = alc883_dac_nids,
7369                 .dig_out_nid = ALC883_DIGOUT_NID,
7370                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7371                 .adc_nids = alc883_adc_nids,
7372                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7373                 .channel_mode = alc883_3ST_6ch_modes,
7374                 .need_dac_fix = 1,
7375                 .input_mux = &alc883_capture_source,
7376                 .unsol_event = alc883_tagra_unsol_event,
7377                 .init_hook = alc883_tagra_automute,
7378         },
7379         [ALC883_TARGA_2ch_DIG] = {
7380                 .mixers = { alc883_tagra_2ch_mixer},
7381                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
7382                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7383                 .dac_nids = alc883_dac_nids,
7384                 .dig_out_nid = ALC883_DIGOUT_NID,
7385                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7386                 .adc_nids = alc883_adc_nids,
7387                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7388                 .channel_mode = alc883_3ST_2ch_modes,
7389                 .input_mux = &alc883_capture_source,
7390                 .unsol_event = alc883_tagra_unsol_event,
7391                 .init_hook = alc883_tagra_automute,
7392         },
7393         [ALC883_ACER] = {
7394                 .mixers = { alc883_base_mixer },
7395                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
7396                  * and the headphone jack.  Turn this on and rely on the
7397                  * standard mute methods whenever the user wants to turn
7398                  * these outputs off.
7399                  */
7400                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
7401                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7402                 .dac_nids = alc883_dac_nids,
7403                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7404                 .adc_nids = alc883_adc_nids,
7405                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7406                 .channel_mode = alc883_3ST_2ch_modes,
7407                 .input_mux = &alc883_capture_source,
7408         },
7409         [ALC883_ACER_ASPIRE] = {
7410                 .mixers = { alc883_acer_aspire_mixer },
7411                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
7412                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7413                 .dac_nids = alc883_dac_nids,
7414                 .dig_out_nid = ALC883_DIGOUT_NID,
7415                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7416                 .adc_nids = alc883_adc_nids,
7417                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7418                 .channel_mode = alc883_3ST_2ch_modes,
7419                 .input_mux = &alc883_capture_source,
7420                 .unsol_event = alc883_acer_aspire_unsol_event,
7421                 .init_hook = alc883_acer_aspire_automute,
7422         },
7423         [ALC883_MEDION] = {
7424                 .mixers = { alc883_fivestack_mixer,
7425                             alc883_chmode_mixer },
7426                 .init_verbs = { alc883_init_verbs,
7427                                 alc883_medion_eapd_verbs },
7428                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7429                 .dac_nids = alc883_dac_nids,
7430                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7431                 .adc_nids = alc883_adc_nids,
7432                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7433                 .channel_mode = alc883_sixstack_modes,
7434                 .input_mux = &alc883_capture_source,
7435         },
7436         [ALC883_MEDION_MD2] = {
7437                 .mixers = { alc883_medion_md2_mixer},
7438                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
7439                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7440                 .dac_nids = alc883_dac_nids,
7441                 .dig_out_nid = ALC883_DIGOUT_NID,
7442                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7443                 .adc_nids = alc883_adc_nids,
7444                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7445                 .channel_mode = alc883_3ST_2ch_modes,
7446                 .input_mux = &alc883_capture_source,
7447                 .unsol_event = alc883_medion_md2_unsol_event,
7448                 .init_hook = alc883_medion_md2_automute,
7449         },      
7450         [ALC883_LAPTOP_EAPD] = {
7451                 .mixers = { alc883_base_mixer },
7452                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
7453                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7454                 .dac_nids = alc883_dac_nids,
7455                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7456                 .adc_nids = alc883_adc_nids,
7457                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7458                 .channel_mode = alc883_3ST_2ch_modes,
7459                 .input_mux = &alc883_capture_source,
7460         },
7461         [ALC883_LENOVO_101E_2ch] = {
7462                 .mixers = { alc883_lenovo_101e_2ch_mixer},
7463                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
7464                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7465                 .dac_nids = alc883_dac_nids,
7466                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7467                 .adc_nids = alc883_adc_nids,
7468                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7469                 .channel_mode = alc883_3ST_2ch_modes,
7470                 .input_mux = &alc883_lenovo_101e_capture_source,
7471                 .unsol_event = alc883_lenovo_101e_unsol_event,
7472                 .init_hook = alc883_lenovo_101e_all_automute,
7473         },
7474         [ALC883_LENOVO_NB0763] = {
7475                 .mixers = { alc883_lenovo_nb0763_mixer },
7476                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
7477                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7478                 .dac_nids = alc883_dac_nids,
7479                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7480                 .adc_nids = alc883_adc_nids,
7481                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7482                 .channel_mode = alc883_3ST_2ch_modes,
7483                 .need_dac_fix = 1,
7484                 .input_mux = &alc883_lenovo_nb0763_capture_source,
7485                 .unsol_event = alc883_medion_md2_unsol_event,
7486                 .init_hook = alc883_medion_md2_automute,
7487         },
7488         [ALC888_LENOVO_MS7195_DIG] = {
7489                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7490                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
7491                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7492                 .dac_nids = alc883_dac_nids,
7493                 .dig_out_nid = ALC883_DIGOUT_NID,
7494                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7495                 .adc_nids = alc883_adc_nids,
7496                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7497                 .channel_mode = alc883_3ST_6ch_modes,
7498                 .need_dac_fix = 1,
7499                 .input_mux = &alc883_capture_source,
7500                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
7501                 .init_hook = alc888_lenovo_ms7195_front_automute,
7502         },
7503         [ALC883_HAIER_W66] = {
7504                 .mixers = { alc883_tagra_2ch_mixer},
7505                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
7506                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7507                 .dac_nids = alc883_dac_nids,
7508                 .dig_out_nid = ALC883_DIGOUT_NID,
7509                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7510                 .adc_nids = alc883_adc_nids,
7511                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7512                 .channel_mode = alc883_3ST_2ch_modes,
7513                 .input_mux = &alc883_capture_source,
7514                 .unsol_event = alc883_haier_w66_unsol_event,
7515                 .init_hook = alc883_haier_w66_automute,
7516         },      
7517         [ALC888_6ST_HP] = {
7518                 .mixers = { alc888_6st_hp_mixer, alc883_chmode_mixer },
7519                 .init_verbs = { alc883_init_verbs, alc888_6st_hp_verbs },
7520                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7521                 .dac_nids = alc883_dac_nids,
7522                 .dig_out_nid = ALC883_DIGOUT_NID,
7523                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7524                 .adc_nids = alc883_adc_nids,
7525                 .dig_in_nid = ALC883_DIGIN_NID,
7526                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7527                 .channel_mode = alc883_sixstack_modes,
7528                 .input_mux = &alc883_capture_source,
7529         },
7530         [ALC888_3ST_HP] = {
7531                 .mixers = { alc888_3st_hp_mixer, alc883_chmode_mixer },
7532                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
7533                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7534                 .dac_nids = alc883_dac_nids,
7535                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7536                 .adc_nids = alc883_adc_nids,
7537                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
7538                 .channel_mode = alc888_3st_hp_modes,
7539                 .need_dac_fix = 1,
7540                 .input_mux = &alc883_capture_source,
7541         },
7542         [ALC883_MITAC] = {
7543                 .mixers = { alc883_mitac_mixer },
7544                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
7545                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7546                 .dac_nids = alc883_dac_nids,
7547                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7548                 .adc_nids = alc883_adc_nids,
7549                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7550                 .channel_mode = alc883_3ST_2ch_modes,
7551                 .input_mux = &alc883_capture_source,
7552                 .unsol_event = alc883_mitac_unsol_event,
7553                 .init_hook = alc883_mitac_automute,
7554         },
7555 };
7556
7557
7558 /*
7559  * BIOS auto configuration
7560  */
7561 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
7562                                               hda_nid_t nid, int pin_type,
7563                                               int dac_idx)
7564 {
7565         /* set as output */
7566         struct alc_spec *spec = codec->spec;
7567         int idx;
7568
7569         if (spec->multiout.dac_nids[dac_idx] == 0x25)
7570                 idx = 4;
7571         else
7572                 idx = spec->multiout.dac_nids[dac_idx] - 2;
7573
7574         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
7575                             pin_type);
7576         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
7577                             AMP_OUT_UNMUTE);
7578         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
7579
7580 }
7581
7582 static void alc883_auto_init_multi_out(struct hda_codec *codec)
7583 {
7584         struct alc_spec *spec = codec->spec;
7585         int i;
7586
7587         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
7588         for (i = 0; i <= HDA_SIDE; i++) {
7589                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
7590                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
7591                 if (nid)
7592                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
7593                                                           i);
7594         }
7595 }
7596
7597 static void alc883_auto_init_hp_out(struct hda_codec *codec)
7598 {
7599         struct alc_spec *spec = codec->spec;
7600         hda_nid_t pin;
7601
7602         pin = spec->autocfg.hp_pins[0];
7603         if (pin) /* connect to front */
7604                 /* use dac 0 */
7605                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
7606 }
7607
7608 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
7609 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
7610
7611 static void alc883_auto_init_analog_input(struct hda_codec *codec)
7612 {
7613         struct alc_spec *spec = codec->spec;
7614         int i;
7615
7616         for (i = 0; i < AUTO_PIN_LAST; i++) {
7617                 hda_nid_t nid = spec->autocfg.input_pins[i];
7618                 if (alc883_is_input_pin(nid)) {
7619                         snd_hda_codec_write(codec, nid, 0,
7620                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
7621                                             (i <= AUTO_PIN_FRONT_MIC ?
7622                                              PIN_VREF80 : PIN_IN));
7623                         if (nid != ALC883_PIN_CD_NID)
7624                                 snd_hda_codec_write(codec, nid, 0,
7625                                                     AC_VERB_SET_AMP_GAIN_MUTE,
7626                                                     AMP_OUT_MUTE);
7627                 }
7628         }
7629 }
7630
7631 /* almost identical with ALC880 parser... */
7632 static int alc883_parse_auto_config(struct hda_codec *codec)
7633 {
7634         struct alc_spec *spec = codec->spec;
7635         int err = alc880_parse_auto_config(codec);
7636
7637         if (err < 0)
7638                 return err;
7639         else if (!err)
7640                 return 0; /* no config found */
7641
7642         err = alc_auto_add_mic_boost(codec);
7643         if (err < 0)
7644                 return err;
7645
7646         /* hack - override the init verbs */
7647         spec->init_verbs[0] = alc883_auto_init_verbs;
7648         spec->mixers[spec->num_mixers] = alc883_capture_mixer;
7649         spec->num_mixers++;
7650
7651         return 1; /* config found */
7652 }
7653
7654 /* additional initialization for auto-configuration model */
7655 static void alc883_auto_init(struct hda_codec *codec)
7656 {
7657         alc883_auto_init_multi_out(codec);
7658         alc883_auto_init_hp_out(codec);
7659         alc883_auto_init_analog_input(codec);
7660 }
7661
7662 static int patch_alc883(struct hda_codec *codec)
7663 {
7664         struct alc_spec *spec;
7665         int err, board_config;
7666
7667         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7668         if (spec == NULL)
7669                 return -ENOMEM;
7670
7671         codec->spec = spec;
7672
7673         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
7674                                                   alc883_models,
7675                                                   alc883_cfg_tbl);
7676         if (board_config < 0) {
7677                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
7678                        "trying auto-probe from BIOS...\n");
7679                 board_config = ALC883_AUTO;
7680         }
7681
7682         if (board_config == ALC883_AUTO) {
7683                 /* automatic parse from the BIOS config */
7684                 err = alc883_parse_auto_config(codec);
7685                 if (err < 0) {
7686                         alc_free(codec);
7687                         return err;
7688                 } else if (!err) {
7689                         printk(KERN_INFO
7690                                "hda_codec: Cannot set up configuration "
7691                                "from BIOS.  Using base mode...\n");
7692                         board_config = ALC883_3ST_2ch_DIG;
7693                 }
7694         }
7695
7696         if (board_config != ALC883_AUTO)
7697                 setup_preset(spec, &alc883_presets[board_config]);
7698
7699         spec->stream_name_analog = "ALC883 Analog";
7700         spec->stream_analog_playback = &alc883_pcm_analog_playback;
7701         spec->stream_analog_capture = &alc883_pcm_analog_capture;
7702
7703         spec->stream_name_digital = "ALC883 Digital";
7704         spec->stream_digital_playback = &alc883_pcm_digital_playback;
7705         spec->stream_digital_capture = &alc883_pcm_digital_capture;
7706
7707         if (!spec->adc_nids && spec->input_mux) {
7708                 spec->adc_nids = alc883_adc_nids;
7709                 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
7710         }
7711
7712         codec->patch_ops = alc_patch_ops;
7713         if (board_config == ALC883_AUTO)
7714                 spec->init_hook = alc883_auto_init;
7715 #ifdef CONFIG_SND_HDA_POWER_SAVE
7716         if (!spec->loopback.amplist)
7717                 spec->loopback.amplist = alc883_loopbacks;
7718 #endif
7719
7720         return 0;
7721 }
7722
7723 /*
7724  * ALC262 support
7725  */
7726
7727 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
7728 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
7729
7730 #define alc262_dac_nids         alc260_dac_nids
7731 #define alc262_adc_nids         alc882_adc_nids
7732 #define alc262_adc_nids_alt     alc882_adc_nids_alt
7733
7734 #define alc262_modes            alc260_modes
7735 #define alc262_capture_source   alc882_capture_source
7736
7737 static struct snd_kcontrol_new alc262_base_mixer[] = {
7738         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7739         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7740         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7741         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7742         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7743         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7744         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7745         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7746         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7747         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7748         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7749         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7750         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7751            HDA_CODEC_MUTE("PC Beelp Playback Switch", 0x0b, 0x05, HDA_INPUT), */
7752         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
7753         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7754         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7755         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
7756         { } /* end */
7757 };
7758
7759 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
7760         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7761         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7762         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7763         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7764         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7765         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7766         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7767         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7768         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7769         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7770         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7771         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7772         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7773            HDA_CODEC_MUTE("PC Beelp Playback Switch", 0x0b, 0x05, HDA_INPUT), */
7774         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
7775         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7776         { } /* end */
7777 };
7778
7779 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
7780         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7781         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7782         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7783         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7784         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
7785
7786         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7787         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7788         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7789         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7790         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7791         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7792         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7793         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7794         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7795         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7796         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7797         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
7798         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
7799         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
7800         { } /* end */
7801 };
7802
7803 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
7804         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7805         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7806         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7807         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7808         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7809         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
7810         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
7811         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
7812         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
7813         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
7814         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
7815         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7816         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7817         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
7818         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
7819         { } /* end */
7820 };
7821
7822 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
7823         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7824         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7825         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
7826         { } /* end */
7827 };
7828
7829 static struct hda_bind_ctls alc262_hp_t5735_bind_front_vol = {
7830         .ops = &snd_hda_bind_vol,
7831         .values = {
7832                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
7833                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
7834                 0
7835         },
7836 };
7837
7838 static struct hda_bind_ctls alc262_hp_t5735_bind_front_sw = {
7839         .ops = &snd_hda_bind_sw,
7840         .values = {
7841                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
7842                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
7843                 0
7844         },
7845 };
7846
7847 /* mute/unmute internal speaker according to the hp jack and mute state */
7848 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
7849 {
7850         struct alc_spec *spec = codec->spec;
7851         unsigned int mute;
7852
7853         if (force || !spec->sense_updated) {
7854                 unsigned int present;
7855                 present = snd_hda_codec_read(codec, 0x15, 0,
7856                                              AC_VERB_GET_PIN_SENSE, 0);
7857                 spec->jack_present = (present & 0x80000000) != 0;
7858                 spec->sense_updated = 1;
7859         }
7860         if (spec->jack_present)
7861                 mute = (0x7080 | ((0)<<8));  /* mute internal speaker */
7862         else    /* unmute internal speaker if necessary */
7863                 mute = (0x7000 | ((0)<<8));
7864         snd_hda_codec_write(codec, 0x0c, 0,
7865                             AC_VERB_SET_AMP_GAIN_MUTE, mute );
7866 }
7867
7868 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
7869                                         unsigned int res)
7870 {
7871         if ((res >> 26) != ALC880_HP_EVENT)
7872                 return;
7873         alc262_hp_t5735_automute(codec, 1);
7874 }
7875
7876 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
7877 {
7878         alc262_hp_t5735_automute(codec, 1);
7879 }
7880
7881 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
7882         HDA_BIND_VOL("PCM Playback Volume", &alc262_hp_t5735_bind_front_vol),
7883         HDA_BIND_SW("PCM Playback Switch",&alc262_hp_t5735_bind_front_sw),
7884         HDA_CODEC_VOLUME("LineOut Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7885         HDA_CODEC_MUTE("LineOut Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7886         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7887         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7888         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7889         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7890         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7891         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7892         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7893         { } /* end */
7894 };
7895
7896 static struct hda_verb alc262_hp_t5735_verbs[] = {
7897         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7898         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7899
7900         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7901         { }
7902 };
7903
7904 /* bind hp and internal speaker mute (with plug check) */
7905 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
7906                                      struct snd_ctl_elem_value *ucontrol)
7907 {
7908         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
7909         long *valp = ucontrol->value.integer.value;
7910         int change;
7911
7912         /* change hp mute */
7913         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
7914                                           HDA_AMP_MUTE,
7915                                           valp[0] ? 0 : HDA_AMP_MUTE);
7916         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
7917                                            HDA_AMP_MUTE,
7918                                            valp[1] ? 0 : HDA_AMP_MUTE);
7919         if (change) {
7920                 /* change speaker according to HP jack state */
7921                 struct alc_spec *spec = codec->spec;
7922                 unsigned int mute;
7923                 if (spec->jack_present)
7924                         mute = HDA_AMP_MUTE;
7925                 else
7926                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
7927                                                       HDA_OUTPUT, 0);
7928                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7929                                          HDA_AMP_MUTE, mute);
7930         }
7931         return change;
7932 }
7933
7934 static struct snd_kcontrol_new alc262_sony_mixer[] = {
7935         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7936         {
7937                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7938                 .name = "Master Playback Switch",
7939                 .info = snd_hda_mixer_amp_switch_info,
7940                 .get = snd_hda_mixer_amp_switch_get,
7941                 .put = alc262_sony_master_sw_put,
7942                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
7943         },
7944         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7945         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7946         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7947         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7948         { } /* end */
7949 };
7950
7951 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
7952         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7953         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7954         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7955         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7956         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7957         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7958         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7959         { } /* end */
7960 };
7961
7962 #define alc262_capture_mixer            alc882_capture_mixer
7963 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
7964
7965 /*
7966  * generic initialization of ADC, input mixers and output mixers
7967  */
7968 static struct hda_verb alc262_init_verbs[] = {
7969         /*
7970          * Unmute ADC0-2 and set the default input to mic-in
7971          */
7972         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7973         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7974         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7975         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7976         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7977         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7978
7979         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7980          * mixer widget
7981          * Note: PASD motherboards uses the Line In 2 as the input for
7982          * front panel mic (mic 2)
7983          */
7984         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7985         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7986         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7987         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7988         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7989         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7990
7991         /*
7992          * Set up output mixers (0x0c - 0x0e)
7993          */
7994         /* set vol=0 to output mixers */
7995         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7996         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7997         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7998         /* set up input amps for analog loopback */
7999         /* Amp Indices: DAC = 0, mixer = 1 */
8000         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8001         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8002         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8003         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8004         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8005         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8006
8007         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8008         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8009         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8010         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8011         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8012         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8013
8014         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8015         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8016         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8017         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8018         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8019         
8020         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8021         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8022         
8023         /* FIXME: use matrix-type input source selection */
8024         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8025         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8026         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8027         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8028         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8029         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8030         /* Input mixer2 */
8031         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8032         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8033         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8034         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8035         /* Input mixer3 */
8036         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8037         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8038         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8039         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8040
8041         { }
8042 };
8043
8044 static struct hda_verb alc262_hippo_unsol_verbs[] = {
8045         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8046         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8047         {}
8048 };
8049
8050 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
8051         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8052         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8053         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
8054
8055         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8056         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8057         {}
8058 };
8059
8060 static struct hda_verb alc262_sony_unsol_verbs[] = {
8061         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8062         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8063         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
8064
8065         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8066         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8067 };
8068
8069 /* mute/unmute internal speaker according to the hp jack and mute state */
8070 static void alc262_hippo_automute(struct hda_codec *codec)
8071 {
8072         struct alc_spec *spec = codec->spec;
8073         unsigned int mute;
8074         unsigned int present;
8075
8076         /* need to execute and sync at first */
8077         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
8078         present = snd_hda_codec_read(codec, 0x15, 0,
8079                                      AC_VERB_GET_PIN_SENSE, 0);
8080         spec->jack_present = (present & 0x80000000) != 0;
8081         if (spec->jack_present) {
8082                 /* mute internal speaker */
8083                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8084                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8085         } else {
8086                 /* unmute internal speaker if necessary */
8087                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
8088                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8089                                          HDA_AMP_MUTE, mute);
8090         }
8091 }
8092
8093 /* unsolicited event for HP jack sensing */
8094 static void alc262_hippo_unsol_event(struct hda_codec *codec,
8095                                        unsigned int res)
8096 {
8097         if ((res >> 26) != ALC880_HP_EVENT)
8098                 return;
8099         alc262_hippo_automute(codec);
8100 }
8101
8102 static void alc262_hippo1_automute(struct hda_codec *codec)
8103 {
8104         unsigned int mute;
8105         unsigned int present;
8106
8107         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8108         present = snd_hda_codec_read(codec, 0x1b, 0,
8109                                      AC_VERB_GET_PIN_SENSE, 0);
8110         present = (present & 0x80000000) != 0;
8111         if (present) {
8112                 /* mute internal speaker */
8113                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8114                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8115         } else {
8116                 /* unmute internal speaker if necessary */
8117                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8118                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8119                                          HDA_AMP_MUTE, mute);
8120         }
8121 }
8122
8123 /* unsolicited event for HP jack sensing */
8124 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
8125                                        unsigned int res)
8126 {
8127         if ((res >> 26) != ALC880_HP_EVENT)
8128                 return;
8129         alc262_hippo1_automute(codec);
8130 }
8131
8132 /*
8133  * fujitsu model
8134  *  0x14 = headphone/spdif-out, 0x15 = internal speaker
8135  */
8136
8137 #define ALC_HP_EVENT    0x37
8138
8139 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
8140         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8141         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8142         {}
8143 };
8144
8145 static struct hda_input_mux alc262_fujitsu_capture_source = {
8146         .num_items = 3,
8147         .items = {
8148                 { "Mic", 0x0 },
8149                 { "Int Mic", 0x1 },
8150                 { "CD", 0x4 },
8151         },
8152 };
8153
8154 static struct hda_input_mux alc262_HP_capture_source = {
8155         .num_items = 5,
8156         .items = {
8157                 { "Mic", 0x0 },
8158                 { "Front Mic", 0x1 },
8159                 { "Line", 0x2 },
8160                 { "CD", 0x4 },
8161                 { "AUX IN", 0x6 },
8162         },
8163 };
8164
8165 static struct hda_input_mux alc262_HP_D7000_capture_source = {
8166         .num_items = 4,
8167         .items = {
8168                 { "Mic", 0x0 },
8169                 { "Front Mic", 0x2 },
8170                 { "Line", 0x1 },
8171                 { "CD", 0x4 },
8172         },
8173 };
8174
8175 /* mute/unmute internal speaker according to the hp jack and mute state */
8176 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
8177 {
8178         struct alc_spec *spec = codec->spec;
8179         unsigned int mute;
8180
8181         if (force || !spec->sense_updated) {
8182                 unsigned int present;
8183                 /* need to execute and sync at first */
8184                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
8185                 present = snd_hda_codec_read(codec, 0x14, 0,
8186                                          AC_VERB_GET_PIN_SENSE, 0);
8187                 spec->jack_present = (present & 0x80000000) != 0;
8188                 spec->sense_updated = 1;
8189         }
8190         if (spec->jack_present) {
8191                 /* mute internal speaker */
8192                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8193                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8194         } else {
8195                 /* unmute internal speaker if necessary */
8196                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
8197                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8198                                          HDA_AMP_MUTE, mute);
8199         }
8200 }
8201
8202 /* unsolicited event for HP jack sensing */
8203 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
8204                                        unsigned int res)
8205 {
8206         if ((res >> 26) != ALC_HP_EVENT)
8207                 return;
8208         alc262_fujitsu_automute(codec, 1);
8209 }
8210
8211 /* bind volumes of both NID 0x0c and 0x0d */
8212 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
8213         .ops = &snd_hda_bind_vol,
8214         .values = {
8215                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
8216                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
8217                 0
8218         },
8219 };
8220
8221 /* bind hp and internal speaker mute (with plug check) */
8222 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
8223                                          struct snd_ctl_elem_value *ucontrol)
8224 {
8225         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8226         long *valp = ucontrol->value.integer.value;
8227         int change;
8228
8229         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
8230                                           HDA_AMP_MUTE,
8231                                           valp[0] ? 0 : HDA_AMP_MUTE);
8232         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
8233                                            HDA_AMP_MUTE,
8234                                            valp[1] ? 0 : HDA_AMP_MUTE);
8235         if (change)
8236                 alc262_fujitsu_automute(codec, 0);
8237         return change;
8238 }
8239
8240 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
8241         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
8242         {
8243                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8244                 .name = "Master Playback Switch",
8245                 .info = snd_hda_mixer_amp_switch_info,
8246                 .get = snd_hda_mixer_amp_switch_get,
8247                 .put = alc262_fujitsu_master_sw_put,
8248                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
8249         },
8250         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8251         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8252         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8253         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8254         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8255         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
8256         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8257         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8258         { } /* end */
8259 };
8260
8261 /* additional init verbs for Benq laptops */
8262 static struct hda_verb alc262_EAPD_verbs[] = {
8263         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8264         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
8265         {}
8266 };
8267
8268 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
8269         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8270         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8271
8272         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8273         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
8274         {}
8275 };
8276
8277 /* Samsung Q1 Ultra Vista model setup */
8278 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
8279         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8280         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8281         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8282         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8283         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8284         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
8285         { } /* end */
8286 };
8287
8288 static struct hda_verb alc262_ultra_verbs[] = {
8289         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8290         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8291         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
8292         /* Mic is on Node 0x19 */
8293         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8294         {0x22, AC_VERB_SET_CONNECT_SEL, 0x01},
8295         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8296         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
8297         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8298         {0x24, AC_VERB_SET_CONNECT_SEL, 0x01},
8299         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8300         {}
8301 };
8302
8303 static struct hda_input_mux alc262_ultra_capture_source = {
8304         .num_items = 1,
8305         .items = {
8306                 { "Mic", 0x1 },
8307         },
8308 };
8309
8310 /* mute/unmute internal speaker according to the hp jack and mute state */
8311 static void alc262_ultra_automute(struct hda_codec *codec)
8312 {
8313         struct alc_spec *spec = codec->spec;
8314         unsigned int mute;
8315         unsigned int present;
8316
8317         /* need to execute and sync at first */
8318         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
8319         present = snd_hda_codec_read(codec, 0x15, 0,
8320                                      AC_VERB_GET_PIN_SENSE, 0);
8321         spec->jack_present = (present & 0x80000000) != 0;
8322         if (spec->jack_present) {
8323                 /* mute internal speaker */
8324                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8325                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8326         } else {
8327                 /* unmute internal speaker if necessary */
8328                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
8329                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8330                                          HDA_AMP_MUTE, mute);
8331         }
8332 }
8333
8334 /* unsolicited event for HP jack sensing */
8335 static void alc262_ultra_unsol_event(struct hda_codec *codec,
8336                                        unsigned int res)
8337 {
8338         if ((res >> 26) != ALC880_HP_EVENT)
8339                 return;
8340         alc262_ultra_automute(codec);
8341 }
8342
8343 /* add playback controls from the parsed DAC table */
8344 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
8345                                              const struct auto_pin_cfg *cfg)
8346 {
8347         hda_nid_t nid;
8348         int err;
8349
8350         spec->multiout.num_dacs = 1;    /* only use one dac */
8351         spec->multiout.dac_nids = spec->private_dac_nids;
8352         spec->multiout.dac_nids[0] = 2;
8353
8354         nid = cfg->line_out_pins[0];
8355         if (nid) {
8356                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
8357                                   "Front Playback Volume",
8358                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
8359                 if (err < 0)
8360                         return err;
8361                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
8362                                   "Front Playback Switch",
8363                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
8364                 if (err < 0)
8365                         return err;
8366         }
8367
8368         nid = cfg->speaker_pins[0];
8369         if (nid) {
8370                 if (nid == 0x16) {
8371                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
8372                                           "Speaker Playback Volume",
8373                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
8374                                                               HDA_OUTPUT));
8375                         if (err < 0)
8376                                 return err;
8377                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
8378                                           "Speaker Playback Switch",
8379                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
8380                                                               HDA_OUTPUT));
8381                         if (err < 0)
8382                                 return err;
8383                 } else {
8384                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
8385                                           "Speaker Playback Switch",
8386                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
8387                                                               HDA_OUTPUT));
8388                         if (err < 0)
8389                                 return err;
8390                 }
8391         }
8392         nid = cfg->hp_pins[0];
8393         if (nid) {
8394                 /* spec->multiout.hp_nid = 2; */
8395                 if (nid == 0x16) {
8396                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
8397                                           "Headphone Playback Volume",
8398                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
8399                                                               HDA_OUTPUT));
8400                         if (err < 0)
8401                                 return err;
8402                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
8403                                           "Headphone Playback Switch",
8404                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
8405                                                               HDA_OUTPUT));
8406                         if (err < 0)
8407                                 return err;
8408                 } else {
8409                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
8410                                           "Headphone Playback Switch",
8411                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
8412                                                               HDA_OUTPUT));
8413                         if (err < 0)
8414                                 return err;
8415                 }
8416         }
8417         return 0;
8418 }
8419
8420 /* identical with ALC880 */
8421 #define alc262_auto_create_analog_input_ctls \
8422         alc880_auto_create_analog_input_ctls
8423
8424 /*
8425  * generic initialization of ADC, input mixers and output mixers
8426  */
8427 static struct hda_verb alc262_volume_init_verbs[] = {
8428         /*
8429          * Unmute ADC0-2 and set the default input to mic-in
8430          */
8431         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8432         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8433         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8434         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8435         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8436         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8437
8438         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8439          * mixer widget
8440          * Note: PASD motherboards uses the Line In 2 as the input for
8441          * front panel mic (mic 2)
8442          */
8443         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8444         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8445         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8446         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8447         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8448         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8449
8450         /*
8451          * Set up output mixers (0x0c - 0x0f)
8452          */
8453         /* set vol=0 to output mixers */
8454         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8455         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8456         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8457         
8458         /* set up input amps for analog loopback */
8459         /* Amp Indices: DAC = 0, mixer = 1 */
8460         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8461         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8462         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8463         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8464         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8465         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8466
8467         /* FIXME: use matrix-type input source selection */
8468         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8469         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8470         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8471         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8472         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8473         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8474         /* Input mixer2 */
8475         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8476         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8477         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8478         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8479         /* Input mixer3 */
8480         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8481         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
8482         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
8483         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
8484
8485         { }
8486 };
8487
8488 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
8489         /*
8490          * Unmute ADC0-2 and set the default input to mic-in
8491          */
8492         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8493         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8494         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8495         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8496         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8497         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8498
8499         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8500          * mixer widget
8501          * Note: PASD motherboards uses the Line In 2 as the input for
8502          * front panel mic (mic 2)
8503          */
8504         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8505         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8506         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8507         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8508         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8509         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8510         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
8511         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
8512         
8513         /*
8514          * Set up output mixers (0x0c - 0x0e)
8515          */
8516         /* set vol=0 to output mixers */
8517         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8518         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8519         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8520
8521         /* set up input amps for analog loopback */
8522         /* Amp Indices: DAC = 0, mixer = 1 */
8523         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8524         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8525         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8526         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8527         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8528         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8529
8530         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
8531         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8532         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8533
8534         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8535         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8536
8537         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8538         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8539
8540         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8541         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8542         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
8543         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8544         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
8545
8546         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
8547         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8548         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8549         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
8550         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8551         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8552
8553
8554         /* FIXME: use matrix-type input source selection */
8555         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8556         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8557         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8558         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8559         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8560         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8561         /* Input mixer2 */
8562         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8563         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8564         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8565         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8566         /* Input mixer3 */
8567         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8568         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8569         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8570         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8571
8572         { }
8573 };
8574
8575 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
8576         /*
8577          * Unmute ADC0-2 and set the default input to mic-in
8578          */
8579         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
8580         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8581         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8582         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8583         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8584         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8585
8586         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8587          * mixer widget
8588          * Note: PASD motherboards uses the Line In 2 as the input for front
8589          * panel mic (mic 2)
8590          */
8591         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8592         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8593         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8594         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8595         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8596         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8597         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
8598         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
8599         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
8600         /*
8601          * Set up output mixers (0x0c - 0x0e)
8602          */
8603         /* set vol=0 to output mixers */
8604         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8605         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8606         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8607
8608         /* set up input amps for analog loopback */
8609         /* Amp Indices: DAC = 0, mixer = 1 */
8610         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8611         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8612         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8613         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8614         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8615         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8616
8617
8618         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
8619         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
8620         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
8621         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
8622         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
8623         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
8624         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
8625
8626         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8627         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8628
8629         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8630         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8631
8632         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
8633         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8634         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8635         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
8636         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8637         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
8638
8639         /* FIXME: use matrix-type input source selection */
8640         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8641         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
8642         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
8643         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
8644         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
8645         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
8646         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
8647         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
8648         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
8649         /* Input mixer2 */
8650         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8651         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8652         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8653         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8654         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8655         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
8656         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
8657         /* Input mixer3 */
8658         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
8659         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
8660         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
8661         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
8662         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
8663         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
8664         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
8665
8666         { }
8667 };
8668
8669 #ifdef CONFIG_SND_HDA_POWER_SAVE
8670 #define alc262_loopbacks        alc880_loopbacks
8671 #endif
8672
8673 /* pcm configuration: identiacal with ALC880 */
8674 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
8675 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
8676 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
8677 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
8678
8679 /*
8680  * BIOS auto configuration
8681  */
8682 static int alc262_parse_auto_config(struct hda_codec *codec)
8683 {
8684         struct alc_spec *spec = codec->spec;
8685         int err;
8686         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
8687
8688         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
8689                                            alc262_ignore);
8690         if (err < 0)
8691                 return err;
8692         if (!spec->autocfg.line_outs)
8693                 return 0; /* can't find valid BIOS pin config */
8694         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
8695         if (err < 0)
8696                 return err;
8697         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
8698         if (err < 0)
8699                 return err;
8700
8701         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
8702
8703         if (spec->autocfg.dig_out_pin)
8704                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
8705         if (spec->autocfg.dig_in_pin)
8706                 spec->dig_in_nid = ALC262_DIGIN_NID;
8707
8708         if (spec->kctl_alloc)
8709                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
8710
8711         spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs;
8712         spec->num_mux_defs = 1;
8713         spec->input_mux = &spec->private_imux;
8714
8715         err = alc_auto_add_mic_boost(codec);
8716         if (err < 0)
8717                 return err;
8718
8719         return 1;
8720 }
8721
8722 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
8723 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
8724 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
8725
8726
8727 /* init callback for auto-configuration model -- overriding the default init */
8728 static void alc262_auto_init(struct hda_codec *codec)
8729 {
8730         alc262_auto_init_multi_out(codec);
8731         alc262_auto_init_hp_out(codec);
8732         alc262_auto_init_analog_input(codec);
8733 }
8734
8735 /*
8736  * configuration and preset
8737  */
8738 static const char *alc262_models[ALC262_MODEL_LAST] = {
8739         [ALC262_BASIC]          = "basic",
8740         [ALC262_HIPPO]          = "hippo",
8741         [ALC262_HIPPO_1]        = "hippo_1",
8742         [ALC262_FUJITSU]        = "fujitsu",
8743         [ALC262_HP_BPC]         = "hp-bpc",
8744         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
8745         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
8746         [ALC262_BENQ_ED8]       = "benq",
8747         [ALC262_BENQ_T31]       = "benq-t31",
8748         [ALC262_SONY_ASSAMD]    = "sony-assamd",
8749         [ALC262_ULTRA]          = "ultra",
8750         [ALC262_AUTO]           = "auto",
8751 };
8752
8753 static struct snd_pci_quirk alc262_cfg_tbl[] = {
8754         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
8755         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
8756         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
8757         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
8758         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
8759         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
8760         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
8761         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
8762         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
8763         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
8764         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
8765         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
8766         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
8767         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
8768         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
8769         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
8770         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
8771         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
8772         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
8773         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
8774         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
8775                       ALC262_HP_TC_T5735),
8776         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
8777         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
8778         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
8779         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
8780         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
8781         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
8782         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
8783         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
8784         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
8785         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
8786         {}
8787 };
8788
8789 static struct alc_config_preset alc262_presets[] = {
8790         [ALC262_BASIC] = {
8791                 .mixers = { alc262_base_mixer },
8792                 .init_verbs = { alc262_init_verbs },
8793                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8794                 .dac_nids = alc262_dac_nids,
8795                 .hp_nid = 0x03,
8796                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8797                 .channel_mode = alc262_modes,
8798                 .input_mux = &alc262_capture_source,
8799         },
8800         [ALC262_HIPPO] = {
8801                 .mixers = { alc262_base_mixer },
8802                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
8803                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8804                 .dac_nids = alc262_dac_nids,
8805                 .hp_nid = 0x03,
8806                 .dig_out_nid = ALC262_DIGOUT_NID,
8807                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8808                 .channel_mode = alc262_modes,
8809                 .input_mux = &alc262_capture_source,
8810                 .unsol_event = alc262_hippo_unsol_event,
8811                 .init_hook = alc262_hippo_automute,
8812         },
8813         [ALC262_HIPPO_1] = {
8814                 .mixers = { alc262_hippo1_mixer },
8815                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
8816                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8817                 .dac_nids = alc262_dac_nids,
8818                 .hp_nid = 0x02,
8819                 .dig_out_nid = ALC262_DIGOUT_NID,
8820                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8821                 .channel_mode = alc262_modes,
8822                 .input_mux = &alc262_capture_source,
8823                 .unsol_event = alc262_hippo1_unsol_event,
8824                 .init_hook = alc262_hippo1_automute,
8825         },
8826         [ALC262_FUJITSU] = {
8827                 .mixers = { alc262_fujitsu_mixer },
8828                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
8829                                 alc262_fujitsu_unsol_verbs },
8830                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8831                 .dac_nids = alc262_dac_nids,
8832                 .hp_nid = 0x03,
8833                 .dig_out_nid = ALC262_DIGOUT_NID,
8834                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8835                 .channel_mode = alc262_modes,
8836                 .input_mux = &alc262_fujitsu_capture_source,
8837                 .unsol_event = alc262_fujitsu_unsol_event,
8838         },
8839         [ALC262_HP_BPC] = {
8840                 .mixers = { alc262_HP_BPC_mixer },
8841                 .init_verbs = { alc262_HP_BPC_init_verbs },
8842                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8843                 .dac_nids = alc262_dac_nids,
8844                 .hp_nid = 0x03,
8845                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8846                 .channel_mode = alc262_modes,
8847                 .input_mux = &alc262_HP_capture_source,
8848         },
8849         [ALC262_HP_BPC_D7000_WF] = {
8850                 .mixers = { alc262_HP_BPC_WildWest_mixer },
8851                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
8852                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8853                 .dac_nids = alc262_dac_nids,
8854                 .hp_nid = 0x03,
8855                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8856                 .channel_mode = alc262_modes,
8857                 .input_mux = &alc262_HP_D7000_capture_source,
8858         },
8859         [ALC262_HP_BPC_D7000_WL] = {
8860                 .mixers = { alc262_HP_BPC_WildWest_mixer,
8861                             alc262_HP_BPC_WildWest_option_mixer },
8862                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
8863                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8864                 .dac_nids = alc262_dac_nids,
8865                 .hp_nid = 0x03,
8866                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8867                 .channel_mode = alc262_modes,
8868                 .input_mux = &alc262_HP_D7000_capture_source,
8869         },
8870         [ALC262_HP_TC_T5735] = {
8871                 .mixers = { alc262_hp_t5735_mixer },
8872                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
8873                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8874                 .dac_nids = alc262_dac_nids,
8875                 .hp_nid = 0x03,
8876                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8877                 .channel_mode = alc262_modes,
8878                 .input_mux = &alc262_capture_source,
8879                 .unsol_event = alc262_hp_t5735_unsol_event,
8880                 .init_hook = alc262_hp_t5735_init_hook,
8881         },
8882         [ALC262_BENQ_ED8] = {
8883                 .mixers = { alc262_base_mixer },
8884                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
8885                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8886                 .dac_nids = alc262_dac_nids,
8887                 .hp_nid = 0x03,
8888                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8889                 .channel_mode = alc262_modes,
8890                 .input_mux = &alc262_capture_source,
8891         },
8892         [ALC262_SONY_ASSAMD] = {
8893                 .mixers = { alc262_sony_mixer },
8894                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
8895                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8896                 .dac_nids = alc262_dac_nids,
8897                 .hp_nid = 0x02,
8898                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8899                 .channel_mode = alc262_modes,
8900                 .input_mux = &alc262_capture_source,
8901                 .unsol_event = alc262_hippo_unsol_event,
8902                 .init_hook = alc262_hippo_automute,
8903         },
8904         [ALC262_BENQ_T31] = {
8905                 .mixers = { alc262_benq_t31_mixer },
8906                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
8907                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8908                 .dac_nids = alc262_dac_nids,
8909                 .hp_nid = 0x03,
8910                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8911                 .channel_mode = alc262_modes,
8912                 .input_mux = &alc262_capture_source,
8913                 .unsol_event = alc262_hippo_unsol_event,
8914                 .init_hook = alc262_hippo_automute,
8915         },      
8916         [ALC262_ULTRA] = {
8917                 .mixers = { alc262_ultra_mixer },
8918                 .init_verbs = { alc262_init_verbs, alc262_ultra_verbs },
8919                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
8920                 .dac_nids = alc262_dac_nids,
8921                 .hp_nid = 0x03,
8922                 .dig_out_nid = ALC262_DIGOUT_NID,
8923                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
8924                 .channel_mode = alc262_modes,
8925                 .input_mux = &alc262_ultra_capture_source,
8926                 .unsol_event = alc262_ultra_unsol_event,
8927                 .init_hook = alc262_ultra_automute,
8928         },
8929 };
8930
8931 static int patch_alc262(struct hda_codec *codec)
8932 {
8933         struct alc_spec *spec;
8934         int board_config;
8935         int err;
8936
8937         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
8938         if (spec == NULL)
8939                 return -ENOMEM;
8940
8941         codec->spec = spec;
8942 #if 0
8943         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
8944          * under-run
8945          */
8946         {
8947         int tmp;
8948         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
8949         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
8950         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
8951         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
8952         }
8953 #endif
8954
8955         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
8956                                                   alc262_models,
8957                                                   alc262_cfg_tbl);
8958
8959         if (board_config < 0) {
8960                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
8961                        "trying auto-probe from BIOS...\n");
8962                 board_config = ALC262_AUTO;
8963         }
8964
8965         if (board_config == ALC262_AUTO) {
8966                 /* automatic parse from the BIOS config */
8967                 err = alc262_parse_auto_config(codec);
8968                 if (err < 0) {
8969                         alc_free(codec);
8970                         return err;
8971                 } else if (!err) {
8972                         printk(KERN_INFO
8973                                "hda_codec: Cannot set up configuration "
8974                                "from BIOS.  Using base mode...\n");
8975                         board_config = ALC262_BASIC;
8976                 }
8977         }
8978
8979         if (board_config != ALC262_AUTO)
8980                 setup_preset(spec, &alc262_presets[board_config]);
8981
8982         spec->stream_name_analog = "ALC262 Analog";
8983         spec->stream_analog_playback = &alc262_pcm_analog_playback;
8984         spec->stream_analog_capture = &alc262_pcm_analog_capture;
8985                 
8986         spec->stream_name_digital = "ALC262 Digital";
8987         spec->stream_digital_playback = &alc262_pcm_digital_playback;
8988         spec->stream_digital_capture = &alc262_pcm_digital_capture;
8989
8990         if (!spec->adc_nids && spec->input_mux) {
8991                 /* check whether NID 0x07 is valid */
8992                 unsigned int wcap = get_wcaps(codec, 0x07);
8993
8994                 /* get type */
8995                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
8996                 if (wcap != AC_WID_AUD_IN) {
8997                         spec->adc_nids = alc262_adc_nids_alt;
8998                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
8999                         spec->mixers[spec->num_mixers] =
9000                                 alc262_capture_alt_mixer;
9001                         spec->num_mixers++;
9002                 } else {
9003                         spec->adc_nids = alc262_adc_nids;
9004                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
9005                         spec->mixers[spec->num_mixers] = alc262_capture_mixer;
9006                         spec->num_mixers++;
9007                 }
9008         }
9009
9010         codec->patch_ops = alc_patch_ops;
9011         if (board_config == ALC262_AUTO)
9012                 spec->init_hook = alc262_auto_init;
9013 #ifdef CONFIG_SND_HDA_POWER_SAVE
9014         if (!spec->loopback.amplist)
9015                 spec->loopback.amplist = alc262_loopbacks;
9016 #endif
9017                 
9018         return 0;
9019 }
9020
9021 /*
9022  *  ALC268 channel source setting (2 channel)
9023  */
9024 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
9025 #define alc268_modes            alc260_modes
9026         
9027 static hda_nid_t alc268_dac_nids[2] = {
9028         /* front, hp */
9029         0x02, 0x03
9030 };
9031
9032 static hda_nid_t alc268_adc_nids[2] = {
9033         /* ADC0-1 */
9034         0x08, 0x07
9035 };
9036
9037 static hda_nid_t alc268_adc_nids_alt[1] = {
9038         /* ADC0 */
9039         0x08
9040 };
9041
9042 static struct snd_kcontrol_new alc268_base_mixer[] = {
9043         /* output mixer control */
9044         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
9045         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9046         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
9047         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9048         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9049         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9050         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
9051         { }
9052 };
9053
9054 static struct hda_verb alc268_eapd_verbs[] = {
9055         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9056         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9057         { }
9058 };
9059
9060 /* Toshiba specific */
9061 #define alc268_toshiba_automute alc262_hippo_automute
9062
9063 static struct hda_verb alc268_toshiba_verbs[] = {
9064         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9065         { } /* end */
9066 };
9067
9068 /* Acer specific */
9069 /* bind volumes of both NID 0x02 and 0x03 */
9070 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
9071         .ops = &snd_hda_bind_vol,
9072         .values = {
9073                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
9074                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
9075                 0
9076         },
9077 };
9078
9079 /* mute/unmute internal speaker according to the hp jack and mute state */
9080 static void alc268_acer_automute(struct hda_codec *codec, int force)
9081 {
9082         struct alc_spec *spec = codec->spec;
9083         unsigned int mute;
9084
9085         if (force || !spec->sense_updated) {
9086                 unsigned int present;
9087                 present = snd_hda_codec_read(codec, 0x14, 0,
9088                                          AC_VERB_GET_PIN_SENSE, 0);
9089                 spec->jack_present = (present & 0x80000000) != 0;
9090                 spec->sense_updated = 1;
9091         }
9092         if (spec->jack_present)
9093                 mute = HDA_AMP_MUTE; /* mute internal speaker */
9094         else /* unmute internal speaker if necessary */
9095                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9096         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9097                                  HDA_AMP_MUTE, mute);
9098 }
9099
9100
9101 /* bind hp and internal speaker mute (with plug check) */
9102 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
9103                                      struct snd_ctl_elem_value *ucontrol)
9104 {
9105         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9106         long *valp = ucontrol->value.integer.value;
9107         int change;
9108
9109         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
9110                                           HDA_AMP_MUTE,
9111                                           valp[0] ? 0 : HDA_AMP_MUTE);
9112         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
9113                                            HDA_AMP_MUTE,
9114                                            valp[1] ? 0 : HDA_AMP_MUTE);
9115         if (change)
9116                 alc268_acer_automute(codec, 0);
9117         return change;
9118 }
9119
9120 static struct snd_kcontrol_new alc268_acer_mixer[] = {
9121         /* output mixer control */
9122         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
9123         {
9124                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9125                 .name = "Master Playback Switch",
9126                 .info = snd_hda_mixer_amp_switch_info,
9127                 .get = snd_hda_mixer_amp_switch_get,
9128                 .put = alc268_acer_master_sw_put,
9129                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9130         },
9131         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9132         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
9133         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
9134         { }
9135 };
9136
9137 static struct hda_verb alc268_acer_verbs[] = {
9138         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9139         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9140
9141         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9142         { }
9143 };
9144
9145 /* unsolicited event for HP jack sensing */
9146 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
9147                                        unsigned int res)
9148 {
9149         if ((res >> 26) != ALC880_HP_EVENT)
9150                 return;
9151         alc268_toshiba_automute(codec);
9152 }
9153
9154 static void alc268_acer_unsol_event(struct hda_codec *codec,
9155                                        unsigned int res)
9156 {
9157         if ((res >> 26) != ALC880_HP_EVENT)
9158                 return;
9159         alc268_acer_automute(codec, 1);
9160 }
9161
9162 static void alc268_acer_init_hook(struct hda_codec *codec)
9163 {
9164         alc268_acer_automute(codec, 1);
9165 }
9166
9167 /*
9168  * generic initialization of ADC, input mixers and output mixers
9169  */
9170 static struct hda_verb alc268_base_init_verbs[] = {
9171         /* Unmute DAC0-1 and set vol = 0 */
9172         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9173         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9174         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9175         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9176         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9177         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9178
9179         /*
9180          * Set up output mixers (0x0c - 0x0e)
9181          */
9182         /* set vol=0 to output mixers */
9183         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9184         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9185         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9186         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
9187
9188         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9189         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9190
9191         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9192         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9193         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9194         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9195         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9196         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9197         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9198         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9199
9200         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9201         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9202         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9203         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9204         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9205         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9206         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9207         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9208
9209         /* FIXME: use matrix-type input source selection */
9210         /* Mixer elements: 0x18, 19, 1a, 1c, 14, 15, 0b */
9211         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9212         /* Input mixer2 */
9213         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9214         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9215         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9216         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9217
9218         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9219         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9220         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
9221         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
9222         { }
9223 };
9224
9225 /*
9226  * generic initialization of ADC, input mixers and output mixers
9227  */
9228 static struct hda_verb alc268_volume_init_verbs[] = {
9229         /* set output DAC */
9230         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9231         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9232         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9233         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9234
9235         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9236         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9237         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9238         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9239         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9240
9241         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9242         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9243         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9244         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9245         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9246
9247         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9248         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9249         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9250         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9251
9252         /* set PCBEEP vol = 0 */
9253         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, (0xb000 | (0x00 << 8))},
9254
9255         { }
9256 };
9257
9258 #define alc268_mux_enum_info alc_mux_enum_info
9259 #define alc268_mux_enum_get alc_mux_enum_get
9260
9261 static int alc268_mux_enum_put(struct snd_kcontrol *kcontrol,
9262                                struct snd_ctl_elem_value *ucontrol)
9263 {
9264         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9265         struct alc_spec *spec = codec->spec;
9266         const struct hda_input_mux *imux = spec->input_mux;
9267         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
9268         static hda_nid_t capture_mixers[3] = { 0x23, 0x24 };
9269         hda_nid_t nid = capture_mixers[adc_idx];
9270         unsigned int *cur_val = &spec->cur_mux[adc_idx];
9271         unsigned int i, idx;
9272
9273         idx = ucontrol->value.enumerated.item[0];
9274         if (idx >= imux->num_items)
9275                 idx = imux->num_items - 1;
9276         if (*cur_val == idx)
9277                 return 0;
9278         for (i = 0; i < imux->num_items; i++) {
9279                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
9280                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
9281                                          imux->items[i].index,
9282                                          HDA_AMP_MUTE, v);
9283                 snd_hda_codec_write_cache(codec, nid, 0,
9284                                           AC_VERB_SET_CONNECT_SEL,
9285                                           idx );
9286         }
9287         *cur_val = idx;
9288         return 1;
9289 }
9290
9291 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
9292         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
9293         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
9294         {
9295                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9296                 /* The multiple "Capture Source" controls confuse alsamixer
9297                  * So call somewhat different..
9298                  * FIXME: the controls appear in the "playback" view!
9299                  */
9300                 /* .name = "Capture Source", */
9301                 .name = "Input Source",
9302                 .count = 1,
9303                 .info = alc268_mux_enum_info,
9304                 .get = alc268_mux_enum_get,
9305                 .put = alc268_mux_enum_put,
9306         },
9307         { } /* end */
9308 };
9309
9310 static struct snd_kcontrol_new alc268_capture_mixer[] = {
9311         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
9312         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
9313         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
9314         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
9315         {
9316                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9317                 /* The multiple "Capture Source" controls confuse alsamixer
9318                  * So call somewhat different..
9319                  * FIXME: the controls appear in the "playback" view!
9320                  */
9321                 /* .name = "Capture Source", */
9322                 .name = "Input Source",
9323                 .count = 2,
9324                 .info = alc268_mux_enum_info,
9325                 .get = alc268_mux_enum_get,
9326                 .put = alc268_mux_enum_put,
9327         },
9328         { } /* end */
9329 };
9330
9331 static struct hda_input_mux alc268_capture_source = {
9332         .num_items = 4,
9333         .items = {
9334                 { "Mic", 0x0 },
9335                 { "Front Mic", 0x1 },
9336                 { "Line", 0x2 },
9337                 { "CD", 0x3 },
9338         },
9339 };
9340
9341 /* create input playback/capture controls for the given pin */
9342 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
9343                                     const char *ctlname, int idx)
9344 {
9345         char name[32];
9346         int err;
9347
9348         sprintf(name, "%s Playback Volume", ctlname);
9349         if (nid == 0x14) {
9350                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
9351                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
9352                                                       HDA_OUTPUT));
9353                 if (err < 0)
9354                         return err;
9355         } else if (nid == 0x15) {
9356                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
9357                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
9358                                                       HDA_OUTPUT));
9359                 if (err < 0)
9360                         return err;
9361         } else
9362                 return -1;
9363         sprintf(name, "%s Playback Switch", ctlname);
9364         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
9365                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
9366         if (err < 0)
9367                 return err;
9368         return 0;
9369 }
9370
9371 /* add playback controls from the parsed DAC table */
9372 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
9373                                              const struct auto_pin_cfg *cfg)
9374 {
9375         hda_nid_t nid;
9376         int err;
9377
9378         spec->multiout.num_dacs = 2;    /* only use one dac */
9379         spec->multiout.dac_nids = spec->private_dac_nids;
9380         spec->multiout.dac_nids[0] = 2;
9381         spec->multiout.dac_nids[1] = 3;
9382
9383         nid = cfg->line_out_pins[0];
9384         if (nid)
9385                 alc268_new_analog_output(spec, nid, "Front", 0);        
9386
9387         nid = cfg->speaker_pins[0];
9388         if (nid == 0x1d) {
9389                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9390                                   "Speaker Playback Volume",
9391                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
9392                 if (err < 0)
9393                         return err;
9394         }
9395         nid = cfg->hp_pins[0];
9396         if (nid)
9397                 alc268_new_analog_output(spec, nid, "Headphone", 0);
9398
9399         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
9400         if (nid == 0x16) {
9401                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9402                                   "Mono Playback Switch",
9403                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
9404                 if (err < 0)
9405                         return err;
9406         }
9407         return 0;       
9408 }
9409
9410 /* create playback/capture controls for input pins */
9411 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
9412                                                 const struct auto_pin_cfg *cfg)
9413 {
9414         struct hda_input_mux *imux = &spec->private_imux;
9415         int i, idx1;
9416
9417         for (i = 0; i < AUTO_PIN_LAST; i++) {
9418                 switch(cfg->input_pins[i]) {
9419                 case 0x18:
9420                         idx1 = 0;       /* Mic 1 */
9421                         break;
9422                 case 0x19:
9423                         idx1 = 1;       /* Mic 2 */
9424                         break;
9425                 case 0x1a:
9426                         idx1 = 2;       /* Line In */
9427                         break;
9428                 case 0x1c:      
9429                         idx1 = 3;       /* CD */
9430                         break;
9431                 default:
9432                         continue;
9433                 }
9434                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
9435                 imux->items[imux->num_items].index = idx1;
9436                 imux->num_items++;      
9437         }
9438         return 0;
9439 }
9440
9441 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
9442 {
9443         struct alc_spec *spec = codec->spec;
9444         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
9445         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
9446         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
9447         unsigned int    dac_vol1, dac_vol2;
9448
9449         if (speaker_nid) {
9450                 snd_hda_codec_write(codec, speaker_nid, 0,
9451                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
9452                 snd_hda_codec_write(codec, 0x0f, 0,
9453                                     AC_VERB_SET_AMP_GAIN_MUTE,
9454                                     AMP_IN_UNMUTE(1));
9455                 snd_hda_codec_write(codec, 0x10, 0,
9456                                     AC_VERB_SET_AMP_GAIN_MUTE,
9457                                     AMP_IN_UNMUTE(1));
9458         } else {
9459                 snd_hda_codec_write(codec, 0x0f, 0,
9460                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
9461                 snd_hda_codec_write(codec, 0x10, 0,
9462                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
9463         }
9464
9465         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
9466         if (line_nid == 0x14)   
9467                 dac_vol2 = AMP_OUT_ZERO;
9468         else if (line_nid == 0x15)
9469                 dac_vol1 = AMP_OUT_ZERO;
9470         if (hp_nid == 0x14)     
9471                 dac_vol2 = AMP_OUT_ZERO;
9472         else if (hp_nid == 0x15)
9473                 dac_vol1 = AMP_OUT_ZERO;
9474         if (line_nid != 0x16 || hp_nid != 0x16 ||
9475             spec->autocfg.line_out_pins[1] != 0x16 ||
9476             spec->autocfg.line_out_pins[2] != 0x16)
9477                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
9478
9479         snd_hda_codec_write(codec, 0x02, 0,
9480                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
9481         snd_hda_codec_write(codec, 0x03, 0,
9482                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
9483 }
9484
9485 /* pcm configuration: identiacal with ALC880 */
9486 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
9487 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
9488 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
9489
9490 /*
9491  * BIOS auto configuration
9492  */
9493 static int alc268_parse_auto_config(struct hda_codec *codec)
9494 {
9495         struct alc_spec *spec = codec->spec;
9496         int err;
9497         static hda_nid_t alc268_ignore[] = { 0 };
9498
9499         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9500                                            alc268_ignore);
9501         if (err < 0)
9502                 return err;
9503         if (!spec->autocfg.line_outs)
9504                 return 0; /* can't find valid BIOS pin config */
9505
9506         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
9507         if (err < 0)
9508                 return err;
9509         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
9510         if (err < 0)
9511                 return err;
9512
9513         spec->multiout.max_channels = 2;
9514
9515         /* digital only support output */
9516         if (spec->autocfg.dig_out_pin)
9517                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
9518
9519         if (spec->kctl_alloc)
9520                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
9521
9522         spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs;
9523         spec->num_mux_defs = 1;
9524         spec->input_mux = &spec->private_imux;
9525
9526         err = alc_auto_add_mic_boost(codec);
9527         if (err < 0)
9528                 return err;
9529
9530         return 1;
9531 }
9532
9533 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
9534 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
9535 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
9536
9537 /* init callback for auto-configuration model -- overriding the default init */
9538 static void alc268_auto_init(struct hda_codec *codec)
9539 {
9540         alc268_auto_init_multi_out(codec);
9541         alc268_auto_init_hp_out(codec);
9542         alc268_auto_init_mono_speaker_out(codec);
9543         alc268_auto_init_analog_input(codec);
9544 }
9545
9546 /*
9547  * configuration and preset
9548  */
9549 static const char *alc268_models[ALC268_MODEL_LAST] = {
9550         [ALC268_3ST]            = "3stack",
9551         [ALC268_TOSHIBA]        = "toshiba",
9552         [ALC268_ACER]           = "acer",
9553         [ALC268_AUTO]           = "auto",
9554 };
9555
9556 static struct snd_pci_quirk alc268_cfg_tbl[] = {
9557         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
9558         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
9559         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
9560         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
9561         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
9562         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
9563         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
9564         {}
9565 };
9566
9567 static struct alc_config_preset alc268_presets[] = {
9568         [ALC268_3ST] = {
9569                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer },
9570                 .init_verbs = { alc268_base_init_verbs },
9571                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
9572                 .dac_nids = alc268_dac_nids,
9573                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
9574                 .adc_nids = alc268_adc_nids_alt,
9575                 .hp_nid = 0x03,
9576                 .dig_out_nid = ALC268_DIGOUT_NID,
9577                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
9578                 .channel_mode = alc268_modes,
9579                 .input_mux = &alc268_capture_source,
9580         },
9581         [ALC268_TOSHIBA] = {
9582                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer },
9583                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
9584                                 alc268_toshiba_verbs },
9585                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
9586                 .dac_nids = alc268_dac_nids,
9587                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
9588                 .adc_nids = alc268_adc_nids_alt,
9589                 .hp_nid = 0x03,
9590                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
9591                 .channel_mode = alc268_modes,
9592                 .input_mux = &alc268_capture_source,
9593                 .unsol_event = alc268_toshiba_unsol_event,
9594                 .init_hook = alc268_toshiba_automute,
9595         },
9596         [ALC268_ACER] = {
9597                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer },
9598                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
9599                                 alc268_acer_verbs },
9600                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
9601                 .dac_nids = alc268_dac_nids,
9602                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
9603                 .adc_nids = alc268_adc_nids_alt,
9604                 .hp_nid = 0x02,
9605                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
9606                 .channel_mode = alc268_modes,
9607                 .input_mux = &alc268_capture_source,
9608                 .unsol_event = alc268_acer_unsol_event,
9609                 .init_hook = alc268_acer_init_hook,
9610         },
9611 };
9612
9613 static int patch_alc268(struct hda_codec *codec)
9614 {
9615         struct alc_spec *spec;
9616         int board_config;
9617         int err;
9618
9619         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
9620         if (spec == NULL)
9621                 return -ENOMEM;
9622
9623         codec->spec = spec;
9624
9625         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
9626                                                   alc268_models,
9627                                                   alc268_cfg_tbl);
9628
9629         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
9630                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
9631                        "trying auto-probe from BIOS...\n");
9632                 board_config = ALC268_AUTO;
9633         }
9634
9635         if (board_config == ALC268_AUTO) {
9636                 /* automatic parse from the BIOS config */
9637                 err = alc268_parse_auto_config(codec);
9638                 if (err < 0) {
9639                         alc_free(codec);
9640                         return err;
9641                 } else if (!err) {
9642                         printk(KERN_INFO
9643                                "hda_codec: Cannot set up configuration "
9644                                "from BIOS.  Using base mode...\n");
9645                         board_config = ALC268_3ST;
9646                 }
9647         }
9648
9649         if (board_config != ALC268_AUTO)
9650                 setup_preset(spec, &alc268_presets[board_config]);
9651
9652         spec->stream_name_analog = "ALC268 Analog";
9653         spec->stream_analog_playback = &alc268_pcm_analog_playback;
9654         spec->stream_analog_capture = &alc268_pcm_analog_capture;
9655
9656         spec->stream_name_digital = "ALC268 Digital";
9657         spec->stream_digital_playback = &alc268_pcm_digital_playback;
9658
9659         if (board_config == ALC268_AUTO) {
9660                 if (!spec->adc_nids && spec->input_mux) {
9661                         /* check whether NID 0x07 is valid */
9662                         unsigned int wcap = get_wcaps(codec, 0x07);
9663
9664                         /* get type */
9665                         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
9666                         if (wcap != AC_WID_AUD_IN) {
9667                                 spec->adc_nids = alc268_adc_nids_alt;
9668                                 spec->num_adc_nids =
9669                                         ARRAY_SIZE(alc268_adc_nids_alt);
9670                                 spec->mixers[spec->num_mixers] =
9671                                         alc268_capture_alt_mixer;
9672                                 spec->num_mixers++;
9673                         } else {
9674                                 spec->adc_nids = alc268_adc_nids;
9675                                 spec->num_adc_nids =
9676                                         ARRAY_SIZE(alc268_adc_nids);
9677                                 spec->mixers[spec->num_mixers] =
9678                                         alc268_capture_mixer;
9679                                 spec->num_mixers++;
9680                         }
9681                 }
9682         }
9683         codec->patch_ops = alc_patch_ops;
9684         if (board_config == ALC268_AUTO)
9685                 spec->init_hook = alc268_auto_init;
9686                 
9687         return 0;
9688 }
9689
9690 /*
9691  *  ALC269 channel source setting (2 channel)
9692  */
9693 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
9694
9695 #define alc269_dac_nids         alc260_dac_nids
9696
9697 static hda_nid_t alc269_adc_nids[1] = {
9698         /* ADC1 */
9699         0x07,
9700 };
9701
9702 #define alc269_modes            alc260_modes
9703 #define alc269_capture_source   alc880_lg_lw_capture_source
9704
9705 static struct snd_kcontrol_new alc269_base_mixer[] = {
9706         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
9707         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9708         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9709         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9710         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9711         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9712         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9713         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9714         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9715         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9716         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9717         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
9718         { } /* end */
9719 };
9720
9721 /* capture mixer elements */
9722 static struct snd_kcontrol_new alc269_capture_mixer[] = {
9723         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
9724         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
9725         {
9726                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9727                 /* The multiple "Capture Source" controls confuse alsamixer
9728                  * So call somewhat different..
9729                  * FIXME: the controls appear in the "playback" view!
9730                  */
9731                 /* .name = "Capture Source", */
9732                 .name = "Input Source",
9733                 .count = 1,
9734                 .info = alc_mux_enum_info,
9735                 .get = alc_mux_enum_get,
9736                 .put = alc_mux_enum_put,
9737         },
9738         { } /* end */
9739 };
9740
9741 /*
9742  * generic initialization of ADC, input mixers and output mixers
9743  */
9744 static struct hda_verb alc269_init_verbs[] = {
9745         /*
9746          * Unmute ADC0 and set the default input to mic-in
9747          */
9748         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9749
9750         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
9751          * analog-loopback mixer widget
9752          * Note: PASD motherboards uses the Line In 2 as the input for
9753          * front panel mic (mic 2)
9754          */
9755         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9756         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9757         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9758         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9759         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9760         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9761
9762         /*
9763          * Set up output mixers (0x0c - 0x0e)
9764          */
9765         /* set vol=0 to output mixers */
9766         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9767         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9768
9769         /* set up input amps for analog loopback */
9770         /* Amp Indices: DAC = 0, mixer = 1 */
9771         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9772         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9773         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9774         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9775         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9776         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9777
9778         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9779         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9780         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9781         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9782         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9783         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9784         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9785
9786         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9787         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9788         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9789         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9790         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9791         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9792         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9793
9794         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9795         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9796
9797         /* FIXME: use matrix-type input source selection */
9798         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
9799         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9800         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9801         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9802         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9803         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9804
9805         /* set EAPD */
9806         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9807         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9808         { }
9809 };
9810
9811 /* add playback controls from the parsed DAC table */
9812 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
9813                                              const struct auto_pin_cfg *cfg)
9814 {
9815         hda_nid_t nid;
9816         int err;
9817
9818         spec->multiout.num_dacs = 1;    /* only use one dac */
9819         spec->multiout.dac_nids = spec->private_dac_nids;
9820         spec->multiout.dac_nids[0] = 2;
9821
9822         nid = cfg->line_out_pins[0];
9823         if (nid) {
9824                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9825                                   "Front Playback Volume",
9826                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
9827                 if (err < 0)
9828                         return err;
9829                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9830                                   "Front Playback Switch",
9831                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
9832                 if (err < 0)
9833                         return err;
9834         }
9835
9836         nid = cfg->speaker_pins[0];
9837         if (nid) {
9838                 if (!cfg->line_out_pins[0]) {
9839                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9840                                           "Speaker Playback Volume",
9841                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
9842                                                               HDA_OUTPUT));
9843                         if (err < 0)
9844                                 return err;
9845                 }
9846                 if (nid == 0x16) {
9847                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9848                                           "Speaker Playback Switch",
9849                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9850                                                               HDA_OUTPUT));
9851                         if (err < 0)
9852                                 return err;
9853                 } else {
9854                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9855                                           "Speaker Playback Switch",
9856                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9857                                                               HDA_OUTPUT));
9858                         if (err < 0)
9859                                 return err;
9860                 }
9861         }
9862         nid = cfg->hp_pins[0];
9863         if (nid) {
9864                 /* spec->multiout.hp_nid = 2; */
9865                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
9866                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
9867                                           "Headphone Playback Volume",
9868                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
9869                                                               HDA_OUTPUT));
9870                         if (err < 0)
9871                                 return err;
9872                 }
9873                 if (nid == 0x16) {
9874                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9875                                           "Headphone Playback Switch",
9876                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9877                                                               HDA_OUTPUT));
9878                         if (err < 0)
9879                                 return err;
9880                 } else {
9881                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9882                                           "Headphone Playback Switch",
9883                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9884                                                               HDA_OUTPUT));
9885                         if (err < 0)
9886                                 return err;
9887                 }
9888         }
9889         return 0;
9890 }
9891
9892 #define alc269_auto_create_analog_input_ctls \
9893         alc880_auto_create_analog_input_ctls
9894
9895 #ifdef CONFIG_SND_HDA_POWER_SAVE
9896 #define alc269_loopbacks        alc880_loopbacks
9897 #endif
9898
9899 /* pcm configuration: identiacal with ALC880 */
9900 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
9901 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
9902 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
9903 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
9904
9905 /*
9906  * BIOS auto configuration
9907  */
9908 static int alc269_parse_auto_config(struct hda_codec *codec)
9909 {
9910         struct alc_spec *spec = codec->spec;
9911         int err;
9912         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
9913
9914         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9915                                            alc269_ignore);
9916         if (err < 0)
9917                 return err;
9918
9919         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
9920         if (err < 0)
9921                 return err;
9922         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
9923         if (err < 0)
9924                 return err;
9925
9926         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
9927
9928         if (spec->autocfg.dig_out_pin)
9929                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
9930
9931         if (spec->kctl_alloc)
9932                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
9933
9934         spec->init_verbs[spec->num_init_verbs++] = alc269_init_verbs;
9935         spec->num_mux_defs = 1;
9936         spec->input_mux = &spec->private_imux;
9937
9938         err = alc_auto_add_mic_boost(codec);
9939         if (err < 0)
9940                 return err;
9941
9942         return 1;
9943 }
9944
9945 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
9946 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
9947 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
9948
9949
9950 /* init callback for auto-configuration model -- overriding the default init */
9951 static void alc269_auto_init(struct hda_codec *codec)
9952 {
9953         alc269_auto_init_multi_out(codec);
9954         alc269_auto_init_hp_out(codec);
9955         alc269_auto_init_analog_input(codec);
9956 }
9957
9958 /*
9959  * configuration and preset
9960  */
9961 static const char *alc269_models[ALC269_MODEL_LAST] = {
9962         [ALC269_BASIC]          = "basic",
9963 };
9964
9965 static struct snd_pci_quirk alc269_cfg_tbl[] = {
9966         {}
9967 };
9968
9969 static struct alc_config_preset alc269_presets[] = {
9970         [ALC269_BASIC] = {
9971                 .mixers = { alc269_base_mixer },
9972                 .init_verbs = { alc269_init_verbs },
9973                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
9974                 .dac_nids = alc269_dac_nids,
9975                 .hp_nid = 0x03,
9976                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
9977                 .channel_mode = alc269_modes,
9978                 .input_mux = &alc269_capture_source,
9979         },
9980 };
9981
9982 static int patch_alc269(struct hda_codec *codec)
9983 {
9984         struct alc_spec *spec;
9985         int board_config;
9986         int err;
9987
9988         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9989         if (spec == NULL)
9990                 return -ENOMEM;
9991
9992         codec->spec = spec;
9993
9994         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
9995                                                   alc269_models,
9996                                                   alc269_cfg_tbl);
9997
9998         if (board_config < 0) {
9999                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
10000                        "trying auto-probe from BIOS...\n");
10001                 board_config = ALC269_AUTO;
10002         }
10003
10004         if (board_config == ALC269_AUTO) {
10005                 /* automatic parse from the BIOS config */
10006                 err = alc269_parse_auto_config(codec);
10007                 if (err < 0) {
10008                         alc_free(codec);
10009                         return err;
10010                 } else if (!err) {
10011                         printk(KERN_INFO
10012                                "hda_codec: Cannot set up configuration "
10013                                "from BIOS.  Using base mode...\n");
10014                         board_config = ALC269_BASIC;
10015                 }
10016         }
10017
10018         if (board_config != ALC269_AUTO)
10019                 setup_preset(spec, &alc269_presets[board_config]);
10020
10021         spec->stream_name_analog = "ALC269 Analog";
10022         spec->stream_analog_playback = &alc269_pcm_analog_playback;
10023         spec->stream_analog_capture = &alc269_pcm_analog_capture;
10024
10025         spec->stream_name_digital = "ALC269 Digital";
10026         spec->stream_digital_playback = &alc269_pcm_digital_playback;
10027         spec->stream_digital_capture = &alc269_pcm_digital_capture;
10028
10029         spec->adc_nids = alc269_adc_nids;
10030         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
10031         spec->mixers[spec->num_mixers] = alc269_capture_mixer;
10032         spec->num_mixers++;
10033
10034         codec->patch_ops = alc_patch_ops;
10035         if (board_config == ALC269_AUTO)
10036                 spec->init_hook = alc269_auto_init;
10037 #ifdef CONFIG_SND_HDA_POWER_SAVE
10038         if (!spec->loopback.amplist)
10039                 spec->loopback.amplist = alc269_loopbacks;
10040 #endif
10041
10042         return 0;
10043 }
10044
10045 /*
10046  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
10047  */
10048
10049 /*
10050  * set the path ways for 2 channel output
10051  * need to set the codec line out and mic 1 pin widgets to inputs
10052  */
10053 static struct hda_verb alc861_threestack_ch2_init[] = {
10054         /* set pin widget 1Ah (line in) for input */
10055         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10056         /* set pin widget 18h (mic1/2) for input, for mic also enable
10057          * the vref
10058          */
10059         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10060
10061         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
10062 #if 0
10063         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
10064         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
10065 #endif
10066         { } /* end */
10067 };
10068 /*
10069  * 6ch mode
10070  * need to set the codec line out and mic 1 pin widgets to outputs
10071  */
10072 static struct hda_verb alc861_threestack_ch6_init[] = {
10073         /* set pin widget 1Ah (line in) for output (Back Surround)*/
10074         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10075         /* set pin widget 18h (mic1) for output (CLFE)*/
10076         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10077
10078         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
10079         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
10080
10081         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
10082 #if 0
10083         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
10084         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
10085 #endif
10086         { } /* end */
10087 };
10088
10089 static struct hda_channel_mode alc861_threestack_modes[2] = {
10090         { 2, alc861_threestack_ch2_init },
10091         { 6, alc861_threestack_ch6_init },
10092 };
10093 /* Set mic1 as input and unmute the mixer */
10094 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
10095         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10096         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
10097         { } /* end */
10098 };
10099 /* Set mic1 as output and mute mixer */
10100 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
10101         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10102         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
10103         { } /* end */
10104 };
10105
10106 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
10107         { 2, alc861_uniwill_m31_ch2_init },
10108         { 4, alc861_uniwill_m31_ch4_init },
10109 };
10110
10111 /* Set mic1 and line-in as input and unmute the mixer */
10112 static struct hda_verb alc861_asus_ch2_init[] = {
10113         /* set pin widget 1Ah (line in) for input */
10114         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10115         /* set pin widget 18h (mic1/2) for input, for mic also enable
10116          * the vref
10117          */
10118         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10119
10120         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
10121 #if 0
10122         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
10123         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
10124 #endif
10125         { } /* end */
10126 };
10127 /* Set mic1 nad line-in as output and mute mixer */
10128 static struct hda_verb alc861_asus_ch6_init[] = {
10129         /* set pin widget 1Ah (line in) for output (Back Surround)*/
10130         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10131         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
10132         /* set pin widget 18h (mic1) for output (CLFE)*/
10133         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10134         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
10135         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
10136         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
10137
10138         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
10139 #if 0
10140         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
10141         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
10142 #endif
10143         { } /* end */
10144 };
10145
10146 static struct hda_channel_mode alc861_asus_modes[2] = {
10147         { 2, alc861_asus_ch2_init },
10148         { 6, alc861_asus_ch6_init },
10149 };
10150
10151 /* patch-ALC861 */
10152
10153 static struct snd_kcontrol_new alc861_base_mixer[] = {
10154         /* output mixer control */
10155         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
10156         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
10157         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
10158         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
10159         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
10160
10161         /*Input mixer control */
10162         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
10163            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
10164         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
10165         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
10166         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
10167         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
10168         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
10169         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
10170         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
10171         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
10172
10173         /* Capture mixer control */
10174         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
10175         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
10176         {
10177                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10178                 .name = "Capture Source",
10179                 .count = 1,
10180                 .info = alc_mux_enum_info,
10181                 .get = alc_mux_enum_get,
10182                 .put = alc_mux_enum_put,
10183         },
10184         { } /* end */
10185 };
10186
10187 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
10188         /* output mixer control */
10189         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
10190         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
10191         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
10192         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
10193         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
10194
10195         /* Input mixer control */
10196         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
10197            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
10198         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
10199         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
10200         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
10201         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
10202         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
10203         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
10204         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
10205         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
10206
10207         /* Capture mixer control */
10208         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
10209         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
10210         {
10211                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10212                 .name = "Capture Source",
10213                 .count = 1,
10214                 .info = alc_mux_enum_info,
10215                 .get = alc_mux_enum_get,
10216                 .put = alc_mux_enum_put,
10217         },
10218         {
10219                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10220                 .name = "Channel Mode",
10221                 .info = alc_ch_mode_info,
10222                 .get = alc_ch_mode_get,
10223                 .put = alc_ch_mode_put,
10224                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
10225         },
10226         { } /* end */
10227 };
10228
10229 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
10230         /* output mixer control */
10231         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
10232         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
10233         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
10234         
10235         /*Capture mixer control */
10236         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
10237         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
10238         {
10239                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10240                 .name = "Capture Source",
10241                 .count = 1,
10242                 .info = alc_mux_enum_info,
10243                 .get = alc_mux_enum_get,
10244                 .put = alc_mux_enum_put,
10245         },
10246
10247         { } /* end */
10248 };
10249
10250 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
10251         /* output mixer control */
10252         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
10253         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
10254         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
10255         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
10256         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
10257
10258         /* Input mixer control */
10259         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
10260            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
10261         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
10262         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
10263         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
10264         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
10265         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
10266         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
10267         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
10268         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
10269
10270         /* Capture mixer control */
10271         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
10272         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
10273         {
10274                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10275                 .name = "Capture Source",
10276                 .count = 1,
10277                 .info = alc_mux_enum_info,
10278                 .get = alc_mux_enum_get,
10279                 .put = alc_mux_enum_put,
10280         },
10281         {
10282                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10283                 .name = "Channel Mode",
10284                 .info = alc_ch_mode_info,
10285                 .get = alc_ch_mode_get,
10286                 .put = alc_ch_mode_put,
10287                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
10288         },
10289         { } /* end */
10290 };
10291
10292 static struct snd_kcontrol_new alc861_asus_mixer[] = {
10293         /* output mixer control */
10294         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
10295         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
10296         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
10297         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
10298         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
10299
10300         /* Input mixer control */
10301         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
10302         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10303         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
10304         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
10305         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
10306         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
10307         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
10308         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
10309         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
10310         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
10311
10312         /* Capture mixer control */
10313         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
10314         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
10315         {
10316                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10317                 .name = "Capture Source",
10318                 .count = 1,
10319                 .info = alc_mux_enum_info,
10320                 .get = alc_mux_enum_get,
10321                 .put = alc_mux_enum_put,
10322         },
10323         {
10324                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10325                 .name = "Channel Mode",
10326                 .info = alc_ch_mode_info,
10327                 .get = alc_ch_mode_get,
10328                 .put = alc_ch_mode_put,
10329                 .private_value = ARRAY_SIZE(alc861_asus_modes),
10330         },
10331         { }
10332 };
10333
10334 /* additional mixer */
10335 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
10336         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
10337         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
10338         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
10339         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
10340         { }
10341 };
10342
10343 /*
10344  * generic initialization of ADC, input mixers and output mixers
10345  */
10346 static struct hda_verb alc861_base_init_verbs[] = {
10347         /*
10348          * Unmute ADC0 and set the default input to mic-in
10349          */
10350         /* port-A for surround (rear panel) */
10351         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10352         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
10353         /* port-B for mic-in (rear panel) with vref */
10354         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10355         /* port-C for line-in (rear panel) */
10356         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10357         /* port-D for Front */
10358         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10359         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
10360         /* port-E for HP out (front panel) */
10361         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
10362         /* route front PCM to HP */
10363         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
10364         /* port-F for mic-in (front panel) with vref */
10365         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10366         /* port-G for CLFE (rear panel) */
10367         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10368         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
10369         /* port-H for side (rear panel) */
10370         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10371         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
10372         /* CD-in */
10373         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10374         /* route front mic to ADC1*/
10375         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10376         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10377         
10378         /* Unmute DAC0~3 & spdif out*/
10379         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10380         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10381         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10382         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10383         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10384         
10385         /* Unmute Mixer 14 (mic) 1c (Line in)*/
10386         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10387         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10388         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10389         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10390         
10391         /* Unmute Stereo Mixer 15 */
10392         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10393         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10394         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10395         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
10396
10397         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10398         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10399         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10400         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10401         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10402         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10403         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10404         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10405         /* hp used DAC 3 (Front) */
10406         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
10407         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10408
10409         { }
10410 };
10411
10412 static struct hda_verb alc861_threestack_init_verbs[] = {
10413         /*
10414          * Unmute ADC0 and set the default input to mic-in
10415          */
10416         /* port-A for surround (rear panel) */
10417         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10418         /* port-B for mic-in (rear panel) with vref */
10419         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10420         /* port-C for line-in (rear panel) */
10421         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10422         /* port-D for Front */
10423         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10424         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
10425         /* port-E for HP out (front panel) */
10426         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
10427         /* route front PCM to HP */
10428         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
10429         /* port-F for mic-in (front panel) with vref */
10430         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10431         /* port-G for CLFE (rear panel) */
10432         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10433         /* port-H for side (rear panel) */
10434         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10435         /* CD-in */
10436         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10437         /* route front mic to ADC1*/
10438         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10439         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10440         /* Unmute DAC0~3 & spdif out*/
10441         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10442         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10443         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10444         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10445         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10446         
10447         /* Unmute Mixer 14 (mic) 1c (Line in)*/
10448         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10449         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10450         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10451         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10452         
10453         /* Unmute Stereo Mixer 15 */
10454         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10455         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10456         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10457         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
10458
10459         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10460         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10461         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10462         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10463         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10464         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10465         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10466         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10467         /* hp used DAC 3 (Front) */
10468         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
10469         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10470         { }
10471 };
10472
10473 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
10474         /*
10475          * Unmute ADC0 and set the default input to mic-in
10476          */
10477         /* port-A for surround (rear panel) */
10478         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10479         /* port-B for mic-in (rear panel) with vref */
10480         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10481         /* port-C for line-in (rear panel) */
10482         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10483         /* port-D for Front */
10484         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10485         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
10486         /* port-E for HP out (front panel) */
10487         /* this has to be set to VREF80 */
10488         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10489         /* route front PCM to HP */
10490         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
10491         /* port-F for mic-in (front panel) with vref */
10492         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10493         /* port-G for CLFE (rear panel) */
10494         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10495         /* port-H for side (rear panel) */
10496         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10497         /* CD-in */
10498         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10499         /* route front mic to ADC1*/
10500         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10501         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10502         /* Unmute DAC0~3 & spdif out*/
10503         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10504         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10505         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10506         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10507         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10508         
10509         /* Unmute Mixer 14 (mic) 1c (Line in)*/
10510         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10511         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10512         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10513         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10514         
10515         /* Unmute Stereo Mixer 15 */
10516         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10517         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10518         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10519         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
10520
10521         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10522         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10523         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10524         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10525         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10526         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10527         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10528         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10529         /* hp used DAC 3 (Front) */
10530         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
10531         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10532         { }
10533 };
10534
10535 static struct hda_verb alc861_asus_init_verbs[] = {
10536         /*
10537          * Unmute ADC0 and set the default input to mic-in
10538          */
10539         /* port-A for surround (rear panel)
10540          * according to codec#0 this is the HP jack
10541          */
10542         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
10543         /* route front PCM to HP */
10544         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
10545         /* port-B for mic-in (rear panel) with vref */
10546         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10547         /* port-C for line-in (rear panel) */
10548         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10549         /* port-D for Front */
10550         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10551         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
10552         /* port-E for HP out (front panel) */
10553         /* this has to be set to VREF80 */
10554         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10555         /* route front PCM to HP */
10556         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
10557         /* port-F for mic-in (front panel) with vref */
10558         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
10559         /* port-G for CLFE (rear panel) */
10560         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10561         /* port-H for side (rear panel) */
10562         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
10563         /* CD-in */
10564         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
10565         /* route front mic to ADC1*/
10566         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10567         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10568         /* Unmute DAC0~3 & spdif out*/
10569         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10570         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10571         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10572         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10573         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10574         /* Unmute Mixer 14 (mic) 1c (Line in)*/
10575         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10576         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10577         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10578         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10579         
10580         /* Unmute Stereo Mixer 15 */
10581         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10582         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10583         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10584         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
10585
10586         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10587         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10588         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10589         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10590         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10591         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10592         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10593         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10594         /* hp used DAC 3 (Front) */
10595         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
10596         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10597         { }
10598 };
10599
10600 /* additional init verbs for ASUS laptops */
10601 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
10602         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
10603         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
10604         { }
10605 };
10606
10607 /*
10608  * generic initialization of ADC, input mixers and output mixers
10609  */
10610 static struct hda_verb alc861_auto_init_verbs[] = {
10611         /*
10612          * Unmute ADC0 and set the default input to mic-in
10613          */
10614         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
10615         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10616         
10617         /* Unmute DAC0~3 & spdif out*/
10618         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10619         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10620         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10621         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10622         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10623         
10624         /* Unmute Mixer 14 (mic) 1c (Line in)*/
10625         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10626         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10627         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10628         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10629         
10630         /* Unmute Stereo Mixer 15 */
10631         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10632         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10633         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10634         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
10635
10636         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10637         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10638         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10639         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10640         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10641         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10642         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10643         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10644
10645         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10646         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10647         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10648         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
10649         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10650         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10651         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10652         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
10653
10654         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
10655
10656         { }
10657 };
10658
10659 static struct hda_verb alc861_toshiba_init_verbs[] = {
10660         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10661
10662         { }
10663 };
10664
10665 /* toggle speaker-output according to the hp-jack state */
10666 static void alc861_toshiba_automute(struct hda_codec *codec)
10667 {
10668         unsigned int present;
10669
10670         present = snd_hda_codec_read(codec, 0x0f, 0,
10671                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10672         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
10673                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
10674         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
10675                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
10676 }
10677
10678 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
10679                                        unsigned int res)
10680 {
10681         if ((res >> 26) == ALC880_HP_EVENT)
10682                 alc861_toshiba_automute(codec);
10683 }
10684
10685 /* pcm configuration: identiacal with ALC880 */
10686 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
10687 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
10688 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
10689 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
10690
10691
10692 #define ALC861_DIGOUT_NID       0x07
10693
10694 static struct hda_channel_mode alc861_8ch_modes[1] = {
10695         { 8, NULL }
10696 };
10697
10698 static hda_nid_t alc861_dac_nids[4] = {
10699         /* front, surround, clfe, side */
10700         0x03, 0x06, 0x05, 0x04
10701 };
10702
10703 static hda_nid_t alc660_dac_nids[3] = {
10704         /* front, clfe, surround */
10705         0x03, 0x05, 0x06
10706 };
10707
10708 static hda_nid_t alc861_adc_nids[1] = {
10709         /* ADC0-2 */
10710         0x08,
10711 };
10712
10713 static struct hda_input_mux alc861_capture_source = {
10714         .num_items = 5,
10715         .items = {
10716                 { "Mic", 0x0 },
10717                 { "Front Mic", 0x3 },
10718                 { "Line", 0x1 },
10719                 { "CD", 0x4 },
10720                 { "Mixer", 0x5 },
10721         },
10722 };
10723
10724 /* fill in the dac_nids table from the parsed pin configuration */
10725 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
10726                                      const struct auto_pin_cfg *cfg)
10727 {
10728         int i;
10729         hda_nid_t nid;
10730
10731         spec->multiout.dac_nids = spec->private_dac_nids;
10732         for (i = 0; i < cfg->line_outs; i++) {
10733                 nid = cfg->line_out_pins[i];
10734                 if (nid) {
10735                         if (i >= ARRAY_SIZE(alc861_dac_nids))
10736                                 continue;
10737                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
10738                 }
10739         }
10740         spec->multiout.num_dacs = cfg->line_outs;
10741         return 0;
10742 }
10743
10744 /* add playback controls from the parsed DAC table */
10745 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
10746                                              const struct auto_pin_cfg *cfg)
10747 {
10748         char name[32];
10749         static const char *chname[4] = {
10750                 "Front", "Surround", NULL /*CLFE*/, "Side"
10751         };
10752         hda_nid_t nid;
10753         int i, idx, err;
10754
10755         for (i = 0; i < cfg->line_outs; i++) {
10756                 nid = spec->multiout.dac_nids[i];
10757                 if (!nid)
10758                         continue;
10759                 if (nid == 0x05) {
10760                         /* Center/LFE */
10761                         err = add_control(spec, ALC_CTL_BIND_MUTE,
10762                                           "Center Playback Switch",
10763                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
10764                                                               HDA_OUTPUT));
10765                         if (err < 0)
10766                                 return err;
10767                         err = add_control(spec, ALC_CTL_BIND_MUTE,
10768                                           "LFE Playback Switch",
10769                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10770                                                               HDA_OUTPUT));
10771                         if (err < 0)
10772                                 return err;
10773                 } else {
10774                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
10775                              idx++)
10776                                 if (nid == alc861_dac_nids[idx])
10777                                         break;
10778                         sprintf(name, "%s Playback Switch", chname[idx]);
10779                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
10780                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10781                                                               HDA_OUTPUT));
10782                         if (err < 0)
10783                                 return err;
10784                 }
10785         }
10786         return 0;
10787 }
10788
10789 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
10790 {
10791         int err;
10792         hda_nid_t nid;
10793
10794         if (!pin)
10795                 return 0;
10796
10797         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
10798                 nid = 0x03;
10799                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10800                                   "Headphone Playback Switch",
10801                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
10802                 if (err < 0)
10803                         return err;
10804                 spec->multiout.hp_nid = nid;
10805         }
10806         return 0;
10807 }
10808
10809 /* create playback/capture controls for input pins */
10810 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
10811                                                 const struct auto_pin_cfg *cfg)
10812 {
10813         struct hda_input_mux *imux = &spec->private_imux;
10814         int i, err, idx, idx1;
10815
10816         for (i = 0; i < AUTO_PIN_LAST; i++) {
10817                 switch (cfg->input_pins[i]) {
10818                 case 0x0c:
10819                         idx1 = 1;
10820                         idx = 2;        /* Line In */
10821                         break;
10822                 case 0x0f:
10823                         idx1 = 2;
10824                         idx = 2;        /* Line In */
10825                         break;
10826                 case 0x0d:
10827                         idx1 = 0;
10828                         idx = 1;        /* Mic In */
10829                         break;
10830                 case 0x10:
10831                         idx1 = 3;
10832                         idx = 1;        /* Mic In */
10833                         break;
10834                 case 0x11:
10835                         idx1 = 4;
10836                         idx = 0;        /* CD */
10837                         break;
10838                 default:
10839                         continue;
10840                 }
10841
10842                 err = new_analog_input(spec, cfg->input_pins[i],
10843                                        auto_pin_cfg_labels[i], idx, 0x15);
10844                 if (err < 0)
10845                         return err;
10846
10847                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
10848                 imux->items[imux->num_items].index = idx1;
10849                 imux->num_items++;
10850         }
10851         return 0;
10852 }
10853
10854 static struct snd_kcontrol_new alc861_capture_mixer[] = {
10855         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
10856         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
10857
10858         {
10859                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10860                 /* The multiple "Capture Source" controls confuse alsamixer
10861                  * So call somewhat different..
10862                  *FIXME: the controls appear in the "playback" view!
10863                  */
10864                 /* .name = "Capture Source", */
10865                 .name = "Input Source",
10866                 .count = 1,
10867                 .info = alc_mux_enum_info,
10868                 .get = alc_mux_enum_get,
10869                 .put = alc_mux_enum_put,
10870         },
10871         { } /* end */
10872 };
10873
10874 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
10875                                               hda_nid_t nid,
10876                                               int pin_type, int dac_idx)
10877 {
10878         /* set as output */
10879
10880         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
10881                             pin_type);
10882         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
10883                             AMP_OUT_UNMUTE);
10884
10885 }
10886
10887 static void alc861_auto_init_multi_out(struct hda_codec *codec)
10888 {
10889         struct alc_spec *spec = codec->spec;
10890         int i;
10891
10892         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
10893         for (i = 0; i < spec->autocfg.line_outs; i++) {
10894                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
10895                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
10896                 if (nid)
10897                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
10898                                                           spec->multiout.dac_nids[i]);
10899         }
10900 }
10901
10902 static void alc861_auto_init_hp_out(struct hda_codec *codec)
10903 {
10904         struct alc_spec *spec = codec->spec;
10905         hda_nid_t pin;
10906
10907         pin = spec->autocfg.hp_pins[0];
10908         if (pin) /* connect to front */
10909                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
10910                                                   spec->multiout.dac_nids[0]);
10911 }
10912
10913 static void alc861_auto_init_analog_input(struct hda_codec *codec)
10914 {
10915         struct alc_spec *spec = codec->spec;
10916         int i;
10917
10918         for (i = 0; i < AUTO_PIN_LAST; i++) {
10919                 hda_nid_t nid = spec->autocfg.input_pins[i];
10920                 if (nid >= 0x0c && nid <= 0x11) {
10921                         snd_hda_codec_write(codec, nid, 0,
10922                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
10923                                             i <= AUTO_PIN_FRONT_MIC ?
10924                                             PIN_VREF80 : PIN_IN);
10925                 }
10926         }
10927 }
10928
10929 /* parse the BIOS configuration and set up the alc_spec */
10930 /* return 1 if successful, 0 if the proper config is not found,
10931  * or a negative error code
10932  */
10933 static int alc861_parse_auto_config(struct hda_codec *codec)
10934 {
10935         struct alc_spec *spec = codec->spec;
10936         int err;
10937         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
10938
10939         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10940                                            alc861_ignore);
10941         if (err < 0)
10942                 return err;
10943         if (!spec->autocfg.line_outs)
10944                 return 0; /* can't find valid BIOS pin config */
10945
10946         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
10947         if (err < 0)
10948                 return err;
10949         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
10950         if (err < 0)
10951                 return err;
10952         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
10953         if (err < 0)
10954                 return err;
10955         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
10956         if (err < 0)
10957                 return err;
10958
10959         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10960
10961         if (spec->autocfg.dig_out_pin)
10962                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
10963
10964         if (spec->kctl_alloc)
10965                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10966
10967         spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs;
10968
10969         spec->num_mux_defs = 1;
10970         spec->input_mux = &spec->private_imux;
10971
10972         spec->adc_nids = alc861_adc_nids;
10973         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
10974         spec->mixers[spec->num_mixers] = alc861_capture_mixer;
10975         spec->num_mixers++;
10976
10977         return 1;
10978 }
10979
10980 /* additional initialization for auto-configuration model */
10981 static void alc861_auto_init(struct hda_codec *codec)
10982 {
10983         alc861_auto_init_multi_out(codec);
10984         alc861_auto_init_hp_out(codec);
10985         alc861_auto_init_analog_input(codec);
10986 }
10987
10988 #ifdef CONFIG_SND_HDA_POWER_SAVE
10989 static struct hda_amp_list alc861_loopbacks[] = {
10990         { 0x15, HDA_INPUT, 0 },
10991         { 0x15, HDA_INPUT, 1 },
10992         { 0x15, HDA_INPUT, 2 },
10993         { 0x15, HDA_INPUT, 3 },
10994         { } /* end */
10995 };
10996 #endif
10997
10998
10999 /*
11000  * configuration and preset
11001  */
11002 static const char *alc861_models[ALC861_MODEL_LAST] = {
11003         [ALC861_3ST]            = "3stack",
11004         [ALC660_3ST]            = "3stack-660",
11005         [ALC861_3ST_DIG]        = "3stack-dig",
11006         [ALC861_6ST_DIG]        = "6stack-dig",
11007         [ALC861_UNIWILL_M31]    = "uniwill-m31",
11008         [ALC861_TOSHIBA]        = "toshiba",
11009         [ALC861_ASUS]           = "asus",
11010         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
11011         [ALC861_AUTO]           = "auto",
11012 };
11013
11014 static struct snd_pci_quirk alc861_cfg_tbl[] = {
11015         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
11016         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
11017         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
11018         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
11019         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
11020         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
11021         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
11022         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
11023         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
11024          *        Any other models that need this preset?
11025          */
11026         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
11027         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
11028         SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31),
11029         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
11030         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
11031         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
11032         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
11033         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
11034         {}
11035 };
11036
11037 static struct alc_config_preset alc861_presets[] = {
11038         [ALC861_3ST] = {
11039                 .mixers = { alc861_3ST_mixer },
11040                 .init_verbs = { alc861_threestack_init_verbs },
11041                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11042                 .dac_nids = alc861_dac_nids,
11043                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
11044                 .channel_mode = alc861_threestack_modes,
11045                 .need_dac_fix = 1,
11046                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11047                 .adc_nids = alc861_adc_nids,
11048                 .input_mux = &alc861_capture_source,
11049         },
11050         [ALC861_3ST_DIG] = {
11051                 .mixers = { alc861_base_mixer },
11052                 .init_verbs = { alc861_threestack_init_verbs },
11053                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11054                 .dac_nids = alc861_dac_nids,
11055                 .dig_out_nid = ALC861_DIGOUT_NID,
11056                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
11057                 .channel_mode = alc861_threestack_modes,
11058                 .need_dac_fix = 1,
11059                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11060                 .adc_nids = alc861_adc_nids,
11061                 .input_mux = &alc861_capture_source,
11062         },
11063         [ALC861_6ST_DIG] = {
11064                 .mixers = { alc861_base_mixer },
11065                 .init_verbs = { alc861_base_init_verbs },
11066                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11067                 .dac_nids = alc861_dac_nids,
11068                 .dig_out_nid = ALC861_DIGOUT_NID,
11069                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
11070                 .channel_mode = alc861_8ch_modes,
11071                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11072                 .adc_nids = alc861_adc_nids,
11073                 .input_mux = &alc861_capture_source,
11074         },
11075         [ALC660_3ST] = {
11076                 .mixers = { alc861_3ST_mixer },
11077                 .init_verbs = { alc861_threestack_init_verbs },
11078                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
11079                 .dac_nids = alc660_dac_nids,
11080                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
11081                 .channel_mode = alc861_threestack_modes,
11082                 .need_dac_fix = 1,
11083                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11084                 .adc_nids = alc861_adc_nids,
11085                 .input_mux = &alc861_capture_source,
11086         },
11087         [ALC861_UNIWILL_M31] = {
11088                 .mixers = { alc861_uniwill_m31_mixer },
11089                 .init_verbs = { alc861_uniwill_m31_init_verbs },
11090                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11091                 .dac_nids = alc861_dac_nids,
11092                 .dig_out_nid = ALC861_DIGOUT_NID,
11093                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
11094                 .channel_mode = alc861_uniwill_m31_modes,
11095                 .need_dac_fix = 1,
11096                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11097                 .adc_nids = alc861_adc_nids,
11098                 .input_mux = &alc861_capture_source,
11099         },
11100         [ALC861_TOSHIBA] = {
11101                 .mixers = { alc861_toshiba_mixer },
11102                 .init_verbs = { alc861_base_init_verbs,
11103                                 alc861_toshiba_init_verbs },
11104                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11105                 .dac_nids = alc861_dac_nids,
11106                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
11107                 .channel_mode = alc883_3ST_2ch_modes,
11108                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11109                 .adc_nids = alc861_adc_nids,
11110                 .input_mux = &alc861_capture_source,
11111                 .unsol_event = alc861_toshiba_unsol_event,
11112                 .init_hook = alc861_toshiba_automute,
11113         },
11114         [ALC861_ASUS] = {
11115                 .mixers = { alc861_asus_mixer },
11116                 .init_verbs = { alc861_asus_init_verbs },
11117                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11118                 .dac_nids = alc861_dac_nids,
11119                 .dig_out_nid = ALC861_DIGOUT_NID,
11120                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
11121                 .channel_mode = alc861_asus_modes,
11122                 .need_dac_fix = 1,
11123                 .hp_nid = 0x06,
11124                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11125                 .adc_nids = alc861_adc_nids,
11126                 .input_mux = &alc861_capture_source,
11127         },
11128         [ALC861_ASUS_LAPTOP] = {
11129                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
11130                 .init_verbs = { alc861_asus_init_verbs,
11131                                 alc861_asus_laptop_init_verbs },
11132                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
11133                 .dac_nids = alc861_dac_nids,
11134                 .dig_out_nid = ALC861_DIGOUT_NID,
11135                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
11136                 .channel_mode = alc883_3ST_2ch_modes,
11137                 .need_dac_fix = 1,
11138                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
11139                 .adc_nids = alc861_adc_nids,
11140                 .input_mux = &alc861_capture_source,
11141         },
11142 };
11143
11144
11145 static int patch_alc861(struct hda_codec *codec)
11146 {
11147         struct alc_spec *spec;
11148         int board_config;
11149         int err;
11150
11151         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11152         if (spec == NULL)
11153                 return -ENOMEM;
11154
11155         codec->spec = spec;
11156
11157         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
11158                                                   alc861_models,
11159                                                   alc861_cfg_tbl);
11160
11161         if (board_config < 0) {
11162                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
11163                        "trying auto-probe from BIOS...\n");
11164                 board_config = ALC861_AUTO;
11165         }
11166
11167         if (board_config == ALC861_AUTO) {
11168                 /* automatic parse from the BIOS config */
11169                 err = alc861_parse_auto_config(codec);
11170                 if (err < 0) {
11171                         alc_free(codec);
11172                         return err;
11173                 } else if (!err) {
11174                         printk(KERN_INFO
11175                                "hda_codec: Cannot set up configuration "
11176                                "from BIOS.  Using base mode...\n");
11177                    board_config = ALC861_3ST_DIG;
11178                 }
11179         }
11180
11181         if (board_config != ALC861_AUTO)
11182                 setup_preset(spec, &alc861_presets[board_config]);
11183
11184         spec->stream_name_analog = "ALC861 Analog";
11185         spec->stream_analog_playback = &alc861_pcm_analog_playback;
11186         spec->stream_analog_capture = &alc861_pcm_analog_capture;
11187
11188         spec->stream_name_digital = "ALC861 Digital";
11189         spec->stream_digital_playback = &alc861_pcm_digital_playback;
11190         spec->stream_digital_capture = &alc861_pcm_digital_capture;
11191
11192         codec->patch_ops = alc_patch_ops;
11193         if (board_config == ALC861_AUTO)
11194                 spec->init_hook = alc861_auto_init;
11195 #ifdef CONFIG_SND_HDA_POWER_SAVE
11196         if (!spec->loopback.amplist)
11197                 spec->loopback.amplist = alc861_loopbacks;
11198 #endif
11199                 
11200         return 0;
11201 }
11202
11203 /*
11204  * ALC861-VD support
11205  *
11206  * Based on ALC882
11207  *
11208  * In addition, an independent DAC
11209  */
11210 #define ALC861VD_DIGOUT_NID     0x06
11211
11212 static hda_nid_t alc861vd_dac_nids[4] = {
11213         /* front, surr, clfe, side surr */
11214         0x02, 0x03, 0x04, 0x05
11215 };
11216
11217 /* dac_nids for ALC660vd are in a different order - according to
11218  * Realtek's driver.
11219  * This should probably tesult in a different mixer for 6stack models
11220  * of ALC660vd codecs, but for now there is only 3stack mixer
11221  * - and it is the same as in 861vd.
11222  * adc_nids in ALC660vd are (is) the same as in 861vd
11223  */
11224 static hda_nid_t alc660vd_dac_nids[3] = {
11225         /* front, rear, clfe, rear_surr */
11226         0x02, 0x04, 0x03
11227 };
11228
11229 static hda_nid_t alc861vd_adc_nids[1] = {
11230         /* ADC0 */
11231         0x09,
11232 };
11233
11234 /* input MUX */
11235 /* FIXME: should be a matrix-type input source selection */
11236 static struct hda_input_mux alc861vd_capture_source = {
11237         .num_items = 4,
11238         .items = {
11239                 { "Mic", 0x0 },
11240                 { "Front Mic", 0x1 },
11241                 { "Line", 0x2 },
11242                 { "CD", 0x4 },
11243         },
11244 };
11245
11246 static struct hda_input_mux alc861vd_dallas_capture_source = {
11247         .num_items = 3,
11248         .items = {
11249                 { "Front Mic", 0x0 },
11250                 { "ATAPI Mic", 0x1 },
11251                 { "Line In", 0x5 },
11252         },
11253 };
11254
11255 static struct hda_input_mux alc861vd_hp_capture_source = {
11256         .num_items = 2,
11257         .items = {
11258                 { "Front Mic", 0x0 },
11259                 { "ATAPI Mic", 0x1 },
11260         },
11261 };
11262
11263 #define alc861vd_mux_enum_info alc_mux_enum_info
11264 #define alc861vd_mux_enum_get alc_mux_enum_get
11265
11266 static int alc861vd_mux_enum_put(struct snd_kcontrol *kcontrol,
11267                                 struct snd_ctl_elem_value *ucontrol)
11268 {
11269         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11270         struct alc_spec *spec = codec->spec;
11271         const struct hda_input_mux *imux = spec->input_mux;
11272         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
11273         static hda_nid_t capture_mixers[1] = { 0x22 };
11274         hda_nid_t nid = capture_mixers[adc_idx];
11275         unsigned int *cur_val = &spec->cur_mux[adc_idx];
11276         unsigned int i, idx;
11277
11278         idx = ucontrol->value.enumerated.item[0];
11279         if (idx >= imux->num_items)
11280                 idx = imux->num_items - 1;
11281         if (*cur_val == idx)
11282                 return 0;
11283         for (i = 0; i < imux->num_items; i++) {
11284                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
11285                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
11286                                          imux->items[i].index,
11287                                          HDA_AMP_MUTE, v);
11288         }
11289         *cur_val = idx;
11290         return 1;
11291 }
11292
11293 /*
11294  * 2ch mode
11295  */
11296 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
11297         { 2, NULL }
11298 };
11299
11300 /*
11301  * 6ch mode
11302  */
11303 static struct hda_verb alc861vd_6stack_ch6_init[] = {
11304         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
11305         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11306         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11307         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11308         { } /* end */
11309 };
11310
11311 /*
11312  * 8ch mode
11313  */
11314 static struct hda_verb alc861vd_6stack_ch8_init[] = {
11315         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11316         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11317         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11318         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11319         { } /* end */
11320 };
11321
11322 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
11323         { 6, alc861vd_6stack_ch6_init },
11324         { 8, alc861vd_6stack_ch8_init },
11325 };
11326
11327 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
11328         {
11329                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11330                 .name = "Channel Mode",
11331                 .info = alc_ch_mode_info,
11332                 .get = alc_ch_mode_get,
11333                 .put = alc_ch_mode_put,
11334         },
11335         { } /* end */
11336 };
11337
11338 static struct snd_kcontrol_new alc861vd_capture_mixer[] = {
11339         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
11340         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
11341
11342         {
11343                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11344                 /* The multiple "Capture Source" controls confuse alsamixer
11345                  * So call somewhat different..
11346                  *FIXME: the controls appear in the "playback" view!
11347                  */
11348                 /* .name = "Capture Source", */
11349                 .name = "Input Source",
11350                 .count = 1,
11351                 .info = alc861vd_mux_enum_info,
11352                 .get = alc861vd_mux_enum_get,
11353                 .put = alc861vd_mux_enum_put,
11354         },
11355         { } /* end */
11356 };
11357
11358 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
11359  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
11360  */
11361 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
11362         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11363         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
11364
11365         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11366         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
11367
11368         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
11369                                 HDA_OUTPUT),
11370         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
11371                                 HDA_OUTPUT),
11372         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
11373         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
11374
11375         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
11376         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
11377
11378         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11379
11380         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11381         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11382         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11383
11384         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11385         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11386         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11387
11388         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11389         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11390
11391         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11392         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11393
11394         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
11395         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
11396
11397         { } /* end */
11398 };
11399
11400 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
11401         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11402         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
11403
11404         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11405
11406         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11407         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11408         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11409
11410         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11411         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11412         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11413
11414         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
11415         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
11416
11417         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11418         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11419
11420         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
11421         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
11422
11423         { } /* end */
11424 };
11425
11426 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
11427         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11428         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
11429         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11430
11431         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
11432
11433         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11434         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11435         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11436
11437         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11438         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11439         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11440
11441         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
11442         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
11443
11444         { } /* end */
11445 };
11446
11447 /* Pin assignment: Front=0x14, HP = 0x15,
11448  *                 Front Mic=0x18, ATAPI Mic = 0x19, Line In = 0x1d
11449  */
11450 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
11451         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11452         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
11453         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11454         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
11455         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11456         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11457         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11458         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11459         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x05, HDA_INPUT),
11460         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x05, HDA_INPUT),
11461         { } /* end */
11462 };
11463
11464 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
11465  *                 Front Mic=0x18, ATAPI Mic = 0x19,
11466  */
11467 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
11468         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11469         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
11470         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11471         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
11472         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
11473         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
11474         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
11475         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
11476         
11477         { } /* end */
11478 };
11479
11480 /*
11481  * generic initialization of ADC, input mixers and output mixers
11482  */
11483 static struct hda_verb alc861vd_volume_init_verbs[] = {
11484         /*
11485          * Unmute ADC0 and set the default input to mic-in
11486          */
11487         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11488         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11489
11490         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
11491          * the analog-loopback mixer widget
11492          */
11493         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11494         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11495         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11496         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11497         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11498         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11499
11500         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
11501         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11502         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11503         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
11504         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
11505
11506         /*
11507          * Set up output mixers (0x02 - 0x05)
11508          */
11509         /* set vol=0 to output mixers */
11510         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11511         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11512         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11513         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11514
11515         /* set up input amps for analog loopback */
11516         /* Amp Indices: DAC = 0, mixer = 1 */
11517         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11518         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11519         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11520         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11521         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11522         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11523         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11524         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11525
11526         { }
11527 };
11528
11529 /*
11530  * 3-stack pin configuration:
11531  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
11532  */
11533 static struct hda_verb alc861vd_3stack_init_verbs[] = {
11534         /*
11535          * Set pin mode and muting
11536          */
11537         /* set front pin widgets 0x14 for output */
11538         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11539         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11540         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
11541
11542         /* Mic (rear) pin: input vref at 80% */
11543         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11544         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11545         /* Front Mic pin: input vref at 80% */
11546         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11547         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11548         /* Line In pin: input */
11549         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11550         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11551         /* Line-2 In: Headphone output (output 0 - 0x0c) */
11552         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11553         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11554         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11555         /* CD pin widget for input */
11556         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11557
11558         { }
11559 };
11560
11561 /*
11562  * 6-stack pin configuration:
11563  */
11564 static struct hda_verb alc861vd_6stack_init_verbs[] = {
11565         /*
11566          * Set pin mode and muting
11567          */
11568         /* set front pin widgets 0x14 for output */
11569         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11570         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11571         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
11572
11573         /* Rear Pin: output 1 (0x0d) */
11574         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11575         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11576         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11577         /* CLFE Pin: output 2 (0x0e) */
11578         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11579         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11580         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
11581         /* Side Pin: output 3 (0x0f) */
11582         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11583         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11584         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
11585
11586         /* Mic (rear) pin: input vref at 80% */
11587         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11588         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11589         /* Front Mic pin: input vref at 80% */
11590         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11591         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11592         /* Line In pin: input */
11593         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11594         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11595         /* Line-2 In: Headphone output (output 0 - 0x0c) */
11596         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11597         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11598         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11599         /* CD pin widget for input */
11600         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11601
11602         { }
11603 };
11604
11605 static struct hda_verb alc861vd_eapd_verbs[] = {
11606         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11607         { }
11608 };
11609
11610 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
11611         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11612         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11613         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
11614         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11615         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT}, 
11616         {}
11617 };
11618
11619 /* toggle speaker-output according to the hp-jack state */
11620 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
11621 {
11622         unsigned int present;
11623         unsigned char bits;
11624
11625         present = snd_hda_codec_read(codec, 0x1b, 0,
11626                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11627         bits = present ? HDA_AMP_MUTE : 0;
11628         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
11629                                  HDA_AMP_MUTE, bits);
11630 }
11631
11632 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
11633 {
11634         unsigned int present;
11635         unsigned char bits;
11636
11637         present = snd_hda_codec_read(codec, 0x18, 0,
11638                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11639         bits = present ? HDA_AMP_MUTE : 0;
11640         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
11641                                  HDA_AMP_MUTE, bits);
11642 }
11643
11644 static void alc861vd_lenovo_automute(struct hda_codec *codec)
11645 {
11646         alc861vd_lenovo_hp_automute(codec);
11647         alc861vd_lenovo_mic_automute(codec);
11648 }
11649
11650 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
11651                                         unsigned int res)
11652 {
11653         switch (res >> 26) {
11654         case ALC880_HP_EVENT:
11655                 alc861vd_lenovo_hp_automute(codec);
11656                 break;
11657         case ALC880_MIC_EVENT:
11658                 alc861vd_lenovo_mic_automute(codec);
11659                 break;
11660         }
11661 }
11662
11663 static struct hda_verb alc861vd_dallas_verbs[] = {
11664         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11665         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11666         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11667         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11668
11669         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11670         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11671         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11672         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11673         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11674         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11675         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11676         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11677         
11678         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11679         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11680         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11681         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11682         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11683         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11684         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11685         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11686
11687         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
11688         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11689         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
11690         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11691         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11692         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11693         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11694         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11695
11696         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11697         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11698         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11699         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11700
11701         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11702         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},  
11703         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11704
11705         { } /* end */
11706 };
11707
11708 /* toggle speaker-output according to the hp-jack state */
11709 static void alc861vd_dallas_automute(struct hda_codec *codec)
11710 {
11711         unsigned int present;
11712
11713         present = snd_hda_codec_read(codec, 0x15, 0,
11714                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11715         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
11716                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
11717 }
11718
11719 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
11720 {
11721         if ((res >> 26) == ALC880_HP_EVENT)
11722                 alc861vd_dallas_automute(codec);
11723 }
11724
11725 #ifdef CONFIG_SND_HDA_POWER_SAVE
11726 #define alc861vd_loopbacks      alc880_loopbacks
11727 #endif
11728
11729 /* pcm configuration: identiacal with ALC880 */
11730 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
11731 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
11732 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
11733 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
11734
11735 /*
11736  * configuration and preset
11737  */
11738 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
11739         [ALC660VD_3ST]          = "3stack-660",
11740         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
11741         [ALC861VD_3ST]          = "3stack",
11742         [ALC861VD_3ST_DIG]      = "3stack-digout",
11743         [ALC861VD_6ST_DIG]      = "6stack-digout",
11744         [ALC861VD_LENOVO]       = "lenovo",
11745         [ALC861VD_DALLAS]       = "dallas",
11746         [ALC861VD_HP]           = "hp",
11747         [ALC861VD_AUTO]         = "auto",
11748 };
11749
11750 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
11751         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
11752         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
11753         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
11754         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
11755         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
11756
11757         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
11758         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
11759         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
11760         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
11761         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
11762         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
11763         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
11764         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
11765         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
11766         {}
11767 };
11768
11769 static struct alc_config_preset alc861vd_presets[] = {
11770         [ALC660VD_3ST] = {
11771                 .mixers = { alc861vd_3st_mixer },
11772                 .init_verbs = { alc861vd_volume_init_verbs,
11773                                  alc861vd_3stack_init_verbs },
11774                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
11775                 .dac_nids = alc660vd_dac_nids,
11776                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
11777                 .adc_nids = alc861vd_adc_nids,
11778                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
11779                 .channel_mode = alc861vd_3stack_2ch_modes,
11780                 .input_mux = &alc861vd_capture_source,
11781         },
11782         [ALC660VD_3ST_DIG] = {
11783                 .mixers = { alc861vd_3st_mixer },
11784                 .init_verbs = { alc861vd_volume_init_verbs,
11785                                  alc861vd_3stack_init_verbs },
11786                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
11787                 .dac_nids = alc660vd_dac_nids,
11788                 .dig_out_nid = ALC861VD_DIGOUT_NID,
11789                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
11790                 .adc_nids = alc861vd_adc_nids,
11791                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
11792                 .channel_mode = alc861vd_3stack_2ch_modes,
11793                 .input_mux = &alc861vd_capture_source,
11794         },
11795         [ALC861VD_3ST] = {
11796                 .mixers = { alc861vd_3st_mixer },
11797                 .init_verbs = { alc861vd_volume_init_verbs,
11798                                  alc861vd_3stack_init_verbs },
11799                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
11800                 .dac_nids = alc861vd_dac_nids,
11801                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
11802                 .channel_mode = alc861vd_3stack_2ch_modes,
11803                 .input_mux = &alc861vd_capture_source,
11804         },
11805         [ALC861VD_3ST_DIG] = {
11806                 .mixers = { alc861vd_3st_mixer },
11807                 .init_verbs = { alc861vd_volume_init_verbs,
11808                                  alc861vd_3stack_init_verbs },
11809                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
11810                 .dac_nids = alc861vd_dac_nids,
11811                 .dig_out_nid = ALC861VD_DIGOUT_NID,
11812                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
11813                 .channel_mode = alc861vd_3stack_2ch_modes,
11814                 .input_mux = &alc861vd_capture_source,
11815         },
11816         [ALC861VD_6ST_DIG] = {
11817                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
11818                 .init_verbs = { alc861vd_volume_init_verbs,
11819                                 alc861vd_6stack_init_verbs },
11820                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
11821                 .dac_nids = alc861vd_dac_nids,
11822                 .dig_out_nid = ALC861VD_DIGOUT_NID,
11823                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
11824                 .channel_mode = alc861vd_6stack_modes,
11825                 .input_mux = &alc861vd_capture_source,
11826         },
11827         [ALC861VD_LENOVO] = {
11828                 .mixers = { alc861vd_lenovo_mixer },
11829                 .init_verbs = { alc861vd_volume_init_verbs,
11830                                 alc861vd_3stack_init_verbs,
11831                                 alc861vd_eapd_verbs,
11832                                 alc861vd_lenovo_unsol_verbs },
11833                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
11834                 .dac_nids = alc660vd_dac_nids,
11835                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
11836                 .adc_nids = alc861vd_adc_nids,
11837                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
11838                 .channel_mode = alc861vd_3stack_2ch_modes,
11839                 .input_mux = &alc861vd_capture_source,
11840                 .unsol_event = alc861vd_lenovo_unsol_event,
11841                 .init_hook = alc861vd_lenovo_automute,
11842         },
11843         [ALC861VD_DALLAS] = {
11844                 .mixers = { alc861vd_dallas_mixer },
11845                 .init_verbs = { alc861vd_dallas_verbs },
11846                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
11847                 .dac_nids = alc861vd_dac_nids,
11848                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
11849                 .adc_nids = alc861vd_adc_nids,
11850                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
11851                 .channel_mode = alc861vd_3stack_2ch_modes,
11852                 .input_mux = &alc861vd_dallas_capture_source,
11853                 .unsol_event = alc861vd_dallas_unsol_event,
11854                 .init_hook = alc861vd_dallas_automute,
11855         },
11856         [ALC861VD_HP] = {
11857                 .mixers = { alc861vd_hp_mixer },
11858                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
11859                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
11860                 .dac_nids = alc861vd_dac_nids,
11861                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
11862                 .dig_out_nid = ALC861VD_DIGOUT_NID,
11863                 .adc_nids = alc861vd_adc_nids,
11864                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
11865                 .channel_mode = alc861vd_3stack_2ch_modes,
11866                 .input_mux = &alc861vd_hp_capture_source,
11867                 .unsol_event = alc861vd_dallas_unsol_event,
11868                 .init_hook = alc861vd_dallas_automute,
11869         },              
11870 };
11871
11872 /*
11873  * BIOS auto configuration
11874  */
11875 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
11876                                 hda_nid_t nid, int pin_type, int dac_idx)
11877 {
11878         /* set as output */
11879         snd_hda_codec_write(codec, nid, 0,
11880                                 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
11881         snd_hda_codec_write(codec, nid, 0,
11882                                 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
11883 }
11884
11885 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
11886 {
11887         struct alc_spec *spec = codec->spec;
11888         int i;
11889
11890         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
11891         for (i = 0; i <= HDA_SIDE; i++) {
11892                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
11893                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
11894                 if (nid)
11895                         alc861vd_auto_set_output_and_unmute(codec, nid,
11896                                                             pin_type, i);
11897         }
11898 }
11899
11900
11901 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
11902 {
11903         struct alc_spec *spec = codec->spec;
11904         hda_nid_t pin;
11905
11906         pin = spec->autocfg.hp_pins[0];
11907         if (pin) /* connect to front and  use dac 0 */
11908                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
11909 }
11910
11911 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
11912 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
11913
11914 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
11915 {
11916         struct alc_spec *spec = codec->spec;
11917         int i;
11918
11919         for (i = 0; i < AUTO_PIN_LAST; i++) {
11920                 hda_nid_t nid = spec->autocfg.input_pins[i];
11921                 if (alc861vd_is_input_pin(nid)) {
11922                         snd_hda_codec_write(codec, nid, 0,
11923                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
11924                                         i <= AUTO_PIN_FRONT_MIC ?
11925                                                         PIN_VREF80 : PIN_IN);
11926                         if (nid != ALC861VD_PIN_CD_NID)
11927                                 snd_hda_codec_write(codec, nid, 0,
11928                                                 AC_VERB_SET_AMP_GAIN_MUTE,
11929                                                 AMP_OUT_MUTE);
11930                 }
11931         }
11932 }
11933
11934 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
11935 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
11936
11937 /* add playback controls from the parsed DAC table */
11938 /* Based on ALC880 version. But ALC861VD has separate,
11939  * different NIDs for mute/unmute switch and volume control */
11940 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
11941                                              const struct auto_pin_cfg *cfg)
11942 {
11943         char name[32];
11944         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
11945         hda_nid_t nid_v, nid_s;
11946         int i, err;
11947
11948         for (i = 0; i < cfg->line_outs; i++) {
11949                 if (!spec->multiout.dac_nids[i])
11950                         continue;
11951                 nid_v = alc861vd_idx_to_mixer_vol(
11952                                 alc880_dac_to_idx(
11953                                         spec->multiout.dac_nids[i]));
11954                 nid_s = alc861vd_idx_to_mixer_switch(
11955                                 alc880_dac_to_idx(
11956                                         spec->multiout.dac_nids[i]));
11957
11958                 if (i == 2) {
11959                         /* Center/LFE */
11960                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11961                                           "Center Playback Volume",
11962                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
11963                                                               HDA_OUTPUT));
11964                         if (err < 0)
11965                                 return err;
11966                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
11967                                           "LFE Playback Volume",
11968                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
11969                                                               HDA_OUTPUT));
11970                         if (err < 0)
11971                                 return err;
11972                         err = add_control(spec, ALC_CTL_BIND_MUTE,
11973                                           "Center Playback Switch",
11974                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
11975                                                               HDA_INPUT));
11976                         if (err < 0)
11977                                 return err;
11978                         err = add_control(spec, ALC_CTL_BIND_MUTE,
11979                                           "LFE Playback Switch",
11980                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
11981                                                               HDA_INPUT));
11982                         if (err < 0)
11983                                 return err;
11984                 } else {
11985                         sprintf(name, "%s Playback Volume", chname[i]);
11986                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11987                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
11988                                                               HDA_OUTPUT));
11989                         if (err < 0)
11990                                 return err;
11991                         sprintf(name, "%s Playback Switch", chname[i]);
11992                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
11993                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
11994                                                               HDA_INPUT));
11995                         if (err < 0)
11996                                 return err;
11997                 }
11998         }
11999         return 0;
12000 }
12001
12002 /* add playback controls for speaker and HP outputs */
12003 /* Based on ALC880 version. But ALC861VD has separate,
12004  * different NIDs for mute/unmute switch and volume control */
12005 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
12006                                         hda_nid_t pin, const char *pfx)
12007 {
12008         hda_nid_t nid_v, nid_s;
12009         int err;
12010         char name[32];
12011
12012         if (!pin)
12013                 return 0;
12014
12015         if (alc880_is_fixed_pin(pin)) {
12016                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
12017                 /* specify the DAC as the extra output */
12018                 if (!spec->multiout.hp_nid)
12019                         spec->multiout.hp_nid = nid_v;
12020                 else
12021                         spec->multiout.extra_out_nid[0] = nid_v;
12022                 /* control HP volume/switch on the output mixer amp */
12023                 nid_v = alc861vd_idx_to_mixer_vol(
12024                                 alc880_fixed_pin_idx(pin));
12025                 nid_s = alc861vd_idx_to_mixer_switch(
12026                                 alc880_fixed_pin_idx(pin));
12027
12028                 sprintf(name, "%s Playback Volume", pfx);
12029                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
12030                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
12031                 if (err < 0)
12032                         return err;
12033                 sprintf(name, "%s Playback Switch", pfx);
12034                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
12035                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
12036                 if (err < 0)
12037                         return err;
12038         } else if (alc880_is_multi_pin(pin)) {
12039                 /* set manual connection */
12040                 /* we have only a switch on HP-out PIN */
12041                 sprintf(name, "%s Playback Switch", pfx);
12042                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
12043                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
12044                 if (err < 0)
12045                         return err;
12046         }
12047         return 0;
12048 }
12049
12050 /* parse the BIOS configuration and set up the alc_spec
12051  * return 1 if successful, 0 if the proper config is not found,
12052  * or a negative error code
12053  * Based on ALC880 version - had to change it to override
12054  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
12055 static int alc861vd_parse_auto_config(struct hda_codec *codec)
12056 {
12057         struct alc_spec *spec = codec->spec;
12058         int err;
12059         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
12060
12061         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12062                                            alc861vd_ignore);
12063         if (err < 0)
12064                 return err;
12065         if (!spec->autocfg.line_outs)
12066                 return 0; /* can't find valid BIOS pin config */
12067
12068         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
12069         if (err < 0)
12070                 return err;
12071         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
12072         if (err < 0)
12073                 return err;
12074         err = alc861vd_auto_create_extra_out(spec,
12075                                              spec->autocfg.speaker_pins[0],
12076                                              "Speaker");
12077         if (err < 0)
12078                 return err;
12079         err = alc861vd_auto_create_extra_out(spec,
12080                                              spec->autocfg.hp_pins[0],
12081                                              "Headphone");
12082         if (err < 0)
12083                 return err;
12084         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
12085         if (err < 0)
12086                 return err;
12087
12088         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12089
12090         if (spec->autocfg.dig_out_pin)
12091                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
12092
12093         if (spec->kctl_alloc)
12094                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
12095
12096         spec->init_verbs[spec->num_init_verbs++]
12097                 = alc861vd_volume_init_verbs;
12098
12099         spec->num_mux_defs = 1;
12100         spec->input_mux = &spec->private_imux;
12101
12102         err = alc_auto_add_mic_boost(codec);
12103         if (err < 0)
12104                 return err;
12105
12106         return 1;
12107 }
12108
12109 /* additional initialization for auto-configuration model */
12110 static void alc861vd_auto_init(struct hda_codec *codec)
12111 {
12112         alc861vd_auto_init_multi_out(codec);
12113         alc861vd_auto_init_hp_out(codec);
12114         alc861vd_auto_init_analog_input(codec);
12115 }
12116
12117 static int patch_alc861vd(struct hda_codec *codec)
12118 {
12119         struct alc_spec *spec;
12120         int err, board_config;
12121
12122         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12123         if (spec == NULL)
12124                 return -ENOMEM;
12125
12126         codec->spec = spec;
12127
12128         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
12129                                                   alc861vd_models,
12130                                                   alc861vd_cfg_tbl);
12131
12132         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
12133                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
12134                         "ALC861VD, trying auto-probe from BIOS...\n");
12135                 board_config = ALC861VD_AUTO;
12136         }
12137
12138         if (board_config == ALC861VD_AUTO) {
12139                 /* automatic parse from the BIOS config */
12140                 err = alc861vd_parse_auto_config(codec);
12141                 if (err < 0) {
12142                         alc_free(codec);
12143                         return err;
12144                 } else if (!err) {
12145                         printk(KERN_INFO
12146                                "hda_codec: Cannot set up configuration "
12147                                "from BIOS.  Using base mode...\n");
12148                         board_config = ALC861VD_3ST;
12149                 }
12150         }
12151
12152         if (board_config != ALC861VD_AUTO)
12153                 setup_preset(spec, &alc861vd_presets[board_config]);
12154
12155         spec->stream_name_analog = "ALC861VD Analog";
12156         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
12157         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
12158
12159         spec->stream_name_digital = "ALC861VD Digital";
12160         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
12161         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
12162
12163         spec->adc_nids = alc861vd_adc_nids;
12164         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
12165
12166         spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
12167         spec->num_mixers++;
12168
12169         codec->patch_ops = alc_patch_ops;
12170
12171         if (board_config == ALC861VD_AUTO)
12172                 spec->init_hook = alc861vd_auto_init;
12173 #ifdef CONFIG_SND_HDA_POWER_SAVE
12174         if (!spec->loopback.amplist)
12175                 spec->loopback.amplist = alc861vd_loopbacks;
12176 #endif
12177
12178         return 0;
12179 }
12180
12181 /*
12182  * ALC662 support
12183  *
12184  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
12185  * configuration.  Each pin widget can choose any input DACs and a mixer.
12186  * Each ADC is connected from a mixer of all inputs.  This makes possible
12187  * 6-channel independent captures.
12188  *
12189  * In addition, an independent DAC for the multi-playback (not used in this
12190  * driver yet).
12191  */
12192 #define ALC662_DIGOUT_NID       0x06
12193 #define ALC662_DIGIN_NID        0x0a
12194
12195 static hda_nid_t alc662_dac_nids[4] = {
12196         /* front, rear, clfe, rear_surr */
12197         0x02, 0x03, 0x04
12198 };
12199
12200 static hda_nid_t alc662_adc_nids[1] = {
12201         /* ADC1-2 */
12202         0x09,
12203 };
12204 /* input MUX */
12205 /* FIXME: should be a matrix-type input source selection */
12206
12207 static struct hda_input_mux alc662_capture_source = {
12208         .num_items = 4,
12209         .items = {
12210                 { "Mic", 0x0 },
12211                 { "Front Mic", 0x1 },
12212                 { "Line", 0x2 },
12213                 { "CD", 0x4 },
12214         },
12215 };
12216
12217 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
12218         .num_items = 2,
12219         .items = {
12220                 { "Mic", 0x1 },
12221                 { "Line", 0x2 },
12222         },
12223 };
12224
12225 static struct hda_input_mux alc662_eeepc_capture_source = {
12226         .num_items = 2,
12227         .items = {
12228                 { "i-Mic", 0x1 },
12229                 { "e-Mic", 0x0 },
12230         },
12231 };
12232
12233 #define alc662_mux_enum_info alc_mux_enum_info
12234 #define alc662_mux_enum_get alc_mux_enum_get
12235
12236 static int alc662_mux_enum_put(struct snd_kcontrol *kcontrol,
12237                                struct snd_ctl_elem_value *ucontrol)
12238 {
12239         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
12240         struct alc_spec *spec = codec->spec;
12241         const struct hda_input_mux *imux = spec->input_mux;
12242         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
12243         static hda_nid_t capture_mixers[2] = { 0x23, 0x22 };
12244         hda_nid_t nid = capture_mixers[adc_idx];
12245         unsigned int *cur_val = &spec->cur_mux[adc_idx];
12246         unsigned int i, idx;
12247
12248         idx = ucontrol->value.enumerated.item[0];
12249         if (idx >= imux->num_items)
12250                 idx = imux->num_items - 1;
12251         if (*cur_val == idx)
12252                 return 0;
12253         for (i = 0; i < imux->num_items; i++) {
12254                 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
12255                 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
12256                                          imux->items[i].index,
12257                                          HDA_AMP_MUTE, v);
12258         }
12259         *cur_val = idx;
12260         return 1;
12261 }
12262 /*
12263  * 2ch mode
12264  */
12265 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
12266         { 2, NULL }
12267 };
12268
12269 /*
12270  * 2ch mode
12271  */
12272 static struct hda_verb alc662_3ST_ch2_init[] = {
12273         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
12274         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
12275         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
12276         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
12277         { } /* end */
12278 };
12279
12280 /*
12281  * 6ch mode
12282  */
12283 static struct hda_verb alc662_3ST_ch6_init[] = {
12284         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12285         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
12286         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
12287         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12288         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
12289         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
12290         { } /* end */
12291 };
12292
12293 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
12294         { 2, alc662_3ST_ch2_init },
12295         { 6, alc662_3ST_ch6_init },
12296 };
12297
12298 /*
12299  * 2ch mode
12300  */
12301 static struct hda_verb alc662_sixstack_ch6_init[] = {
12302         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12303         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
12304         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12305         { } /* end */
12306 };
12307
12308 /*
12309  * 6ch mode
12310  */
12311 static struct hda_verb alc662_sixstack_ch8_init[] = {
12312         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12313         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12314         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
12315         { } /* end */
12316 };
12317
12318 static struct hda_channel_mode alc662_5stack_modes[2] = {
12319         { 2, alc662_sixstack_ch6_init },
12320         { 6, alc662_sixstack_ch8_init },
12321 };
12322
12323 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
12324  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
12325  */
12326
12327 static struct snd_kcontrol_new alc662_base_mixer[] = {
12328         /* output mixer control */
12329         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
12330         HDA_CODEC_MUTE("Front Playback Switch", 0x02, 0x0, HDA_OUTPUT),
12331         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
12332         HDA_CODEC_MUTE("Surround Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12333         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
12334         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
12335         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
12336         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
12337         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12338
12339         /*Input mixer control */
12340         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
12341         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
12342         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
12343         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
12344         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
12345         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
12346         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
12347         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
12348
12349         /* Capture mixer control */
12350         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
12351         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
12352         {
12353                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12354                 .name = "Capture Source",
12355                 .count = 1,
12356                 .info = alc_mux_enum_info,
12357                 .get = alc_mux_enum_get,
12358                 .put = alc_mux_enum_put,
12359         },
12360         { } /* end */
12361 };
12362
12363 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
12364         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12365         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
12366         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12367         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12368         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12369         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12370         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12371         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12372         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12373         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12374         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12375         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
12376         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
12377         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
12378         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
12379         {
12380                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12381                 /* .name = "Capture Source", */
12382                 .name = "Input Source",
12383                 .count = 1,
12384                 .info = alc662_mux_enum_info,
12385                 .get = alc662_mux_enum_get,
12386                 .put = alc662_mux_enum_put,
12387         },
12388         { } /* end */
12389 };
12390
12391 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
12392         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12393         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
12394         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12395         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
12396         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
12397         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
12398         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
12399         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
12400         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12401         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12402         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
12403         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12404         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12405         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12406         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12407         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12408         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12409         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
12410         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
12411         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
12412         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
12413         {
12414                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12415                 /* .name = "Capture Source", */
12416                 .name = "Input Source",
12417                 .count = 1,
12418                 .info = alc662_mux_enum_info,
12419                 .get = alc662_mux_enum_get,
12420                 .put = alc662_mux_enum_put,
12421         },
12422         { } /* end */
12423 };
12424
12425 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
12426         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12427         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
12428         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12429         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x03, 2, HDA_INPUT),
12430         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12431         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12432         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12433         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12434         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12435         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
12436         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
12437         {
12438                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12439                 /* .name = "Capture Source", */
12440                 .name = "Input Source",
12441                 .count = 1,
12442                 .info = alc662_mux_enum_info,
12443                 .get = alc662_mux_enum_get,
12444                 .put = alc662_mux_enum_put,
12445         },
12446         { } /* end */
12447 };
12448
12449 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
12450         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12451
12452         HDA_CODEC_VOLUME("LineOut Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12453         HDA_CODEC_MUTE("LineOut Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12454
12455         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
12456         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12457         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12458
12459         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
12460         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12461         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12462         { } /* end */
12463 };
12464
12465 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
12466         {
12467                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12468                 .name = "Channel Mode",
12469                 .info = alc_ch_mode_info,
12470                 .get = alc_ch_mode_get,
12471                 .put = alc_ch_mode_put,
12472         },
12473         { } /* end */
12474 };
12475
12476 static struct hda_verb alc662_init_verbs[] = {
12477         /* ADC: mute amp left and right */
12478         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12479         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
12480         /* Front mixer: unmute input/output amp left and right (volume = 0) */
12481
12482         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12483         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12484         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12485         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12486         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12487
12488         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12489         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12490         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12491         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12492         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12493         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12494
12495         /* Front Pin: output 0 (0x0c) */
12496         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12497         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12498
12499         /* Rear Pin: output 1 (0x0d) */
12500         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12501         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12502
12503         /* CLFE Pin: output 2 (0x0e) */
12504         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12505         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12506
12507         /* Mic (rear) pin: input vref at 80% */
12508         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12509         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12510         /* Front Mic pin: input vref at 80% */
12511         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12512         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12513         /* Line In pin: input */
12514         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12515         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12516         /* Line-2 In: Headphone output (output 0 - 0x0c) */
12517         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12518         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12519         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
12520         /* CD pin widget for input */
12521         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12522
12523         /* FIXME: use matrix-type input source selection */
12524         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
12525         /* Input mixer */
12526         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12527         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12528         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12529         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
12530
12531         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12532         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12533         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
12534         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
12535         { }
12536 };
12537
12538 static struct hda_verb alc662_sue_init_verbs[] = {
12539         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
12540         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
12541         {}
12542 };
12543
12544 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
12545         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12546         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12547         {}
12548 };
12549
12550 /*
12551  * generic initialization of ADC, input mixers and output mixers
12552  */
12553 static struct hda_verb alc662_auto_init_verbs[] = {
12554         /*
12555          * Unmute ADC and set the default input to mic-in
12556          */
12557         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
12558         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12559
12560         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
12561          * mixer widget
12562          * Note: PASD motherboards uses the Line In 2 as the input for front
12563          * panel mic (mic 2)
12564          */
12565         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12566         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12567         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12568         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12569         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12570         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12571
12572         /*
12573          * Set up output mixers (0x0c - 0x0f)
12574          */
12575         /* set vol=0 to output mixers */
12576         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12577         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12578         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12579
12580         /* set up input amps for analog loopback */
12581         /* Amp Indices: DAC = 0, mixer = 1 */
12582         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12583         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12584         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12585         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12586         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12587         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12588
12589
12590         /* FIXME: use matrix-type input source selection */
12591         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
12592         /* Input mixer */
12593         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12594         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12595         { }
12596 };
12597
12598 /* capture mixer elements */
12599 static struct snd_kcontrol_new alc662_capture_mixer[] = {
12600         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
12601         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
12602         {
12603                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12604                 /* The multiple "Capture Source" controls confuse alsamixer
12605                  * So call somewhat different..
12606                  * FIXME: the controls appear in the "playback" view!
12607                  */
12608                 /* .name = "Capture Source", */
12609                 .name = "Input Source",
12610                 .count = 1,
12611                 .info = alc882_mux_enum_info,
12612                 .get = alc882_mux_enum_get,
12613                 .put = alc882_mux_enum_put,
12614         },
12615         { } /* end */
12616 };
12617
12618 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
12619 {
12620         unsigned int present;
12621         unsigned char bits;
12622
12623         present = snd_hda_codec_read(codec, 0x14, 0,
12624                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12625         bits = present ? HDA_AMP_MUTE : 0;
12626         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
12627                                  HDA_AMP_MUTE, bits);
12628 }
12629
12630 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
12631 {
12632         unsigned int present;
12633         unsigned char bits;
12634
12635         present = snd_hda_codec_read(codec, 0x1b, 0,
12636                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12637         bits = present ? HDA_AMP_MUTE : 0;
12638         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
12639                                  HDA_AMP_MUTE, bits);
12640         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
12641                                  HDA_AMP_MUTE, bits);
12642 }
12643
12644 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
12645                                            unsigned int res)
12646 {
12647         if ((res >> 26) == ALC880_HP_EVENT)
12648                 alc662_lenovo_101e_all_automute(codec);
12649         if ((res >> 26) == ALC880_FRONT_EVENT)
12650                 alc662_lenovo_101e_ispeaker_automute(codec);
12651 }
12652
12653 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
12654 {
12655         unsigned int present;
12656
12657         present = snd_hda_codec_read(codec, 0x18, 0,
12658                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12659         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12660                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
12661         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12662                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
12663         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12664                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
12665         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12666                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
12667 }
12668
12669 /* unsolicited event for HP jack sensing */
12670 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
12671                                      unsigned int res)
12672 {
12673         if ((res >> 26) == ALC880_HP_EVENT)
12674                 alc262_hippo1_automute( codec );
12675
12676         if ((res >> 26) == ALC880_MIC_EVENT)
12677                 alc662_eeepc_mic_automute(codec);
12678 }
12679
12680 static void alc662_eeepc_inithook(struct hda_codec *codec)
12681 {
12682         alc262_hippo1_automute( codec );
12683         alc662_eeepc_mic_automute(codec);
12684 }
12685
12686 #ifdef CONFIG_SND_HDA_POWER_SAVE
12687 #define alc662_loopbacks        alc880_loopbacks
12688 #endif
12689
12690
12691 /* pcm configuration: identiacal with ALC880 */
12692 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
12693 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
12694 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
12695 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
12696
12697 /*
12698  * configuration and preset
12699  */
12700 static const char *alc662_models[ALC662_MODEL_LAST] = {
12701         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
12702         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
12703         [ALC662_3ST_6ch]        = "3stack-6ch",
12704         [ALC662_5ST_DIG]        = "6stack-dig",
12705         [ALC662_LENOVO_101E]    = "lenovo-101e",
12706         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
12707         [ALC662_AUTO]           = "auto",
12708 };
12709
12710 static struct snd_pci_quirk alc662_cfg_tbl[] = {
12711         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
12712         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
12713         {}
12714 };
12715
12716 static struct alc_config_preset alc662_presets[] = {
12717         [ALC662_3ST_2ch_DIG] = {
12718                 .mixers = { alc662_3ST_2ch_mixer, alc662_capture_mixer },
12719                 .init_verbs = { alc662_init_verbs },
12720                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
12721                 .dac_nids = alc662_dac_nids,
12722                 .dig_out_nid = ALC662_DIGOUT_NID,
12723                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
12724                 .adc_nids = alc662_adc_nids,
12725                 .dig_in_nid = ALC662_DIGIN_NID,
12726                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
12727                 .channel_mode = alc662_3ST_2ch_modes,
12728                 .input_mux = &alc662_capture_source,
12729         },
12730         [ALC662_3ST_6ch_DIG] = {
12731                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
12732                             alc662_capture_mixer },
12733                 .init_verbs = { alc662_init_verbs },
12734                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
12735                 .dac_nids = alc662_dac_nids,
12736                 .dig_out_nid = ALC662_DIGOUT_NID,
12737                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
12738                 .adc_nids = alc662_adc_nids,
12739                 .dig_in_nid = ALC662_DIGIN_NID,
12740                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
12741                 .channel_mode = alc662_3ST_6ch_modes,
12742                 .need_dac_fix = 1,
12743                 .input_mux = &alc662_capture_source,
12744         },
12745         [ALC662_3ST_6ch] = {
12746                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer,
12747                             alc662_capture_mixer },
12748                 .init_verbs = { alc662_init_verbs },
12749                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
12750                 .dac_nids = alc662_dac_nids,
12751                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
12752                 .adc_nids = alc662_adc_nids,
12753                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
12754                 .channel_mode = alc662_3ST_6ch_modes,
12755                 .need_dac_fix = 1,
12756                 .input_mux = &alc662_capture_source,
12757         },
12758         [ALC662_5ST_DIG] = {
12759                 .mixers = { alc662_base_mixer, alc662_chmode_mixer,
12760                             alc662_capture_mixer },
12761                 .init_verbs = { alc662_init_verbs },
12762                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
12763                 .dac_nids = alc662_dac_nids,
12764                 .dig_out_nid = ALC662_DIGOUT_NID,
12765                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
12766                 .adc_nids = alc662_adc_nids,
12767                 .dig_in_nid = ALC662_DIGIN_NID,
12768                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
12769                 .channel_mode = alc662_5stack_modes,
12770                 .input_mux = &alc662_capture_source,
12771         },
12772         [ALC662_LENOVO_101E] = {
12773                 .mixers = { alc662_lenovo_101e_mixer, alc662_capture_mixer },
12774                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
12775                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
12776                 .dac_nids = alc662_dac_nids,
12777                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
12778                 .adc_nids = alc662_adc_nids,
12779                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
12780                 .channel_mode = alc662_3ST_2ch_modes,
12781                 .input_mux = &alc662_lenovo_101e_capture_source,
12782                 .unsol_event = alc662_lenovo_101e_unsol_event,
12783                 .init_hook = alc662_lenovo_101e_all_automute,
12784         },
12785         [ALC662_ASUS_EEEPC_P701] = {
12786                 .mixers = { alc662_eeepc_p701_mixer, alc662_capture_mixer },
12787                 .init_verbs = { alc662_init_verbs,
12788                                 alc662_eeepc_sue_init_verbs },
12789                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
12790                 .dac_nids = alc662_dac_nids,
12791                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
12792                 .adc_nids = alc662_adc_nids,
12793                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
12794                 .channel_mode = alc662_3ST_2ch_modes,
12795                 .input_mux = &alc662_eeepc_capture_source,
12796                 .unsol_event = alc662_eeepc_unsol_event,
12797                 .init_hook = alc662_eeepc_inithook,
12798         },
12799
12800 };
12801
12802
12803 /*
12804  * BIOS auto configuration
12805  */
12806
12807 /* add playback controls from the parsed DAC table */
12808 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
12809                                              const struct auto_pin_cfg *cfg)
12810 {
12811         char name[32];
12812         static const char *chname[4] = {
12813                 "Front", "Surround", NULL /*CLFE*/, "Side"
12814         };
12815         hda_nid_t nid;
12816         int i, err;
12817
12818         for (i = 0; i < cfg->line_outs; i++) {
12819                 if (!spec->multiout.dac_nids[i])
12820                         continue;
12821                 nid = alc880_idx_to_dac(i);
12822                 if (i == 2) {
12823                         /* Center/LFE */
12824                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12825                                           "Center Playback Volume",
12826                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
12827                                                               HDA_OUTPUT));
12828                         if (err < 0)
12829                                 return err;
12830                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12831                                           "LFE Playback Volume",
12832                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12833                                                               HDA_OUTPUT));
12834                         if (err < 0)
12835                                 return err;
12836                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12837                                           "Center Playback Switch",
12838                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
12839                                                               HDA_INPUT));
12840                         if (err < 0)
12841                                 return err;
12842                         err = add_control(spec, ALC_CTL_BIND_MUTE,
12843                                           "LFE Playback Switch",
12844                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
12845                                                               HDA_INPUT));
12846                         if (err < 0)
12847                                 return err;
12848                 } else {
12849                         sprintf(name, "%s Playback Volume", chname[i]);
12850                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
12851                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12852                                                               HDA_OUTPUT));
12853                         if (err < 0)
12854                                 return err;
12855                         sprintf(name, "%s Playback Switch", chname[i]);
12856                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
12857                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
12858                                                               HDA_INPUT));
12859                         if (err < 0)
12860                                 return err;
12861                 }
12862         }
12863         return 0;
12864 }
12865
12866 /* add playback controls for speaker and HP outputs */
12867 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
12868                                         const char *pfx)
12869 {
12870         hda_nid_t nid;
12871         int err;
12872         char name[32];
12873
12874         if (!pin)
12875                 return 0;
12876
12877         if (alc880_is_fixed_pin(pin)) {
12878                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
12879                 /* printk("DAC nid=%x\n",nid); */
12880                 /* specify the DAC as the extra output */
12881                 if (!spec->multiout.hp_nid)
12882                         spec->multiout.hp_nid = nid;
12883                 else
12884                         spec->multiout.extra_out_nid[0] = nid;
12885                 /* control HP volume/switch on the output mixer amp */
12886                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
12887                 sprintf(name, "%s Playback Volume", pfx);
12888                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
12889                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12890                 if (err < 0)
12891                         return err;
12892                 sprintf(name, "%s Playback Switch", pfx);
12893                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
12894                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
12895                 if (err < 0)
12896                         return err;
12897         } else if (alc880_is_multi_pin(pin)) {
12898                 /* set manual connection */
12899                 /* we have only a switch on HP-out PIN */
12900                 sprintf(name, "%s Playback Switch", pfx);
12901                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
12902                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
12903                 if (err < 0)
12904                         return err;
12905         }
12906         return 0;
12907 }
12908
12909 /* create playback/capture controls for input pins */
12910 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
12911                                                 const struct auto_pin_cfg *cfg)
12912 {
12913         struct hda_input_mux *imux = &spec->private_imux;
12914         int i, err, idx;
12915
12916         for (i = 0; i < AUTO_PIN_LAST; i++) {
12917                 if (alc880_is_input_pin(cfg->input_pins[i])) {
12918                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
12919                         err = new_analog_input(spec, cfg->input_pins[i],
12920                                                auto_pin_cfg_labels[i],
12921                                                idx, 0x0b);
12922                         if (err < 0)
12923                                 return err;
12924                         imux->items[imux->num_items].label =
12925                                 auto_pin_cfg_labels[i];
12926                         imux->items[imux->num_items].index =
12927                                 alc880_input_pin_idx(cfg->input_pins[i]);
12928                         imux->num_items++;
12929                 }
12930         }
12931         return 0;
12932 }
12933
12934 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
12935                                               hda_nid_t nid, int pin_type,
12936                                               int dac_idx)
12937 {
12938         /* set as output */
12939         snd_hda_codec_write(codec, nid, 0,
12940                             AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
12941         snd_hda_codec_write(codec, nid, 0,
12942                             AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
12943         /* need the manual connection? */
12944         if (alc880_is_multi_pin(nid)) {
12945                 struct alc_spec *spec = codec->spec;
12946                 int idx = alc880_multi_pin_idx(nid);
12947                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
12948                                     AC_VERB_SET_CONNECT_SEL,
12949                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
12950         }
12951 }
12952
12953 static void alc662_auto_init_multi_out(struct hda_codec *codec)
12954 {
12955         struct alc_spec *spec = codec->spec;
12956         int i;
12957
12958         for (i = 0; i <= HDA_SIDE; i++) {
12959                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
12960                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
12961                 if (nid)
12962                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
12963                                                           i);
12964         }
12965 }
12966
12967 static void alc662_auto_init_hp_out(struct hda_codec *codec)
12968 {
12969         struct alc_spec *spec = codec->spec;
12970         hda_nid_t pin;
12971
12972         pin = spec->autocfg.hp_pins[0];
12973         if (pin) /* connect to front */
12974                 /* use dac 0 */
12975                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
12976 }
12977
12978 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
12979 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
12980
12981 static void alc662_auto_init_analog_input(struct hda_codec *codec)
12982 {
12983         struct alc_spec *spec = codec->spec;
12984         int i;
12985
12986         for (i = 0; i < AUTO_PIN_LAST; i++) {
12987                 hda_nid_t nid = spec->autocfg.input_pins[i];
12988                 if (alc662_is_input_pin(nid)) {
12989                         snd_hda_codec_write(codec, nid, 0,
12990                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
12991                                             (i <= AUTO_PIN_FRONT_MIC ?
12992                                              PIN_VREF80 : PIN_IN));
12993                         if (nid != ALC662_PIN_CD_NID)
12994                                 snd_hda_codec_write(codec, nid, 0,
12995                                                     AC_VERB_SET_AMP_GAIN_MUTE,
12996                                                     AMP_OUT_MUTE);
12997                 }
12998         }
12999 }
13000
13001 static int alc662_parse_auto_config(struct hda_codec *codec)
13002 {
13003         struct alc_spec *spec = codec->spec;
13004         int err;
13005         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
13006
13007         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13008                                            alc662_ignore);
13009         if (err < 0)
13010                 return err;
13011         if (!spec->autocfg.line_outs)
13012                 return 0; /* can't find valid BIOS pin config */
13013
13014         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
13015         if (err < 0)
13016                 return err;
13017         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
13018         if (err < 0)
13019                 return err;
13020         err = alc662_auto_create_extra_out(spec,
13021                                            spec->autocfg.speaker_pins[0],
13022                                            "Speaker");
13023         if (err < 0)
13024                 return err;
13025         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
13026                                            "Headphone");
13027         if (err < 0)
13028                 return err;
13029         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
13030         if (err < 0)
13031                 return err;
13032
13033         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13034
13035         if (spec->autocfg.dig_out_pin)
13036                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
13037
13038         if (spec->kctl_alloc)
13039                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
13040
13041         spec->num_mux_defs = 1;
13042         spec->input_mux = &spec->private_imux;
13043         
13044         spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs;
13045         spec->mixers[spec->num_mixers] = alc662_capture_mixer;
13046         spec->num_mixers++;
13047         return 1;
13048 }
13049
13050 /* additional initialization for auto-configuration model */
13051 static void alc662_auto_init(struct hda_codec *codec)
13052 {
13053         alc662_auto_init_multi_out(codec);
13054         alc662_auto_init_hp_out(codec);
13055         alc662_auto_init_analog_input(codec);
13056 }
13057
13058 static int patch_alc662(struct hda_codec *codec)
13059 {
13060         struct alc_spec *spec;
13061         int err, board_config;
13062
13063         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13064         if (!spec)
13065                 return -ENOMEM;
13066
13067         codec->spec = spec;
13068
13069         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
13070                                                   alc662_models,
13071                                                   alc662_cfg_tbl);
13072         if (board_config < 0) {
13073                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
13074                        "trying auto-probe from BIOS...\n");
13075                 board_config = ALC662_AUTO;
13076         }
13077
13078         if (board_config == ALC662_AUTO) {
13079                 /* automatic parse from the BIOS config */
13080                 err = alc662_parse_auto_config(codec);
13081                 if (err < 0) {
13082                         alc_free(codec);
13083                         return err;
13084                 } else if (!err) {
13085                         printk(KERN_INFO
13086                                "hda_codec: Cannot set up configuration "
13087                                "from BIOS.  Using base mode...\n");
13088                         board_config = ALC662_3ST_2ch_DIG;
13089                 }
13090         }
13091
13092         if (board_config != ALC662_AUTO)
13093                 setup_preset(spec, &alc662_presets[board_config]);
13094
13095         spec->stream_name_analog = "ALC662 Analog";
13096         spec->stream_analog_playback = &alc662_pcm_analog_playback;
13097         spec->stream_analog_capture = &alc662_pcm_analog_capture;
13098
13099         spec->stream_name_digital = "ALC662 Digital";
13100         spec->stream_digital_playback = &alc662_pcm_digital_playback;
13101         spec->stream_digital_capture = &alc662_pcm_digital_capture;
13102
13103         if (!spec->adc_nids && spec->input_mux) {
13104                 spec->adc_nids = alc662_adc_nids;
13105                 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
13106         }
13107
13108         codec->patch_ops = alc_patch_ops;
13109         if (board_config == ALC662_AUTO)
13110                 spec->init_hook = alc662_auto_init;
13111 #ifdef CONFIG_SND_HDA_POWER_SAVE
13112         if (!spec->loopback.amplist)
13113                 spec->loopback.amplist = alc662_loopbacks;
13114 #endif
13115
13116         return 0;
13117 }
13118
13119 /*
13120  * patch entries
13121  */
13122 struct hda_codec_preset snd_hda_preset_realtek[] = {
13123         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
13124         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
13125         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
13126         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
13127         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
13128         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
13129           .patch = patch_alc861 },
13130         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
13131         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
13132         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
13133         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
13134           .patch = patch_alc883 },
13135         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
13136           .patch = patch_alc662 },
13137         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
13138         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
13139         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
13140         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
13141         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
13142         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
13143         {} /* terminator */
13144 };