a4876a31311ec1cc6709bd27ecb376d47743caec
[pandora-kernel.git] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <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_BENQ_ED8,
96         ALC262_SONY_ASSAMD,
97         ALC262_AUTO,
98         ALC262_MODEL_LAST /* last tag */
99 };
100
101 /* ALC268 models */
102 enum {
103         ALC268_3ST,
104         ALC268_AUTO,
105         ALC268_MODEL_LAST /* last tag */
106 };
107
108 /* ALC861 models */
109 enum {
110         ALC861_3ST,
111         ALC660_3ST,
112         ALC861_3ST_DIG,
113         ALC861_6ST_DIG,
114         ALC861_UNIWILL_M31,
115         ALC861_TOSHIBA,
116         ALC861_ASUS,
117         ALC861_ASUS_LAPTOP,
118         ALC861_AUTO,
119         ALC861_MODEL_LAST,
120 };
121
122 /* ALC861-VD models */
123 enum {
124         ALC660VD_3ST,
125         ALC660VD_3ST_DIG,
126         ALC861VD_3ST,
127         ALC861VD_3ST_DIG,
128         ALC861VD_6ST_DIG,
129         ALC861VD_LENOVO,
130         ALC861VD_DALLAS,
131         ALC861VD_AUTO,
132         ALC861VD_MODEL_LAST,
133 };
134
135 /* ALC662 models */
136 enum {
137         ALC662_3ST_2ch_DIG,
138         ALC662_3ST_6ch_DIG,
139         ALC662_3ST_6ch,
140         ALC662_5ST_DIG,
141         ALC662_LENOVO_101E,
142         ALC662_AUTO,
143         ALC662_MODEL_LAST,
144 };
145
146 /* ALC882 models */
147 enum {
148         ALC882_3ST_DIG,
149         ALC882_6ST_DIG,
150         ALC882_ARIMA,
151         ALC882_W2JC,
152         ALC882_TARGA,
153         ALC882_ASUS_A7J,
154         ALC885_MACPRO,
155         ALC882_AUTO,
156         ALC882_MODEL_LAST,
157 };
158
159 /* ALC883 models */
160 enum {
161         ALC883_3ST_2ch_DIG,
162         ALC883_3ST_6ch_DIG,
163         ALC883_3ST_6ch,
164         ALC883_6ST_DIG,
165         ALC883_TARGA_DIG,
166         ALC883_TARGA_2ch_DIG,
167         ALC883_ACER,
168         ALC883_MEDION,
169         ALC883_MEDION_MD2,      
170         ALC883_LAPTOP_EAPD,
171         ALC883_LENOVO_101E_2ch,
172         ALC883_LENOVO_NB0763,
173         ALC888_LENOVO_MS7195_DIG,               
174         ALC883_AUTO,
175         ALC883_MODEL_LAST,
176 };
177
178 /* for GPIO Poll */
179 #define GPIO_MASK       0x03
180
181 struct alc_spec {
182         /* codec parameterization */
183         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
184         unsigned int num_mixers;
185
186         const struct hda_verb *init_verbs[5];   /* initialization verbs
187                                                  * don't forget NULL
188                                                  * termination!
189                                                  */
190         unsigned int num_init_verbs;
191
192         char *stream_name_analog;       /* analog PCM stream */
193         struct hda_pcm_stream *stream_analog_playback;
194         struct hda_pcm_stream *stream_analog_capture;
195
196         char *stream_name_digital;      /* digital PCM stream */
197         struct hda_pcm_stream *stream_digital_playback;
198         struct hda_pcm_stream *stream_digital_capture;
199
200         /* playback */
201         struct hda_multi_out multiout;  /* playback set-up
202                                          * max_channels, dacs must be set
203                                          * dig_out_nid and hp_nid are optional
204                                          */
205
206         /* capture */
207         unsigned int num_adc_nids;
208         hda_nid_t *adc_nids;
209         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
210
211         /* capture source */
212         unsigned int num_mux_defs;
213         const struct hda_input_mux *input_mux;
214         unsigned int cur_mux[3];
215
216         /* channel model */
217         const struct hda_channel_mode *channel_mode;
218         int num_channel_mode;
219         int need_dac_fix;
220
221         /* PCM information */
222         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
223
224         /* dynamic controls, init_verbs and input_mux */
225         struct auto_pin_cfg autocfg;
226         unsigned int num_kctl_alloc, num_kctl_used;
227         struct snd_kcontrol_new *kctl_alloc;
228         struct hda_input_mux private_imux;
229         hda_nid_t private_dac_nids[5];
230
231         /* hooks */
232         void (*init_hook)(struct hda_codec *codec);
233         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
234
235         /* for pin sensing */
236         unsigned int sense_updated: 1;
237         unsigned int jack_present: 1;
238 };
239
240 /*
241  * configuration template - to be copied to the spec instance
242  */
243 struct alc_config_preset {
244         struct snd_kcontrol_new *mixers[5]; /* should be identical size
245                                              * with spec
246                                              */
247         const struct hda_verb *init_verbs[5];
248         unsigned int num_dacs;
249         hda_nid_t *dac_nids;
250         hda_nid_t dig_out_nid;          /* optional */
251         hda_nid_t hp_nid;               /* optional */
252         unsigned int num_adc_nids;
253         hda_nid_t *adc_nids;
254         hda_nid_t dig_in_nid;
255         unsigned int num_channel_mode;
256         const struct hda_channel_mode *channel_mode;
257         int need_dac_fix;
258         unsigned int num_mux_defs;
259         const struct hda_input_mux *input_mux;
260         void (*unsol_event)(struct hda_codec *, unsigned int);
261         void (*init_hook)(struct hda_codec *);
262 };
263
264
265 /*
266  * input MUX handling
267  */
268 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
269                              struct snd_ctl_elem_info *uinfo)
270 {
271         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
272         struct alc_spec *spec = codec->spec;
273         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
274         if (mux_idx >= spec->num_mux_defs)
275                 mux_idx = 0;
276         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
277 }
278
279 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
280                             struct snd_ctl_elem_value *ucontrol)
281 {
282         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
283         struct alc_spec *spec = codec->spec;
284         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
285
286         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
287         return 0;
288 }
289
290 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
291                             struct snd_ctl_elem_value *ucontrol)
292 {
293         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
294         struct alc_spec *spec = codec->spec;
295         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
296         unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
297         return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
298                                      spec->adc_nids[adc_idx],
299                                      &spec->cur_mux[adc_idx]);
300 }
301
302
303 /*
304  * channel mode setting
305  */
306 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
307                             struct snd_ctl_elem_info *uinfo)
308 {
309         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
310         struct alc_spec *spec = codec->spec;
311         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
312                                     spec->num_channel_mode);
313 }
314
315 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
316                            struct snd_ctl_elem_value *ucontrol)
317 {
318         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
319         struct alc_spec *spec = codec->spec;
320         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
321                                    spec->num_channel_mode,
322                                    spec->multiout.max_channels);
323 }
324
325 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
326                            struct snd_ctl_elem_value *ucontrol)
327 {
328         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
329         struct alc_spec *spec = codec->spec;
330         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
331                                       spec->num_channel_mode,
332                                       &spec->multiout.max_channels);
333         if (err >= 0 && spec->need_dac_fix)
334                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
335         return err;
336 }
337
338 /*
339  * Control the mode of pin widget settings via the mixer.  "pc" is used
340  * instead of "%" to avoid consequences of accidently treating the % as 
341  * being part of a format specifier.  Maximum allowed length of a value is
342  * 63 characters plus NULL terminator.
343  *
344  * Note: some retasking pin complexes seem to ignore requests for input
345  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
346  * are requested.  Therefore order this list so that this behaviour will not
347  * cause problems when mixer clients move through the enum sequentially.
348  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
349  * March 2006.
350  */
351 static char *alc_pin_mode_names[] = {
352         "Mic 50pc bias", "Mic 80pc bias",
353         "Line in", "Line out", "Headphone out",
354 };
355 static unsigned char alc_pin_mode_values[] = {
356         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
357 };
358 /* The control can present all 5 options, or it can limit the options based
359  * in the pin being assumed to be exclusively an input or an output pin.  In
360  * addition, "input" pins may or may not process the mic bias option
361  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
362  * accept requests for bias as of chip versions up to March 2006) and/or
363  * wiring in the computer.
364  */
365 #define ALC_PIN_DIR_IN              0x00
366 #define ALC_PIN_DIR_OUT             0x01
367 #define ALC_PIN_DIR_INOUT           0x02
368 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
369 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
370
371 /* Info about the pin modes supported by the different pin direction modes. 
372  * For each direction the minimum and maximum values are given.
373  */
374 static signed char alc_pin_mode_dir_info[5][2] = {
375         { 0, 2 },    /* ALC_PIN_DIR_IN */
376         { 3, 4 },    /* ALC_PIN_DIR_OUT */
377         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
378         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
379         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
380 };
381 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
382 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
383 #define alc_pin_mode_n_items(_dir) \
384         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
385
386 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
387                              struct snd_ctl_elem_info *uinfo)
388 {
389         unsigned int item_num = uinfo->value.enumerated.item;
390         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
391
392         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
393         uinfo->count = 1;
394         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
395
396         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
397                 item_num = alc_pin_mode_min(dir);
398         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
399         return 0;
400 }
401
402 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
403                             struct snd_ctl_elem_value *ucontrol)
404 {
405         unsigned int i;
406         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
407         hda_nid_t nid = kcontrol->private_value & 0xffff;
408         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
409         long *valp = ucontrol->value.integer.value;
410         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
411                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
412                                                  0x00);
413
414         /* Find enumerated value for current pinctl setting */
415         i = alc_pin_mode_min(dir);
416         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
417                 i++;
418         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
419         return 0;
420 }
421
422 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
423                             struct snd_ctl_elem_value *ucontrol)
424 {
425         signed int change;
426         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
427         hda_nid_t nid = kcontrol->private_value & 0xffff;
428         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
429         long val = *ucontrol->value.integer.value;
430         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
431                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
432                                                  0x00);
433
434         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
435                 val = alc_pin_mode_min(dir);
436
437         change = pinctl != alc_pin_mode_values[val];
438         if (change) {
439                 /* Set pin mode to that requested */
440                 snd_hda_codec_write(codec,nid,0,AC_VERB_SET_PIN_WIDGET_CONTROL,
441                                     alc_pin_mode_values[val]);
442
443                 /* Also enable the retasking pin's input/output as required 
444                  * for the requested pin mode.  Enum values of 2 or less are
445                  * input modes.
446                  *
447                  * Dynamically switching the input/output buffers probably
448                  * reduces noise slightly (particularly on input) so we'll
449                  * do it.  However, having both input and output buffers
450                  * enabled simultaneously doesn't seem to be problematic if
451                  * this turns out to be necessary in the future.
452                  */
453                 if (val <= 2) {
454                         snd_hda_codec_write(codec, nid, 0,
455                                             AC_VERB_SET_AMP_GAIN_MUTE,
456                                             AMP_OUT_MUTE);
457                         snd_hda_codec_write(codec, nid, 0,
458                                             AC_VERB_SET_AMP_GAIN_MUTE,
459                                             AMP_IN_UNMUTE(0));
460                 } else {
461                         snd_hda_codec_write(codec, nid, 0,
462                                             AC_VERB_SET_AMP_GAIN_MUTE,
463                                             AMP_IN_MUTE(0));
464                         snd_hda_codec_write(codec, nid, 0,
465                                             AC_VERB_SET_AMP_GAIN_MUTE,
466                                             AMP_OUT_UNMUTE);
467                 }
468         }
469         return change;
470 }
471
472 #define ALC_PIN_MODE(xname, nid, dir) \
473         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
474           .info = alc_pin_mode_info, \
475           .get = alc_pin_mode_get, \
476           .put = alc_pin_mode_put, \
477           .private_value = nid | (dir<<16) }
478
479 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
480  * together using a mask with more than one bit set.  This control is
481  * currently used only by the ALC260 test model.  At this stage they are not
482  * needed for any "production" models.
483  */
484 #ifdef CONFIG_SND_DEBUG
485 static int alc_gpio_data_info(struct snd_kcontrol *kcontrol,
486                               struct snd_ctl_elem_info *uinfo)
487 {
488         uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
489         uinfo->count = 1;
490         uinfo->value.integer.min = 0;
491         uinfo->value.integer.max = 1;
492         return 0;
493 }
494
495 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
496                              struct snd_ctl_elem_value *ucontrol)
497 {
498         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
499         hda_nid_t nid = kcontrol->private_value & 0xffff;
500         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
501         long *valp = ucontrol->value.integer.value;
502         unsigned int val = snd_hda_codec_read(codec, nid, 0,
503                                               AC_VERB_GET_GPIO_DATA, 0x00);
504
505         *valp = (val & mask) != 0;
506         return 0;
507 }
508 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
509                              struct snd_ctl_elem_value *ucontrol)
510 {
511         signed int change;
512         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
513         hda_nid_t nid = kcontrol->private_value & 0xffff;
514         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
515         long val = *ucontrol->value.integer.value;
516         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
517                                                     AC_VERB_GET_GPIO_DATA,
518                                                     0x00);
519
520         /* Set/unset the masked GPIO bit(s) as needed */
521         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
522         if (val == 0)
523                 gpio_data &= ~mask;
524         else
525                 gpio_data |= mask;
526         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_GPIO_DATA, gpio_data);
527
528         return change;
529 }
530 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
531         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
532           .info = alc_gpio_data_info, \
533           .get = alc_gpio_data_get, \
534           .put = alc_gpio_data_put, \
535           .private_value = nid | (mask<<16) }
536 #endif   /* CONFIG_SND_DEBUG */
537
538 /* A switch control to allow the enabling of the digital IO pins on the
539  * ALC260.  This is incredibly simplistic; the intention of this control is
540  * to provide something in the test model allowing digital outputs to be
541  * identified if present.  If models are found which can utilise these
542  * outputs a more complete mixer control can be devised for those models if
543  * necessary.
544  */
545 #ifdef CONFIG_SND_DEBUG
546 static int alc_spdif_ctrl_info(struct snd_kcontrol *kcontrol,
547                                struct snd_ctl_elem_info *uinfo)
548 {
549         uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
550         uinfo->count = 1;
551         uinfo->value.integer.min = 0;
552         uinfo->value.integer.max = 1;
553         return 0;
554 }
555
556 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
557                               struct snd_ctl_elem_value *ucontrol)
558 {
559         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
560         hda_nid_t nid = kcontrol->private_value & 0xffff;
561         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
562         long *valp = ucontrol->value.integer.value;
563         unsigned int val = snd_hda_codec_read(codec, nid, 0,
564                                               AC_VERB_GET_DIGI_CONVERT, 0x00);
565
566         *valp = (val & mask) != 0;
567         return 0;
568 }
569 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
570                               struct snd_ctl_elem_value *ucontrol)
571 {
572         signed int change;
573         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
574         hda_nid_t nid = kcontrol->private_value & 0xffff;
575         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
576         long val = *ucontrol->value.integer.value;
577         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
578                                                     AC_VERB_GET_DIGI_CONVERT,
579                                                     0x00);
580
581         /* Set/unset the masked control bit(s) as needed */
582         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
583         if (val==0)
584                 ctrl_data &= ~mask;
585         else
586                 ctrl_data |= mask;
587         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
588                             ctrl_data);
589
590         return change;
591 }
592 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
593         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
594           .info = alc_spdif_ctrl_info, \
595           .get = alc_spdif_ctrl_get, \
596           .put = alc_spdif_ctrl_put, \
597           .private_value = nid | (mask<<16) }
598 #endif   /* CONFIG_SND_DEBUG */
599
600 /*
601  * set up from the preset table
602  */
603 static void setup_preset(struct alc_spec *spec,
604                          const struct alc_config_preset *preset)
605 {
606         int i;
607
608         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
609                 spec->mixers[spec->num_mixers++] = preset->mixers[i];
610         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
611              i++)
612                 spec->init_verbs[spec->num_init_verbs++] =
613                         preset->init_verbs[i];
614         
615         spec->channel_mode = preset->channel_mode;
616         spec->num_channel_mode = preset->num_channel_mode;
617         spec->need_dac_fix = preset->need_dac_fix;
618
619         spec->multiout.max_channels = spec->channel_mode[0].channels;
620
621         spec->multiout.num_dacs = preset->num_dacs;
622         spec->multiout.dac_nids = preset->dac_nids;
623         spec->multiout.dig_out_nid = preset->dig_out_nid;
624         spec->multiout.hp_nid = preset->hp_nid;
625         
626         spec->num_mux_defs = preset->num_mux_defs;
627         if (!spec->num_mux_defs)
628                 spec->num_mux_defs = 1;
629         spec->input_mux = preset->input_mux;
630
631         spec->num_adc_nids = preset->num_adc_nids;
632         spec->adc_nids = preset->adc_nids;
633         spec->dig_in_nid = preset->dig_in_nid;
634
635         spec->unsol_event = preset->unsol_event;
636         spec->init_hook = preset->init_hook;
637 }
638
639 /* Enable GPIO mask and set output */
640 static struct hda_verb alc_gpio1_init_verbs[] = {
641         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
642         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
643         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
644         { }
645 };
646
647 static struct hda_verb alc_gpio2_init_verbs[] = {
648         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
649         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
650         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
651         { }
652 };
653
654 static struct hda_verb alc_gpio3_init_verbs[] = {
655         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
656         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
657         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
658         { }
659 };
660
661 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
662  *      31 ~ 16 :       Manufacture ID
663  *      15 ~ 8  :       SKU ID
664  *      7  ~ 0  :       Assembly ID
665  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
666  */
667 static void alc_subsystem_id(struct hda_codec *codec,
668                              unsigned int porta, unsigned int porte,
669                              unsigned int portd)
670 {
671         unsigned int ass, tmp;
672
673         ass = codec->subsystem_id;
674         if (!(ass & 1))
675                 return;
676
677         /* Override */
678         tmp = (ass & 0x38) >> 3;        /* external Amp control */
679         switch (tmp) {
680         case 1:
681                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
682                 break;
683         case 3:
684                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
685                 break;
686         case 7:
687                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
688                 break;
689         case 5:
690                 switch (codec->vendor_id) {
691                 case 0x10ec0862:
692                 case 0x10ec0660:
693                 case 0x10ec0662:        
694                 case 0x10ec0267:
695                 case 0x10ec0268:
696                         snd_hda_codec_write(codec, 0x14, 0,
697                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
698                         snd_hda_codec_write(codec, 0x15, 0,
699                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
700                         return;
701                 }
702         case 6:
703                 if (ass & 4) {  /* bit 2 : 0 = Desktop, 1 = Laptop */
704                         hda_nid_t port = 0;
705                         tmp = (ass & 0x1800) >> 11;
706                         switch (tmp) {
707                         case 0: port = porta; break;
708                         case 1: port = porte; break;
709                         case 2: port = portd; break;
710                         }
711                         if (port)
712                                 snd_hda_codec_write(codec, port, 0,
713                                                     AC_VERB_SET_EAPD_BTLENABLE,
714                                                     2);
715                 }
716                 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
717                 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF,
718                                     (tmp == 5 ? 0x3040 : 0x3050));
719                 break;
720         }
721 }
722
723 /*
724  * ALC880 3-stack model
725  *
726  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
727  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
728  *                 F-Mic = 0x1b, HP = 0x19
729  */
730
731 static hda_nid_t alc880_dac_nids[4] = {
732         /* front, rear, clfe, rear_surr */
733         0x02, 0x05, 0x04, 0x03
734 };
735
736 static hda_nid_t alc880_adc_nids[3] = {
737         /* ADC0-2 */
738         0x07, 0x08, 0x09,
739 };
740
741 /* The datasheet says the node 0x07 is connected from inputs,
742  * but it shows zero connection in the real implementation on some devices.
743  * Note: this is a 915GAV bug, fixed on 915GLV
744  */
745 static hda_nid_t alc880_adc_nids_alt[2] = {
746         /* ADC1-2 */
747         0x08, 0x09,
748 };
749
750 #define ALC880_DIGOUT_NID       0x06
751 #define ALC880_DIGIN_NID        0x0a
752
753 static struct hda_input_mux alc880_capture_source = {
754         .num_items = 4,
755         .items = {
756                 { "Mic", 0x0 },
757                 { "Front Mic", 0x3 },
758                 { "Line", 0x2 },
759                 { "CD", 0x4 },
760         },
761 };
762
763 /* channel source setting (2/6 channel selection for 3-stack) */
764 /* 2ch mode */
765 static struct hda_verb alc880_threestack_ch2_init[] = {
766         /* set line-in to input, mute it */
767         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
768         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
769         /* set mic-in to input vref 80%, mute it */
770         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
771         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
772         { } /* end */
773 };
774
775 /* 6ch mode */
776 static struct hda_verb alc880_threestack_ch6_init[] = {
777         /* set line-in to output, unmute it */
778         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
779         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
780         /* set mic-in to output, unmute it */
781         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
782         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
783         { } /* end */
784 };
785
786 static struct hda_channel_mode alc880_threestack_modes[2] = {
787         { 2, alc880_threestack_ch2_init },
788         { 6, alc880_threestack_ch6_init },
789 };
790
791 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
792         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
793         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
794         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
795         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
796         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
797         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
798         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
799         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
800         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
801         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
802         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
803         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
804         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
805         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
806         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
807         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
808         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
809         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
810         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
811         {
812                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
813                 .name = "Channel Mode",
814                 .info = alc_ch_mode_info,
815                 .get = alc_ch_mode_get,
816                 .put = alc_ch_mode_put,
817         },
818         { } /* end */
819 };
820
821 /* capture mixer elements */
822 static struct snd_kcontrol_new alc880_capture_mixer[] = {
823         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
824         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
825         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
826         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
827         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
828         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
829         {
830                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
831                 /* The multiple "Capture Source" controls confuse alsamixer
832                  * So call somewhat different..
833                  * FIXME: the controls appear in the "playback" view!
834                  */
835                 /* .name = "Capture Source", */
836                 .name = "Input Source",
837                 .count = 3,
838                 .info = alc_mux_enum_info,
839                 .get = alc_mux_enum_get,
840                 .put = alc_mux_enum_put,
841         },
842         { } /* end */
843 };
844
845 /* capture mixer elements (in case NID 0x07 not available) */
846 static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
847         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
848         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
849         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
850         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
851         {
852                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
853                 /* The multiple "Capture Source" controls confuse alsamixer
854                  * So call somewhat different..
855                  * FIXME: the controls appear in the "playback" view!
856                  */
857                 /* .name = "Capture Source", */
858                 .name = "Input Source",
859                 .count = 2,
860                 .info = alc_mux_enum_info,
861                 .get = alc_mux_enum_get,
862                 .put = alc_mux_enum_put,
863         },
864         { } /* end */
865 };
866
867
868
869 /*
870  * ALC880 5-stack model
871  *
872  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
873  *      Side = 0x02 (0xd)
874  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
875  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
876  */
877
878 /* additional mixers to alc880_three_stack_mixer */
879 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
880         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
881         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
882         { } /* end */
883 };
884
885 /* channel source setting (6/8 channel selection for 5-stack) */
886 /* 6ch mode */
887 static struct hda_verb alc880_fivestack_ch6_init[] = {
888         /* set line-in to input, mute it */
889         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
890         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
891         { } /* end */
892 };
893
894 /* 8ch mode */
895 static struct hda_verb alc880_fivestack_ch8_init[] = {
896         /* set line-in to output, unmute it */
897         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
898         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
899         { } /* end */
900 };
901
902 static struct hda_channel_mode alc880_fivestack_modes[2] = {
903         { 6, alc880_fivestack_ch6_init },
904         { 8, alc880_fivestack_ch8_init },
905 };
906
907
908 /*
909  * ALC880 6-stack model
910  *
911  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
912  *      Side = 0x05 (0x0f)
913  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
914  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
915  */
916
917 static hda_nid_t alc880_6st_dac_nids[4] = {
918         /* front, rear, clfe, rear_surr */
919         0x02, 0x03, 0x04, 0x05
920 };
921
922 static struct hda_input_mux alc880_6stack_capture_source = {
923         .num_items = 4,
924         .items = {
925                 { "Mic", 0x0 },
926                 { "Front Mic", 0x1 },
927                 { "Line", 0x2 },
928                 { "CD", 0x4 },
929         },
930 };
931
932 /* fixed 8-channels */
933 static struct hda_channel_mode alc880_sixstack_modes[1] = {
934         { 8, NULL },
935 };
936
937 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
938         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
939         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
940         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
941         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
942         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
943         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
944         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
945         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
946         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
947         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
948         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
949         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
950         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
951         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
952         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
953         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
954         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
955         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
956         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
957         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
958         {
959                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
960                 .name = "Channel Mode",
961                 .info = alc_ch_mode_info,
962                 .get = alc_ch_mode_get,
963                 .put = alc_ch_mode_put,
964         },
965         { } /* end */
966 };
967
968
969 /*
970  * ALC880 W810 model
971  *
972  * W810 has rear IO for:
973  * Front (DAC 02)
974  * Surround (DAC 03)
975  * Center/LFE (DAC 04)
976  * Digital out (06)
977  *
978  * The system also has a pair of internal speakers, and a headphone jack.
979  * These are both connected to Line2 on the codec, hence to DAC 02.
980  * 
981  * There is a variable resistor to control the speaker or headphone
982  * volume. This is a hardware-only device without a software API.
983  *
984  * Plugging headphones in will disable the internal speakers. This is
985  * implemented in hardware, not via the driver using jack sense. In
986  * a similar fashion, plugging into the rear socket marked "front" will
987  * disable both the speakers and headphones.
988  *
989  * For input, there's a microphone jack, and an "audio in" jack.
990  * These may not do anything useful with this driver yet, because I
991  * haven't setup any initialization verbs for these yet...
992  */
993
994 static hda_nid_t alc880_w810_dac_nids[3] = {
995         /* front, rear/surround, clfe */
996         0x02, 0x03, 0x04
997 };
998
999 /* fixed 6 channels */
1000 static struct hda_channel_mode alc880_w810_modes[1] = {
1001         { 6, NULL }
1002 };
1003
1004 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1005 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1006         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1007         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1008         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1009         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1010         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1011         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1012         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1013         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1014         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1015         { } /* end */
1016 };
1017
1018
1019 /*
1020  * Z710V model
1021  *
1022  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1023  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1024  *                 Line = 0x1a
1025  */
1026
1027 static hda_nid_t alc880_z71v_dac_nids[1] = {
1028         0x02
1029 };
1030 #define ALC880_Z71V_HP_DAC      0x03
1031
1032 /* fixed 2 channels */
1033 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1034         { 2, NULL }
1035 };
1036
1037 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1038         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1039         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1040         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1041         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1042         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1043         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1044         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1045         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1046         { } /* end */
1047 };
1048
1049
1050 /* FIXME! */
1051 /*
1052  * ALC880 F1734 model
1053  *
1054  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1055  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1056  */
1057
1058 static hda_nid_t alc880_f1734_dac_nids[1] = {
1059         0x03
1060 };
1061 #define ALC880_F1734_HP_DAC     0x02
1062
1063 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1064         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1065         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1066         HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1067         HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1068         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1069         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1070         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1071         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1072         { } /* end */
1073 };
1074
1075
1076 /* FIXME! */
1077 /*
1078  * ALC880 ASUS model
1079  *
1080  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1081  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1082  *  Mic = 0x18, Line = 0x1a
1083  */
1084
1085 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1086 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1087
1088 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1089         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1090         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1091         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1092         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1093         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1094         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1095         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1096         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1097         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1098         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1099         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1100         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1101         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1102         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1103         {
1104                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1105                 .name = "Channel Mode",
1106                 .info = alc_ch_mode_info,
1107                 .get = alc_ch_mode_get,
1108                 .put = alc_ch_mode_put,
1109         },
1110         { } /* end */
1111 };
1112
1113 /* FIXME! */
1114 /*
1115  * ALC880 ASUS W1V model
1116  *
1117  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1118  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1119  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1120  */
1121
1122 /* additional mixers to alc880_asus_mixer */
1123 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1124         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1125         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1126         { } /* end */
1127 };
1128
1129 /* additional mixers to alc880_asus_mixer */
1130 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1131         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1132         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1133         { } /* end */
1134 };
1135
1136 /* TCL S700 */
1137 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1138         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1139         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1140         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1141         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1142         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1143         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1144         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1145         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1146         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1147         {
1148                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1149                 /* The multiple "Capture Source" controls confuse alsamixer
1150                  * So call somewhat different..
1151                  * FIXME: the controls appear in the "playback" view!
1152                  */
1153                 /* .name = "Capture Source", */
1154                 .name = "Input Source",
1155                 .count = 1,
1156                 .info = alc_mux_enum_info,
1157                 .get = alc_mux_enum_get,
1158                 .put = alc_mux_enum_put,
1159         },
1160         { } /* end */
1161 };
1162
1163 /* Uniwill */
1164 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1165         HDA_CODEC_VOLUME("HPhone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1166         HDA_BIND_MUTE("HPhone Playback Switch", 0x0c, 2, HDA_INPUT),
1167         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1168         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
1169         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1170         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1171         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1172         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1173         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1174         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1175         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1176         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1177         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1178         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1179         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1180         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1181         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1182         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1183         {
1184                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1185                 .name = "Channel Mode",
1186                 .info = alc_ch_mode_info,
1187                 .get = alc_ch_mode_get,
1188                 .put = alc_ch_mode_put,
1189         },
1190         { } /* end */
1191 };
1192
1193 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1194         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1195         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1196         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1197         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1198         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1199         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1200         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1201         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1202         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1203         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1204         { } /* end */
1205 };
1206
1207 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1208         HDA_CODEC_VOLUME("HPhone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1209         HDA_BIND_MUTE("HPhone Playback Switch", 0x0c, 2, HDA_INPUT),
1210         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1211         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
1212         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1213         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1214         { } /* end */
1215 };
1216
1217 /*
1218  * build control elements
1219  */
1220 static int alc_build_controls(struct hda_codec *codec)
1221 {
1222         struct alc_spec *spec = codec->spec;
1223         int err;
1224         int i;
1225
1226         for (i = 0; i < spec->num_mixers; i++) {
1227                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1228                 if (err < 0)
1229                         return err;
1230         }
1231
1232         if (spec->multiout.dig_out_nid) {
1233                 err = snd_hda_create_spdif_out_ctls(codec,
1234                                                     spec->multiout.dig_out_nid);
1235                 if (err < 0)
1236                         return err;
1237         }
1238         if (spec->dig_in_nid) {
1239                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1240                 if (err < 0)
1241                         return err;
1242         }
1243         return 0;
1244 }
1245
1246
1247 /*
1248  * initialize the codec volumes, etc
1249  */
1250
1251 /*
1252  * generic initialization of ADC, input mixers and output mixers
1253  */
1254 static struct hda_verb alc880_volume_init_verbs[] = {
1255         /*
1256          * Unmute ADC0-2 and set the default input to mic-in
1257          */
1258         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
1259         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1260         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
1261         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1262         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
1263         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1264
1265         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
1266          * mixer widget
1267          * Note: PASD motherboards uses the Line In 2 as the input for front
1268          * panel mic (mic 2)
1269          */
1270         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
1271         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1272         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1273         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
1274         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
1275         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
1276
1277         /*
1278          * Set up output mixers (0x0c - 0x0f)
1279          */
1280         /* set vol=0 to output mixers */
1281         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1282         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1283         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1284         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1285         /* set up input amps for analog loopback */
1286         /* Amp Indices: DAC = 0, mixer = 1 */
1287         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1288         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1289         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1290         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1291         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1292         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1293         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1294         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1295
1296         { }
1297 };
1298
1299 /*
1300  * 3-stack pin configuration:
1301  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
1302  */
1303 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
1304         /*
1305          * preset connection lists of input pins
1306          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1307          */
1308         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
1309         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1310         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
1311
1312         /*
1313          * Set pin mode and muting
1314          */
1315         /* set front pin widgets 0x14 for output */
1316         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1317         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1318         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1319         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1320         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1321         /* Mic2 (as headphone out) for HP output */
1322         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1323         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1324         /* Line In pin widget for input */
1325         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1326         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1327         /* Line2 (as front mic) pin widget for input and vref at 80% */
1328         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1329         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1330         /* CD pin widget for input */
1331         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1332
1333         { }
1334 };
1335
1336 /*
1337  * 5-stack pin configuration:
1338  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
1339  * line-in/side = 0x1a, f-mic = 0x1b
1340  */
1341 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
1342         /*
1343          * preset connection lists of input pins
1344          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
1345          */
1346         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1347         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
1348
1349         /*
1350          * Set pin mode and muting
1351          */
1352         /* set pin widgets 0x14-0x17 for output */
1353         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1354         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1355         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1356         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1357         /* unmute pins for output (no gain on this amp) */
1358         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1359         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1360         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1361         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1362
1363         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1364         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1365         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1366         /* Mic2 (as headphone out) for HP output */
1367         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1368         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1369         /* Line In pin widget for input */
1370         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1371         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1372         /* Line2 (as front mic) pin widget for input and vref at 80% */
1373         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1374         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1375         /* CD pin widget for input */
1376         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1377
1378         { }
1379 };
1380
1381 /*
1382  * W810 pin configuration:
1383  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
1384  */
1385 static struct hda_verb alc880_pin_w810_init_verbs[] = {
1386         /* hphone/speaker input selector: front DAC */
1387         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1388
1389         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1390         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1391         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1392         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1393         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1394         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1395
1396         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1397         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1398
1399         { }
1400 };
1401
1402 /*
1403  * Z71V pin configuration:
1404  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
1405  */
1406 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
1407         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1408         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1409         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1410         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1411
1412         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1413         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1414         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1415         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1416
1417         { }
1418 };
1419
1420 /*
1421  * 6-stack pin configuration:
1422  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
1423  * f-mic = 0x19, line = 0x1a, HP = 0x1b
1424  */
1425 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
1426         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1427
1428         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1429         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1430         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1431         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1432         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1433         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1434         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1435         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1436
1437         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1438         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1439         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1440         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1441         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1442         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1443         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1444         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1445         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1446         
1447         { }
1448 };
1449
1450 /*
1451  * Uniwill pin configuration:
1452  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
1453  * line = 0x1a
1454  */
1455 static struct hda_verb alc880_uniwill_init_verbs[] = {
1456         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1457
1458         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1459         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1460         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1461         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1462         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1463         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1464         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1465         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1466         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1467         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1468         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1469         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1470         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1471         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1472
1473         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1474         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1475         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1476         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1477         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1478         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1479         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
1480         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
1481         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1482
1483         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1484         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
1485
1486         { }
1487 };
1488
1489 /*
1490 * Uniwill P53
1491 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19, 
1492  */
1493 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
1494         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
1495
1496         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1497         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1498         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1499         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1500         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1501         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1502         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1503         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1504         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1505         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1506         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1507         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1508
1509         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1510         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1511         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1512         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1513         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1514         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1515
1516         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
1517         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
1518
1519         { }
1520 };
1521
1522 static struct hda_verb alc880_beep_init_verbs[] = {
1523         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
1524         { }
1525 };
1526
1527 /* toggle speaker-output according to the hp-jack state */
1528 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
1529 {
1530         unsigned int present;
1531         unsigned char bits;
1532
1533         present = snd_hda_codec_read(codec, 0x14, 0,
1534                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1535         bits = present ? 0x80 : 0;
1536         snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
1537                                  0x80, bits);
1538         snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
1539                                  0x80, bits);
1540         snd_hda_codec_amp_update(codec, 0x16, 0, HDA_OUTPUT, 0,
1541                                  0x80, bits);
1542         snd_hda_codec_amp_update(codec, 0x16, 1, HDA_OUTPUT, 0,
1543                                  0x80, bits);
1544 }
1545
1546 /* auto-toggle front mic */
1547 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
1548 {
1549         unsigned int present;
1550         unsigned char bits;
1551
1552         present = snd_hda_codec_read(codec, 0x18, 0,
1553                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1554         bits = present ? 0x80 : 0;
1555         snd_hda_codec_amp_update(codec, 0x0b, 0, HDA_INPUT, 1,
1556                                  0x80, bits);
1557         snd_hda_codec_amp_update(codec, 0x0b, 1, HDA_INPUT, 1,
1558                                  0x80, bits);
1559 }
1560
1561 static void alc880_uniwill_automute(struct hda_codec *codec)
1562 {
1563         alc880_uniwill_hp_automute(codec);
1564         alc880_uniwill_mic_automute(codec);
1565 }
1566
1567 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
1568                                        unsigned int res)
1569 {
1570         /* Looks like the unsol event is incompatible with the standard
1571          * definition.  4bit tag is placed at 28 bit!
1572          */
1573         switch (res >> 28) {
1574         case ALC880_HP_EVENT:
1575                 alc880_uniwill_hp_automute(codec);
1576                 break;
1577         case ALC880_MIC_EVENT:
1578                 alc880_uniwill_mic_automute(codec);
1579                 break;
1580         }
1581 }
1582
1583 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
1584 {
1585         unsigned int present;
1586         unsigned char bits;
1587
1588         present = snd_hda_codec_read(codec, 0x14, 0,
1589                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1590         bits = present ? 0x80 : 0;
1591         snd_hda_codec_amp_update(codec, 0x15, 0, HDA_INPUT, 0,
1592                                  0x80, bits);
1593         snd_hda_codec_amp_update(codec, 0x15, 1, HDA_INPUT, 0,
1594                                  0x80, bits);
1595 }
1596
1597 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
1598 {
1599         unsigned int present;
1600         
1601         present = snd_hda_codec_read(codec, 0x21, 0,
1602                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0) & 0x7f;
1603
1604         snd_hda_codec_amp_update(codec, 0x0c, 0, HDA_OUTPUT, 0,
1605                                  0x7f, present);
1606         snd_hda_codec_amp_update(codec, 0x0c, 1, HDA_OUTPUT, 0,
1607                                  0x7f,  present);
1608
1609         snd_hda_codec_amp_update(codec, 0x0d, 0, HDA_OUTPUT, 0,
1610                                  0x7f,  present);
1611         snd_hda_codec_amp_update(codec, 0x0d, 1, HDA_OUTPUT, 0,
1612                                  0x7f, present);
1613
1614 }
1615 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
1616                                            unsigned int res)
1617 {
1618         /* Looks like the unsol event is incompatible with the standard
1619          * definition.  4bit tag is placed at 28 bit!
1620          */
1621         if ((res >> 28) == ALC880_HP_EVENT)
1622                 alc880_uniwill_p53_hp_automute(codec);
1623         if ((res >> 28) == ALC880_DCVOL_EVENT)
1624                 alc880_uniwill_p53_dcvol_automute(codec);
1625 }
1626
1627 /* FIXME! */
1628 /*
1629  * F1734 pin configuration:
1630  * HP = 0x14, speaker-out = 0x15, mic = 0x18
1631  */
1632 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1633         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1634         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1635         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1636         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1637
1638         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1639         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1640         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1641         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1642
1643         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1644         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1645         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1646         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1647         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1648         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1649         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1650         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1651         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1652
1653         { }
1654 };
1655
1656 /* FIXME! */
1657 /*
1658  * ASUS pin configuration:
1659  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
1660  */
1661 static struct hda_verb alc880_pin_asus_init_verbs[] = {
1662         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1663         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1664         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
1665         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1666
1667         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1668         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1669         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1670         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1671         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1672         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1673         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1674         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1675
1676         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1677         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1678         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1679         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1680         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1681         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1682         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1683         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1684         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1685         
1686         { }
1687 };
1688
1689 /* Enable GPIO mask and set output */
1690 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
1691 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
1692
1693 /* Clevo m520g init */
1694 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
1695         /* headphone output */
1696         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
1697         /* line-out */
1698         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1699         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1700         /* Line-in */
1701         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1702         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1703         /* CD */
1704         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1705         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1706         /* Mic1 (rear panel) */
1707         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1708         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1709         /* Mic2 (front panel) */
1710         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1711         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1712         /* headphone */
1713         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1714         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1715         /* change to EAPD mode */
1716         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1717         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
1718
1719         { }
1720 };
1721
1722 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
1723         /* change to EAPD mode */
1724         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1725         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
1726
1727         /* Headphone output */
1728         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1729         /* Front output*/
1730         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1731         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1732
1733         /* Line In pin widget for input */
1734         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1735         /* CD pin widget for input */
1736         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1737         /* Mic1 (rear panel) pin widget for input and vref at 80% */
1738         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1739
1740         /* change to EAPD mode */
1741         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
1742         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
1743
1744         { }
1745 };
1746
1747 /*
1748  * LG m1 express dual
1749  *
1750  * Pin assignment:
1751  *   Rear Line-In/Out (blue): 0x14
1752  *   Build-in Mic-In: 0x15
1753  *   Speaker-out: 0x17
1754  *   HP-Out (green): 0x1b
1755  *   Mic-In/Out (red): 0x19
1756  *   SPDIF-Out: 0x1e
1757  */
1758
1759 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
1760 static hda_nid_t alc880_lg_dac_nids[3] = {
1761         0x05, 0x02, 0x03
1762 };
1763
1764 /* seems analog CD is not working */
1765 static struct hda_input_mux alc880_lg_capture_source = {
1766         .num_items = 3,
1767         .items = {
1768                 { "Mic", 0x1 },
1769                 { "Line", 0x5 },
1770                 { "Internal Mic", 0x6 },
1771         },
1772 };
1773
1774 /* 2,4,6 channel modes */
1775 static struct hda_verb alc880_lg_ch2_init[] = {
1776         /* set line-in and mic-in to input */
1777         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1778         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1779         { }
1780 };
1781
1782 static struct hda_verb alc880_lg_ch4_init[] = {
1783         /* set line-in to out and mic-in to input */
1784         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1785         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1786         { }
1787 };
1788
1789 static struct hda_verb alc880_lg_ch6_init[] = {
1790         /* set line-in and mic-in to output */
1791         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1792         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1793         { }
1794 };
1795
1796 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
1797         { 2, alc880_lg_ch2_init },
1798         { 4, alc880_lg_ch4_init },
1799         { 6, alc880_lg_ch6_init },
1800 };
1801
1802 static struct snd_kcontrol_new alc880_lg_mixer[] = {
1803         /* FIXME: it's not really "master" but front channels */
1804         HDA_CODEC_VOLUME("Master Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1805         HDA_BIND_MUTE("Master Playback Switch", 0x0f, 2, HDA_INPUT),
1806         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1807         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
1808         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1809         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
1810         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
1811         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
1812         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1813         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1814         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
1815         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
1816         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
1817         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
1818         {
1819                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1820                 .name = "Channel Mode",
1821                 .info = alc_ch_mode_info,
1822                 .get = alc_ch_mode_get,
1823                 .put = alc_ch_mode_put,
1824         },
1825         { } /* end */
1826 };
1827
1828 static struct hda_verb alc880_lg_init_verbs[] = {
1829         /* set capture source to mic-in */
1830         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1831         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1832         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1833         /* mute all amp mixer inputs */
1834         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
1835         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(6)},
1836         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(7)},
1837         /* line-in to input */
1838         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1839         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1840         /* built-in mic */
1841         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1842         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1843         /* speaker-out */
1844         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1845         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1846         /* mic-in to input */
1847         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
1848         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1849         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1850         /* HP-out */
1851         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
1852         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1853         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1854         /* jack sense */
1855         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
1856         { }
1857 };
1858
1859 /* toggle speaker-output according to the hp-jack state */
1860 static void alc880_lg_automute(struct hda_codec *codec)
1861 {
1862         unsigned int present;
1863         unsigned char bits;
1864
1865         present = snd_hda_codec_read(codec, 0x1b, 0,
1866                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1867         bits = present ? 0x80 : 0;
1868         snd_hda_codec_amp_update(codec, 0x17, 0, HDA_OUTPUT, 0,
1869                                  0x80, bits);
1870         snd_hda_codec_amp_update(codec, 0x17, 1, HDA_OUTPUT, 0,
1871                                  0x80, bits);
1872 }
1873
1874 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
1875 {
1876         /* Looks like the unsol event is incompatible with the standard
1877          * definition.  4bit tag is placed at 28 bit!
1878          */
1879         if ((res >> 28) == 0x01)
1880                 alc880_lg_automute(codec);
1881 }
1882
1883 /*
1884  * LG LW20
1885  *
1886  * Pin assignment:
1887  *   Speaker-out: 0x14
1888  *   Mic-In: 0x18
1889  *   Built-in Mic-In: 0x19 (?)
1890  *   HP-Out: 0x1b
1891  *   SPDIF-Out: 0x1e
1892  */
1893
1894 /* seems analog CD is not working */
1895 static struct hda_input_mux alc880_lg_lw_capture_source = {
1896         .num_items = 2,
1897         .items = {
1898                 { "Mic", 0x0 },
1899                 { "Internal Mic", 0x1 },
1900         },
1901 };
1902
1903 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
1904         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1905         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
1906         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1907         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1908         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
1909         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
1910         { } /* end */
1911 };
1912
1913 static struct hda_verb alc880_lg_lw_init_verbs[] = {
1914         /* set capture source to mic-in */
1915         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1916         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1917         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1918         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(7)},
1919         /* speaker-out */
1920         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1921         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1922         /* HP-out */
1923         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
1924         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1925         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1926         /* mic-in to input */
1927         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1928         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1929         /* built-in mic */
1930         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1931         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1932         /* jack sense */
1933         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
1934         { }
1935 };
1936
1937 /* toggle speaker-output according to the hp-jack state */
1938 static void alc880_lg_lw_automute(struct hda_codec *codec)
1939 {
1940         unsigned int present;
1941         unsigned char bits;
1942
1943         present = snd_hda_codec_read(codec, 0x1b, 0,
1944                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1945         bits = present ? 0x80 : 0;
1946         snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
1947                                  0x80, bits);
1948         snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
1949                                  0x80, bits);
1950 }
1951
1952 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
1953 {
1954         /* Looks like the unsol event is incompatible with the standard
1955          * definition.  4bit tag is placed at 28 bit!
1956          */
1957         if ((res >> 28) == 0x01)
1958                 alc880_lg_lw_automute(codec);
1959 }
1960
1961 /*
1962  * Common callbacks
1963  */
1964
1965 static int alc_init(struct hda_codec *codec)
1966 {
1967         struct alc_spec *spec = codec->spec;
1968         unsigned int i;
1969
1970         for (i = 0; i < spec->num_init_verbs; i++)
1971                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
1972
1973         if (spec->init_hook)
1974                 spec->init_hook(codec);
1975
1976         return 0;
1977 }
1978
1979 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
1980 {
1981         struct alc_spec *spec = codec->spec;
1982
1983         if (spec->unsol_event)
1984                 spec->unsol_event(codec, res);
1985 }
1986
1987 #ifdef CONFIG_PM
1988 /*
1989  * resume
1990  */
1991 static int alc_resume(struct hda_codec *codec)
1992 {
1993         struct alc_spec *spec = codec->spec;
1994         int i;
1995
1996         alc_init(codec);
1997         for (i = 0; i < spec->num_mixers; i++)
1998                 snd_hda_resume_ctls(codec, spec->mixers[i]);
1999         if (spec->multiout.dig_out_nid)
2000                 snd_hda_resume_spdif_out(codec);
2001         if (spec->dig_in_nid)
2002                 snd_hda_resume_spdif_in(codec);
2003
2004         return 0;
2005 }
2006 #endif
2007
2008 /*
2009  * Analog playback callbacks
2010  */
2011 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2012                                     struct hda_codec *codec,
2013                                     struct snd_pcm_substream *substream)
2014 {
2015         struct alc_spec *spec = codec->spec;
2016         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
2017 }
2018
2019 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2020                                        struct hda_codec *codec,
2021                                        unsigned int stream_tag,
2022                                        unsigned int format,
2023                                        struct snd_pcm_substream *substream)
2024 {
2025         struct alc_spec *spec = codec->spec;
2026         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2027                                                 stream_tag, format, substream);
2028 }
2029
2030 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2031                                        struct hda_codec *codec,
2032                                        struct snd_pcm_substream *substream)
2033 {
2034         struct alc_spec *spec = codec->spec;
2035         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2036 }
2037
2038 /*
2039  * Digital out
2040  */
2041 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2042                                         struct hda_codec *codec,
2043                                         struct snd_pcm_substream *substream)
2044 {
2045         struct alc_spec *spec = codec->spec;
2046         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2047 }
2048
2049 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2050                                            struct hda_codec *codec,
2051                                            unsigned int stream_tag,
2052                                            unsigned int format,
2053                                            struct snd_pcm_substream *substream)
2054 {
2055         struct alc_spec *spec = codec->spec;
2056         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2057                                              stream_tag, format, substream);
2058 }
2059
2060 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2061                                          struct hda_codec *codec,
2062                                          struct snd_pcm_substream *substream)
2063 {
2064         struct alc_spec *spec = codec->spec;
2065         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2066 }
2067
2068 /*
2069  * Analog capture
2070  */
2071 static int alc880_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2072                                       struct hda_codec *codec,
2073                                       unsigned int stream_tag,
2074                                       unsigned int format,
2075                                       struct snd_pcm_substream *substream)
2076 {
2077         struct alc_spec *spec = codec->spec;
2078
2079         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
2080                                    stream_tag, 0, format);
2081         return 0;
2082 }
2083
2084 static int alc880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2085                                       struct hda_codec *codec,
2086                                       struct snd_pcm_substream *substream)
2087 {
2088         struct alc_spec *spec = codec->spec;
2089
2090         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
2091                                    0, 0, 0);
2092         return 0;
2093 }
2094
2095
2096 /*
2097  */
2098 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2099         .substreams = 1,
2100         .channels_min = 2,
2101         .channels_max = 8,
2102         /* NID is set in alc_build_pcms */
2103         .ops = {
2104                 .open = alc880_playback_pcm_open,
2105                 .prepare = alc880_playback_pcm_prepare,
2106                 .cleanup = alc880_playback_pcm_cleanup
2107         },
2108 };
2109
2110 static struct hda_pcm_stream alc880_pcm_analog_capture = {
2111         .substreams = 2,
2112         .channels_min = 2,
2113         .channels_max = 2,
2114         /* NID is set in alc_build_pcms */
2115         .ops = {
2116                 .prepare = alc880_capture_pcm_prepare,
2117                 .cleanup = alc880_capture_pcm_cleanup
2118         },
2119 };
2120
2121 static struct hda_pcm_stream alc880_pcm_digital_playback = {
2122         .substreams = 1,
2123         .channels_min = 2,
2124         .channels_max = 2,
2125         /* NID is set in alc_build_pcms */
2126         .ops = {
2127                 .open = alc880_dig_playback_pcm_open,
2128                 .close = alc880_dig_playback_pcm_close,
2129                 .prepare = alc880_dig_playback_pcm_prepare
2130         },
2131 };
2132
2133 static struct hda_pcm_stream alc880_pcm_digital_capture = {
2134         .substreams = 1,
2135         .channels_min = 2,
2136         .channels_max = 2,
2137         /* NID is set in alc_build_pcms */
2138 };
2139
2140 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
2141 static struct hda_pcm_stream alc_pcm_null_playback = {
2142         .substreams = 0,
2143         .channels_min = 0,
2144         .channels_max = 0,
2145 };
2146
2147 static int alc_build_pcms(struct hda_codec *codec)
2148 {
2149         struct alc_spec *spec = codec->spec;
2150         struct hda_pcm *info = spec->pcm_rec;
2151         int i;
2152
2153         codec->num_pcms = 1;
2154         codec->pcm_info = info;
2155
2156         info->name = spec->stream_name_analog;
2157         if (spec->stream_analog_playback) {
2158                 snd_assert(spec->multiout.dac_nids, return -EINVAL);
2159                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
2160                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2161         }
2162         if (spec->stream_analog_capture) {
2163                 snd_assert(spec->adc_nids, return -EINVAL);
2164                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2165                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2166         }
2167
2168         if (spec->channel_mode) {
2169                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2170                 for (i = 0; i < spec->num_channel_mode; i++) {
2171                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2172                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2173                         }
2174                 }
2175         }
2176
2177         /* SPDIF for stream index #1 */
2178         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2179                 codec->num_pcms = 2;
2180                 info = spec->pcm_rec + 1;
2181                 info->name = spec->stream_name_digital;
2182                 if (spec->multiout.dig_out_nid &&
2183                     spec->stream_digital_playback) {
2184                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
2185                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2186                 }
2187                 if (spec->dig_in_nid &&
2188                     spec->stream_digital_capture) {
2189                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
2190                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2191                 }
2192         }
2193
2194         /* If the use of more than one ADC is requested for the current
2195          * model, configure a second analog capture-only PCM.
2196          */
2197         /* Additional Analaog capture for index #2 */
2198         if (spec->num_adc_nids > 1 && spec->stream_analog_capture &&
2199             spec->adc_nids) {
2200                 codec->num_pcms = 3;
2201                 info = spec->pcm_rec + 2;
2202                 info->name = spec->stream_name_analog;
2203                 /* No playback stream for second PCM */
2204                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = alc_pcm_null_playback;
2205                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2206                 if (spec->stream_analog_capture) {
2207                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
2208                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[1];
2209                 }
2210         }
2211
2212         return 0;
2213 }
2214
2215 static void alc_free(struct hda_codec *codec)
2216 {
2217         struct alc_spec *spec = codec->spec;
2218         unsigned int i;
2219
2220         if (!spec)
2221                 return;
2222
2223         if (spec->kctl_alloc) {
2224                 for (i = 0; i < spec->num_kctl_used; i++)
2225                         kfree(spec->kctl_alloc[i].name);
2226                 kfree(spec->kctl_alloc);
2227         }
2228         kfree(spec);
2229 }
2230
2231 /*
2232  */
2233 static struct hda_codec_ops alc_patch_ops = {
2234         .build_controls = alc_build_controls,
2235         .build_pcms = alc_build_pcms,
2236         .init = alc_init,
2237         .free = alc_free,
2238         .unsol_event = alc_unsol_event,
2239 #ifdef CONFIG_PM
2240         .resume = alc_resume,
2241 #endif
2242 };
2243
2244
2245 /*
2246  * Test configuration for debugging
2247  *
2248  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
2249  * enum controls.
2250  */
2251 #ifdef CONFIG_SND_DEBUG
2252 static hda_nid_t alc880_test_dac_nids[4] = {
2253         0x02, 0x03, 0x04, 0x05
2254 };
2255
2256 static struct hda_input_mux alc880_test_capture_source = {
2257         .num_items = 7,
2258         .items = {
2259                 { "In-1", 0x0 },
2260                 { "In-2", 0x1 },
2261                 { "In-3", 0x2 },
2262                 { "In-4", 0x3 },
2263                 { "CD", 0x4 },
2264                 { "Front", 0x5 },
2265                 { "Surround", 0x6 },
2266         },
2267 };
2268
2269 static struct hda_channel_mode alc880_test_modes[4] = {
2270         { 2, NULL },
2271         { 4, NULL },
2272         { 6, NULL },
2273         { 8, NULL },
2274 };
2275
2276 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
2277                                  struct snd_ctl_elem_info *uinfo)
2278 {
2279         static char *texts[] = {
2280                 "N/A", "Line Out", "HP Out",
2281                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
2282         };
2283         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2284         uinfo->count = 1;
2285         uinfo->value.enumerated.items = 8;
2286         if (uinfo->value.enumerated.item >= 8)
2287                 uinfo->value.enumerated.item = 7;
2288         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2289         return 0;
2290 }
2291
2292 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
2293                                 struct snd_ctl_elem_value *ucontrol)
2294 {
2295         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2296         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2297         unsigned int pin_ctl, item = 0;
2298
2299         pin_ctl = snd_hda_codec_read(codec, nid, 0,
2300                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2301         if (pin_ctl & AC_PINCTL_OUT_EN) {
2302                 if (pin_ctl & AC_PINCTL_HP_EN)
2303                         item = 2;
2304                 else
2305                         item = 1;
2306         } else if (pin_ctl & AC_PINCTL_IN_EN) {
2307                 switch (pin_ctl & AC_PINCTL_VREFEN) {
2308                 case AC_PINCTL_VREF_HIZ: item = 3; break;
2309                 case AC_PINCTL_VREF_50:  item = 4; break;
2310                 case AC_PINCTL_VREF_GRD: item = 5; break;
2311                 case AC_PINCTL_VREF_80:  item = 6; break;
2312                 case AC_PINCTL_VREF_100: item = 7; break;
2313                 }
2314         }
2315         ucontrol->value.enumerated.item[0] = item;
2316         return 0;
2317 }
2318
2319 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
2320                                 struct snd_ctl_elem_value *ucontrol)
2321 {
2322         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2323         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2324         static unsigned int ctls[] = {
2325                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
2326                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
2327                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
2328                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
2329                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
2330                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
2331         };
2332         unsigned int old_ctl, new_ctl;
2333
2334         old_ctl = snd_hda_codec_read(codec, nid, 0,
2335                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2336         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
2337         if (old_ctl != new_ctl) {
2338                 snd_hda_codec_write(codec, nid, 0,
2339                                     AC_VERB_SET_PIN_WIDGET_CONTROL, new_ctl);
2340                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2341                                     (ucontrol->value.enumerated.item[0] >= 3 ?
2342                                      0xb080 : 0xb000));
2343                 return 1;
2344         }
2345         return 0;
2346 }
2347
2348 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
2349                                  struct snd_ctl_elem_info *uinfo)
2350 {
2351         static char *texts[] = {
2352                 "Front", "Surround", "CLFE", "Side"
2353         };
2354         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2355         uinfo->count = 1;
2356         uinfo->value.enumerated.items = 4;
2357         if (uinfo->value.enumerated.item >= 4)
2358                 uinfo->value.enumerated.item = 3;
2359         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2360         return 0;
2361 }
2362
2363 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
2364                                 struct snd_ctl_elem_value *ucontrol)
2365 {
2366         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2367         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2368         unsigned int sel;
2369
2370         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
2371         ucontrol->value.enumerated.item[0] = sel & 3;
2372         return 0;
2373 }
2374
2375 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
2376                                 struct snd_ctl_elem_value *ucontrol)
2377 {
2378         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2379         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
2380         unsigned int sel;
2381
2382         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
2383         if (ucontrol->value.enumerated.item[0] != sel) {
2384                 sel = ucontrol->value.enumerated.item[0] & 3;
2385                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, sel);
2386                 return 1;
2387         }
2388         return 0;
2389 }
2390
2391 #define PIN_CTL_TEST(xname,nid) {                       \
2392                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2393                         .name = xname,                 \
2394                         .info = alc_test_pin_ctl_info, \
2395                         .get = alc_test_pin_ctl_get,   \
2396                         .put = alc_test_pin_ctl_put,   \
2397                         .private_value = nid           \
2398                         }
2399
2400 #define PIN_SRC_TEST(xname,nid) {                       \
2401                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
2402                         .name = xname,                 \
2403                         .info = alc_test_pin_src_info, \
2404                         .get = alc_test_pin_src_get,   \
2405                         .put = alc_test_pin_src_put,   \
2406                         .private_value = nid           \
2407                         }
2408
2409 static struct snd_kcontrol_new alc880_test_mixer[] = {
2410         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2411         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2412         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
2413         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2414         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2415         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2416         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
2417         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2418         PIN_CTL_TEST("Front Pin Mode", 0x14),
2419         PIN_CTL_TEST("Surround Pin Mode", 0x15),
2420         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
2421         PIN_CTL_TEST("Side Pin Mode", 0x17),
2422         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
2423         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
2424         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
2425         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
2426         PIN_SRC_TEST("In-1 Pin Source", 0x18),
2427         PIN_SRC_TEST("In-2 Pin Source", 0x19),
2428         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
2429         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
2430         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
2431         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
2432         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
2433         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
2434         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
2435         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
2436         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
2437         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
2438         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
2439         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
2440         {
2441                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2442                 .name = "Channel Mode",
2443                 .info = alc_ch_mode_info,
2444                 .get = alc_ch_mode_get,
2445                 .put = alc_ch_mode_put,
2446         },
2447         { } /* end */
2448 };
2449
2450 static struct hda_verb alc880_test_init_verbs[] = {
2451         /* Unmute inputs of 0x0c - 0x0f */
2452         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2453         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2454         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2455         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2456         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2457         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2458         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2459         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2460         /* Vol output for 0x0c-0x0f */
2461         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2462         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2463         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2464         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2465         /* Set output pins 0x14-0x17 */
2466         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2467         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2468         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2469         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2470         /* Unmute output pins 0x14-0x17 */
2471         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2472         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2473         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2474         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2475         /* Set input pins 0x18-0x1c */
2476         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2477         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2478         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2479         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2480         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2481         /* Mute input pins 0x18-0x1b */
2482         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2483         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2484         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2485         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2486         /* ADC set up */
2487         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2488         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2489         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2490         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2491         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2492         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2493         /* Analog input/passthru */
2494         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2495         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2496         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2497         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2498         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2499         { }
2500 };
2501 #endif
2502
2503 /*
2504  */
2505
2506 static const char *alc880_models[ALC880_MODEL_LAST] = {
2507         [ALC880_3ST]            = "3stack",
2508         [ALC880_TCL_S700]       = "tcl",
2509         [ALC880_3ST_DIG]        = "3stack-digout",
2510         [ALC880_CLEVO]          = "clevo",
2511         [ALC880_5ST]            = "5stack",
2512         [ALC880_5ST_DIG]        = "5stack-digout",
2513         [ALC880_W810]           = "w810",
2514         [ALC880_Z71V]           = "z71v",
2515         [ALC880_6ST]            = "6stack",
2516         [ALC880_6ST_DIG]        = "6stack-digout",
2517         [ALC880_ASUS]           = "asus",
2518         [ALC880_ASUS_W1V]       = "asus-w1v",
2519         [ALC880_ASUS_DIG]       = "asus-dig",
2520         [ALC880_ASUS_DIG2]      = "asus-dig2",
2521         [ALC880_UNIWILL_DIG]    = "uniwill",
2522         [ALC880_UNIWILL_P53]    = "uniwill-p53",
2523         [ALC880_FUJITSU]        = "fujitsu",
2524         [ALC880_F1734]          = "F1734",
2525         [ALC880_LG]             = "lg",
2526         [ALC880_LG_LW]          = "lg-lw",
2527 #ifdef CONFIG_SND_DEBUG
2528         [ALC880_TEST]           = "test",
2529 #endif
2530         [ALC880_AUTO]           = "auto",
2531 };
2532
2533 static struct snd_pci_quirk alc880_cfg_tbl[] = {
2534         /* Broken BIOS configuration */
2535         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG),
2536         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
2537
2538         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
2539         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
2540         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
2541         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
2542         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
2543         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
2544         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
2545         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
2546         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
2547
2548         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
2549         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
2550
2551         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
2552         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
2553         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
2554         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
2555         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
2556         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
2557         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
2558         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
2559         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
2560         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
2561         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS", ALC880_ASUS),
2562         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
2563         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
2564         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
2565         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS),
2566
2567         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
2568         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
2569         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
2570         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
2571         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
2572         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
2573         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
2574         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
2575         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
2576         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
2577         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
2578         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
2579         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
2580         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
2581         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
2582         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
2583         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
2584         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
2585
2586         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
2587         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
2588         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
2589         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
2590
2591         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
2592         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
2593         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
2594         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
2595
2596         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
2597         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
2598         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
2599         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
2600
2601         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
2602         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
2603         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
2604         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
2605         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
2606         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
2607         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
2608         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
2609         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
2610         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
2611         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST),
2612
2613         {}
2614 };
2615
2616 /*
2617  * ALC880 codec presets
2618  */
2619 static struct alc_config_preset alc880_presets[] = {
2620         [ALC880_3ST] = {
2621                 .mixers = { alc880_three_stack_mixer },
2622                 .init_verbs = { alc880_volume_init_verbs,
2623                                 alc880_pin_3stack_init_verbs },
2624                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2625                 .dac_nids = alc880_dac_nids,
2626                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2627                 .channel_mode = alc880_threestack_modes,
2628                 .need_dac_fix = 1,
2629                 .input_mux = &alc880_capture_source,
2630         },
2631         [ALC880_3ST_DIG] = {
2632                 .mixers = { alc880_three_stack_mixer },
2633                 .init_verbs = { alc880_volume_init_verbs,
2634                                 alc880_pin_3stack_init_verbs },
2635                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2636                 .dac_nids = alc880_dac_nids,
2637                 .dig_out_nid = ALC880_DIGOUT_NID,
2638                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2639                 .channel_mode = alc880_threestack_modes,
2640                 .need_dac_fix = 1,
2641                 .input_mux = &alc880_capture_source,
2642         },
2643         [ALC880_TCL_S700] = {
2644                 .mixers = { alc880_tcl_s700_mixer },
2645                 .init_verbs = { alc880_volume_init_verbs,
2646                                 alc880_pin_tcl_S700_init_verbs,
2647                                 alc880_gpio2_init_verbs },
2648                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2649                 .dac_nids = alc880_dac_nids,
2650                 .hp_nid = 0x03,
2651                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2652                 .channel_mode = alc880_2_jack_modes,
2653                 .input_mux = &alc880_capture_source,
2654         },
2655         [ALC880_5ST] = {
2656                 .mixers = { alc880_three_stack_mixer,
2657                             alc880_five_stack_mixer},
2658                 .init_verbs = { alc880_volume_init_verbs,
2659                                 alc880_pin_5stack_init_verbs },
2660                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2661                 .dac_nids = alc880_dac_nids,
2662                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
2663                 .channel_mode = alc880_fivestack_modes,
2664                 .input_mux = &alc880_capture_source,
2665         },
2666         [ALC880_5ST_DIG] = {
2667                 .mixers = { alc880_three_stack_mixer,
2668                             alc880_five_stack_mixer },
2669                 .init_verbs = { alc880_volume_init_verbs,
2670                                 alc880_pin_5stack_init_verbs },
2671                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2672                 .dac_nids = alc880_dac_nids,
2673                 .dig_out_nid = ALC880_DIGOUT_NID,
2674                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
2675                 .channel_mode = alc880_fivestack_modes,
2676                 .input_mux = &alc880_capture_source,
2677         },
2678         [ALC880_6ST] = {
2679                 .mixers = { alc880_six_stack_mixer },
2680                 .init_verbs = { alc880_volume_init_verbs,
2681                                 alc880_pin_6stack_init_verbs },
2682                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
2683                 .dac_nids = alc880_6st_dac_nids,
2684                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
2685                 .channel_mode = alc880_sixstack_modes,
2686                 .input_mux = &alc880_6stack_capture_source,
2687         },
2688         [ALC880_6ST_DIG] = {
2689                 .mixers = { alc880_six_stack_mixer },
2690                 .init_verbs = { alc880_volume_init_verbs,
2691                                 alc880_pin_6stack_init_verbs },
2692                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
2693                 .dac_nids = alc880_6st_dac_nids,
2694                 .dig_out_nid = ALC880_DIGOUT_NID,
2695                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
2696                 .channel_mode = alc880_sixstack_modes,
2697                 .input_mux = &alc880_6stack_capture_source,
2698         },
2699         [ALC880_W810] = {
2700                 .mixers = { alc880_w810_base_mixer },
2701                 .init_verbs = { alc880_volume_init_verbs,
2702                                 alc880_pin_w810_init_verbs,
2703                                 alc880_gpio2_init_verbs },
2704                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
2705                 .dac_nids = alc880_w810_dac_nids,
2706                 .dig_out_nid = ALC880_DIGOUT_NID,
2707                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
2708                 .channel_mode = alc880_w810_modes,
2709                 .input_mux = &alc880_capture_source,
2710         },
2711         [ALC880_Z71V] = {
2712                 .mixers = { alc880_z71v_mixer },
2713                 .init_verbs = { alc880_volume_init_verbs,
2714                                 alc880_pin_z71v_init_verbs },
2715                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
2716                 .dac_nids = alc880_z71v_dac_nids,
2717                 .dig_out_nid = ALC880_DIGOUT_NID,
2718                 .hp_nid = 0x03,
2719                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2720                 .channel_mode = alc880_2_jack_modes,
2721                 .input_mux = &alc880_capture_source,
2722         },
2723         [ALC880_F1734] = {
2724                 .mixers = { alc880_f1734_mixer },
2725                 .init_verbs = { alc880_volume_init_verbs,
2726                                 alc880_pin_f1734_init_verbs },
2727                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
2728                 .dac_nids = alc880_f1734_dac_nids,
2729                 .hp_nid = 0x02,
2730                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2731                 .channel_mode = alc880_2_jack_modes,
2732                 .input_mux = &alc880_capture_source,
2733         },
2734         [ALC880_ASUS] = {
2735                 .mixers = { alc880_asus_mixer },
2736                 .init_verbs = { alc880_volume_init_verbs,
2737                                 alc880_pin_asus_init_verbs,
2738                                 alc880_gpio1_init_verbs },
2739                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2740                 .dac_nids = alc880_asus_dac_nids,
2741                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2742                 .channel_mode = alc880_asus_modes,
2743                 .need_dac_fix = 1,
2744                 .input_mux = &alc880_capture_source,
2745         },
2746         [ALC880_ASUS_DIG] = {
2747                 .mixers = { alc880_asus_mixer },
2748                 .init_verbs = { alc880_volume_init_verbs,
2749                                 alc880_pin_asus_init_verbs,
2750                                 alc880_gpio1_init_verbs },
2751                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2752                 .dac_nids = alc880_asus_dac_nids,
2753                 .dig_out_nid = ALC880_DIGOUT_NID,
2754                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2755                 .channel_mode = alc880_asus_modes,
2756                 .need_dac_fix = 1,
2757                 .input_mux = &alc880_capture_source,
2758         },
2759         [ALC880_ASUS_DIG2] = {
2760                 .mixers = { alc880_asus_mixer },
2761                 .init_verbs = { alc880_volume_init_verbs,
2762                                 alc880_pin_asus_init_verbs,
2763                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
2764                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2765                 .dac_nids = alc880_asus_dac_nids,
2766                 .dig_out_nid = ALC880_DIGOUT_NID,
2767                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2768                 .channel_mode = alc880_asus_modes,
2769                 .need_dac_fix = 1,
2770                 .input_mux = &alc880_capture_source,
2771         },
2772         [ALC880_ASUS_W1V] = {
2773                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
2774                 .init_verbs = { alc880_volume_init_verbs,
2775                                 alc880_pin_asus_init_verbs,
2776                                 alc880_gpio1_init_verbs },
2777                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2778                 .dac_nids = alc880_asus_dac_nids,
2779                 .dig_out_nid = ALC880_DIGOUT_NID,
2780                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2781                 .channel_mode = alc880_asus_modes,
2782                 .need_dac_fix = 1,
2783                 .input_mux = &alc880_capture_source,
2784         },
2785         [ALC880_UNIWILL_DIG] = {
2786                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
2787                 .init_verbs = { alc880_volume_init_verbs,
2788                                 alc880_pin_asus_init_verbs },
2789                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2790                 .dac_nids = alc880_asus_dac_nids,
2791                 .dig_out_nid = ALC880_DIGOUT_NID,
2792                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
2793                 .channel_mode = alc880_asus_modes,
2794                 .need_dac_fix = 1,
2795                 .input_mux = &alc880_capture_source,
2796         },
2797         [ALC880_UNIWILL] = {
2798                 .mixers = { alc880_uniwill_mixer },
2799                 .init_verbs = { alc880_volume_init_verbs,
2800                                 alc880_uniwill_init_verbs },
2801                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2802                 .dac_nids = alc880_asus_dac_nids,
2803                 .dig_out_nid = ALC880_DIGOUT_NID,
2804                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2805                 .channel_mode = alc880_threestack_modes,
2806                 .need_dac_fix = 1,
2807                 .input_mux = &alc880_capture_source,
2808                 .unsol_event = alc880_uniwill_unsol_event,
2809                 .init_hook = alc880_uniwill_automute,
2810         },
2811         [ALC880_UNIWILL_P53] = {
2812                 .mixers = { alc880_uniwill_p53_mixer },
2813                 .init_verbs = { alc880_volume_init_verbs,
2814                                 alc880_uniwill_p53_init_verbs },
2815                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
2816                 .dac_nids = alc880_asus_dac_nids,
2817                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
2818                 .channel_mode = alc880_threestack_modes,
2819                 .input_mux = &alc880_capture_source,
2820                 .unsol_event = alc880_uniwill_p53_unsol_event,
2821                 .init_hook = alc880_uniwill_p53_hp_automute,
2822         },
2823         [ALC880_FUJITSU] = {
2824                 .mixers = { alc880_fujitsu_mixer,
2825                             alc880_pcbeep_mixer, },
2826                 .init_verbs = { alc880_volume_init_verbs,
2827                                 alc880_uniwill_p53_init_verbs,
2828                                 alc880_beep_init_verbs },
2829                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2830                 .dac_nids = alc880_dac_nids,
2831                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2832                 .channel_mode = alc880_2_jack_modes,
2833                 .input_mux = &alc880_capture_source,
2834                 .unsol_event = alc880_uniwill_p53_unsol_event,
2835                 .init_hook = alc880_uniwill_p53_hp_automute,
2836         },
2837         [ALC880_CLEVO] = {
2838                 .mixers = { alc880_three_stack_mixer },
2839                 .init_verbs = { alc880_volume_init_verbs,
2840                                 alc880_pin_clevo_init_verbs },
2841                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
2842                 .dac_nids = alc880_dac_nids,
2843                 .hp_nid = 0x03,
2844                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
2845                 .channel_mode = alc880_threestack_modes,
2846                 .need_dac_fix = 1,
2847                 .input_mux = &alc880_capture_source,
2848         },
2849         [ALC880_LG] = {
2850                 .mixers = { alc880_lg_mixer },
2851                 .init_verbs = { alc880_volume_init_verbs,
2852                                 alc880_lg_init_verbs },
2853                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
2854                 .dac_nids = alc880_lg_dac_nids,
2855                 .dig_out_nid = ALC880_DIGOUT_NID,
2856                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
2857                 .channel_mode = alc880_lg_ch_modes,
2858                 .need_dac_fix = 1,
2859                 .input_mux = &alc880_lg_capture_source,
2860                 .unsol_event = alc880_lg_unsol_event,
2861                 .init_hook = alc880_lg_automute,
2862         },
2863         [ALC880_LG_LW] = {
2864                 .mixers = { alc880_lg_lw_mixer },
2865                 .init_verbs = { alc880_volume_init_verbs,
2866                                 alc880_lg_lw_init_verbs },
2867                 .num_dacs = 1,
2868                 .dac_nids = alc880_dac_nids,
2869                 .dig_out_nid = ALC880_DIGOUT_NID,
2870                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
2871                 .channel_mode = alc880_2_jack_modes,
2872                 .input_mux = &alc880_lg_lw_capture_source,
2873                 .unsol_event = alc880_lg_lw_unsol_event,
2874                 .init_hook = alc880_lg_lw_automute,
2875         },
2876 #ifdef CONFIG_SND_DEBUG
2877         [ALC880_TEST] = {
2878                 .mixers = { alc880_test_mixer },
2879                 .init_verbs = { alc880_test_init_verbs },
2880                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
2881                 .dac_nids = alc880_test_dac_nids,
2882                 .dig_out_nid = ALC880_DIGOUT_NID,
2883                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
2884                 .channel_mode = alc880_test_modes,
2885                 .input_mux = &alc880_test_capture_source,
2886         },
2887 #endif
2888 };
2889
2890 /*
2891  * Automatic parse of I/O pins from the BIOS configuration
2892  */
2893
2894 #define NUM_CONTROL_ALLOC       32
2895 #define NUM_VERB_ALLOC          32
2896
2897 enum {
2898         ALC_CTL_WIDGET_VOL,
2899         ALC_CTL_WIDGET_MUTE,
2900         ALC_CTL_BIND_MUTE,
2901 };
2902 static struct snd_kcontrol_new alc880_control_templates[] = {
2903         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2904         HDA_CODEC_MUTE(NULL, 0, 0, 0),
2905         HDA_BIND_MUTE(NULL, 0, 0, 0),
2906 };
2907
2908 /* add dynamic controls */
2909 static int add_control(struct alc_spec *spec, int type, const char *name,
2910                        unsigned long val)
2911 {
2912         struct snd_kcontrol_new *knew;
2913
2914         if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2915                 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2916
2917                 /* array + terminator */
2918                 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL);
2919                 if (!knew)
2920                         return -ENOMEM;
2921                 if (spec->kctl_alloc) {
2922                         memcpy(knew, spec->kctl_alloc,
2923                                sizeof(*knew) * spec->num_kctl_alloc);
2924                         kfree(spec->kctl_alloc);
2925                 }
2926                 spec->kctl_alloc = knew;
2927                 spec->num_kctl_alloc = num;
2928         }
2929
2930         knew = &spec->kctl_alloc[spec->num_kctl_used];
2931         *knew = alc880_control_templates[type];
2932         knew->name = kstrdup(name, GFP_KERNEL);
2933         if (!knew->name)
2934                 return -ENOMEM;
2935         knew->private_value = val;
2936         spec->num_kctl_used++;
2937         return 0;
2938 }
2939
2940 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
2941 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
2942 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
2943 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
2944 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
2945 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
2946 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
2947 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
2948 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
2949 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
2950 #define ALC880_PIN_CD_NID               0x1c
2951
2952 /* fill in the dac_nids table from the parsed pin configuration */
2953 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
2954                                      const struct auto_pin_cfg *cfg)
2955 {
2956         hda_nid_t nid;
2957         int assigned[4];
2958         int i, j;
2959
2960         memset(assigned, 0, sizeof(assigned));
2961         spec->multiout.dac_nids = spec->private_dac_nids;
2962
2963         /* check the pins hardwired to audio widget */
2964         for (i = 0; i < cfg->line_outs; i++) {
2965                 nid = cfg->line_out_pins[i];
2966                 if (alc880_is_fixed_pin(nid)) {
2967                         int idx = alc880_fixed_pin_idx(nid);
2968                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
2969                         assigned[idx] = 1;
2970                 }
2971         }
2972         /* left pins can be connect to any audio widget */
2973         for (i = 0; i < cfg->line_outs; i++) {
2974                 nid = cfg->line_out_pins[i];
2975                 if (alc880_is_fixed_pin(nid))
2976                         continue;
2977                 /* search for an empty channel */
2978                 for (j = 0; j < cfg->line_outs; j++) {
2979                         if (!assigned[j]) {
2980                                 spec->multiout.dac_nids[i] =
2981                                         alc880_idx_to_dac(j);
2982                                 assigned[j] = 1;
2983                                 break;
2984                         }
2985                 }
2986         }
2987         spec->multiout.num_dacs = cfg->line_outs;
2988         return 0;
2989 }
2990
2991 /* add playback controls from the parsed DAC table */
2992 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
2993                                              const struct auto_pin_cfg *cfg)
2994 {
2995         char name[32];
2996         static const char *chname[4] = {
2997                 "Front", "Surround", NULL /*CLFE*/, "Side"
2998         };
2999         hda_nid_t nid;
3000         int i, err;
3001
3002         for (i = 0; i < cfg->line_outs; i++) {
3003                 if (!spec->multiout.dac_nids[i])
3004                         continue;
3005                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
3006                 if (i == 2) {
3007                         /* Center/LFE */
3008                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3009                                           "Center Playback Volume",
3010                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
3011                                                               HDA_OUTPUT));
3012                         if (err < 0)
3013                                 return err;
3014                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
3015                                           "LFE Playback Volume",
3016                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
3017                                                               HDA_OUTPUT));
3018                         if (err < 0)
3019                                 return err;
3020                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3021                                           "Center Playback Switch",
3022                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
3023                                                               HDA_INPUT));
3024                         if (err < 0)
3025                                 return err;
3026                         err = add_control(spec, ALC_CTL_BIND_MUTE,
3027                                           "LFE Playback Switch",
3028                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
3029                                                               HDA_INPUT));
3030                         if (err < 0)
3031                                 return err;
3032                 } else {
3033                         sprintf(name, "%s Playback Volume", chname[i]);
3034                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3035                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3036                                                               HDA_OUTPUT));
3037                         if (err < 0)
3038                                 return err;
3039                         sprintf(name, "%s Playback Switch", chname[i]);
3040                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3041                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
3042                                                               HDA_INPUT));
3043                         if (err < 0)
3044                                 return err;
3045                 }
3046         }
3047         return 0;
3048 }
3049
3050 /* add playback controls for speaker and HP outputs */
3051 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
3052                                         const char *pfx)
3053 {
3054         hda_nid_t nid;
3055         int err;
3056         char name[32];
3057
3058         if (!pin)
3059                 return 0;
3060
3061         if (alc880_is_fixed_pin(pin)) {
3062                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
3063                 /* specify the DAC as the extra output */
3064                 if (!spec->multiout.hp_nid)
3065                         spec->multiout.hp_nid = nid;
3066                 else
3067                         spec->multiout.extra_out_nid[0] = nid;
3068                 /* control HP volume/switch on the output mixer amp */
3069                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
3070                 sprintf(name, "%s Playback Volume", pfx);
3071                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3072                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3073                 if (err < 0)
3074                         return err;
3075                 sprintf(name, "%s Playback Switch", pfx);
3076                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
3077                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
3078                 if (err < 0)
3079                         return err;
3080         } else if (alc880_is_multi_pin(pin)) {
3081                 /* set manual connection */
3082                 /* we have only a switch on HP-out PIN */
3083                 sprintf(name, "%s Playback Switch", pfx);
3084                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3085                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3086                 if (err < 0)
3087                         return err;
3088         }
3089         return 0;
3090 }
3091
3092 /* create input playback/capture controls for the given pin */
3093 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
3094                             const char *ctlname,
3095                             int idx, hda_nid_t mix_nid)
3096 {
3097         char name[32];
3098         int err;
3099
3100         sprintf(name, "%s Playback Volume", ctlname);
3101         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
3102                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3103         if (err < 0)
3104                 return err;
3105         sprintf(name, "%s Playback Switch", ctlname);
3106         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
3107                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
3108         if (err < 0)
3109                 return err;
3110         return 0;
3111 }
3112
3113 /* create playback/capture controls for input pins */
3114 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3115                                                 const struct auto_pin_cfg *cfg)
3116 {
3117         struct hda_input_mux *imux = &spec->private_imux;
3118         int i, err, idx;
3119
3120         for (i = 0; i < AUTO_PIN_LAST; i++) {
3121                 if (alc880_is_input_pin(cfg->input_pins[i])) {
3122                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
3123                         err = new_analog_input(spec, cfg->input_pins[i],
3124                                                auto_pin_cfg_labels[i],
3125                                                idx, 0x0b);
3126                         if (err < 0)
3127                                 return err;
3128                         imux->items[imux->num_items].label =
3129                                 auto_pin_cfg_labels[i];
3130                         imux->items[imux->num_items].index =
3131                                 alc880_input_pin_idx(cfg->input_pins[i]);
3132                         imux->num_items++;
3133                 }
3134         }
3135         return 0;
3136 }
3137
3138 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3139                                               hda_nid_t nid, int pin_type,
3140                                               int dac_idx)
3141 {
3142         /* set as output */
3143         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3144                             pin_type);
3145         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3146                             AMP_OUT_UNMUTE);
3147         /* need the manual connection? */
3148         if (alc880_is_multi_pin(nid)) {
3149                 struct alc_spec *spec = codec->spec;
3150                 int idx = alc880_multi_pin_idx(nid);
3151                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
3152                                     AC_VERB_SET_CONNECT_SEL,
3153                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
3154         }
3155 }
3156
3157 static int get_pin_type(int line_out_type)
3158 {
3159         if (line_out_type == AUTO_PIN_HP_OUT)
3160                 return PIN_HP;
3161         else
3162                 return PIN_OUT;
3163 }
3164
3165 static void alc880_auto_init_multi_out(struct hda_codec *codec)
3166 {
3167         struct alc_spec *spec = codec->spec;
3168         int i;
3169         
3170         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
3171         for (i = 0; i < spec->autocfg.line_outs; i++) {
3172                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3173                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
3174                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
3175         }
3176 }
3177
3178 static void alc880_auto_init_extra_out(struct hda_codec *codec)
3179 {
3180         struct alc_spec *spec = codec->spec;
3181         hda_nid_t pin;
3182
3183         pin = spec->autocfg.speaker_pins[0];
3184         if (pin) /* connect to front */
3185                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
3186         pin = spec->autocfg.hp_pins[0];
3187         if (pin) /* connect to front */
3188                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
3189 }
3190
3191 static void alc880_auto_init_analog_input(struct hda_codec *codec)
3192 {
3193         struct alc_spec *spec = codec->spec;
3194         int i;
3195
3196         for (i = 0; i < AUTO_PIN_LAST; i++) {
3197                 hda_nid_t nid = spec->autocfg.input_pins[i];
3198                 if (alc880_is_input_pin(nid)) {
3199                         snd_hda_codec_write(codec, nid, 0,
3200                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
3201                                             i <= AUTO_PIN_FRONT_MIC ?
3202                                             PIN_VREF80 : PIN_IN);
3203                         if (nid != ALC880_PIN_CD_NID)
3204                                 snd_hda_codec_write(codec, nid, 0,
3205                                                     AC_VERB_SET_AMP_GAIN_MUTE,
3206                                                     AMP_OUT_MUTE);
3207                 }
3208         }
3209 }
3210
3211 /* parse the BIOS configuration and set up the alc_spec */
3212 /* return 1 if successful, 0 if the proper config is not found,
3213  * or a negative error code
3214  */
3215 static int alc880_parse_auto_config(struct hda_codec *codec)
3216 {
3217         struct alc_spec *spec = codec->spec;
3218         int err;
3219         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3220
3221         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
3222                                            alc880_ignore);
3223         if (err < 0)
3224                 return err;
3225         if (!spec->autocfg.line_outs)
3226                 return 0; /* can't find valid BIOS pin config */
3227
3228         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
3229         if (err < 0)
3230                 return err;
3231         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
3232         if (err < 0)
3233                 return err;
3234         err = alc880_auto_create_extra_out(spec,
3235                                            spec->autocfg.speaker_pins[0],
3236                                            "Speaker");
3237         if (err < 0)
3238                 return err;
3239         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
3240                                            "Headphone");
3241         if (err < 0)
3242                 return err;
3243         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
3244         if (err < 0)
3245                 return err;
3246
3247         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3248
3249         if (spec->autocfg.dig_out_pin)
3250                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
3251         if (spec->autocfg.dig_in_pin)
3252                 spec->dig_in_nid = ALC880_DIGIN_NID;
3253
3254         if (spec->kctl_alloc)
3255                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
3256
3257         spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
3258
3259         spec->num_mux_defs = 1;
3260         spec->input_mux = &spec->private_imux;
3261
3262         return 1;
3263 }
3264
3265 /* additional initialization for auto-configuration model */
3266 static void alc880_auto_init(struct hda_codec *codec)
3267 {
3268         alc880_auto_init_multi_out(codec);
3269         alc880_auto_init_extra_out(codec);
3270         alc880_auto_init_analog_input(codec);
3271 }
3272
3273 /*
3274  * OK, here we have finally the patch for ALC880
3275  */
3276
3277 static int patch_alc880(struct hda_codec *codec)
3278 {
3279         struct alc_spec *spec;
3280         int board_config;
3281         int err;
3282
3283         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3284         if (spec == NULL)
3285                 return -ENOMEM;
3286
3287         codec->spec = spec;
3288
3289         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
3290                                                   alc880_models,
3291                                                   alc880_cfg_tbl);
3292         if (board_config < 0) {
3293                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
3294                        "trying auto-probe from BIOS...\n");
3295                 board_config = ALC880_AUTO;
3296         }
3297
3298         if (board_config == ALC880_AUTO) {
3299                 /* automatic parse from the BIOS config */
3300                 err = alc880_parse_auto_config(codec);
3301                 if (err < 0) {
3302                         alc_free(codec);
3303                         return err;
3304                 } else if (!err) {
3305                         printk(KERN_INFO
3306                                "hda_codec: Cannot set up configuration "
3307                                "from BIOS.  Using 3-stack mode...\n");
3308                         board_config = ALC880_3ST;
3309                 }
3310         }
3311
3312         if (board_config != ALC880_AUTO)
3313                 setup_preset(spec, &alc880_presets[board_config]);
3314
3315         spec->stream_name_analog = "ALC880 Analog";
3316         spec->stream_analog_playback = &alc880_pcm_analog_playback;
3317         spec->stream_analog_capture = &alc880_pcm_analog_capture;
3318
3319         spec->stream_name_digital = "ALC880 Digital";
3320         spec->stream_digital_playback = &alc880_pcm_digital_playback;
3321         spec->stream_digital_capture = &alc880_pcm_digital_capture;
3322
3323         if (!spec->adc_nids && spec->input_mux) {
3324                 /* check whether NID 0x07 is valid */
3325                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
3326                 /* get type */
3327                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3328                 if (wcap != AC_WID_AUD_IN) {
3329                         spec->adc_nids = alc880_adc_nids_alt;
3330                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
3331                         spec->mixers[spec->num_mixers] =
3332                                 alc880_capture_alt_mixer;
3333                         spec->num_mixers++;
3334                 } else {
3335                         spec->adc_nids = alc880_adc_nids;
3336                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
3337                         spec->mixers[spec->num_mixers] = alc880_capture_mixer;
3338                         spec->num_mixers++;
3339                 }
3340         }
3341
3342         codec->patch_ops = alc_patch_ops;
3343         if (board_config == ALC880_AUTO)
3344                 spec->init_hook = alc880_auto_init;
3345
3346         return 0;
3347 }
3348
3349
3350 /*
3351  * ALC260 support
3352  */
3353
3354 static hda_nid_t alc260_dac_nids[1] = {
3355         /* front */
3356         0x02,
3357 };
3358
3359 static hda_nid_t alc260_adc_nids[1] = {
3360         /* ADC0 */
3361         0x04,
3362 };
3363
3364 static hda_nid_t alc260_adc_nids_alt[1] = {
3365         /* ADC1 */
3366         0x05,
3367 };
3368
3369 static hda_nid_t alc260_hp_adc_nids[2] = {
3370         /* ADC1, 0 */
3371         0x05, 0x04
3372 };
3373
3374 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
3375  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
3376  */
3377 static hda_nid_t alc260_dual_adc_nids[2] = {
3378         /* ADC0, ADC1 */
3379         0x04, 0x05
3380 };
3381
3382 #define ALC260_DIGOUT_NID       0x03
3383 #define ALC260_DIGIN_NID        0x06
3384
3385 static struct hda_input_mux alc260_capture_source = {
3386         .num_items = 4,
3387         .items = {
3388                 { "Mic", 0x0 },
3389                 { "Front Mic", 0x1 },
3390                 { "Line", 0x2 },
3391                 { "CD", 0x4 },
3392         },
3393 };
3394
3395 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
3396  * headphone jack and the internal CD lines since these are the only pins at
3397  * which audio can appear.  For flexibility, also allow the option of
3398  * recording the mixer output on the second ADC (ADC0 doesn't have a
3399  * connection to the mixer output).
3400  */
3401 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
3402         {
3403                 .num_items = 3,
3404                 .items = {
3405                         { "Mic/Line", 0x0 },
3406                         { "CD", 0x4 },
3407                         { "Headphone", 0x2 },
3408                 },
3409         },
3410         {
3411                 .num_items = 4,
3412                 .items = {
3413                         { "Mic/Line", 0x0 },
3414                         { "CD", 0x4 },
3415                         { "Headphone", 0x2 },
3416                         { "Mixer", 0x5 },
3417                 },
3418         },
3419
3420 };
3421
3422 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
3423  * the Fujitsu S702x, but jacks are marked differently.
3424  */
3425 static struct hda_input_mux alc260_acer_capture_sources[2] = {
3426         {
3427                 .num_items = 4,
3428                 .items = {
3429                         { "Mic", 0x0 },
3430                         { "Line", 0x2 },
3431                         { "CD", 0x4 },
3432                         { "Headphone", 0x5 },
3433                 },
3434         },
3435         {
3436                 .num_items = 5,
3437                 .items = {
3438                         { "Mic", 0x0 },
3439                         { "Line", 0x2 },
3440                         { "CD", 0x4 },
3441                         { "Headphone", 0x6 },
3442                         { "Mixer", 0x5 },
3443                 },
3444         },
3445 };
3446 /*
3447  * This is just place-holder, so there's something for alc_build_pcms to look
3448  * at when it calculates the maximum number of channels. ALC260 has no mixer
3449  * element which allows changing the channel mode, so the verb list is
3450  * never used.
3451  */
3452 static struct hda_channel_mode alc260_modes[1] = {
3453         { 2, NULL },
3454 };
3455
3456
3457 /* Mixer combinations
3458  *
3459  * basic: base_output + input + pc_beep + capture
3460  * HP: base_output + input + capture_alt
3461  * HP_3013: hp_3013 + input + capture
3462  * fujitsu: fujitsu + capture
3463  * acer: acer + capture
3464  */
3465
3466 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
3467         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3468         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
3469         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3470         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
3471         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3472         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
3473         { } /* end */
3474 };
3475
3476 static struct snd_kcontrol_new alc260_input_mixer[] = {
3477         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3478         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3479         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3480         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3481         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3482         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3483         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
3484         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
3485         { } /* end */
3486 };
3487
3488 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
3489         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
3490         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
3491         { } /* end */
3492 };
3493
3494 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
3495         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3496         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
3497         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
3498         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
3499         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3500         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
3501         HDA_CODEC_VOLUME_MONO("iSpeaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
3502         HDA_CODEC_MUTE_MONO("iSpeaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
3503         { } /* end */
3504 };
3505
3506 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12, 
3507  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
3508  */
3509 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
3510         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3511         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
3512         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3513         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3514         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3515         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
3516         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
3517         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
3518         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3519         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3520         HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
3521         HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x09, 2, HDA_INPUT),
3522         { } /* end */
3523 };
3524
3525 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
3526  * versions of the ALC260 don't act on requests to enable mic bias from NID
3527  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
3528  * datasheet doesn't mention this restriction.  At this stage it's not clear
3529  * whether this behaviour is intentional or is a hardware bug in chip
3530  * revisions available in early 2006.  Therefore for now allow the
3531  * "Headphone Jack Mode" control to span all choices, but if it turns out
3532  * that the lack of mic bias for this NID is intentional we could change the
3533  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
3534  *
3535  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
3536  * don't appear to make the mic bias available from the "line" jack, even
3537  * though the NID used for this jack (0x14) can supply it.  The theory is
3538  * that perhaps Acer have included blocking capacitors between the ALC260
3539  * and the output jack.  If this turns out to be the case for all such
3540  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
3541  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
3542  *
3543  * The C20x Tablet series have a mono internal speaker which is controlled
3544  * via the chip's Mono sum widget and pin complex, so include the necessary
3545  * controls for such models.  On models without a "mono speaker" the control
3546  * won't do anything.
3547  */
3548 static struct snd_kcontrol_new alc260_acer_mixer[] = {
3549         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3550         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
3551         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
3552         HDA_CODEC_VOLUME_MONO("Mono Speaker Playback Volume", 0x0a, 1, 0x0,
3553                               HDA_OUTPUT),
3554         HDA_BIND_MUTE_MONO("Mono Speaker Playback Switch", 0x0a, 1, 2,
3555                            HDA_INPUT),
3556         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3557         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3558         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3559         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3560         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3561         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3562         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3563         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3564         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3565         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3566         { } /* end */
3567 };
3568
3569 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
3570  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
3571  */
3572 static struct snd_kcontrol_new alc260_will_mixer[] = {
3573         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3574         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
3575         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3576         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3577         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3578         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3579         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3580         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3581         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
3582         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
3583         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
3584         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
3585         { } /* end */
3586 };
3587
3588 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
3589  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
3590  */
3591 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
3592         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
3593         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
3594         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
3595         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
3596         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
3597         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
3598         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
3599         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
3600         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
3601         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
3602         { } /* end */
3603 };
3604
3605 /* capture mixer elements */
3606 static struct snd_kcontrol_new alc260_capture_mixer[] = {
3607         HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
3608         HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
3609         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
3610         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),
3611         {
3612                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3613                 /* The multiple "Capture Source" controls confuse alsamixer
3614                  * So call somewhat different..
3615                  * FIXME: the controls appear in the "playback" view!
3616                  */
3617                 /* .name = "Capture Source", */
3618                 .name = "Input Source",
3619                 .count = 2,
3620                 .info = alc_mux_enum_info,
3621                 .get = alc_mux_enum_get,
3622                 .put = alc_mux_enum_put,
3623         },
3624         { } /* end */
3625 };
3626
3627 static struct snd_kcontrol_new alc260_capture_alt_mixer[] = {
3628         HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
3629         HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
3630         {
3631                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3632                 /* The multiple "Capture Source" controls confuse alsamixer
3633                  * So call somewhat different..
3634                  * FIXME: the controls appear in the "playback" view!
3635                  */
3636                 /* .name = "Capture Source", */
3637                 .name = "Input Source",
3638                 .count = 1,
3639                 .info = alc_mux_enum_info,
3640                 .get = alc_mux_enum_get,
3641                 .put = alc_mux_enum_put,
3642         },
3643         { } /* end */
3644 };
3645
3646 /*
3647  * initialization verbs
3648  */
3649 static struct hda_verb alc260_init_verbs[] = {
3650         /* Line In pin widget for input */
3651         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3652         /* CD pin widget for input */
3653         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3654         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3655         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3656         /* Mic2 (front panel) pin widget for input and vref at 80% */
3657         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3658         /* LINE-2 is used for line-out in rear */
3659         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3660         /* select line-out */
3661         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
3662         /* LINE-OUT pin */
3663         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3664         /* enable HP */
3665         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3666         /* enable Mono */
3667         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3668         /* mute capture amp left and right */
3669         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3670         /* set connection select to line in (default select for this ADC) */
3671         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3672         /* mute capture amp left and right */
3673         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3674         /* set connection select to line in (default select for this ADC) */
3675         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
3676         /* set vol=0 Line-Out mixer amp left and right */
3677         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3678         /* unmute pin widget amp left and right (no gain on this amp) */
3679         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3680         /* set vol=0 HP mixer amp left and right */
3681         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3682         /* unmute pin widget amp left and right (no gain on this amp) */
3683         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3684         /* set vol=0 Mono mixer amp left and right */
3685         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3686         /* unmute pin widget amp left and right (no gain on this amp) */
3687         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3688         /* unmute LINE-2 out pin */
3689         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3690         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
3691          * Line In 2 = 0x03
3692          */
3693         /* mute CD */
3694         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
3695         /* mute Line In */
3696         {0x07,  AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
3697         /* mute Mic */
3698         {0x07,  AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3699         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3700         /* mute Front out path */
3701         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3702         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3703         /* mute Headphone out path */
3704         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3705         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3706         /* mute Mono out path */
3707         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3708         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3709         { }
3710 };
3711
3712 #if 0 /* should be identical with alc260_init_verbs? */
3713 static struct hda_verb alc260_hp_init_verbs[] = {
3714         /* Headphone and output */
3715         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
3716         /* mono output */
3717         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3718         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3719         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3720         /* Mic2 (front panel) pin widget for input and vref at 80% */
3721         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3722         /* Line In pin widget for input */
3723         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3724         /* Line-2 pin widget for output */
3725         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3726         /* CD pin widget for input */
3727         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3728         /* unmute amp left and right */
3729         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
3730         /* set connection select to line in (default select for this ADC) */
3731         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3732         /* unmute Line-Out mixer amp left and right (volume = 0) */
3733         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3734         /* mute pin widget amp left and right (no gain on this amp) */
3735         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3736         /* unmute HP mixer amp left and right (volume = 0) */
3737         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3738         /* mute pin widget amp left and right (no gain on this amp) */
3739         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3740         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
3741          * Line In 2 = 0x03
3742          */
3743         /* unmute CD */
3744         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
3745         /* unmute Line In */
3746         {0x07,  AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
3747         /* unmute Mic */
3748         {0x07,  AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3749         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3750         /* Unmute Front out path */
3751         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3752         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3753         /* Unmute Headphone out path */
3754         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3755         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3756         /* Unmute Mono out path */
3757         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3758         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3759         { }
3760 };
3761 #endif
3762
3763 static struct hda_verb alc260_hp_3013_init_verbs[] = {
3764         /* Line out and output */
3765         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3766         /* mono output */
3767         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
3768         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3769         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3770         /* Mic2 (front panel) pin widget for input and vref at 80% */
3771         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
3772         /* Line In pin widget for input */
3773         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3774         /* Headphone pin widget for output */
3775         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
3776         /* CD pin widget for input */
3777         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
3778         /* unmute amp left and right */
3779         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
3780         /* set connection select to line in (default select for this ADC) */
3781         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
3782         /* unmute Line-Out mixer amp left and right (volume = 0) */
3783         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3784         /* mute pin widget amp left and right (no gain on this amp) */
3785         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3786         /* unmute HP mixer amp left and right (volume = 0) */
3787         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
3788         /* mute pin widget amp left and right (no gain on this amp) */
3789         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
3790         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
3791          * Line In 2 = 0x03
3792          */
3793         /* unmute CD */
3794         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
3795         /* unmute Line In */
3796         {0x07,  AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
3797         /* unmute Mic */
3798         {0x07,  AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3799         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
3800         /* Unmute Front out path */
3801         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3802         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3803         /* Unmute Headphone out path */
3804         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3805         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3806         /* Unmute Mono out path */
3807         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3808         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3809         { }
3810 };
3811
3812 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
3813  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
3814  * audio = 0x16, internal speaker = 0x10.
3815  */
3816 static struct hda_verb alc260_fujitsu_init_verbs[] = {
3817         /* Disable all GPIOs */
3818         {0x01, AC_VERB_SET_GPIO_MASK, 0},
3819         /* Internal speaker is connected to headphone pin */
3820         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3821         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
3822         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3823         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
3824         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3825         /* Ensure all other unused pins are disabled and muted. */
3826         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3827         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3828         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3829         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3830         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3831         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3832         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3833         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3834
3835         /* Disable digital (SPDIF) pins */
3836         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
3837         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
3838
3839         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus 
3840          * when acting as an output.
3841          */
3842         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
3843
3844         /* Start with output sum widgets muted and their output gains at min */
3845         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3846         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3847         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3848         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3849         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3850         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3851         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3852         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3853         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3854
3855         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
3856         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3857         /* Unmute Line1 pin widget output buffer since it starts as an output.
3858          * If the pin mode is changed by the user the pin mode control will
3859          * take care of enabling the pin's input/output buffers as needed.
3860          * Therefore there's no need to enable the input buffer at this
3861          * stage.
3862          */
3863         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3864         /* Unmute input buffer of pin widget used for Line-in (no equiv 
3865          * mixer ctrl)
3866          */
3867         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3868
3869         /* Mute capture amp left and right */
3870         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3871         /* Set ADC connection select to match default mixer setting - line 
3872          * in (on mic1 pin)
3873          */
3874         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
3875
3876         /* Do the same for the second ADC: mute capture input amp and
3877          * set ADC connection to line in (on mic1 pin)
3878          */
3879         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3880         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
3881
3882         /* Mute all inputs to mixer widget (even unconnected ones) */
3883         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
3884         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
3885         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
3886         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
3887         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
3888         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
3889         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
3890         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
3891
3892         { }
3893 };
3894
3895 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
3896  * similar laptops (adapted from Fujitsu init verbs).
3897  */
3898 static struct hda_verb alc260_acer_init_verbs[] = {
3899         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
3900          * the headphone jack.  Turn this on and rely on the standard mute
3901          * methods whenever the user wants to turn these outputs off.
3902          */
3903         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
3904         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
3905         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
3906         /* Internal speaker/Headphone jack is connected to Line-out pin */
3907         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3908         /* Internal microphone/Mic jack is connected to Mic1 pin */
3909         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
3910         /* Line In jack is connected to Line1 pin */
3911         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3912         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
3913         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3914         /* Ensure all other unused pins are disabled and muted. */
3915         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3916         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3917         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3918         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3919         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
3920         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3921         /* Disable digital (SPDIF) pins */
3922         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
3923         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
3924
3925         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum 
3926          * bus when acting as outputs.
3927          */
3928         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
3929         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
3930
3931         /* Start with output sum widgets muted and their output gains at min */
3932         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3933         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3934         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3935         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3936         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3937         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3938         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3939         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3940         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3941
3942         /* Unmute Line-out pin widget amp left and right
3943          * (no equiv mixer ctrl)
3944          */
3945         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3946         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
3947         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3948         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
3949          * inputs. If the pin mode is changed by the user the pin mode control
3950          * will take care of enabling the pin's input/output buffers as needed.
3951          * Therefore there's no need to enable the input buffer at this
3952          * stage.
3953          */
3954         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3955         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3956
3957         /* Mute capture amp left and right */
3958         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3959         /* Set ADC connection select to match default mixer setting - mic
3960          * (on mic1 pin)
3961          */
3962         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
3963
3964         /* Do similar with the second ADC: mute capture input amp and
3965          * set ADC connection to mic to match ALSA's default state.
3966          */
3967         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3968         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
3969
3970         /* Mute all inputs to mixer widget (even unconnected ones) */
3971         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
3972         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
3973         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
3974         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
3975         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
3976         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
3977         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
3978         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
3979
3980         { }
3981 };
3982
3983 static struct hda_verb alc260_will_verbs[] = {
3984         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3985         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
3986         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
3987         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3988         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
3989         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
3990         {}
3991 };
3992
3993 static struct hda_verb alc260_replacer_672v_verbs[] = {
3994         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3995         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
3996         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
3997
3998         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
3999         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4000         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4001
4002         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4003         {}
4004 };
4005
4006 /* toggle speaker-output according to the hp-jack state */
4007 static void alc260_replacer_672v_automute(struct hda_codec *codec)
4008 {
4009         unsigned int present;
4010
4011         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
4012         present = snd_hda_codec_read(codec, 0x0f, 0,
4013                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
4014         if (present) {
4015                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 1);
4016                 snd_hda_codec_write(codec, 0x0f, 0,
4017                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
4018         } else {
4019                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
4020                 snd_hda_codec_write(codec, 0x0f, 0,
4021                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
4022         }
4023 }
4024
4025 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
4026                                        unsigned int res)
4027 {
4028         if ((res >> 26) == ALC880_HP_EVENT)
4029                 alc260_replacer_672v_automute(codec);
4030 }
4031
4032 /* Test configuration for debugging, modelled after the ALC880 test
4033  * configuration.
4034  */
4035 #ifdef CONFIG_SND_DEBUG
4036 static hda_nid_t alc260_test_dac_nids[1] = {
4037         0x02,
4038 };
4039 static hda_nid_t alc260_test_adc_nids[2] = {
4040         0x04, 0x05,
4041 };
4042 /* For testing the ALC260, each input MUX needs its own definition since
4043  * the signal assignments are different.  This assumes that the first ADC 
4044  * is NID 0x04.
4045  */
4046 static struct hda_input_mux alc260_test_capture_sources[2] = {
4047         {
4048                 .num_items = 7,
4049                 .items = {
4050                         { "MIC1 pin", 0x0 },
4051                         { "MIC2 pin", 0x1 },
4052                         { "LINE1 pin", 0x2 },
4053                         { "LINE2 pin", 0x3 },
4054                         { "CD pin", 0x4 },
4055                         { "LINE-OUT pin", 0x5 },
4056                         { "HP-OUT pin", 0x6 },
4057                 },
4058         },
4059         {
4060                 .num_items = 8,
4061                 .items = {
4062                         { "MIC1 pin", 0x0 },
4063                         { "MIC2 pin", 0x1 },
4064                         { "LINE1 pin", 0x2 },
4065                         { "LINE2 pin", 0x3 },
4066                         { "CD pin", 0x4 },
4067                         { "Mixer", 0x5 },
4068                         { "LINE-OUT pin", 0x6 },
4069                         { "HP-OUT pin", 0x7 },
4070                 },
4071         },
4072 };
4073 static struct snd_kcontrol_new alc260_test_mixer[] = {
4074         /* Output driver widgets */
4075         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4076         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4077         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4078         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
4079         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4080         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
4081
4082         /* Modes for retasking pin widgets
4083          * Note: the ALC260 doesn't seem to act on requests to enable mic
4084          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
4085          * mention this restriction.  At this stage it's not clear whether
4086          * this behaviour is intentional or is a hardware bug in chip
4087          * revisions available at least up until early 2006.  Therefore for
4088          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
4089          * choices, but if it turns out that the lack of mic bias for these
4090          * NIDs is intentional we could change their modes from
4091          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4092          */
4093         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
4094         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
4095         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
4096         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
4097         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
4098         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
4099
4100         /* Loopback mixer controls */
4101         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
4102         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
4103         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
4104         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
4105         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
4106         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
4107         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
4108         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
4109         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4110         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4111         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4112         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4113         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
4114         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
4115         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
4116         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
4117
4118         /* Controls for GPIO pins, assuming they are configured as outputs */
4119         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
4120         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
4121         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
4122         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
4123
4124         /* Switches to allow the digital IO pins to be enabled.  The datasheet
4125          * is ambigious as to which NID is which; testing on laptops which
4126          * make this output available should provide clarification. 
4127          */
4128         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
4129         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
4130
4131         { } /* end */
4132 };
4133 static struct hda_verb alc260_test_init_verbs[] = {
4134         /* Enable all GPIOs as outputs with an initial value of 0 */
4135         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
4136         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4137         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
4138
4139         /* Enable retasking pins as output, initially without power amp */
4140         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4141         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4142         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4143         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4144         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4145         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4146
4147         /* Disable digital (SPDIF) pins initially, but users can enable
4148          * them via a mixer switch.  In the case of SPDIF-out, this initverb
4149          * payload also sets the generation to 0, output to be in "consumer"
4150          * PCM format, copyright asserted, no pre-emphasis and no validity
4151          * control.
4152          */
4153         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4154         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
4155
4156         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the 
4157          * OUT1 sum bus when acting as an output.
4158          */
4159         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
4160         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
4161         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
4162         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
4163
4164         /* Start with output sum widgets muted and their output gains at min */
4165         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4166         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4167         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4168         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4169         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4170         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4171         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4172         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4173         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4174
4175         /* Unmute retasking pin widget output buffers since the default
4176          * state appears to be output.  As the pin mode is changed by the
4177          * user the pin mode control will take care of enabling the pin's
4178          * input/output buffers as needed.
4179          */
4180         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4181         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4182         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4183         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4184         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4185         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4186         /* Also unmute the mono-out pin widget */
4187         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4188
4189         /* Mute capture amp left and right */
4190         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4191         /* Set ADC connection select to match default mixer setting (mic1
4192          * pin)
4193          */
4194         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4195
4196         /* Do the same for the second ADC: mute capture input amp and
4197          * set ADC connection to mic1 pin
4198          */
4199         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4200         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4201
4202         /* Mute all inputs to mixer widget (even unconnected ones) */
4203         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
4204         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
4205         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
4206         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
4207         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
4208         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
4209         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
4210         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
4211
4212         { }
4213 };
4214 #endif
4215
4216 static struct hda_pcm_stream alc260_pcm_analog_playback = {
4217         .substreams = 1,
4218         .channels_min = 2,
4219         .channels_max = 2,
4220 };
4221
4222 static struct hda_pcm_stream alc260_pcm_analog_capture = {
4223         .substreams = 1,
4224         .channels_min = 2,
4225         .channels_max = 2,
4226 };
4227
4228 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
4229 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
4230
4231 /*
4232  * for BIOS auto-configuration
4233  */
4234
4235 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
4236                                         const char *pfx)
4237 {
4238         hda_nid_t nid_vol;
4239         unsigned long vol_val, sw_val;
4240         char name[32];
4241         int err;
4242
4243         if (nid >= 0x0f && nid < 0x11) {
4244                 nid_vol = nid - 0x7;
4245                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4246                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4247         } else if (nid == 0x11) {
4248                 nid_vol = nid - 0x7;
4249                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
4250                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
4251         } else if (nid >= 0x12 && nid <= 0x15) {
4252                 nid_vol = 0x08;
4253                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
4254                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
4255         } else
4256                 return 0; /* N/A */
4257         
4258         snprintf(name, sizeof(name), "%s Playback Volume", pfx);
4259         err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
4260         if (err < 0)
4261                 return err;
4262         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
4263         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
4264         if (err < 0)
4265                 return err;
4266         return 1;
4267 }
4268
4269 /* add playback controls from the parsed DAC table */
4270 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
4271                                              const struct auto_pin_cfg *cfg)
4272 {
4273         hda_nid_t nid;
4274         int err;
4275
4276         spec->multiout.num_dacs = 1;
4277         spec->multiout.dac_nids = spec->private_dac_nids;
4278         spec->multiout.dac_nids[0] = 0x02;
4279
4280         nid = cfg->line_out_pins[0];
4281         if (nid) {
4282                 err = alc260_add_playback_controls(spec, nid, "Front");
4283                 if (err < 0)
4284                         return err;
4285         }
4286
4287         nid = cfg->speaker_pins[0];
4288         if (nid) {
4289                 err = alc260_add_playback_controls(spec, nid, "Speaker");
4290                 if (err < 0)
4291                         return err;
4292         }
4293
4294         nid = cfg->hp_pins[0];
4295         if (nid) {
4296                 err = alc260_add_playback_controls(spec, nid, "Headphone");
4297                 if (err < 0)
4298                         return err;
4299         }
4300         return 0;
4301 }
4302
4303 /* create playback/capture controls for input pins */
4304 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
4305                                                 const struct auto_pin_cfg *cfg)
4306 {
4307         struct hda_input_mux *imux = &spec->private_imux;
4308         int i, err, idx;
4309
4310         for (i = 0; i < AUTO_PIN_LAST; i++) {
4311                 if (cfg->input_pins[i] >= 0x12) {
4312                         idx = cfg->input_pins[i] - 0x12;
4313                         err = new_analog_input(spec, cfg->input_pins[i],
4314                                                auto_pin_cfg_labels[i], idx,
4315                                                0x07);
4316                         if (err < 0)
4317                                 return err;
4318                         imux->items[imux->num_items].label =
4319                                 auto_pin_cfg_labels[i];
4320                         imux->items[imux->num_items].index = idx;
4321                         imux->num_items++;
4322                 }
4323                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
4324                         idx = cfg->input_pins[i] - 0x09;
4325                         err = new_analog_input(spec, cfg->input_pins[i],
4326                                                auto_pin_cfg_labels[i], idx,
4327                                                0x07);
4328                         if (err < 0)
4329                                 return err;
4330                         imux->items[imux->num_items].label =
4331                                 auto_pin_cfg_labels[i];
4332                         imux->items[imux->num_items].index = idx;
4333                         imux->num_items++;
4334                 }
4335         }
4336         return 0;
4337 }
4338
4339 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
4340                                               hda_nid_t nid, int pin_type,
4341                                               int sel_idx)
4342 {
4343         /* set as output */
4344         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4345                             pin_type);
4346         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4347                             AMP_OUT_UNMUTE);
4348         /* need the manual connection? */
4349         if (nid >= 0x12) {
4350                 int idx = nid - 0x12;
4351                 snd_hda_codec_write(codec, idx + 0x0b, 0,
4352                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
4353         }
4354 }
4355
4356 static void alc260_auto_init_multi_out(struct hda_codec *codec)
4357 {
4358         struct alc_spec *spec = codec->spec;
4359         hda_nid_t nid;
4360
4361         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
4362         nid = spec->autocfg.line_out_pins[0];
4363         if (nid) {
4364                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4365                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
4366         }
4367         
4368         nid = spec->autocfg.speaker_pins[0];
4369         if (nid)
4370                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
4371
4372         nid = spec->autocfg.hp_pins[0];
4373         if (nid)
4374                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
4375 }
4376
4377 #define ALC260_PIN_CD_NID               0x16
4378 static void alc260_auto_init_analog_input(struct hda_codec *codec)
4379 {
4380         struct alc_spec *spec = codec->spec;
4381         int i;
4382
4383         for (i = 0; i < AUTO_PIN_LAST; i++) {
4384                 hda_nid_t nid = spec->autocfg.input_pins[i];
4385                 if (nid >= 0x12) {
4386                         snd_hda_codec_write(codec, nid, 0,
4387                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
4388                                             i <= AUTO_PIN_FRONT_MIC ?
4389                                             PIN_VREF80 : PIN_IN);
4390                         if (nid != ALC260_PIN_CD_NID)
4391                                 snd_hda_codec_write(codec, nid, 0,
4392                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4393                                                     AMP_OUT_MUTE);
4394                 }
4395         }
4396 }
4397
4398 /*
4399  * generic initialization of ADC, input mixers and output mixers
4400  */
4401 static struct hda_verb alc260_volume_init_verbs[] = {
4402         /*
4403          * Unmute ADC0-1 and set the default input to mic-in
4404          */
4405         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
4406         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4407         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
4408         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4409         
4410         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
4411          * mixer widget
4412          * Note: PASD motherboards uses the Line In 2 as the input for
4413          * front panel mic (mic 2)
4414          */
4415         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
4416         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4417         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4418         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
4419         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
4420         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
4421
4422         /*
4423          * Set up output mixers (0x08 - 0x0a)
4424          */
4425         /* set vol=0 to output mixers */
4426         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4427         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4428         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4429         /* set up input amps for analog loopback */
4430         /* Amp Indices: DAC = 0, mixer = 1 */
4431         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4432         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4433         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4434         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4435         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4436         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4437         
4438         { }
4439 };
4440
4441 static int alc260_parse_auto_config(struct hda_codec *codec)
4442 {
4443         struct alc_spec *spec = codec->spec;
4444         unsigned int wcap;
4445         int err;
4446         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
4447
4448         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4449                                            alc260_ignore);
4450         if (err < 0)
4451                 return err;
4452         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
4453         if (err < 0)
4454                 return err;
4455         if (!spec->kctl_alloc)
4456                 return 0; /* can't find valid BIOS pin config */
4457         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
4458         if (err < 0)
4459                 return err;
4460
4461         spec->multiout.max_channels = 2;
4462
4463         if (spec->autocfg.dig_out_pin)
4464                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
4465         if (spec->kctl_alloc)
4466                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
4467
4468         spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs;
4469
4470         spec->num_mux_defs = 1;
4471         spec->input_mux = &spec->private_imux;
4472
4473         /* check whether NID 0x04 is valid */
4474         wcap = get_wcaps(codec, 0x04);
4475         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
4476         if (wcap != AC_WID_AUD_IN) {
4477                 spec->adc_nids = alc260_adc_nids_alt;
4478                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
4479                 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
4480         } else {
4481                 spec->adc_nids = alc260_adc_nids;
4482                 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
4483                 spec->mixers[spec->num_mixers] = alc260_capture_mixer;
4484         }
4485         spec->num_mixers++;
4486
4487         return 1;
4488 }
4489
4490 /* additional initialization for auto-configuration model */
4491 static void alc260_auto_init(struct hda_codec *codec)
4492 {
4493         alc260_auto_init_multi_out(codec);
4494         alc260_auto_init_analog_input(codec);
4495 }
4496
4497 /*
4498  * ALC260 configurations
4499  */
4500 static const char *alc260_models[ALC260_MODEL_LAST] = {
4501         [ALC260_BASIC]          = "basic",
4502         [ALC260_HP]             = "hp",
4503         [ALC260_HP_3013]        = "hp-3013",
4504         [ALC260_FUJITSU_S702X]  = "fujitsu",
4505         [ALC260_ACER]           = "acer",
4506         [ALC260_WILL]           = "will",
4507         [ALC260_REPLACER_672V]  = "replacer",
4508 #ifdef CONFIG_SND_DEBUG
4509         [ALC260_TEST]           = "test",
4510 #endif
4511         [ALC260_AUTO]           = "auto",
4512 };
4513
4514 static struct snd_pci_quirk alc260_cfg_tbl[] = {
4515         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
4516         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
4517         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
4518         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
4519         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
4520         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP),
4521         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_3013),
4522         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
4523         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
4524         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
4525         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
4526         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
4527         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
4528         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
4529         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
4530         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
4531         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
4532         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
4533         {}
4534 };
4535
4536 static struct alc_config_preset alc260_presets[] = {
4537         [ALC260_BASIC] = {
4538                 .mixers = { alc260_base_output_mixer,
4539                             alc260_input_mixer,
4540                             alc260_pc_beep_mixer,
4541                             alc260_capture_mixer },
4542                 .init_verbs = { alc260_init_verbs },
4543                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4544                 .dac_nids = alc260_dac_nids,
4545                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4546                 .adc_nids = alc260_adc_nids,
4547                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4548                 .channel_mode = alc260_modes,
4549                 .input_mux = &alc260_capture_source,
4550         },
4551         [ALC260_HP] = {
4552                 .mixers = { alc260_base_output_mixer,
4553                             alc260_input_mixer,
4554                             alc260_capture_alt_mixer },
4555                 .init_verbs = { alc260_init_verbs },
4556                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4557                 .dac_nids = alc260_dac_nids,
4558                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
4559                 .adc_nids = alc260_hp_adc_nids,
4560                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4561                 .channel_mode = alc260_modes,
4562                 .input_mux = &alc260_capture_source,
4563         },
4564         [ALC260_HP_3013] = {
4565                 .mixers = { alc260_hp_3013_mixer,
4566                             alc260_input_mixer,
4567                             alc260_capture_alt_mixer },
4568                 .init_verbs = { alc260_hp_3013_init_verbs },
4569                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4570                 .dac_nids = alc260_dac_nids,
4571                 .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
4572                 .adc_nids = alc260_hp_adc_nids,
4573                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4574                 .channel_mode = alc260_modes,
4575                 .input_mux = &alc260_capture_source,
4576         },
4577         [ALC260_FUJITSU_S702X] = {
4578                 .mixers = { alc260_fujitsu_mixer,
4579                             alc260_capture_mixer },
4580                 .init_verbs = { alc260_fujitsu_init_verbs },
4581                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4582                 .dac_nids = alc260_dac_nids,
4583                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
4584                 .adc_nids = alc260_dual_adc_nids,
4585                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4586                 .channel_mode = alc260_modes,
4587                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
4588                 .input_mux = alc260_fujitsu_capture_sources,
4589         },
4590         [ALC260_ACER] = {
4591                 .mixers = { alc260_acer_mixer,
4592                             alc260_capture_mixer },
4593                 .init_verbs = { alc260_acer_init_verbs },
4594                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4595                 .dac_nids = alc260_dac_nids,
4596                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
4597                 .adc_nids = alc260_dual_adc_nids,
4598                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4599                 .channel_mode = alc260_modes,
4600                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
4601                 .input_mux = alc260_acer_capture_sources,
4602         },
4603         [ALC260_WILL] = {
4604                 .mixers = { alc260_will_mixer,
4605                             alc260_capture_mixer },
4606                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
4607                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4608                 .dac_nids = alc260_dac_nids,
4609                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4610                 .adc_nids = alc260_adc_nids,
4611                 .dig_out_nid = ALC260_DIGOUT_NID,
4612                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4613                 .channel_mode = alc260_modes,
4614                 .input_mux = &alc260_capture_source,
4615         },
4616         [ALC260_REPLACER_672V] = {
4617                 .mixers = { alc260_replacer_672v_mixer,
4618                             alc260_capture_mixer },
4619                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
4620                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
4621                 .dac_nids = alc260_dac_nids,
4622                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
4623                 .adc_nids = alc260_adc_nids,
4624                 .dig_out_nid = ALC260_DIGOUT_NID,
4625                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4626                 .channel_mode = alc260_modes,
4627                 .input_mux = &alc260_capture_source,
4628                 .unsol_event = alc260_replacer_672v_unsol_event,
4629                 .init_hook = alc260_replacer_672v_automute,
4630         },
4631 #ifdef CONFIG_SND_DEBUG
4632         [ALC260_TEST] = {
4633                 .mixers = { alc260_test_mixer,
4634                             alc260_capture_mixer },
4635                 .init_verbs = { alc260_test_init_verbs },
4636                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
4637                 .dac_nids = alc260_test_dac_nids,
4638                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
4639                 .adc_nids = alc260_test_adc_nids,
4640                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
4641                 .channel_mode = alc260_modes,
4642                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
4643                 .input_mux = alc260_test_capture_sources,
4644         },
4645 #endif
4646 };
4647
4648 static int patch_alc260(struct hda_codec *codec)
4649 {
4650         struct alc_spec *spec;
4651         int err, board_config;
4652
4653         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4654         if (spec == NULL)
4655                 return -ENOMEM;
4656
4657         codec->spec = spec;
4658
4659         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
4660                                                   alc260_models,
4661                                                   alc260_cfg_tbl);
4662         if (board_config < 0) {
4663                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
4664                            "trying auto-probe from BIOS...\n");
4665                 board_config = ALC260_AUTO;
4666         }
4667
4668         if (board_config == ALC260_AUTO) {
4669                 /* automatic parse from the BIOS config */
4670                 err = alc260_parse_auto_config(codec);
4671                 if (err < 0) {
4672                         alc_free(codec);
4673                         return err;
4674                 } else if (!err) {
4675                         printk(KERN_INFO
4676                                "hda_codec: Cannot set up configuration "
4677                                "from BIOS.  Using base mode...\n");
4678                         board_config = ALC260_BASIC;
4679                 }
4680         }
4681
4682         if (board_config != ALC260_AUTO)
4683                 setup_preset(spec, &alc260_presets[board_config]);
4684
4685         spec->stream_name_analog = "ALC260 Analog";
4686         spec->stream_analog_playback = &alc260_pcm_analog_playback;
4687         spec->stream_analog_capture = &alc260_pcm_analog_capture;
4688
4689         spec->stream_name_digital = "ALC260 Digital";
4690         spec->stream_digital_playback = &alc260_pcm_digital_playback;
4691         spec->stream_digital_capture = &alc260_pcm_digital_capture;
4692
4693         codec->patch_ops = alc_patch_ops;
4694         if (board_config == ALC260_AUTO)
4695                 spec->init_hook = alc260_auto_init;
4696
4697         return 0;
4698 }
4699
4700
4701 /*
4702  * ALC882 support
4703  *
4704  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4705  * configuration.  Each pin widget can choose any input DACs and a mixer.
4706  * Each ADC is connected from a mixer of all inputs.  This makes possible
4707  * 6-channel independent captures.
4708  *
4709  * In addition, an independent DAC for the multi-playback (not used in this
4710  * driver yet).
4711  */
4712 #define ALC882_DIGOUT_NID       0x06
4713 #define ALC882_DIGIN_NID        0x0a
4714
4715 static struct hda_channel_mode alc882_ch_modes[1] = {
4716         { 8, NULL }
4717 };
4718
4719 static hda_nid_t alc882_dac_nids[4] = {
4720         /* front, rear, clfe, rear_surr */
4721         0x02, 0x03, 0x04, 0x05
4722 };
4723
4724 /* identical with ALC880 */
4725 #define alc882_adc_nids         alc880_adc_nids
4726 #define alc882_adc_nids_alt     alc880_adc_nids_alt
4727
4728 /* input MUX */
4729 /* FIXME: should be a matrix-type input source selection */
4730
4731 static struct hda_input_mux alc882_capture_source = {
4732         .num_items = 4,
4733         .items = {
4734                 { "Mic", 0x0 },
4735                 { "Front Mic", 0x1 },
4736                 { "Line", 0x2 },
4737                 { "CD", 0x4 },
4738         },
4739 };
4740 #define alc882_mux_enum_info alc_mux_enum_info
4741 #define alc882_mux_enum_get alc_mux_enum_get
4742
4743 static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol,
4744                                struct snd_ctl_elem_value *ucontrol)
4745 {
4746         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4747         struct alc_spec *spec = codec->spec;
4748         const struct hda_input_mux *imux = spec->input_mux;
4749         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
4750         static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
4751         hda_nid_t nid = capture_mixers[adc_idx];
4752         unsigned int *cur_val = &spec->cur_mux[adc_idx];
4753         unsigned int i, idx;
4754
4755         idx = ucontrol->value.enumerated.item[0];
4756         if (idx >= imux->num_items)
4757                 idx = imux->num_items - 1;
4758         if (*cur_val == idx && !codec->in_resume)
4759                 return 0;
4760         for (i = 0; i < imux->num_items; i++) {
4761                 unsigned int v = (i == idx) ? 0x7000 : 0x7080;
4762                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4763                                     v | (imux->items[i].index << 8));
4764         }
4765         *cur_val = idx;
4766         return 1;
4767 }
4768
4769 /*
4770  * 2ch mode
4771  */
4772 static struct hda_verb alc882_3ST_ch2_init[] = {
4773         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
4774         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
4775         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
4776         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
4777         { } /* end */
4778 };
4779
4780 /*
4781  * 6ch mode
4782  */
4783 static struct hda_verb alc882_3ST_ch6_init[] = {
4784         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4785         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
4786         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
4787         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4788         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
4789         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
4790         { } /* end */
4791 };
4792
4793 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
4794         { 2, alc882_3ST_ch2_init },
4795         { 6, alc882_3ST_ch6_init },
4796 };
4797
4798 /*
4799  * 6ch mode
4800  */
4801 static struct hda_verb alc882_sixstack_ch6_init[] = {
4802         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
4803         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4804         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4805         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4806         { } /* end */
4807 };
4808
4809 /*
4810  * 8ch mode
4811  */
4812 static struct hda_verb alc882_sixstack_ch8_init[] = {
4813         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4814         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4815         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4816         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
4817         { } /* end */
4818 };
4819
4820 static struct hda_channel_mode alc882_sixstack_modes[2] = {
4821         { 6, alc882_sixstack_ch6_init },
4822         { 8, alc882_sixstack_ch8_init },
4823 };
4824
4825 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
4826  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
4827  */
4828 static struct snd_kcontrol_new alc882_base_mixer[] = {
4829         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4830         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4831         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
4832         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
4833         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
4834         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
4835         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
4836         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
4837         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
4838         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
4839         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
4840         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
4841         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
4842         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4843         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4844         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4845         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
4846         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
4847         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
4848         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
4849         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
4850         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
4851         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
4852         { } /* end */
4853 };
4854
4855 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
4856         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4857         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4858         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
4859         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
4860         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4861         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4862         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4863         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
4864         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
4865         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
4866         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
4867         { } /* end */
4868 };
4869
4870 static struct snd_kcontrol_new alc882_targa_mixer[] = {
4871         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4872         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4873         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
4874         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
4875         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
4876         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4877         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4878         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4879         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
4880         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
4881         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
4882         { } /* end */
4883 };
4884
4885 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
4886  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
4887  */
4888 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
4889         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4890         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
4891         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4892         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
4893         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
4894         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
4895         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
4896         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
4897         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
4898         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
4899         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
4900         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
4901         { } /* end */
4902 };
4903
4904 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
4905         {
4906                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4907                 .name = "Channel Mode",
4908                 .info = alc_ch_mode_info,
4909                 .get = alc_ch_mode_get,
4910                 .put = alc_ch_mode_put,
4911         },
4912         { } /* end */
4913 };
4914
4915 static struct hda_verb alc882_init_verbs[] = {
4916         /* Front mixer: unmute input/output amp left and right (volume = 0) */
4917         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4918         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4919         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4920         /* Rear mixer */
4921         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4922         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4923         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4924         /* CLFE mixer */
4925         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4926         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4927         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4928         /* Side mixer */
4929         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4930         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4931         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4932
4933         /* Front Pin: output 0 (0x0c) */
4934         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4935         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4936         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
4937         /* Rear Pin: output 1 (0x0d) */
4938         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4939         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4940         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
4941         /* CLFE Pin: output 2 (0x0e) */
4942         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4943         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4944         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
4945         /* Side Pin: output 3 (0x0f) */
4946         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4947         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4948         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
4949         /* Mic (rear) pin: input vref at 80% */
4950         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4951         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4952         /* Front Mic pin: input vref at 80% */
4953         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4954         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4955         /* Line In pin: input */
4956         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4957         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4958         /* Line-2 In: Headphone output (output 0 - 0x0c) */
4959         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4960         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4961         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
4962         /* CD pin widget for input */
4963         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4964
4965         /* FIXME: use matrix-type input source selection */
4966         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
4967         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
4968         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4969         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4970         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4971         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4972         /* Input mixer2 */
4973         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4974         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4975         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4976         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4977         /* Input mixer3 */
4978         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4979         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4980         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4981         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4982         /* ADC1: mute amp left and right */
4983         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4984         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
4985         /* ADC2: mute amp left and right */
4986         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4987         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
4988         /* ADC3: mute amp left and right */
4989         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4990         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
4991
4992         { }
4993 };
4994
4995 static struct hda_verb alc882_eapd_verbs[] = {
4996         /* change to EAPD mode */
4997         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
4998         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
4999         { }
5000 };
5001
5002 /* Mac Pro test */
5003 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
5004         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5005         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5006         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
5007         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
5008         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
5009         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
5010         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
5011         { } /* end */
5012 };
5013
5014 static struct hda_verb alc882_macpro_init_verbs[] = {
5015         /* Front mixer: unmute input/output amp left and right (volume = 0) */
5016         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5017         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5018         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5019         /* Front Pin: output 0 (0x0c) */
5020         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5021         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5022         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
5023         /* Front Mic pin: input vref at 80% */
5024         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5025         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
5026         /* Speaker:  output */
5027         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5028         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5029         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
5030         /* Headphone output (output 0 - 0x0c) */
5031         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5032         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5033         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
5034
5035         /* FIXME: use matrix-type input source selection */
5036         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5037         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5038         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5039         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5040         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5041         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5042         /* Input mixer2 */
5043         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5044         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5045         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5046         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5047         /* Input mixer3 */
5048         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5049         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5050         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5051         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5052         /* ADC1: mute amp left and right */
5053         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5054         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5055         /* ADC2: mute amp left and right */
5056         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5057         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5058         /* ADC3: mute amp left and right */
5059         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5060         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5061
5062         { }
5063 };
5064
5065 static struct hda_verb alc882_targa_verbs[] = {
5066         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5067         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5068
5069         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5070         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5071         
5072         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5073         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5074         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5075
5076         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
5077         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5078         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
5079         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
5080         { } /* end */
5081 };
5082
5083 /* toggle speaker-output according to the hp-jack state */
5084 static void alc882_targa_automute(struct hda_codec *codec)
5085 {
5086         unsigned int present;
5087  
5088         present = snd_hda_codec_read(codec, 0x14, 0,
5089                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5090         snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
5091                                  0x80, present ? 0x80 : 0);
5092         snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
5093                                  0x80, present ? 0x80 : 0);
5094         snd_hda_codec_write(codec, 1, 0, AC_VERB_SET_GPIO_DATA, present ? 1 : 3);
5095 }
5096
5097 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
5098 {
5099         /* Looks like the unsol event is incompatible with the standard
5100          * definition.  4bit tag is placed at 26 bit!
5101          */
5102         if (((res >> 26) == ALC880_HP_EVENT)) {
5103                 alc882_targa_automute(codec);
5104         }
5105 }
5106
5107 static struct hda_verb alc882_asus_a7j_verbs[] = {
5108         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5109         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5110
5111         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5112         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5113         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5114         
5115         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5116         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5117         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
5118
5119         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
5120         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
5121         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
5122         { } /* end */
5123 };
5124
5125 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5126 {
5127         unsigned int gpiostate, gpiomask, gpiodir;
5128
5129         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5130                                        AC_VERB_GET_GPIO_DATA, 0);
5131
5132         if (!muted)
5133                 gpiostate |= (1 << pin);
5134         else
5135                 gpiostate &= ~(1 << pin);
5136
5137         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5138                                       AC_VERB_GET_GPIO_MASK, 0);
5139         gpiomask |= (1 << pin);
5140
5141         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5142                                      AC_VERB_GET_GPIO_DIRECTION, 0);
5143         gpiodir |= (1 << pin);
5144
5145
5146         snd_hda_codec_write(codec, codec->afg, 0,
5147                             AC_VERB_SET_GPIO_MASK, gpiomask);
5148         snd_hda_codec_write(codec, codec->afg, 0,
5149                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5150
5151         msleep(1);
5152
5153         snd_hda_codec_write(codec, codec->afg, 0,
5154                             AC_VERB_SET_GPIO_DATA, gpiostate);
5155 }
5156
5157 /*
5158  * generic initialization of ADC, input mixers and output mixers
5159  */
5160 static struct hda_verb alc882_auto_init_verbs[] = {
5161         /*
5162          * Unmute ADC0-2 and set the default input to mic-in
5163          */
5164         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
5165         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5166         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
5167         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5168         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
5169         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5170
5171         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5172          * mixer widget
5173          * Note: PASD motherboards uses the Line In 2 as the input for
5174          * front panel mic (mic 2)
5175          */
5176         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5177         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5178         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5179         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
5180         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
5181         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
5182
5183         /*
5184          * Set up output mixers (0x0c - 0x0f)
5185          */
5186         /* set vol=0 to output mixers */
5187         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5188         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5189         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5190         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5191         /* set up input amps for analog loopback */
5192         /* Amp Indices: DAC = 0, mixer = 1 */
5193         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5194         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5195         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5196         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5197         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5198         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5199         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5200         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5201         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5202         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5203
5204         /* FIXME: use matrix-type input source selection */
5205         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
5206         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
5207         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5208         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5209         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5210         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5211         /* Input mixer2 */
5212         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5213         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5214         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5215         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5216         /* Input mixer3 */
5217         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5218         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
5219         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
5220         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
5221
5222         { }
5223 };
5224
5225 /* capture mixer elements */
5226 static struct snd_kcontrol_new alc882_capture_alt_mixer[] = {
5227         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5228         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5229         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5230         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5231         {
5232                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5233                 /* The multiple "Capture Source" controls confuse alsamixer
5234                  * So call somewhat different..
5235                  * FIXME: the controls appear in the "playback" view!
5236                  */
5237                 /* .name = "Capture Source", */
5238                 .name = "Input Source",
5239                 .count = 2,
5240                 .info = alc882_mux_enum_info,
5241                 .get = alc882_mux_enum_get,
5242                 .put = alc882_mux_enum_put,
5243         },
5244         { } /* end */
5245 };
5246
5247 static struct snd_kcontrol_new alc882_capture_mixer[] = {
5248         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
5249         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
5250         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
5251         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
5252         HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
5253         HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
5254         {
5255                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5256                 /* The multiple "Capture Source" controls confuse alsamixer
5257                  * So call somewhat different..
5258                  * FIXME: the controls appear in the "playback" view!
5259                  */
5260                 /* .name = "Capture Source", */
5261                 .name = "Input Source",
5262                 .count = 3,
5263                 .info = alc882_mux_enum_info,
5264                 .get = alc882_mux_enum_get,
5265                 .put = alc882_mux_enum_put,
5266         },
5267         { } /* end */
5268 };
5269
5270 /* pcm configuration: identiacal with ALC880 */
5271 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
5272 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
5273 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
5274 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
5275
5276 /*
5277  * configuration and preset
5278  */
5279 static const char *alc882_models[ALC882_MODEL_LAST] = {
5280         [ALC882_3ST_DIG]        = "3stack-dig",
5281         [ALC882_6ST_DIG]        = "6stack-dig",
5282         [ALC882_ARIMA]          = "arima",
5283         [ALC882_W2JC]           = "w2jc",
5284         [ALC885_MACPRO]         = "macpro",
5285         [ALC882_AUTO]           = "auto",
5286 };
5287
5288 static struct snd_pci_quirk alc882_cfg_tbl[] = {
5289         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
5290         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
5291         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
5292         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
5293         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
5294         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
5295         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
5296         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
5297         {}
5298 };
5299
5300 static struct alc_config_preset alc882_presets[] = {
5301         [ALC882_3ST_DIG] = {
5302                 .mixers = { alc882_base_mixer },
5303                 .init_verbs = { alc882_init_verbs },
5304                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5305                 .dac_nids = alc882_dac_nids,
5306                 .dig_out_nid = ALC882_DIGOUT_NID,
5307                 .dig_in_nid = ALC882_DIGIN_NID,
5308                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
5309                 .channel_mode = alc882_ch_modes,
5310                 .need_dac_fix = 1,
5311                 .input_mux = &alc882_capture_source,
5312         },
5313         [ALC882_6ST_DIG] = {
5314                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
5315                 .init_verbs = { alc882_init_verbs },
5316                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5317                 .dac_nids = alc882_dac_nids,
5318                 .dig_out_nid = ALC882_DIGOUT_NID,
5319                 .dig_in_nid = ALC882_DIGIN_NID,
5320                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
5321                 .channel_mode = alc882_sixstack_modes,
5322                 .input_mux = &alc882_capture_source,
5323         },
5324         [ALC882_ARIMA] = {
5325                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
5326                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
5327                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5328                 .dac_nids = alc882_dac_nids,
5329                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
5330                 .channel_mode = alc882_sixstack_modes,
5331                 .input_mux = &alc882_capture_source,
5332         },
5333         [ALC882_W2JC] = {
5334                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
5335                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
5336                                 alc880_gpio1_init_verbs },
5337                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5338                 .dac_nids = alc882_dac_nids,
5339                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
5340                 .channel_mode = alc880_threestack_modes,
5341                 .need_dac_fix = 1,
5342                 .input_mux = &alc882_capture_source,
5343                 .dig_out_nid = ALC882_DIGOUT_NID,
5344         },
5345         [ALC885_MACPRO] = {
5346                 .mixers = { alc882_macpro_mixer },
5347                 .init_verbs = { alc882_macpro_init_verbs },
5348                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5349                 .dac_nids = alc882_dac_nids,
5350                 .dig_out_nid = ALC882_DIGOUT_NID,
5351                 .dig_in_nid = ALC882_DIGIN_NID,
5352                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
5353                 .channel_mode = alc882_ch_modes,
5354                 .input_mux = &alc882_capture_source,
5355         },
5356         [ALC882_TARGA] = {
5357                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer,
5358                             alc882_capture_mixer },
5359                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
5360                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5361                 .dac_nids = alc882_dac_nids,
5362                 .dig_out_nid = ALC882_DIGOUT_NID,
5363                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
5364                 .adc_nids = alc882_adc_nids,
5365                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
5366                 .channel_mode = alc882_3ST_6ch_modes,
5367                 .need_dac_fix = 1,
5368                 .input_mux = &alc882_capture_source,
5369                 .unsol_event = alc882_targa_unsol_event,
5370                 .init_hook = alc882_targa_automute,
5371         },
5372         [ALC882_ASUS_A7J] = {
5373                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer,
5374                             alc882_capture_mixer },
5375                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
5376                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
5377                 .dac_nids = alc882_dac_nids,
5378                 .dig_out_nid = ALC882_DIGOUT_NID,
5379                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
5380                 .adc_nids = alc882_adc_nids,
5381                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
5382                 .channel_mode = alc882_3ST_6ch_modes,
5383                 .need_dac_fix = 1,
5384                 .input_mux = &alc882_capture_source,
5385         },      
5386 };
5387
5388
5389 /*
5390  * BIOS auto configuration
5391  */
5392 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
5393                                               hda_nid_t nid, int pin_type,
5394                                               int dac_idx)
5395 {
5396         /* set as output */
5397         struct alc_spec *spec = codec->spec;
5398         int idx;
5399
5400         if (spec->multiout.dac_nids[dac_idx] == 0x25)
5401                 idx = 4;
5402         else
5403                 idx = spec->multiout.dac_nids[dac_idx] - 2;
5404
5405         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5406                             pin_type);
5407         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5408                             AMP_OUT_UNMUTE);
5409         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
5410
5411 }
5412
5413 static void alc882_auto_init_multi_out(struct hda_codec *codec)
5414 {
5415         struct alc_spec *spec = codec->spec;
5416         int i;
5417
5418         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
5419         for (i = 0; i <= HDA_SIDE; i++) {
5420                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
5421                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5422                 if (nid)
5423                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
5424                                                           i);
5425         }
5426 }
5427
5428 static void alc882_auto_init_hp_out(struct hda_codec *codec)
5429 {
5430         struct alc_spec *spec = codec->spec;
5431         hda_nid_t pin;
5432
5433         pin = spec->autocfg.hp_pins[0];
5434         if (pin) /* connect to front */
5435                 /* use dac 0 */
5436                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
5437 }
5438
5439 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
5440 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
5441
5442 static void alc882_auto_init_analog_input(struct hda_codec *codec)
5443 {
5444         struct alc_spec *spec = codec->spec;
5445         int i;
5446
5447         for (i = 0; i < AUTO_PIN_LAST; i++) {
5448                 hda_nid_t nid = spec->autocfg.input_pins[i];
5449                 if (alc882_is_input_pin(nid)) {
5450                         snd_hda_codec_write(codec, nid, 0,
5451                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5452                                             i <= AUTO_PIN_FRONT_MIC ?
5453                                             PIN_VREF80 : PIN_IN);
5454                         if (nid != ALC882_PIN_CD_NID)
5455                                 snd_hda_codec_write(codec, nid, 0,
5456                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5457                                                     AMP_OUT_MUTE);
5458                 }
5459         }
5460 }
5461
5462 /* almost identical with ALC880 parser... */
5463 static int alc882_parse_auto_config(struct hda_codec *codec)
5464 {
5465         struct alc_spec *spec = codec->spec;
5466         int err = alc880_parse_auto_config(codec);
5467
5468         if (err < 0)
5469                 return err;
5470         else if (err > 0)
5471                 /* hack - override the init verbs */
5472                 spec->init_verbs[0] = alc882_auto_init_verbs;
5473         return err;
5474 }
5475
5476 /* additional initialization for auto-configuration model */
5477 static void alc882_auto_init(struct hda_codec *codec)
5478 {
5479         alc882_auto_init_multi_out(codec);
5480         alc882_auto_init_hp_out(codec);
5481         alc882_auto_init_analog_input(codec);
5482 }
5483
5484 static int patch_alc882(struct hda_codec *codec)
5485 {
5486         struct alc_spec *spec;
5487         int err, board_config;
5488
5489         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5490         if (spec == NULL)
5491                 return -ENOMEM;
5492
5493         codec->spec = spec;
5494
5495         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
5496                                                   alc882_models,
5497                                                   alc882_cfg_tbl);
5498
5499         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
5500                 /* Pick up systems that don't supply PCI SSID */
5501                 switch (codec->subsystem_id) {
5502                 case 0x106b0c00: /* Mac Pro */
5503                         board_config = ALC885_MACPRO;
5504                         break;
5505                 default:
5506                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
5507                                          "trying auto-probe from BIOS...\n");
5508                         board_config = ALC882_AUTO;
5509                 }
5510         }
5511
5512         if (board_config == ALC882_AUTO) {
5513                 /* automatic parse from the BIOS config */
5514                 err = alc882_parse_auto_config(codec);
5515                 if (err < 0) {
5516                         alc_free(codec);
5517                         return err;
5518                 } else if (!err) {
5519                         printk(KERN_INFO
5520                                "hda_codec: Cannot set up configuration "
5521                                "from BIOS.  Using base mode...\n");
5522                         board_config = ALC882_3ST_DIG;
5523                 }
5524         }
5525
5526         if (board_config != ALC882_AUTO)
5527                 setup_preset(spec, &alc882_presets[board_config]);
5528
5529         if (board_config == ALC885_MACPRO) {
5530                 alc882_gpio_mute(codec, 0, 0);
5531                 alc882_gpio_mute(codec, 1, 0);
5532         }
5533
5534         spec->stream_name_analog = "ALC882 Analog";
5535         spec->stream_analog_playback = &alc882_pcm_analog_playback;
5536         spec->stream_analog_capture = &alc882_pcm_analog_capture;
5537
5538         spec->stream_name_digital = "ALC882 Digital";
5539         spec->stream_digital_playback = &alc882_pcm_digital_playback;
5540         spec->stream_digital_capture = &alc882_pcm_digital_capture;
5541
5542         if (!spec->adc_nids && spec->input_mux) {
5543                 /* check whether NID 0x07 is valid */
5544                 unsigned int wcap = get_wcaps(codec, 0x07);
5545                 /* get type */
5546                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
5547                 if (wcap != AC_WID_AUD_IN) {
5548                         spec->adc_nids = alc882_adc_nids_alt;
5549                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
5550                         spec->mixers[spec->num_mixers] =
5551                                 alc882_capture_alt_mixer;
5552                         spec->num_mixers++;
5553                 } else {
5554                         spec->adc_nids = alc882_adc_nids;
5555                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
5556                         spec->mixers[spec->num_mixers] = alc882_capture_mixer;
5557                         spec->num_mixers++;
5558                 }
5559         }
5560
5561         codec->patch_ops = alc_patch_ops;
5562         if (board_config == ALC882_AUTO)
5563                 spec->init_hook = alc882_auto_init;
5564
5565         return 0;
5566 }
5567
5568 /*
5569  * ALC883 support
5570  *
5571  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
5572  * configuration.  Each pin widget can choose any input DACs and a mixer.
5573  * Each ADC is connected from a mixer of all inputs.  This makes possible
5574  * 6-channel independent captures.
5575  *
5576  * In addition, an independent DAC for the multi-playback (not used in this
5577  * driver yet).
5578  */
5579 #define ALC883_DIGOUT_NID       0x06
5580 #define ALC883_DIGIN_NID        0x0a
5581
5582 static hda_nid_t alc883_dac_nids[4] = {
5583         /* front, rear, clfe, rear_surr */
5584         0x02, 0x04, 0x03, 0x05
5585 };
5586
5587 static hda_nid_t alc883_adc_nids[2] = {
5588         /* ADC1-2 */
5589         0x08, 0x09,
5590 };
5591
5592 /* input MUX */
5593 /* FIXME: should be a matrix-type input source selection */
5594
5595 static struct hda_input_mux alc883_capture_source = {
5596         .num_items = 4,
5597         .items = {
5598                 { "Mic", 0x0 },
5599                 { "Front Mic", 0x1 },
5600                 { "Line", 0x2 },
5601                 { "CD", 0x4 },
5602         },
5603 };
5604
5605 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
5606         .num_items = 2,
5607         .items = {
5608                 { "Mic", 0x1 },
5609                 { "Line", 0x2 },
5610         },
5611 };
5612
5613 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
5614         .num_items = 4,
5615         .items = {
5616                 { "Mic", 0x0 },
5617                 { "iMic", 0x1 },
5618                 { "Line", 0x2 },
5619                 { "CD", 0x4 },
5620         },
5621 };
5622
5623 #define alc883_mux_enum_info alc_mux_enum_info
5624 #define alc883_mux_enum_get alc_mux_enum_get
5625
5626 static int alc883_mux_enum_put(struct snd_kcontrol *kcontrol,
5627                                struct snd_ctl_elem_value *ucontrol)
5628 {
5629         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5630         struct alc_spec *spec = codec->spec;
5631         const struct hda_input_mux *imux = spec->input_mux;
5632         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
5633         static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
5634         hda_nid_t nid = capture_mixers[adc_idx];
5635         unsigned int *cur_val = &spec->cur_mux[adc_idx];
5636         unsigned int i, idx;
5637
5638         idx = ucontrol->value.enumerated.item[0];
5639         if (idx >= imux->num_items)
5640                 idx = imux->num_items - 1;
5641         if (*cur_val == idx && !codec->in_resume)
5642                 return 0;
5643         for (i = 0; i < imux->num_items; i++) {
5644                 unsigned int v = (i == idx) ? 0x7000 : 0x7080;
5645                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5646                                     v | (imux->items[i].index << 8));
5647         }
5648         *cur_val = idx;
5649         return 1;
5650 }
5651
5652 /*
5653  * 2ch mode
5654  */
5655 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
5656         { 2, NULL }
5657 };
5658
5659 /*
5660  * 2ch mode
5661  */
5662 static struct hda_verb alc883_3ST_ch2_init[] = {
5663         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5664         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5665         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5666         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5667         { } /* end */
5668 };
5669
5670 /*
5671  * 6ch mode
5672  */
5673 static struct hda_verb alc883_3ST_ch6_init[] = {
5674         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5675         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5676         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5677         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5678         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5679         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5680         { } /* end */
5681 };
5682
5683 static struct hda_channel_mode alc883_3ST_6ch_modes[2] = {
5684         { 2, alc883_3ST_ch2_init },
5685         { 6, alc883_3ST_ch6_init },
5686 };
5687
5688 /*
5689  * 6ch mode
5690  */
5691 static struct hda_verb alc883_sixstack_ch6_init[] = {
5692         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5693         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5694         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5695         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5696         { } /* end */
5697 };
5698
5699 /*
5700  * 8ch mode
5701  */
5702 static struct hda_verb alc883_sixstack_ch8_init[] = {
5703         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5704         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5705         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5706         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5707         { } /* end */
5708 };
5709
5710 static struct hda_channel_mode alc883_sixstack_modes[2] = {
5711         { 6, alc883_sixstack_ch6_init },
5712         { 8, alc883_sixstack_ch8_init },
5713 };
5714
5715 static struct hda_verb alc883_medion_eapd_verbs[] = {
5716         /* eanable EAPD on medion laptop */
5717         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
5718         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
5719         { }
5720 };
5721
5722 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
5723  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
5724  */
5725
5726 static struct snd_kcontrol_new alc883_base_mixer[] = {
5727         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5728         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5729         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5730         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5731         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5732         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5733         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5734         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5735         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
5736         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
5737         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5738         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5739         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5740         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5741         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5742         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5743         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5744         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5745         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5746         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5747         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5748         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5749         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5750         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5751         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5752         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5753         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5754         {
5755                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5756                 /* .name = "Capture Source", */
5757                 .name = "Input Source",
5758                 .count = 2,
5759                 .info = alc883_mux_enum_info,
5760                 .get = alc883_mux_enum_get,
5761                 .put = alc883_mux_enum_put,
5762         },
5763         { } /* end */
5764 };
5765
5766 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
5767         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5768         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5769         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5770         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5771         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5772         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5773         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5774         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5775         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5776         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5777         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5778         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5779         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5780         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5781         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5782         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5783         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5784         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5785         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5786         {
5787                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5788                 /* .name = "Capture Source", */
5789                 .name = "Input Source",
5790                 .count = 2,
5791                 .info = alc883_mux_enum_info,
5792                 .get = alc883_mux_enum_get,
5793                 .put = alc883_mux_enum_put,
5794         },
5795         { } /* end */
5796 };
5797
5798 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
5799         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5800         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5801         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5802         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5803         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5804         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5805         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5806         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5807         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5808         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5809         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5810         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5811         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5812         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5813         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5814         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5815         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5816         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5817         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5818         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5819         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5820         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5821         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5822         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5823         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5824         {
5825                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5826                 /* .name = "Capture Source", */
5827                 .name = "Input Source",
5828                 .count = 2,
5829                 .info = alc883_mux_enum_info,
5830                 .get = alc883_mux_enum_get,
5831                 .put = alc883_mux_enum_put,
5832         },
5833         { } /* end */
5834 };
5835
5836 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
5837         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5838         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5839         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5840         HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5841         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5842         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5843         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x16, 1, 0x0, HDA_OUTPUT),
5844         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
5845         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5846         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5847         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5848         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5849         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5850         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5851         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5852         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5853         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5854         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
5855         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5856         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
5857         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
5858         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5859         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5860
5861         {
5862                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5863                 /* .name = "Capture Source", */
5864                 .name = "Input Source",
5865                 .count = 1,
5866                 .info = alc883_mux_enum_info,
5867                 .get = alc883_mux_enum_get,
5868                 .put = alc883_mux_enum_put,
5869         },
5870         { } /* end */
5871 };
5872
5873 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
5874         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5875         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5876         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5877         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5878         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
5879         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
5880         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
5881         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
5882         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
5883         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5884         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5885         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5886         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5887         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5888         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5889         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5890         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5891         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5892         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5893         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5894         {
5895                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5896                 /* .name = "Capture Source", */
5897                 .name = "Input Source",
5898                 .count = 2,
5899                 .info = alc883_mux_enum_info,
5900                 .get = alc883_mux_enum_get,
5901                 .put = alc883_mux_enum_put,
5902         },
5903         { } /* end */
5904 };
5905
5906 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
5907         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5908         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5909         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5910         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5911         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5912         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5913         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5914         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5915         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5916         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5917         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5918         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5919         {
5920                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5921                 /* .name = "Capture Source", */
5922                 .name = "Input Source",
5923                 .count = 2,
5924                 .info = alc883_mux_enum_info,
5925                 .get = alc883_mux_enum_get,
5926                 .put = alc883_mux_enum_put,
5927         },
5928         { } /* end */
5929 };
5930
5931 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
5932         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5933         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
5934         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
5935         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x0d, 2, HDA_INPUT),
5936         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
5937         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5938         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
5939         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5940         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5941         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5942         {
5943                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5944                 /* .name = "Capture Source", */
5945                 .name = "Input Source",
5946                 .count = 1,
5947                 .info = alc883_mux_enum_info,
5948                 .get = alc883_mux_enum_get,
5949                 .put = alc883_mux_enum_put,
5950         },
5951         { } /* end */
5952 };
5953
5954 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
5955         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5956         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
5957         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5958         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5959         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5960         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5961         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5962         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
5963         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
5964         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5965         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5966         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5967         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5968         {
5969                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5970                 /* .name = "Capture Source", */
5971                 .name = "Input Source",
5972                 .count = 2,
5973                 .info = alc883_mux_enum_info,
5974                 .get = alc883_mux_enum_get,
5975                 .put = alc883_mux_enum_put,
5976         },
5977         { } /* end */
5978 };
5979
5980 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
5981         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
5982         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
5983         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5984         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
5985         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
5986         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
5987         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
5988         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
5989         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
5990         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
5991         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
5992         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
5993         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
5994         {
5995                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5996                 /* .name = "Capture Source", */
5997                 .name = "Input Source",
5998                 .count = 2,
5999                 .info = alc883_mux_enum_info,
6000                 .get = alc883_mux_enum_get,
6001                 .put = alc883_mux_enum_put,
6002         },
6003         { } /* end */
6004 };      
6005
6006 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
6007         {
6008                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6009                 .name = "Channel Mode",
6010                 .info = alc_ch_mode_info,
6011                 .get = alc_ch_mode_get,
6012                 .put = alc_ch_mode_put,
6013         },
6014         { } /* end */
6015 };
6016
6017 static struct hda_verb alc883_init_verbs[] = {
6018         /* ADC1: mute amp left and right */
6019         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6020         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6021         /* ADC2: mute amp left and right */
6022         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6023         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6024         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6025         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6026         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6027         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6028         /* Rear mixer */
6029         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6030         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6031         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6032         /* CLFE mixer */
6033         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6034         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6035         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6036         /* Side mixer */
6037         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6038         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6039         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6040
6041         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6042         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6043         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6044         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
6045         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6046
6047         /* Front Pin: output 0 (0x0c) */
6048         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6049         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6050         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6051         /* Rear Pin: output 1 (0x0d) */
6052         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6053         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6054         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6055         /* CLFE Pin: output 2 (0x0e) */
6056         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6057         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6058         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
6059         /* Side Pin: output 3 (0x0f) */
6060         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6061         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6062         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
6063         /* Mic (rear) pin: input vref at 80% */
6064         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6065         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6066         /* Front Mic pin: input vref at 80% */
6067         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6068         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6069         /* Line In pin: input */
6070         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6071         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6072         /* Line-2 In: Headphone output (output 0 - 0x0c) */
6073         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6074         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6075         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6076         /* CD pin widget for input */
6077         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6078
6079         /* FIXME: use matrix-type input source selection */
6080         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6081         /* Input mixer2 */
6082         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6083         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6084         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6085         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6086         /* Input mixer3 */
6087         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6088         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6089         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6090         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6091         { }
6092 };
6093
6094 static struct hda_verb alc883_tagra_verbs[] = {
6095         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6096         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6097
6098         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6099         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6100         
6101         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6102         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6103         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6104
6105         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6106         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6107         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6108         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6109
6110         { } /* end */
6111 };
6112
6113 static struct hda_verb alc883_lenovo_101e_verbs[] = {
6114         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6115         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
6116         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
6117         { } /* end */
6118 };
6119
6120 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
6121         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6122         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6123         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6124         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6125         { } /* end */
6126 };
6127
6128 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
6129         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6130         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6131         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6132         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
6133         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
6134         { } /* end */
6135 };
6136
6137 /* toggle front-jack and RCA according to the hp-jack state */
6138 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
6139 {
6140         unsigned int present;
6141  
6142         present = snd_hda_codec_read(codec, 0x1b, 0,
6143                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6144         snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
6145                                  0x80, present ? 0x80 : 0);
6146         snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
6147                                  0x80, present ? 0x80 : 0);
6148         snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
6149                                  0x80, present ? 0x80 : 0);
6150         snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
6151                                  0x80, present ? 0x80 : 0);
6152         
6153 }
6154
6155 /* toggle RCA according to the front-jack state */
6156 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
6157 {
6158         unsigned int present;
6159  
6160         present = snd_hda_codec_read(codec, 0x14, 0,
6161                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6162         snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
6163                                  0x80, present ? 0x80 : 0);
6164         snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
6165                                  0x80, present ? 0x80 : 0);
6166         
6167 }
6168 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
6169                                              unsigned int res)
6170 {
6171         if ((res >> 26) == ALC880_HP_EVENT)
6172                 alc888_lenovo_ms7195_front_automute(codec);
6173         if ((res >> 26) == ALC880_FRONT_EVENT)
6174                 alc888_lenovo_ms7195_rca_automute(codec);
6175 }
6176
6177 static struct hda_verb alc883_medion_md2_verbs[] = {
6178         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6179         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6180
6181         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6182
6183         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6184         { } /* end */
6185 };
6186
6187 /* toggle speaker-output according to the hp-jack state */
6188 static void alc883_medion_md2_automute(struct hda_codec *codec)
6189 {
6190         unsigned int present;
6191  
6192         present = snd_hda_codec_read(codec, 0x14, 0,
6193                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6194         snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
6195                                  0x80, present ? 0x80 : 0);
6196         snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
6197                                  0x80, present ? 0x80 : 0);
6198 }
6199
6200 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
6201                                           unsigned int res)
6202 {
6203         if ((res >> 26) == ALC880_HP_EVENT)
6204                 alc883_medion_md2_automute(codec);
6205 }
6206
6207 /* toggle speaker-output according to the hp-jack state */
6208 static void alc883_tagra_automute(struct hda_codec *codec)
6209 {
6210         unsigned int present;
6211         unsigned char bits;
6212
6213         present = snd_hda_codec_read(codec, 0x14, 0,
6214                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6215         bits = present ? 0x80 : 0;
6216         snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
6217                                  0x80, bits);
6218         snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
6219                                  0x80, bits);
6220         snd_hda_codec_write(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6221                             present ? 1 : 3);
6222 }
6223
6224 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
6225 {
6226         if ((res >> 26) == ALC880_HP_EVENT)
6227                 alc883_tagra_automute(codec);
6228 }
6229
6230 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
6231 {
6232         unsigned int present;
6233         unsigned char bits;
6234
6235         present = snd_hda_codec_read(codec, 0x14, 0,
6236                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6237         bits = present ? 0x80 : 0;
6238         snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
6239                                  0x80, bits);
6240         snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
6241                                  0x80, bits);
6242 }
6243
6244 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
6245 {
6246         unsigned int present;
6247         unsigned char bits;
6248
6249         present = snd_hda_codec_read(codec, 0x1b, 0,
6250                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6251         bits = present ? 0x80 : 0;
6252         snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
6253                                  0x80, bits);
6254         snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
6255                                  0x80, bits);
6256         snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
6257                                  0x80, bits);
6258         snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
6259                                  0x80, bits);
6260 }
6261
6262 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
6263                                            unsigned int res)
6264 {
6265         if ((res >> 26) == ALC880_HP_EVENT)
6266                 alc883_lenovo_101e_all_automute(codec);
6267         if ((res >> 26) == ALC880_FRONT_EVENT)
6268                 alc883_lenovo_101e_ispeaker_automute(codec);
6269 }
6270
6271 /*
6272  * generic initialization of ADC, input mixers and output mixers
6273  */
6274 static struct hda_verb alc883_auto_init_verbs[] = {
6275         /*
6276          * Unmute ADC0-2 and set the default input to mic-in
6277          */
6278         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6279         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6280         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6281         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6282
6283         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6284          * mixer widget
6285          * Note: PASD motherboards uses the Line In 2 as the input for
6286          * front panel mic (mic 2)
6287          */
6288         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6289         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6290         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6291         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6292         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
6293         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6294
6295         /*
6296          * Set up output mixers (0x0c - 0x0f)
6297          */
6298         /* set vol=0 to output mixers */
6299         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6300         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6301         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6302         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6303         /* set up input amps for analog loopback */
6304         /* Amp Indices: DAC = 0, mixer = 1 */
6305         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6306         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6307         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6308         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6309         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6310         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6311         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6312         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6313         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6314         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6315
6316         /* FIXME: use matrix-type input source selection */
6317         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6318         /* Input mixer1 */
6319         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6320         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6321         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6322         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
6323         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6324         /* Input mixer2 */
6325         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6326         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6327         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6328         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
6329         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6330
6331         { }
6332 };
6333
6334 /* capture mixer elements */
6335 static struct snd_kcontrol_new alc883_capture_mixer[] = {
6336         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6337         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6338         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6339         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6340         {
6341                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6342                 /* The multiple "Capture Source" controls confuse alsamixer
6343                  * So call somewhat different..
6344                  * FIXME: the controls appear in the "playback" view!
6345                  */
6346                 /* .name = "Capture Source", */
6347                 .name = "Input Source",
6348                 .count = 2,
6349                 .info = alc882_mux_enum_info,
6350                 .get = alc882_mux_enum_get,
6351                 .put = alc882_mux_enum_put,
6352         },
6353         { } /* end */
6354 };
6355
6356 /* pcm configuration: identiacal with ALC880 */
6357 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
6358 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
6359 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
6360 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
6361
6362 /*
6363  * configuration and preset
6364  */
6365 static const char *alc883_models[ALC883_MODEL_LAST] = {
6366         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
6367         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
6368         [ALC883_3ST_6ch]        = "3stack-6ch",
6369         [ALC883_6ST_DIG]        = "6stack-dig",
6370         [ALC883_TARGA_DIG]      = "targa-dig",
6371         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
6372         [ALC883_ACER]           = "acer",
6373         [ALC883_MEDION]         = "medion",
6374         [ALC883_MEDION_MD2]     = "medion-md2",
6375         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
6376         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
6377         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
6378         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
6379         [ALC883_AUTO]           = "auto",
6380 };
6381
6382 static struct snd_pci_quirk alc883_cfg_tbl[] = {
6383         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
6384         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
6385         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
6386         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
6387         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
6388         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
6389         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
6390         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
6391         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
6392         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
6393         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
6394         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
6395         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
6396         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
6397         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
6398         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
6399         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
6400         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
6401         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
6402         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
6403         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
6404         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
6405         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER),
6406         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
6407         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
6408         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
6409         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
6410         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
6411         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
6412         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
6413         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
6414         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
6415         {}
6416 };
6417
6418 static struct alc_config_preset alc883_presets[] = {
6419         [ALC883_3ST_2ch_DIG] = {
6420                 .mixers = { alc883_3ST_2ch_mixer },
6421                 .init_verbs = { alc883_init_verbs },
6422                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
6423                 .dac_nids = alc883_dac_nids,
6424                 .dig_out_nid = ALC883_DIGOUT_NID,
6425                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6426                 .adc_nids = alc883_adc_nids,
6427                 .dig_in_nid = ALC883_DIGIN_NID,
6428                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
6429                 .channel_mode = alc883_3ST_2ch_modes,
6430                 .input_mux = &alc883_capture_source,
6431         },
6432         [ALC883_3ST_6ch_DIG] = {
6433                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
6434                 .init_verbs = { alc883_init_verbs },
6435                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
6436                 .dac_nids = alc883_dac_nids,
6437                 .dig_out_nid = ALC883_DIGOUT_NID,
6438                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6439                 .adc_nids = alc883_adc_nids,
6440                 .dig_in_nid = ALC883_DIGIN_NID,
6441                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
6442                 .channel_mode = alc883_3ST_6ch_modes,
6443                 .need_dac_fix = 1,
6444                 .input_mux = &alc883_capture_source,
6445         },
6446         [ALC883_3ST_6ch] = {
6447                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
6448                 .init_verbs = { alc883_init_verbs },
6449                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
6450                 .dac_nids = alc883_dac_nids,
6451                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6452                 .adc_nids = alc883_adc_nids,
6453                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
6454                 .channel_mode = alc883_3ST_6ch_modes,
6455                 .need_dac_fix = 1,
6456                 .input_mux = &alc883_capture_source,
6457         },
6458         [ALC883_6ST_DIG] = {
6459                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
6460                 .init_verbs = { alc883_init_verbs },
6461                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
6462                 .dac_nids = alc883_dac_nids,
6463                 .dig_out_nid = ALC883_DIGOUT_NID,
6464                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6465                 .adc_nids = alc883_adc_nids,
6466                 .dig_in_nid = ALC883_DIGIN_NID,
6467                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
6468                 .channel_mode = alc883_sixstack_modes,
6469                 .input_mux = &alc883_capture_source,
6470         },
6471         [ALC883_TARGA_DIG] = {
6472                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
6473                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
6474                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
6475                 .dac_nids = alc883_dac_nids,
6476                 .dig_out_nid = ALC883_DIGOUT_NID,
6477                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6478                 .adc_nids = alc883_adc_nids,
6479                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
6480                 .channel_mode = alc883_3ST_6ch_modes,
6481                 .need_dac_fix = 1,
6482                 .input_mux = &alc883_capture_source,
6483                 .unsol_event = alc883_tagra_unsol_event,
6484                 .init_hook = alc883_tagra_automute,
6485         },
6486         [ALC883_TARGA_2ch_DIG] = {
6487                 .mixers = { alc883_tagra_2ch_mixer},
6488                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
6489                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
6490                 .dac_nids = alc883_dac_nids,
6491                 .dig_out_nid = ALC883_DIGOUT_NID,
6492                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6493                 .adc_nids = alc883_adc_nids,
6494                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
6495                 .channel_mode = alc883_3ST_2ch_modes,
6496                 .input_mux = &alc883_capture_source,
6497                 .unsol_event = alc883_tagra_unsol_event,
6498                 .init_hook = alc883_tagra_automute,
6499         },
6500         [ALC883_ACER] = {
6501                 .mixers = { alc883_base_mixer,
6502                             alc883_chmode_mixer },
6503                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
6504                  * and the headphone jack.  Turn this on and rely on the
6505                  * standard mute methods whenever the user wants to turn
6506                  * these outputs off.
6507                  */
6508                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
6509                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
6510                 .dac_nids = alc883_dac_nids,
6511                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6512                 .adc_nids = alc883_adc_nids,
6513                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
6514                 .channel_mode = alc883_3ST_2ch_modes,
6515                 .input_mux = &alc883_capture_source,
6516         },
6517         [ALC883_MEDION] = {
6518                 .mixers = { alc883_fivestack_mixer,
6519                             alc883_chmode_mixer },
6520                 .init_verbs = { alc883_init_verbs,
6521                                 alc883_medion_eapd_verbs },
6522                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
6523                 .dac_nids = alc883_dac_nids,
6524                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6525                 .adc_nids = alc883_adc_nids,
6526                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
6527                 .channel_mode = alc883_sixstack_modes,
6528                 .input_mux = &alc883_capture_source,
6529         },
6530         [ALC883_MEDION_MD2] = {
6531                 .mixers = { alc883_medion_md2_mixer},
6532                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
6533                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
6534                 .dac_nids = alc883_dac_nids,
6535                 .dig_out_nid = ALC883_DIGOUT_NID,
6536                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6537                 .adc_nids = alc883_adc_nids,
6538                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
6539                 .channel_mode = alc883_3ST_2ch_modes,
6540                 .input_mux = &alc883_capture_source,
6541                 .unsol_event = alc883_medion_md2_unsol_event,
6542                 .init_hook = alc883_medion_md2_automute,
6543         },      
6544         [ALC883_LAPTOP_EAPD] = {
6545                 .mixers = { alc883_base_mixer,
6546                             alc883_chmode_mixer },
6547                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
6548                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
6549                 .dac_nids = alc883_dac_nids,
6550                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6551                 .adc_nids = alc883_adc_nids,
6552                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
6553                 .channel_mode = alc883_3ST_2ch_modes,
6554                 .input_mux = &alc883_capture_source,
6555         },
6556         [ALC883_LENOVO_101E_2ch] = {
6557                 .mixers = { alc883_lenovo_101e_2ch_mixer},
6558                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
6559                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
6560                 .dac_nids = alc883_dac_nids,
6561                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6562                 .adc_nids = alc883_adc_nids,
6563                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
6564                 .channel_mode = alc883_3ST_2ch_modes,
6565                 .input_mux = &alc883_lenovo_101e_capture_source,
6566                 .unsol_event = alc883_lenovo_101e_unsol_event,
6567                 .init_hook = alc883_lenovo_101e_all_automute,
6568         },
6569         [ALC883_LENOVO_NB0763] = {
6570                 .mixers = { alc883_lenovo_nb0763_mixer },
6571                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
6572                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
6573                 .dac_nids = alc883_dac_nids,
6574                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6575                 .adc_nids = alc883_adc_nids,
6576                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
6577                 .channel_mode = alc883_3ST_2ch_modes,
6578                 .need_dac_fix = 1,
6579                 .input_mux = &alc883_lenovo_nb0763_capture_source,
6580                 .unsol_event = alc883_medion_md2_unsol_event,
6581                 .init_hook = alc883_medion_md2_automute,
6582         },
6583         [ALC888_LENOVO_MS7195_DIG] = {
6584                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
6585                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
6586                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
6587                 .dac_nids = alc883_dac_nids,
6588                 .dig_out_nid = ALC883_DIGOUT_NID,
6589                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
6590                 .adc_nids = alc883_adc_nids,
6591                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
6592                 .channel_mode = alc883_3ST_6ch_modes,
6593                 .need_dac_fix = 1,
6594                 .input_mux = &alc883_capture_source,
6595                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
6596                 .init_hook = alc888_lenovo_ms7195_front_automute,
6597         },      
6598 };
6599
6600
6601 /*
6602  * BIOS auto configuration
6603  */
6604 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
6605                                               hda_nid_t nid, int pin_type,
6606                                               int dac_idx)
6607 {
6608         /* set as output */
6609         struct alc_spec *spec = codec->spec;
6610         int idx;
6611
6612         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6613                 idx = 4;
6614         else
6615                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6616
6617         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
6618                             pin_type);
6619         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
6620                             AMP_OUT_UNMUTE);
6621         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6622
6623 }
6624
6625 static void alc883_auto_init_multi_out(struct hda_codec *codec)
6626 {
6627         struct alc_spec *spec = codec->spec;
6628         int i;
6629
6630         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6631         for (i = 0; i <= HDA_SIDE; i++) {
6632                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6633                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6634                 if (nid)
6635                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
6636                                                           i);
6637         }
6638 }
6639
6640 static void alc883_auto_init_hp_out(struct hda_codec *codec)
6641 {
6642         struct alc_spec *spec = codec->spec;
6643         hda_nid_t pin;
6644
6645         pin = spec->autocfg.hp_pins[0];
6646         if (pin) /* connect to front */
6647                 /* use dac 0 */
6648                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6649 }
6650
6651 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
6652 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
6653
6654 static void alc883_auto_init_analog_input(struct hda_codec *codec)
6655 {
6656         struct alc_spec *spec = codec->spec;
6657         int i;
6658
6659         for (i = 0; i < AUTO_PIN_LAST; i++) {
6660                 hda_nid_t nid = spec->autocfg.input_pins[i];
6661                 if (alc883_is_input_pin(nid)) {
6662                         snd_hda_codec_write(codec, nid, 0,
6663                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
6664                                             (i <= AUTO_PIN_FRONT_MIC ?
6665                                              PIN_VREF80 : PIN_IN));
6666                         if (nid != ALC883_PIN_CD_NID)
6667                                 snd_hda_codec_write(codec, nid, 0,
6668                                                     AC_VERB_SET_AMP_GAIN_MUTE,
6669                                                     AMP_OUT_MUTE);
6670                 }
6671         }
6672 }
6673
6674 /* almost identical with ALC880 parser... */
6675 static int alc883_parse_auto_config(struct hda_codec *codec)
6676 {
6677         struct alc_spec *spec = codec->spec;
6678         int err = alc880_parse_auto_config(codec);
6679
6680         if (err < 0)
6681                 return err;
6682         else if (err > 0)
6683                 /* hack - override the init verbs */
6684                 spec->init_verbs[0] = alc883_auto_init_verbs;
6685         spec->mixers[spec->num_mixers] = alc883_capture_mixer;
6686         spec->num_mixers++;
6687         return err;
6688 }
6689
6690 /* additional initialization for auto-configuration model */
6691 static void alc883_auto_init(struct hda_codec *codec)
6692 {
6693         alc883_auto_init_multi_out(codec);
6694         alc883_auto_init_hp_out(codec);
6695         alc883_auto_init_analog_input(codec);
6696 }
6697
6698 static int patch_alc883(struct hda_codec *codec)
6699 {
6700         struct alc_spec *spec;
6701         int err, board_config;
6702
6703         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6704         if (spec == NULL)
6705                 return -ENOMEM;
6706
6707         codec->spec = spec;
6708
6709         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
6710                                                   alc883_models,
6711                                                   alc883_cfg_tbl);
6712         if (board_config < 0) {
6713                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
6714                        "trying auto-probe from BIOS...\n");
6715                 board_config = ALC883_AUTO;
6716         }
6717
6718         if (board_config == ALC883_AUTO) {
6719                 /* automatic parse from the BIOS config */
6720                 err = alc883_parse_auto_config(codec);
6721                 if (err < 0) {
6722                         alc_free(codec);
6723                         return err;
6724                 } else if (!err) {
6725                         printk(KERN_INFO
6726                                "hda_codec: Cannot set up configuration "
6727                                "from BIOS.  Using base mode...\n");
6728                         board_config = ALC883_3ST_2ch_DIG;
6729                 }
6730         }
6731
6732         if (board_config != ALC883_AUTO)
6733                 setup_preset(spec, &alc883_presets[board_config]);
6734
6735         spec->stream_name_analog = "ALC883 Analog";
6736         spec->stream_analog_playback = &alc883_pcm_analog_playback;
6737         spec->stream_analog_capture = &alc883_pcm_analog_capture;
6738
6739         spec->stream_name_digital = "ALC883 Digital";
6740         spec->stream_digital_playback = &alc883_pcm_digital_playback;
6741         spec->stream_digital_capture = &alc883_pcm_digital_capture;
6742
6743         if (!spec->adc_nids && spec->input_mux) {
6744                 spec->adc_nids = alc883_adc_nids;
6745                 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
6746         }
6747
6748         codec->patch_ops = alc_patch_ops;
6749         if (board_config == ALC883_AUTO)
6750                 spec->init_hook = alc883_auto_init;
6751
6752         return 0;
6753 }
6754
6755 /*
6756  * ALC262 support
6757  */
6758
6759 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
6760 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
6761
6762 #define alc262_dac_nids         alc260_dac_nids
6763 #define alc262_adc_nids         alc882_adc_nids
6764 #define alc262_adc_nids_alt     alc882_adc_nids_alt
6765
6766 #define alc262_modes            alc260_modes
6767 #define alc262_capture_source   alc882_capture_source
6768
6769 static struct snd_kcontrol_new alc262_base_mixer[] = {
6770         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6771         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6772         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6773         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6774         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6775         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6776         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6777         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6778         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6779         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
6780         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
6781         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6782         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
6783            HDA_CODEC_MUTE("PC Beelp Playback Switch", 0x0b, 0x05, HDA_INPUT), */
6784         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
6785         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6786         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6787         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
6788         { } /* end */
6789 };
6790
6791 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
6792         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6793         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6794         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6795         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6796         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6797         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6798         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6799         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6800         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6801         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
6802         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
6803         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6804         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
6805            HDA_CODEC_MUTE("PC Beelp Playback Switch", 0x0b, 0x05, HDA_INPUT), */
6806         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
6807         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6808         { } /* end */
6809 };
6810
6811 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
6812         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6813         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6814         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6815         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6816         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
6817
6818         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6819         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6820         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6821         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
6822         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
6823         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6824         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6825         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6826         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6827         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6828         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
6829         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
6830         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
6831         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
6832         { } /* end */
6833 };
6834
6835 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
6836         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6837         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6838         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6839         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6840         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6841         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
6842         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
6843         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
6844         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
6845         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
6846         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
6847         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6848         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6849         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
6850         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
6851         { } /* end */
6852 };
6853
6854 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
6855         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6856         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6857         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
6858         { } /* end */
6859 };
6860
6861 static struct snd_kcontrol_new alc262_sony_mixer[] = {
6862         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6863         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6864         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6865         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6866         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
6867         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
6868         { } /* end */
6869 };
6870
6871
6872
6873 #define alc262_capture_mixer            alc882_capture_mixer
6874 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
6875
6876 /*
6877  * generic initialization of ADC, input mixers and output mixers
6878  */
6879 static struct hda_verb alc262_init_verbs[] = {
6880         /*
6881          * Unmute ADC0-2 and set the default input to mic-in
6882          */
6883         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6884         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6885         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6886         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6887         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6888         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6889
6890         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6891          * mixer widget
6892          * Note: PASD motherboards uses the Line In 2 as the input for
6893          * front panel mic (mic 2)
6894          */
6895         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6896         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6897         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6898         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
6899         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
6900         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
6901
6902         /*
6903          * Set up output mixers (0x0c - 0x0e)
6904          */
6905         /* set vol=0 to output mixers */
6906         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6907         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6908         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6909         /* set up input amps for analog loopback */
6910         /* Amp Indices: DAC = 0, mixer = 1 */
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         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6914         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6915         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6916         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6917
6918         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
6919         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
6920         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
6921         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
6922         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
6923         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
6924
6925         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
6926         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
6927         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
6928         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
6929         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
6930         
6931         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6932         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6933         
6934         /* FIXME: use matrix-type input source selection */
6935         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6936         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6937         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6938         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6939         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6940         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6941         /* Input mixer2 */
6942         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6943         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6944         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6945         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6946         /* Input mixer3 */
6947         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6948         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6949         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6950         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6951
6952         { }
6953 };
6954
6955 static struct hda_verb alc262_hippo_unsol_verbs[] = {
6956         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
6957         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6958         {}
6959 };
6960
6961 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
6962         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
6963         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6964         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
6965
6966         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
6967         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6968         {}
6969 };
6970
6971 static struct hda_verb alc262_sony_unsol_verbs[] = {
6972         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
6973         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6974         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
6975
6976         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
6977         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6978 };
6979
6980 /* mute/unmute internal speaker according to the hp jack and mute state */
6981 static void alc262_hippo_automute(struct hda_codec *codec, int force)
6982 {
6983         struct alc_spec *spec = codec->spec;
6984         unsigned int mute;
6985
6986         if (force || !spec->sense_updated) {
6987                 unsigned int present;
6988                 /* need to execute and sync at first */
6989                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
6990                 present = snd_hda_codec_read(codec, 0x15, 0,
6991                                          AC_VERB_GET_PIN_SENSE, 0);
6992                 spec->jack_present = (present & 0x80000000) != 0;
6993                 spec->sense_updated = 1;
6994         }
6995         if (spec->jack_present) {
6996                 /* mute internal speaker */
6997                 snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
6998                                          0x80, 0x80);
6999                 snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
7000                                          0x80, 0x80);
7001         } else {
7002                 /* unmute internal speaker if necessary */
7003                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
7004                 snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
7005                                          0x80, mute & 0x80);
7006                 mute = snd_hda_codec_amp_read(codec, 0x15, 1, HDA_OUTPUT, 0);
7007                 snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
7008                                          0x80, mute & 0x80);
7009         }
7010 }
7011
7012 /* unsolicited event for HP jack sensing */
7013 static void alc262_hippo_unsol_event(struct hda_codec *codec,
7014                                        unsigned int res)
7015 {
7016         if ((res >> 26) != ALC880_HP_EVENT)
7017                 return;
7018         alc262_hippo_automute(codec, 1);
7019 }
7020
7021 static void alc262_hippo1_automute(struct hda_codec *codec, int force)
7022 {
7023         struct alc_spec *spec = codec->spec;
7024         unsigned int mute;
7025
7026         if (force || !spec->sense_updated) {
7027                 unsigned int present;
7028                 /* need to execute and sync at first */
7029                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
7030                 present = snd_hda_codec_read(codec, 0x1b, 0,
7031                                          AC_VERB_GET_PIN_SENSE, 0);
7032                 spec->jack_present = (present & 0x80000000) != 0;
7033                 spec->sense_updated = 1;
7034         }
7035         if (spec->jack_present) {
7036                 /* mute internal speaker */
7037                 snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
7038                                          0x80, 0x80);
7039                 snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
7040                                          0x80, 0x80);
7041         } else {
7042                 /* unmute internal speaker if necessary */
7043                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
7044                 snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
7045                                          0x80, mute & 0x80);
7046                 mute = snd_hda_codec_amp_read(codec, 0x1b, 1, HDA_OUTPUT, 0);
7047                 snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
7048                                          0x80, mute & 0x80);
7049         }
7050 }
7051
7052 /* unsolicited event for HP jack sensing */
7053 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
7054                                        unsigned int res)
7055 {
7056         if ((res >> 26) != ALC880_HP_EVENT)
7057                 return;
7058         alc262_hippo1_automute(codec, 1);
7059 }
7060
7061 /*
7062  * fujitsu model
7063  *  0x14 = headphone/spdif-out, 0x15 = internal speaker
7064  */
7065
7066 #define ALC_HP_EVENT    0x37
7067
7068 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
7069         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
7070         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7071         {}
7072 };
7073
7074 static struct hda_input_mux alc262_fujitsu_capture_source = {
7075         .num_items = 2,
7076         .items = {
7077                 { "Mic", 0x0 },
7078                 { "CD", 0x4 },
7079         },
7080 };
7081
7082 static struct hda_input_mux alc262_HP_capture_source = {
7083         .num_items = 5,
7084         .items = {
7085                 { "Mic", 0x0 },
7086                 { "Front Mic", 0x3 },
7087                 { "Line", 0x2 },
7088                 { "CD", 0x4 },
7089                 { "AUX IN", 0x6 },
7090         },
7091 };
7092
7093 /* mute/unmute internal speaker according to the hp jack and mute state */
7094 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
7095 {
7096         struct alc_spec *spec = codec->spec;
7097         unsigned int mute;
7098
7099         if (force || !spec->sense_updated) {
7100                 unsigned int present;
7101                 /* need to execute and sync at first */
7102                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
7103                 present = snd_hda_codec_read(codec, 0x14, 0,
7104                                          AC_VERB_GET_PIN_SENSE, 0);
7105                 spec->jack_present = (present & 0x80000000) != 0;
7106                 spec->sense_updated = 1;
7107         }
7108         if (spec->jack_present) {
7109                 /* mute internal speaker */
7110                 snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
7111                                          0x80, 0x80);
7112                 snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
7113                                          0x80, 0x80);
7114         } else {
7115                 /* unmute internal speaker if necessary */
7116                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
7117                 snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
7118                                          0x80, mute & 0x80);
7119                 mute = snd_hda_codec_amp_read(codec, 0x14, 1, HDA_OUTPUT, 0);
7120                 snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
7121                                          0x80, mute & 0x80);
7122         }
7123 }
7124
7125 /* unsolicited event for HP jack sensing */
7126 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
7127                                        unsigned int res)
7128 {
7129         if ((res >> 26) != ALC_HP_EVENT)
7130                 return;
7131         alc262_fujitsu_automute(codec, 1);
7132 }
7133
7134 /* bind volumes of both NID 0x0c and 0x0d */
7135 static int alc262_fujitsu_master_vol_put(struct snd_kcontrol *kcontrol,
7136                                          struct snd_ctl_elem_value *ucontrol)
7137 {
7138         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
7139         long *valp = ucontrol->value.integer.value;
7140         int change;
7141
7142         change = snd_hda_codec_amp_update(codec, 0x0c, 0, HDA_OUTPUT, 0,
7143                                           0x7f, valp[0] & 0x7f);
7144         change |= snd_hda_codec_amp_update(codec, 0x0c, 1, HDA_OUTPUT, 0,
7145                                            0x7f, valp[1] & 0x7f);
7146         snd_hda_codec_amp_update(codec, 0x0d, 0, HDA_OUTPUT, 0,
7147                                  0x7f, valp[0] & 0x7f);
7148         snd_hda_codec_amp_update(codec, 0x0d, 1, HDA_OUTPUT, 0,
7149                                  0x7f, valp[1] & 0x7f);
7150         return change;
7151 }
7152
7153 /* bind hp and internal speaker mute (with plug check) */
7154 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
7155                                          struct snd_ctl_elem_value *ucontrol)
7156 {
7157         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
7158         long *valp = ucontrol->value.integer.value;
7159         int change;
7160
7161         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
7162                                           0x80, valp[0] ? 0 : 0x80);
7163         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
7164                                            0x80, valp[1] ? 0 : 0x80);
7165         if (change || codec->in_resume)
7166                 alc262_fujitsu_automute(codec, codec->in_resume);
7167         return change;
7168 }
7169
7170 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
7171         {
7172                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7173                 .name = "Master Playback Volume",
7174                 .info = snd_hda_mixer_amp_volume_info,
7175                 .get = snd_hda_mixer_amp_volume_get,
7176                 .put = alc262_fujitsu_master_vol_put,
7177                 .tlv = { .c = snd_hda_mixer_amp_tlv },
7178                 .private_value = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
7179         },
7180         {
7181                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7182                 .name = "Master Playback Switch",
7183                 .info = snd_hda_mixer_amp_switch_info,
7184                 .get = snd_hda_mixer_amp_switch_get,
7185                 .put = alc262_fujitsu_master_sw_put,
7186                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
7187         },
7188         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7189         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7190         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7191         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7192         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7193         { } /* end */
7194 };
7195
7196 /* additional init verbs for Benq laptops */
7197 static struct hda_verb alc262_EAPD_verbs[] = {
7198         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7199         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
7200         {}
7201 };
7202
7203 /* add playback controls from the parsed DAC table */
7204 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
7205                                              const struct auto_pin_cfg *cfg)
7206 {
7207         hda_nid_t nid;
7208         int err;
7209
7210         spec->multiout.num_dacs = 1;    /* only use one dac */
7211         spec->multiout.dac_nids = spec->private_dac_nids;
7212         spec->multiout.dac_nids[0] = 2;
7213
7214         nid = cfg->line_out_pins[0];
7215         if (nid) {
7216                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
7217                                   "Front Playback Volume",
7218                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
7219                 if (err < 0)
7220                         return err;
7221                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7222                                   "Front Playback Switch",
7223                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
7224                 if (err < 0)
7225                         return err;
7226         }
7227
7228         nid = cfg->speaker_pins[0];
7229         if (nid) {
7230                 if (nid == 0x16) {
7231                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
7232                                           "Speaker Playback Volume",
7233                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
7234                                                               HDA_OUTPUT));
7235                         if (err < 0)
7236                                 return err;
7237                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7238                                           "Speaker Playback Switch",
7239                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
7240                                                               HDA_OUTPUT));
7241                         if (err < 0)
7242                                 return err;
7243                 } else {
7244                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7245                                           "Speaker Playback Switch",
7246                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
7247                                                               HDA_OUTPUT));
7248                         if (err < 0)
7249                                 return err;
7250                 }
7251         }
7252         nid = cfg->hp_pins[0];
7253         if (nid) {
7254                 /* spec->multiout.hp_nid = 2; */
7255                 if (nid == 0x16) {
7256                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
7257                                           "Headphone Playback Volume",
7258                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
7259                                                               HDA_OUTPUT));
7260                         if (err < 0)
7261                                 return err;
7262                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7263                                           "Headphone Playback Switch",
7264                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
7265                                                               HDA_OUTPUT));
7266                         if (err < 0)
7267                                 return err;
7268                 } else {
7269                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
7270                                           "Headphone Playback Switch",
7271                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
7272                                                               HDA_OUTPUT));
7273                         if (err < 0)
7274                                 return err;
7275                 }
7276         }
7277         return 0;
7278 }
7279
7280 /* identical with ALC880 */
7281 #define alc262_auto_create_analog_input_ctls \
7282         alc880_auto_create_analog_input_ctls
7283
7284 /*
7285  * generic initialization of ADC, input mixers and output mixers
7286  */
7287 static struct hda_verb alc262_volume_init_verbs[] = {
7288         /*
7289          * Unmute ADC0-2 and set the default input to mic-in
7290          */
7291         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7292         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7293         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7294         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7295         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7296         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7297
7298         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7299          * mixer widget
7300          * Note: PASD motherboards uses the Line In 2 as the input for
7301          * front panel mic (mic 2)
7302          */
7303         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7304         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7305         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7306         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7307         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
7308         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7309
7310         /*
7311          * Set up output mixers (0x0c - 0x0f)
7312          */
7313         /* set vol=0 to output mixers */
7314         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7315         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7316         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7317         
7318         /* set up input amps for analog loopback */
7319         /* Amp Indices: DAC = 0, mixer = 1 */
7320         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7321         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7322         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7323         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7324         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7325         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7326
7327         /* FIXME: use matrix-type input source selection */
7328         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7329         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7330         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7331         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7332         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7333         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7334         /* Input mixer2 */
7335         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7336         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7337         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7338         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7339         /* Input mixer3 */
7340         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7341         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7342         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7343         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7344
7345         { }
7346 };
7347
7348 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
7349         /*
7350          * Unmute ADC0-2 and set the default input to mic-in
7351          */
7352         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7353         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7354         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7355         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7356         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7357         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7358
7359         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7360          * mixer widget
7361          * Note: PASD motherboards uses the Line In 2 as the input for
7362          * front panel mic (mic 2)
7363          */
7364         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7365         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7366         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7367         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7368         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
7369         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7370         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
7371         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(6)},
7372         
7373         /*
7374          * Set up output mixers (0x0c - 0x0e)
7375          */
7376         /* set vol=0 to output mixers */
7377         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7378         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7379         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7380
7381         /* set up input amps for analog loopback */
7382         /* Amp Indices: DAC = 0, mixer = 1 */
7383         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7384         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7385         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7386         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7387         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7388         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7389
7390         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
7391         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7392         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7393
7394         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7395         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7396
7397         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7398         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7399
7400         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7401         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
7402         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
7403         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7404         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7405
7406         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
7407         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
7408         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
7409         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
7410         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
7411         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
7412
7413
7414         /* FIXME: use matrix-type input source selection */
7415         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7416         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7417         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7418         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
7419         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
7420         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
7421         /* Input mixer2 */
7422         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7423         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
7424         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
7425         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
7426         /* Input mixer3 */
7427         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7428         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
7429         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
7430         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
7431
7432         { }
7433 };
7434
7435 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
7436         /*
7437          * Unmute ADC0-2 and set the default input to mic-in
7438          */
7439         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7440         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7441         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7442         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7443         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7444         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7445
7446         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7447          * mixer widget
7448          * Note: PASD motherboards uses the Line In 2 as the input for front
7449          * panel mic (mic 2)
7450          */
7451         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7452         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7453         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7454         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7455         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
7456         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
7457         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
7458         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(6)},
7459         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(7)},
7460         /*
7461          * Set up output mixers (0x0c - 0x0e)
7462          */
7463         /* set vol=0 to output mixers */
7464         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7465         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7466         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7467
7468         /* set up input amps for analog loopback */
7469         /* Amp Indices: DAC = 0, mixer = 1 */
7470         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7471         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7472         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7473         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7474         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7475         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7476
7477
7478         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
7479         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
7480         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
7481         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
7482         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
7483         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
7484         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
7485
7486         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7487         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7488
7489         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7490         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7491
7492         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
7493         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
7494         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
7495         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
7496         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
7497         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
7498
7499         /* FIXME: use matrix-type input source selection */
7500         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7501         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7502         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
7503         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
7504         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
7505         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
7506         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
7507         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
7508         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
7509         /* Input mixer2 */
7510         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7511         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
7512         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
7513         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
7514         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
7515         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
7516         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
7517         /* Input mixer3 */
7518         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7519         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
7520         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
7521         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
7522         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
7523         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
7524         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
7525
7526         { }
7527 };
7528
7529 /* pcm configuration: identiacal with ALC880 */
7530 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
7531 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
7532 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
7533 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
7534
7535 /*
7536  * BIOS auto configuration
7537  */
7538 static int alc262_parse_auto_config(struct hda_codec *codec)
7539 {
7540         struct alc_spec *spec = codec->spec;
7541         int err;
7542         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
7543
7544         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
7545                                            alc262_ignore);
7546         if (err < 0)
7547                 return err;
7548         if (!spec->autocfg.line_outs)
7549                 return 0; /* can't find valid BIOS pin config */
7550         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
7551         if (err < 0)
7552                 return err;
7553         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
7554         if (err < 0)
7555                 return err;
7556
7557         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
7558
7559         if (spec->autocfg.dig_out_pin)
7560                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
7561         if (spec->autocfg.dig_in_pin)
7562                 spec->dig_in_nid = ALC262_DIGIN_NID;
7563
7564         if (spec->kctl_alloc)
7565                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
7566
7567         spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs;
7568         spec->num_mux_defs = 1;
7569         spec->input_mux = &spec->private_imux;
7570
7571         return 1;
7572 }
7573
7574 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
7575 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
7576 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
7577
7578
7579 /* init callback for auto-configuration model -- overriding the default init */
7580 static void alc262_auto_init(struct hda_codec *codec)
7581 {
7582         alc262_auto_init_multi_out(codec);
7583         alc262_auto_init_hp_out(codec);
7584         alc262_auto_init_analog_input(codec);
7585 }
7586
7587 /*
7588  * configuration and preset
7589  */
7590 static const char *alc262_models[ALC262_MODEL_LAST] = {
7591         [ALC262_BASIC]          = "basic",
7592         [ALC262_HIPPO]          = "hippo",
7593         [ALC262_HIPPO_1]        = "hippo_1",
7594         [ALC262_FUJITSU]        = "fujitsu",
7595         [ALC262_HP_BPC]         = "hp-bpc",
7596         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
7597         [ALC262_BENQ_ED8]       = "benq",
7598         [ALC262_BENQ_ED8]       = "sony-assamd",
7599         [ALC262_AUTO]           = "auto",
7600 };
7601
7602 static struct snd_pci_quirk alc262_cfg_tbl[] = {
7603         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
7604         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
7605         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
7606         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
7607         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
7608         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
7609         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
7610         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
7611         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
7612         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
7613         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
7614         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
7615         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
7616         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
7617         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
7618         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
7619         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
7620         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
7621         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
7622         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
7623         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
7624         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
7625         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
7626         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
7627         {}
7628 };
7629
7630 static struct alc_config_preset alc262_presets[] = {
7631         [ALC262_BASIC] = {
7632                 .mixers = { alc262_base_mixer },
7633                 .init_verbs = { alc262_init_verbs },
7634                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
7635                 .dac_nids = alc262_dac_nids,
7636                 .hp_nid = 0x03,
7637                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
7638                 .channel_mode = alc262_modes,
7639                 .input_mux = &alc262_capture_source,
7640         },
7641         [ALC262_HIPPO] = {
7642                 .mixers = { alc262_base_mixer },
7643                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
7644                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
7645                 .dac_nids = alc262_dac_nids,
7646                 .hp_nid = 0x03,
7647                 .dig_out_nid = ALC262_DIGOUT_NID,
7648                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
7649                 .channel_mode = alc262_modes,
7650                 .input_mux = &alc262_capture_source,
7651                 .unsol_event = alc262_hippo_unsol_event,
7652         },
7653         [ALC262_HIPPO_1] = {
7654                 .mixers = { alc262_hippo1_mixer },
7655                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
7656                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
7657                 .dac_nids = alc262_dac_nids,
7658                 .hp_nid = 0x02,
7659                 .dig_out_nid = ALC262_DIGOUT_NID,
7660                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
7661                 .channel_mode = alc262_modes,
7662                 .input_mux = &alc262_capture_source,
7663                 .unsol_event = alc262_hippo1_unsol_event,
7664         },
7665         [ALC262_FUJITSU] = {
7666                 .mixers = { alc262_fujitsu_mixer },
7667                 .init_verbs = { alc262_init_verbs, alc262_fujitsu_unsol_verbs },
7668                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
7669                 .dac_nids = alc262_dac_nids,
7670                 .hp_nid = 0x03,
7671                 .dig_out_nid = ALC262_DIGOUT_NID,
7672                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
7673                 .channel_mode = alc262_modes,
7674                 .input_mux = &alc262_fujitsu_capture_source,
7675                 .unsol_event = alc262_fujitsu_unsol_event,
7676         },
7677         [ALC262_HP_BPC] = {
7678                 .mixers = { alc262_HP_BPC_mixer },
7679                 .init_verbs = { alc262_HP_BPC_init_verbs },
7680                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
7681                 .dac_nids = alc262_dac_nids,
7682                 .hp_nid = 0x03,
7683                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
7684                 .channel_mode = alc262_modes,
7685                 .input_mux = &alc262_HP_capture_source,
7686         },
7687         [ALC262_HP_BPC_D7000_WF] = {
7688                 .mixers = { alc262_HP_BPC_WildWest_mixer },
7689                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
7690                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
7691                 .dac_nids = alc262_dac_nids,
7692                 .hp_nid = 0x03,
7693                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
7694                 .channel_mode = alc262_modes,
7695                 .input_mux = &alc262_HP_capture_source,
7696         },
7697         [ALC262_HP_BPC_D7000_WL] = {
7698                 .mixers = { alc262_HP_BPC_WildWest_mixer,
7699                             alc262_HP_BPC_WildWest_option_mixer },
7700                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
7701                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
7702                 .dac_nids = alc262_dac_nids,
7703                 .hp_nid = 0x03,
7704                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
7705                 .channel_mode = alc262_modes,
7706                 .input_mux = &alc262_HP_capture_source,
7707         },
7708         [ALC262_BENQ_ED8] = {
7709                 .mixers = { alc262_base_mixer },
7710                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
7711                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
7712                 .dac_nids = alc262_dac_nids,
7713                 .hp_nid = 0x03,
7714                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
7715                 .channel_mode = alc262_modes,
7716                 .input_mux = &alc262_capture_source,
7717         },
7718         [ALC262_SONY_ASSAMD] = {
7719                 .mixers = { alc262_sony_mixer },
7720                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
7721                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
7722                 .dac_nids = alc262_dac_nids,
7723                 .hp_nid = 0x02,
7724                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
7725                 .channel_mode = alc262_modes,
7726                 .input_mux = &alc262_capture_source,
7727                 .unsol_event = alc262_hippo_unsol_event,
7728         },      
7729 };
7730
7731 static int patch_alc262(struct hda_codec *codec)
7732 {
7733         struct alc_spec *spec;
7734         int board_config;
7735         int err;
7736
7737         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7738         if (spec == NULL)
7739                 return -ENOMEM;
7740
7741         codec->spec = spec;
7742 #if 0
7743         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
7744          * under-run
7745          */
7746         {
7747         int tmp;
7748         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
7749         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
7750         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
7751         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
7752         }
7753 #endif
7754
7755         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
7756                                                   alc262_models,
7757                                                   alc262_cfg_tbl);
7758
7759         if (board_config < 0) {
7760                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
7761                        "trying auto-probe from BIOS...\n");
7762                 board_config = ALC262_AUTO;
7763         }
7764
7765         if (board_config == ALC262_AUTO) {
7766                 /* automatic parse from the BIOS config */
7767                 err = alc262_parse_auto_config(codec);
7768                 if (err < 0) {
7769                         alc_free(codec);
7770                         return err;
7771                 } else if (!err) {
7772                         printk(KERN_INFO
7773                                "hda_codec: Cannot set up configuration "
7774                                "from BIOS.  Using base mode...\n");
7775                         board_config = ALC262_BASIC;
7776                 }
7777         }
7778
7779         if (board_config != ALC262_AUTO)
7780                 setup_preset(spec, &alc262_presets[board_config]);
7781
7782         spec->stream_name_analog = "ALC262 Analog";
7783         spec->stream_analog_playback = &alc262_pcm_analog_playback;
7784         spec->stream_analog_capture = &alc262_pcm_analog_capture;
7785                 
7786         spec->stream_name_digital = "ALC262 Digital";
7787         spec->stream_digital_playback = &alc262_pcm_digital_playback;
7788         spec->stream_digital_capture = &alc262_pcm_digital_capture;
7789
7790         if (!spec->adc_nids && spec->input_mux) {
7791                 /* check whether NID 0x07 is valid */
7792                 unsigned int wcap = get_wcaps(codec, 0x07);
7793
7794                 /* get type */
7795                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
7796                 if (wcap != AC_WID_AUD_IN) {
7797                         spec->adc_nids = alc262_adc_nids_alt;
7798                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
7799                         spec->mixers[spec->num_mixers] =
7800                                 alc262_capture_alt_mixer;
7801                         spec->num_mixers++;
7802                 } else {
7803                         spec->adc_nids = alc262_adc_nids;
7804                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
7805                         spec->mixers[spec->num_mixers] = alc262_capture_mixer;
7806                         spec->num_mixers++;
7807                 }
7808         }
7809
7810         codec->patch_ops = alc_patch_ops;
7811         if (board_config == ALC262_AUTO)
7812                 spec->init_hook = alc262_auto_init;
7813                 
7814         return 0;
7815 }
7816
7817 /*
7818  *  ALC268 channel source setting (2 channel)
7819  */
7820 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
7821 #define alc268_modes            alc260_modes
7822         
7823 static hda_nid_t alc268_dac_nids[2] = {
7824         /* front, hp */
7825         0x02, 0x03
7826 };
7827
7828 static hda_nid_t alc268_adc_nids[2] = {
7829         /* ADC0-1 */
7830         0x08, 0x07
7831 };
7832
7833 static hda_nid_t alc268_adc_nids_alt[1] = {
7834         /* ADC0 */
7835         0x08
7836 };
7837
7838 static struct snd_kcontrol_new alc268_base_mixer[] = {
7839         /* output mixer control */
7840         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
7841         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7842         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
7843         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7844         { }
7845 };
7846
7847 /*
7848  * generic initialization of ADC, input mixers and output mixers
7849  */
7850 static struct hda_verb alc268_base_init_verbs[] = {
7851         /* Unmute DAC0-1 and set vol = 0 */
7852         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7853         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7854         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7855         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7856         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7857         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7858
7859         /*
7860          * Set up output mixers (0x0c - 0x0e)
7861          */
7862         /* set vol=0 to output mixers */
7863         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7864         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7865         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7866         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
7867
7868         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7869         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7870
7871         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
7872         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
7873         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
7874         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
7875         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
7876         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7877         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7878         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7879
7880         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7881         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7882         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7883         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7884         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7885         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7886         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7887         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7888
7889         /* FIXME: use matrix-type input source selection */
7890         /* Mixer elements: 0x18, 19, 1a, 1c, 14, 15, 0b */
7891         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7892         /* Input mixer2 */
7893         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7894         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
7895         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
7896         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
7897
7898         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7899         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
7900         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
7901         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
7902         { }
7903 };
7904
7905 /*
7906  * generic initialization of ADC, input mixers and output mixers
7907  */
7908 static struct hda_verb alc268_volume_init_verbs[] = {
7909         /* set output DAC */
7910         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7911         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7912         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7913         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7914
7915         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
7916         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
7917         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7918         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7919         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
7920
7921         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7922         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7923         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7924         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7925         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7926
7927         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7928         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7929         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7930         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7931
7932         /* set PCBEEP vol = 0 */
7933         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, (0xb000 | (0x00 << 8))},
7934
7935         { }
7936 };
7937
7938 #define alc268_mux_enum_info alc_mux_enum_info
7939 #define alc268_mux_enum_get alc_mux_enum_get
7940
7941 static int alc268_mux_enum_put(struct snd_kcontrol *kcontrol,
7942                                struct snd_ctl_elem_value *ucontrol)
7943 {
7944         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
7945         struct alc_spec *spec = codec->spec;
7946         const struct hda_input_mux *imux = spec->input_mux;
7947         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
7948         static hda_nid_t capture_mixers[3] = { 0x23, 0x24 };
7949         hda_nid_t nid = capture_mixers[adc_idx];
7950         unsigned int *cur_val = &spec->cur_mux[adc_idx];
7951         unsigned int i, idx;
7952
7953         idx = ucontrol->value.enumerated.item[0];
7954         if (idx >= imux->num_items)
7955                 idx = imux->num_items - 1;
7956         if (*cur_val == idx && !codec->in_resume)
7957                 return 0;
7958         for (i = 0; i < imux->num_items; i++) {
7959                 unsigned int v = (i == idx) ? 0x7000 : 0x7080;
7960                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
7961                                     v | (imux->items[i].index << 8));
7962                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
7963                                     idx );
7964         }
7965         *cur_val = idx;
7966         return 1;
7967 }
7968
7969 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
7970         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
7971         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
7972         {
7973                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7974                 /* The multiple "Capture Source" controls confuse alsamixer
7975                  * So call somewhat different..
7976                  * FIXME: the controls appear in the "playback" view!
7977                  */
7978                 /* .name = "Capture Source", */
7979                 .name = "Input Source",
7980                 .count = 1,
7981                 .info = alc268_mux_enum_info,
7982                 .get = alc268_mux_enum_get,
7983                 .put = alc268_mux_enum_put,
7984         },
7985         { } /* end */
7986 };
7987
7988 static struct snd_kcontrol_new alc268_capture_mixer[] = {
7989         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
7990         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
7991         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
7992         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
7993         {
7994                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7995                 /* The multiple "Capture Source" controls confuse alsamixer
7996                  * So call somewhat different..
7997                  * FIXME: the controls appear in the "playback" view!
7998                  */
7999                 /* .name = "Capture Source", */
8000                 .name = "Input Source",
8001                 .count = 2,
8002                 .info = alc268_mux_enum_info,
8003                 .get = alc268_mux_enum_get,
8004                 .put = alc268_mux_enum_put,
8005         },
8006         { } /* end */
8007 };
8008
8009 static struct hda_input_mux alc268_capture_source = {
8010         .num_items = 4,
8011         .items = {
8012                 { "Mic", 0x0 },
8013                 { "Front Mic", 0x1 },
8014                 { "Line", 0x2 },
8015                 { "CD", 0x3 },
8016         },
8017 };
8018
8019 /* create input playback/capture controls for the given pin */
8020 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
8021                                     const char *ctlname, int idx)
8022 {
8023         char name[32];
8024         int err;
8025
8026         sprintf(name, "%s Playback Volume", ctlname);
8027         if (nid == 0x14) {
8028                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
8029                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
8030                                                       HDA_OUTPUT));
8031                 if (err < 0)
8032                         return err;
8033         } else if (nid == 0x15) {
8034                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
8035                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
8036                                                       HDA_OUTPUT));
8037                 if (err < 0)
8038                         return err;
8039         } else
8040                 return -1;
8041         sprintf(name, "%s Playback Switch", ctlname);
8042         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
8043                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
8044         if (err < 0)
8045                 return err;
8046         return 0;
8047 }
8048
8049 /* add playback controls from the parsed DAC table */
8050 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
8051                                              const struct auto_pin_cfg *cfg)
8052 {
8053         hda_nid_t nid;
8054         int err;
8055
8056         spec->multiout.num_dacs = 2;    /* only use one dac */
8057         spec->multiout.dac_nids = spec->private_dac_nids;
8058         spec->multiout.dac_nids[0] = 2;
8059         spec->multiout.dac_nids[1] = 3;
8060
8061         nid = cfg->line_out_pins[0];
8062         if (nid)
8063                 alc268_new_analog_output(spec, nid, "Front", 0);        
8064
8065         nid = cfg->speaker_pins[0];
8066         if (nid == 0x1d) {
8067                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
8068                                   "Speaker Playback Volume",
8069                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
8070                 if (err < 0)
8071                         return err;
8072         }
8073         nid = cfg->hp_pins[0];
8074         if (nid)
8075                 alc268_new_analog_output(spec, nid, "Headphone", 0);
8076
8077         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
8078         if (nid == 0x16) {
8079                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
8080                                   "Mono Playback Switch",
8081                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
8082                 if (err < 0)
8083                         return err;
8084         }
8085         return 0;       
8086 }
8087
8088 /* create playback/capture controls for input pins */
8089 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
8090                                                 const struct auto_pin_cfg *cfg)
8091 {
8092         struct hda_input_mux *imux = &spec->private_imux;
8093         int i, idx1;
8094
8095         for (i = 0; i < AUTO_PIN_LAST; i++) {
8096                 switch(cfg->input_pins[i]) {
8097                 case 0x18:
8098                         idx1 = 0;       /* Mic 1 */
8099                         break;
8100                 case 0x19:
8101                         idx1 = 1;       /* Mic 2 */
8102                         break;
8103                 case 0x1a:
8104                         idx1 = 2;       /* Line In */
8105                         break;
8106                 case 0x1c:      
8107                         idx1 = 3;       /* CD */
8108                         break;
8109                 default:
8110                         continue;
8111                 }
8112                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
8113                 imux->items[imux->num_items].index = idx1;
8114                 imux->num_items++;      
8115         }
8116         return 0;
8117 }
8118
8119 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
8120 {
8121         struct alc_spec *spec = codec->spec;
8122         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
8123         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
8124         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
8125         unsigned int    dac_vol1, dac_vol2;
8126
8127         if (speaker_nid) {
8128                 snd_hda_codec_write(codec, speaker_nid, 0,
8129                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
8130                 snd_hda_codec_write(codec, 0x0f, 0,
8131                                     AC_VERB_SET_AMP_GAIN_MUTE,
8132                                     AMP_IN_UNMUTE(1));
8133                 snd_hda_codec_write(codec, 0x10, 0,
8134                                     AC_VERB_SET_AMP_GAIN_MUTE,
8135                                     AMP_IN_UNMUTE(1));
8136         } else {
8137                 snd_hda_codec_write(codec, 0x0f, 0,
8138                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
8139                 snd_hda_codec_write(codec, 0x10, 0,
8140                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
8141         }
8142
8143         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
8144         if (line_nid == 0x14)   
8145                 dac_vol2 = AMP_OUT_ZERO;
8146         else if (line_nid == 0x15)
8147                 dac_vol1 = AMP_OUT_ZERO;
8148         if (hp_nid == 0x14)     
8149                 dac_vol2 = AMP_OUT_ZERO;
8150         else if (hp_nid == 0x15)
8151                 dac_vol1 = AMP_OUT_ZERO;
8152         if (line_nid != 0x16 || hp_nid != 0x16 ||
8153             spec->autocfg.line_out_pins[1] != 0x16 ||
8154             spec->autocfg.line_out_pins[2] != 0x16)
8155                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
8156
8157         snd_hda_codec_write(codec, 0x02, 0,
8158                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
8159         snd_hda_codec_write(codec, 0x03, 0,
8160                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
8161 }
8162
8163 /* pcm configuration: identiacal with ALC880 */
8164 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
8165 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
8166 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
8167
8168 /*
8169  * BIOS auto configuration
8170  */
8171 static int alc268_parse_auto_config(struct hda_codec *codec)
8172 {
8173         struct alc_spec *spec = codec->spec;
8174         int err;
8175         static hda_nid_t alc268_ignore[] = { 0 };
8176
8177         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
8178                                            alc268_ignore);
8179         if (err < 0)
8180                 return err;
8181         if (!spec->autocfg.line_outs)
8182                 return 0; /* can't find valid BIOS pin config */
8183
8184         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
8185         if (err < 0)
8186                 return err;
8187         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
8188         if (err < 0)
8189                 return err;
8190
8191         spec->multiout.max_channels = 2;
8192
8193         /* digital only support output */
8194         if (spec->autocfg.dig_out_pin)
8195                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
8196
8197         if (spec->kctl_alloc)
8198                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
8199
8200         spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs;
8201         spec->num_mux_defs = 1;
8202         spec->input_mux = &spec->private_imux;
8203
8204         return 1;
8205 }
8206
8207 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
8208 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
8209 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
8210
8211 /* init callback for auto-configuration model -- overriding the default init */
8212 static void alc268_auto_init(struct hda_codec *codec)
8213 {
8214         alc268_auto_init_multi_out(codec);
8215         alc268_auto_init_hp_out(codec);
8216         alc268_auto_init_mono_speaker_out(codec);
8217         alc268_auto_init_analog_input(codec);
8218 }
8219
8220 /*
8221  * configuration and preset
8222  */
8223 static const char *alc268_models[ALC268_MODEL_LAST] = {
8224         [ALC268_3ST]            = "3stack",
8225         [ALC268_AUTO]           = "auto",
8226 };
8227
8228 static struct snd_pci_quirk alc268_cfg_tbl[] = {
8229         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
8230         {}
8231 };
8232
8233 static struct alc_config_preset alc268_presets[] = {
8234         [ALC268_3ST] = {
8235                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer },
8236                 .init_verbs = { alc268_base_init_verbs },
8237                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
8238                 .dac_nids = alc268_dac_nids,
8239                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
8240                 .adc_nids = alc268_adc_nids_alt,
8241                 .hp_nid = 0x03,
8242                 .dig_out_nid = ALC268_DIGOUT_NID,
8243                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
8244                 .channel_mode = alc268_modes,
8245                 .input_mux = &alc268_capture_source,
8246         },
8247 };
8248
8249 static int patch_alc268(struct hda_codec *codec)
8250 {
8251         struct alc_spec *spec;
8252         int board_config;
8253         int err;
8254
8255         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
8256         if (spec == NULL)
8257                 return -ENOMEM;
8258
8259         codec->spec = spec;
8260
8261         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
8262                                                   alc268_models,
8263                                                   alc268_cfg_tbl);
8264
8265         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
8266                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
8267                        "trying auto-probe from BIOS...\n");
8268                 board_config = ALC268_AUTO;
8269         }
8270
8271         if (board_config == ALC268_AUTO) {
8272                 /* automatic parse from the BIOS config */
8273                 err = alc268_parse_auto_config(codec);
8274                 if (err < 0) {
8275                         alc_free(codec);
8276                         return err;
8277                 } else if (!err) {
8278                         printk(KERN_INFO
8279                                "hda_codec: Cannot set up configuration "
8280                                "from BIOS.  Using base mode...\n");
8281                         board_config = ALC268_3ST;
8282                 }
8283         }
8284
8285         if (board_config != ALC268_AUTO)
8286                 setup_preset(spec, &alc268_presets[board_config]);
8287
8288         spec->stream_name_analog = "ALC268 Analog";
8289         spec->stream_analog_playback = &alc268_pcm_analog_playback;
8290         spec->stream_analog_capture = &alc268_pcm_analog_capture;
8291
8292         spec->stream_name_digital = "ALC268 Digital";
8293         spec->stream_digital_playback = &alc268_pcm_digital_playback;
8294
8295         if (board_config == ALC268_AUTO) {
8296                 if (!spec->adc_nids && spec->input_mux) {
8297                         /* check whether NID 0x07 is valid */
8298                         unsigned int wcap = get_wcaps(codec, 0x07);
8299
8300                         /* get type */
8301                         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
8302                         if (wcap != AC_WID_AUD_IN) {
8303                                 spec->adc_nids = alc268_adc_nids_alt;
8304                                 spec->num_adc_nids =
8305                                         ARRAY_SIZE(alc268_adc_nids_alt);
8306                                 spec->mixers[spec->num_mixers] =
8307                                         alc268_capture_alt_mixer;
8308                                 spec->num_mixers++;
8309                         } else {
8310                                 spec->adc_nids = alc268_adc_nids;
8311                                 spec->num_adc_nids =
8312                                         ARRAY_SIZE(alc268_adc_nids);
8313                                 spec->mixers[spec->num_mixers] =
8314                                         alc268_capture_mixer;
8315                                 spec->num_mixers++;
8316                         }
8317                 }
8318         }
8319         codec->patch_ops = alc_patch_ops;
8320         if (board_config == ALC268_AUTO)
8321                 spec->init_hook = alc268_auto_init;
8322                 
8323         return 0;
8324 }
8325
8326 /*
8327  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
8328  */
8329
8330 /*
8331  * set the path ways for 2 channel output
8332  * need to set the codec line out and mic 1 pin widgets to inputs
8333  */
8334 static struct hda_verb alc861_threestack_ch2_init[] = {
8335         /* set pin widget 1Ah (line in) for input */
8336         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
8337         /* set pin widget 18h (mic1/2) for input, for mic also enable
8338          * the vref
8339          */
8340         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8341
8342         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
8343 #if 0
8344         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
8345         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
8346 #endif
8347         { } /* end */
8348 };
8349 /*
8350  * 6ch mode
8351  * need to set the codec line out and mic 1 pin widgets to outputs
8352  */
8353 static struct hda_verb alc861_threestack_ch6_init[] = {
8354         /* set pin widget 1Ah (line in) for output (Back Surround)*/
8355         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8356         /* set pin widget 18h (mic1) for output (CLFE)*/
8357         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8358
8359         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
8360         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
8361
8362         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
8363 #if 0
8364         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
8365         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
8366 #endif
8367         { } /* end */
8368 };
8369
8370 static struct hda_channel_mode alc861_threestack_modes[2] = {
8371         { 2, alc861_threestack_ch2_init },
8372         { 6, alc861_threestack_ch6_init },
8373 };
8374 /* Set mic1 as input and unmute the mixer */
8375 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
8376         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8377         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
8378         { } /* end */
8379 };
8380 /* Set mic1 as output and mute mixer */
8381 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
8382         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8383         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
8384         { } /* end */
8385 };
8386
8387 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
8388         { 2, alc861_uniwill_m31_ch2_init },
8389         { 4, alc861_uniwill_m31_ch4_init },
8390 };
8391
8392 /* Set mic1 and line-in as input and unmute the mixer */
8393 static struct hda_verb alc861_asus_ch2_init[] = {
8394         /* set pin widget 1Ah (line in) for input */
8395         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
8396         /* set pin widget 18h (mic1/2) for input, for mic also enable
8397          * the vref
8398          */
8399         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8400
8401         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
8402 #if 0
8403         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
8404         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
8405 #endif
8406         { } /* end */
8407 };
8408 /* Set mic1 nad line-in as output and mute mixer */
8409 static struct hda_verb alc861_asus_ch6_init[] = {
8410         /* set pin widget 1Ah (line in) for output (Back Surround)*/
8411         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8412         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
8413         /* set pin widget 18h (mic1) for output (CLFE)*/
8414         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8415         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
8416         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
8417         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
8418
8419         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
8420 #if 0
8421         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
8422         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
8423 #endif
8424         { } /* end */
8425 };
8426
8427 static struct hda_channel_mode alc861_asus_modes[2] = {
8428         { 2, alc861_asus_ch2_init },
8429         { 6, alc861_asus_ch6_init },
8430 };
8431
8432 /* patch-ALC861 */
8433
8434 static struct snd_kcontrol_new alc861_base_mixer[] = {
8435         /* output mixer control */
8436         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
8437         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
8438         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
8439         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
8440         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
8441
8442         /*Input mixer control */
8443         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
8444            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
8445         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
8446         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
8447         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
8448         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
8449         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
8450         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
8451         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
8452         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
8453
8454         /* Capture mixer control */
8455         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
8456         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
8457         {
8458                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8459                 .name = "Capture Source",
8460                 .count = 1,
8461                 .info = alc_mux_enum_info,
8462                 .get = alc_mux_enum_get,
8463                 .put = alc_mux_enum_put,
8464         },
8465         { } /* end */
8466 };
8467
8468 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
8469         /* output mixer control */
8470         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
8471         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
8472         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
8473         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
8474         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
8475
8476         /* Input mixer control */
8477         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
8478            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
8479         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
8480         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
8481         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
8482         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
8483         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
8484         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
8485         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
8486         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
8487
8488         /* Capture mixer control */
8489         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
8490         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
8491         {
8492                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8493                 .name = "Capture Source",
8494                 .count = 1,
8495                 .info = alc_mux_enum_info,
8496                 .get = alc_mux_enum_get,
8497                 .put = alc_mux_enum_put,
8498         },
8499         {
8500                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8501                 .name = "Channel Mode",
8502                 .info = alc_ch_mode_info,
8503                 .get = alc_ch_mode_get,
8504                 .put = alc_ch_mode_put,
8505                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
8506         },
8507         { } /* end */
8508 };
8509
8510 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
8511         /* output mixer control */
8512         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
8513         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
8514         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
8515         
8516         /*Capture mixer control */
8517         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
8518         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
8519         {
8520                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8521                 .name = "Capture Source",
8522                 .count = 1,
8523                 .info = alc_mux_enum_info,
8524                 .get = alc_mux_enum_get,
8525                 .put = alc_mux_enum_put,
8526         },
8527
8528         { } /* end */
8529 };
8530
8531 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
8532         /* output mixer control */
8533         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
8534         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
8535         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
8536         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
8537         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
8538
8539         /* Input mixer control */
8540         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
8541            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
8542         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
8543         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
8544         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
8545         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
8546         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
8547         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
8548         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
8549         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
8550
8551         /* Capture mixer control */
8552         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
8553         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
8554         {
8555                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8556                 .name = "Capture Source",
8557                 .count = 1,
8558                 .info = alc_mux_enum_info,
8559                 .get = alc_mux_enum_get,
8560                 .put = alc_mux_enum_put,
8561         },
8562         {
8563                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8564                 .name = "Channel Mode",
8565                 .info = alc_ch_mode_info,
8566                 .get = alc_ch_mode_get,
8567                 .put = alc_ch_mode_put,
8568                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
8569         },
8570         { } /* end */
8571 };
8572
8573 static struct snd_kcontrol_new alc861_asus_mixer[] = {
8574         /* output mixer control */
8575         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
8576         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
8577         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
8578         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
8579         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
8580
8581         /* Input mixer control */
8582         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
8583         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8584         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
8585         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
8586         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
8587         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
8588         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
8589         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
8590         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
8591         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
8592
8593         /* Capture mixer control */
8594         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
8595         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
8596         {
8597                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8598                 .name = "Capture Source",
8599                 .count = 1,
8600                 .info = alc_mux_enum_info,
8601                 .get = alc_mux_enum_get,
8602                 .put = alc_mux_enum_put,
8603         },
8604         {
8605                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8606                 .name = "Channel Mode",
8607                 .info = alc_ch_mode_info,
8608                 .get = alc_ch_mode_get,
8609                 .put = alc_ch_mode_put,
8610                 .private_value = ARRAY_SIZE(alc861_asus_modes),
8611         },
8612         { }
8613 };
8614
8615 /* additional mixer */
8616 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
8617         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
8618         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
8619         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
8620         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
8621         { }
8622 };
8623
8624 /*
8625  * generic initialization of ADC, input mixers and output mixers
8626  */
8627 static struct hda_verb alc861_base_init_verbs[] = {
8628         /*
8629          * Unmute ADC0 and set the default input to mic-in
8630          */
8631         /* port-A for surround (rear panel) */
8632         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8633         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
8634         /* port-B for mic-in (rear panel) with vref */
8635         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8636         /* port-C for line-in (rear panel) */
8637         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
8638         /* port-D for Front */
8639         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8640         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
8641         /* port-E for HP out (front panel) */
8642         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
8643         /* route front PCM to HP */
8644         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
8645         /* port-F for mic-in (front panel) with vref */
8646         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8647         /* port-G for CLFE (rear panel) */
8648         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8649         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
8650         /* port-H for side (rear panel) */
8651         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8652         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
8653         /* CD-in */
8654         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
8655         /* route front mic to ADC1*/
8656         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8657         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8658         
8659         /* Unmute DAC0~3 & spdif out*/
8660         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8661         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8662         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8663         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8664         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8665         
8666         /* Unmute Mixer 14 (mic) 1c (Line in)*/
8667         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8668         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8669         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8670         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8671         
8672         /* Unmute Stereo Mixer 15 */
8673         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8674         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8675         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8676         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
8677
8678         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8679         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8680         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8681         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8682         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8683         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8684         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8685         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8686         /* hp used DAC 3 (Front) */
8687         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
8688         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8689
8690         { }
8691 };
8692
8693 static struct hda_verb alc861_threestack_init_verbs[] = {
8694         /*
8695          * Unmute ADC0 and set the default input to mic-in
8696          */
8697         /* port-A for surround (rear panel) */
8698         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
8699         /* port-B for mic-in (rear panel) with vref */
8700         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8701         /* port-C for line-in (rear panel) */
8702         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
8703         /* port-D for Front */
8704         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8705         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
8706         /* port-E for HP out (front panel) */
8707         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
8708         /* route front PCM to HP */
8709         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
8710         /* port-F for mic-in (front panel) with vref */
8711         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8712         /* port-G for CLFE (rear panel) */
8713         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
8714         /* port-H for side (rear panel) */
8715         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
8716         /* CD-in */
8717         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
8718         /* route front mic to ADC1*/
8719         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8720         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8721         /* Unmute DAC0~3 & spdif out*/
8722         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8723         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8724         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8725         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8726         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8727         
8728         /* Unmute Mixer 14 (mic) 1c (Line in)*/
8729         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8730         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8731         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8732         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8733         
8734         /* Unmute Stereo Mixer 15 */
8735         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8736         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8737         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8738         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
8739
8740         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8741         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8742         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8743         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8744         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8745         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8746         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8747         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8748         /* hp used DAC 3 (Front) */
8749         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
8750         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8751         { }
8752 };
8753
8754 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
8755         /*
8756          * Unmute ADC0 and set the default input to mic-in
8757          */
8758         /* port-A for surround (rear panel) */
8759         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
8760         /* port-B for mic-in (rear panel) with vref */
8761         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8762         /* port-C for line-in (rear panel) */
8763         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
8764         /* port-D for Front */
8765         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8766         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
8767         /* port-E for HP out (front panel) */
8768         /* this has to be set to VREF80 */
8769         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8770         /* route front PCM to HP */
8771         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
8772         /* port-F for mic-in (front panel) with vref */
8773         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8774         /* port-G for CLFE (rear panel) */
8775         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
8776         /* port-H for side (rear panel) */
8777         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
8778         /* CD-in */
8779         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
8780         /* route front mic to ADC1*/
8781         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8782         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8783         /* Unmute DAC0~3 & spdif out*/
8784         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8785         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8786         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8787         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8788         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8789         
8790         /* Unmute Mixer 14 (mic) 1c (Line in)*/
8791         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8792         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8793         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8794         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8795         
8796         /* Unmute Stereo Mixer 15 */
8797         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8798         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8799         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8800         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
8801
8802         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8803         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8804         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8805         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8806         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8807         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8808         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8809         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8810         /* hp used DAC 3 (Front) */
8811         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
8812         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8813         { }
8814 };
8815
8816 static struct hda_verb alc861_asus_init_verbs[] = {
8817         /*
8818          * Unmute ADC0 and set the default input to mic-in
8819          */
8820         /* port-A for surround (rear panel)
8821          * according to codec#0 this is the HP jack
8822          */
8823         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
8824         /* route front PCM to HP */
8825         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
8826         /* port-B for mic-in (rear panel) with vref */
8827         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8828         /* port-C for line-in (rear panel) */
8829         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
8830         /* port-D for Front */
8831         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8832         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
8833         /* port-E for HP out (front panel) */
8834         /* this has to be set to VREF80 */
8835         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8836         /* route front PCM to HP */
8837         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
8838         /* port-F for mic-in (front panel) with vref */
8839         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
8840         /* port-G for CLFE (rear panel) */
8841         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8842         /* port-H for side (rear panel) */
8843         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
8844         /* CD-in */
8845         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
8846         /* route front mic to ADC1*/
8847         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8848         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8849         /* Unmute DAC0~3 & spdif out*/
8850         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8851         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8852         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8853         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8854         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8855         /* Unmute Mixer 14 (mic) 1c (Line in)*/
8856         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8857         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8858         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8859         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8860         
8861         /* Unmute Stereo Mixer 15 */
8862         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8863         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8864         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8865         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
8866
8867         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8868         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8869         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8870         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8871         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8872         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8873         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8874         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8875         /* hp used DAC 3 (Front) */
8876         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
8877         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8878         { }
8879 };
8880
8881 /* additional init verbs for ASUS laptops */
8882 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
8883         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
8884         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
8885         { }
8886 };
8887
8888 /*
8889  * generic initialization of ADC, input mixers and output mixers
8890  */
8891 static struct hda_verb alc861_auto_init_verbs[] = {
8892         /*
8893          * Unmute ADC0 and set the default input to mic-in
8894          */
8895         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
8896         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8897         
8898         /* Unmute DAC0~3 & spdif out*/
8899         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8900         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8901         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8902         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8903         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8904         
8905         /* Unmute Mixer 14 (mic) 1c (Line in)*/
8906         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8907         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8908         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8909         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8910         
8911         /* Unmute Stereo Mixer 15 */
8912         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8913         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8914         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8915         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
8916
8917         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8918         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8919         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8920         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8921         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8922         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8923         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8924         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8925
8926         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8927         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8928         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8929         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
8930         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8931         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8932         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8933         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
8934
8935         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
8936
8937         { }
8938 };
8939
8940 static struct hda_verb alc861_toshiba_init_verbs[] = {
8941         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8942
8943         { }
8944 };
8945
8946 /* toggle speaker-output according to the hp-jack state */
8947 static void alc861_toshiba_automute(struct hda_codec *codec)
8948 {
8949         unsigned int present;
8950
8951         present = snd_hda_codec_read(codec, 0x0f, 0,
8952                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8953         snd_hda_codec_amp_update(codec, 0x16, 0, HDA_INPUT, 0,
8954                                  0x80, present ? 0x80 : 0);
8955         snd_hda_codec_amp_update(codec, 0x16, 1, HDA_INPUT, 0,
8956                                  0x80, present ? 0x80 : 0);
8957         snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_INPUT, 3,
8958                                  0x80, present ? 0 : 0x80);
8959         snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_INPUT, 3,
8960                                  0x80, present ? 0 : 0x80);
8961 }
8962
8963 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
8964                                        unsigned int res)
8965 {
8966         if ((res >> 26) == ALC880_HP_EVENT)
8967                 alc861_toshiba_automute(codec);
8968 }
8969
8970 /* pcm configuration: identiacal with ALC880 */
8971 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
8972 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
8973 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
8974 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
8975
8976
8977 #define ALC861_DIGOUT_NID       0x07
8978
8979 static struct hda_channel_mode alc861_8ch_modes[1] = {
8980         { 8, NULL }
8981 };
8982
8983 static hda_nid_t alc861_dac_nids[4] = {
8984         /* front, surround, clfe, side */
8985         0x03, 0x06, 0x05, 0x04
8986 };
8987
8988 static hda_nid_t alc660_dac_nids[3] = {
8989         /* front, clfe, surround */
8990         0x03, 0x05, 0x06
8991 };
8992
8993 static hda_nid_t alc861_adc_nids[1] = {
8994         /* ADC0-2 */
8995         0x08,
8996 };
8997
8998 static struct hda_input_mux alc861_capture_source = {
8999         .num_items = 5,
9000         .items = {
9001                 { "Mic", 0x0 },
9002                 { "Front Mic", 0x3 },
9003                 { "Line", 0x1 },
9004                 { "CD", 0x4 },
9005                 { "Mixer", 0x5 },
9006         },
9007 };
9008
9009 /* fill in the dac_nids table from the parsed pin configuration */
9010 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
9011                                      const struct auto_pin_cfg *cfg)
9012 {
9013         int i;
9014         hda_nid_t nid;
9015
9016         spec->multiout.dac_nids = spec->private_dac_nids;
9017         for (i = 0; i < cfg->line_outs; i++) {
9018                 nid = cfg->line_out_pins[i];
9019                 if (nid) {
9020                         if (i >= ARRAY_SIZE(alc861_dac_nids))
9021                                 continue;
9022                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
9023                 }
9024         }
9025         spec->multiout.num_dacs = cfg->line_outs;
9026         return 0;
9027 }
9028
9029 /* add playback controls from the parsed DAC table */
9030 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
9031                                              const struct auto_pin_cfg *cfg)
9032 {
9033         char name[32];
9034         static const char *chname[4] = {
9035                 "Front", "Surround", NULL /*CLFE*/, "Side"
9036         };
9037         hda_nid_t nid;
9038         int i, idx, err;
9039
9040         for (i = 0; i < cfg->line_outs; i++) {
9041                 nid = spec->multiout.dac_nids[i];
9042                 if (!nid)
9043                         continue;
9044                 if (nid == 0x05) {
9045                         /* Center/LFE */
9046                         err = add_control(spec, ALC_CTL_BIND_MUTE,
9047                                           "Center Playback Switch",
9048                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
9049                                                               HDA_OUTPUT));
9050                         if (err < 0)
9051                                 return err;
9052                         err = add_control(spec, ALC_CTL_BIND_MUTE,
9053                                           "LFE Playback Switch",
9054                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
9055                                                               HDA_OUTPUT));
9056                         if (err < 0)
9057                                 return err;
9058                 } else {
9059                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
9060                              idx++)
9061                                 if (nid == alc861_dac_nids[idx])
9062                                         break;
9063                         sprintf(name, "%s Playback Switch", chname[idx]);
9064                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
9065                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
9066                                                               HDA_OUTPUT));
9067                         if (err < 0)
9068                                 return err;
9069                 }
9070         }
9071         return 0;
9072 }
9073
9074 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
9075 {
9076         int err;
9077         hda_nid_t nid;
9078
9079         if (!pin)
9080                 return 0;
9081
9082         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
9083                 nid = 0x03;
9084                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
9085                                   "Headphone Playback Switch",
9086                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
9087                 if (err < 0)
9088                         return err;
9089                 spec->multiout.hp_nid = nid;
9090         }
9091         return 0;
9092 }
9093
9094 /* create playback/capture controls for input pins */
9095 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
9096                                                 const struct auto_pin_cfg *cfg)
9097 {
9098         struct hda_input_mux *imux = &spec->private_imux;
9099         int i, err, idx, idx1;
9100
9101         for (i = 0; i < AUTO_PIN_LAST; i++) {
9102                 switch (cfg->input_pins[i]) {
9103                 case 0x0c:
9104                         idx1 = 1;
9105                         idx = 2;        /* Line In */
9106                         break;
9107                 case 0x0f:
9108                         idx1 = 2;
9109                         idx = 2;        /* Line In */
9110                         break;
9111                 case 0x0d:
9112                         idx1 = 0;
9113                         idx = 1;        /* Mic In */
9114                         break;
9115                 case 0x10:
9116                         idx1 = 3;
9117                         idx = 1;        /* Mic In */
9118                         break;
9119                 case 0x11:
9120                         idx1 = 4;
9121                         idx = 0;        /* CD */
9122                         break;
9123                 default:
9124                         continue;
9125                 }
9126
9127                 err = new_analog_input(spec, cfg->input_pins[i],
9128                                        auto_pin_cfg_labels[i], idx, 0x15);
9129                 if (err < 0)
9130                         return err;
9131
9132                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
9133                 imux->items[imux->num_items].index = idx1;
9134                 imux->num_items++;
9135         }
9136         return 0;
9137 }
9138
9139 static struct snd_kcontrol_new alc861_capture_mixer[] = {
9140         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
9141         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
9142
9143         {
9144                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9145                 /* The multiple "Capture Source" controls confuse alsamixer
9146                  * So call somewhat different..
9147                  *FIXME: the controls appear in the "playback" view!
9148                  */
9149                 /* .name = "Capture Source", */
9150                 .name = "Input Source",
9151                 .count = 1,
9152                 .info = alc_mux_enum_info,
9153                 .get = alc_mux_enum_get,
9154                 .put = alc_mux_enum_put,
9155         },
9156         { } /* end */
9157 };
9158
9159 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
9160                                               hda_nid_t nid,
9161                                               int pin_type, int dac_idx)
9162 {
9163         /* set as output */
9164
9165         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
9166                             pin_type);
9167         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
9168                             AMP_OUT_UNMUTE);
9169
9170 }
9171
9172 static void alc861_auto_init_multi_out(struct hda_codec *codec)
9173 {
9174         struct alc_spec *spec = codec->spec;
9175         int i;
9176
9177         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
9178         for (i = 0; i < spec->autocfg.line_outs; i++) {
9179                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
9180                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
9181                 if (nid)
9182                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
9183                                                           spec->multiout.dac_nids[i]);
9184         }
9185 }
9186
9187 static void alc861_auto_init_hp_out(struct hda_codec *codec)
9188 {
9189         struct alc_spec *spec = codec->spec;
9190         hda_nid_t pin;
9191
9192         pin = spec->autocfg.hp_pins[0];
9193         if (pin) /* connect to front */
9194                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
9195                                                   spec->multiout.dac_nids[0]);
9196 }
9197
9198 static void alc861_auto_init_analog_input(struct hda_codec *codec)
9199 {
9200         struct alc_spec *spec = codec->spec;
9201         int i;
9202
9203         for (i = 0; i < AUTO_PIN_LAST; i++) {
9204                 hda_nid_t nid = spec->autocfg.input_pins[i];
9205                 if (nid >= 0x0c && nid <= 0x11) {
9206                         snd_hda_codec_write(codec, nid, 0,
9207                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
9208                                             i <= AUTO_PIN_FRONT_MIC ?
9209                                             PIN_VREF80 : PIN_IN);
9210                 }
9211         }
9212 }
9213
9214 /* parse the BIOS configuration and set up the alc_spec */
9215 /* return 1 if successful, 0 if the proper config is not found,
9216  * or a negative error code
9217  */
9218 static int alc861_parse_auto_config(struct hda_codec *codec)
9219 {
9220         struct alc_spec *spec = codec->spec;
9221         int err;
9222         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
9223
9224         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9225                                            alc861_ignore);
9226         if (err < 0)
9227                 return err;
9228         if (!spec->autocfg.line_outs)
9229                 return 0; /* can't find valid BIOS pin config */
9230
9231         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
9232         if (err < 0)
9233                 return err;
9234         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
9235         if (err < 0)
9236                 return err;
9237         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
9238         if (err < 0)
9239                 return err;
9240         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
9241         if (err < 0)
9242                 return err;
9243
9244         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
9245
9246         if (spec->autocfg.dig_out_pin)
9247                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
9248
9249         if (spec->kctl_alloc)
9250                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
9251
9252         spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs;
9253
9254         spec->num_mux_defs = 1;
9255         spec->input_mux = &spec->private_imux;
9256
9257         spec->adc_nids = alc861_adc_nids;
9258         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
9259         spec->mixers[spec->num_mixers] = alc861_capture_mixer;
9260         spec->num_mixers++;
9261
9262         return 1;
9263 }
9264
9265 /* additional initialization for auto-configuration model */
9266 static void alc861_auto_init(struct hda_codec *codec)
9267 {
9268         alc861_auto_init_multi_out(codec);
9269         alc861_auto_init_hp_out(codec);
9270         alc861_auto_init_analog_input(codec);
9271 }
9272
9273
9274 /*
9275  * configuration and preset
9276  */
9277 static const char *alc861_models[ALC861_MODEL_LAST] = {
9278         [ALC861_3ST]            = "3stack",
9279         [ALC660_3ST]            = "3stack-660",
9280         [ALC861_3ST_DIG]        = "3stack-dig",
9281         [ALC861_6ST_DIG]        = "6stack-dig",
9282         [ALC861_UNIWILL_M31]    = "uniwill-m31",
9283         [ALC861_TOSHIBA]        = "toshiba",
9284         [ALC861_ASUS]           = "asus",
9285         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
9286         [ALC861_AUTO]           = "auto",
9287 };
9288
9289 static struct snd_pci_quirk alc861_cfg_tbl[] = {
9290         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
9291         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
9292         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
9293         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
9294         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
9295         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
9296         SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA),
9297         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
9298         SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31),
9299         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
9300         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
9301         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
9302         {}
9303 };
9304
9305 static struct alc_config_preset alc861_presets[] = {
9306         [ALC861_3ST] = {
9307                 .mixers = { alc861_3ST_mixer },
9308                 .init_verbs = { alc861_threestack_init_verbs },
9309                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
9310                 .dac_nids = alc861_dac_nids,
9311                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
9312                 .channel_mode = alc861_threestack_modes,
9313                 .need_dac_fix = 1,
9314                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
9315                 .adc_nids = alc861_adc_nids,
9316                 .input_mux = &alc861_capture_source,
9317         },
9318         [ALC861_3ST_DIG] = {
9319                 .mixers = { alc861_base_mixer },
9320                 .init_verbs = { alc861_threestack_init_verbs },
9321                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
9322                 .dac_nids = alc861_dac_nids,
9323                 .dig_out_nid = ALC861_DIGOUT_NID,
9324                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
9325                 .channel_mode = alc861_threestack_modes,
9326                 .need_dac_fix = 1,
9327                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
9328                 .adc_nids = alc861_adc_nids,
9329                 .input_mux = &alc861_capture_source,
9330         },
9331         [ALC861_6ST_DIG] = {
9332                 .mixers = { alc861_base_mixer },
9333                 .init_verbs = { alc861_base_init_verbs },
9334                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
9335                 .dac_nids = alc861_dac_nids,
9336                 .dig_out_nid = ALC861_DIGOUT_NID,
9337                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
9338                 .channel_mode = alc861_8ch_modes,
9339                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
9340                 .adc_nids = alc861_adc_nids,
9341                 .input_mux = &alc861_capture_source,
9342         },
9343         [ALC660_3ST] = {
9344                 .mixers = { alc861_3ST_mixer },
9345                 .init_verbs = { alc861_threestack_init_verbs },
9346                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
9347                 .dac_nids = alc660_dac_nids,
9348                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
9349                 .channel_mode = alc861_threestack_modes,
9350                 .need_dac_fix = 1,
9351                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
9352                 .adc_nids = alc861_adc_nids,
9353                 .input_mux = &alc861_capture_source,
9354         },
9355         [ALC861_UNIWILL_M31] = {
9356                 .mixers = { alc861_uniwill_m31_mixer },
9357                 .init_verbs = { alc861_uniwill_m31_init_verbs },
9358                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
9359                 .dac_nids = alc861_dac_nids,
9360                 .dig_out_nid = ALC861_DIGOUT_NID,
9361                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
9362                 .channel_mode = alc861_uniwill_m31_modes,
9363                 .need_dac_fix = 1,
9364                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
9365                 .adc_nids = alc861_adc_nids,
9366                 .input_mux = &alc861_capture_source,
9367         },
9368         [ALC861_TOSHIBA] = {
9369                 .mixers = { alc861_toshiba_mixer },
9370                 .init_verbs = { alc861_base_init_verbs,
9371                                 alc861_toshiba_init_verbs },
9372                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
9373                 .dac_nids = alc861_dac_nids,
9374                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9375                 .channel_mode = alc883_3ST_2ch_modes,
9376                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
9377                 .adc_nids = alc861_adc_nids,
9378                 .input_mux = &alc861_capture_source,
9379                 .unsol_event = alc861_toshiba_unsol_event,
9380                 .init_hook = alc861_toshiba_automute,
9381         },
9382         [ALC861_ASUS] = {
9383                 .mixers = { alc861_asus_mixer },
9384                 .init_verbs = { alc861_asus_init_verbs },
9385                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
9386                 .dac_nids = alc861_dac_nids,
9387                 .dig_out_nid = ALC861_DIGOUT_NID,
9388                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
9389                 .channel_mode = alc861_asus_modes,
9390                 .need_dac_fix = 1,
9391                 .hp_nid = 0x06,
9392                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
9393                 .adc_nids = alc861_adc_nids,
9394                 .input_mux = &alc861_capture_source,
9395         },
9396         [ALC861_ASUS_LAPTOP] = {
9397                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
9398                 .init_verbs = { alc861_asus_init_verbs,
9399                                 alc861_asus_laptop_init_verbs },
9400                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
9401                 .dac_nids = alc861_dac_nids,
9402                 .dig_out_nid = ALC861_DIGOUT_NID,
9403                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9404                 .channel_mode = alc883_3ST_2ch_modes,
9405                 .need_dac_fix = 1,
9406                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
9407                 .adc_nids = alc861_adc_nids,
9408                 .input_mux = &alc861_capture_source,
9409         },
9410 };
9411
9412
9413 static int patch_alc861(struct hda_codec *codec)
9414 {
9415         struct alc_spec *spec;
9416         int board_config;
9417         int err;
9418
9419         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9420         if (spec == NULL)
9421                 return -ENOMEM;
9422
9423         codec->spec = spec;
9424
9425         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
9426                                                   alc861_models,
9427                                                   alc861_cfg_tbl);
9428
9429         if (board_config < 0) {
9430                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
9431                        "trying auto-probe from BIOS...\n");
9432                 board_config = ALC861_AUTO;
9433         }
9434
9435         if (board_config == ALC861_AUTO) {
9436                 /* automatic parse from the BIOS config */
9437                 err = alc861_parse_auto_config(codec);
9438                 if (err < 0) {
9439                         alc_free(codec);
9440                         return err;
9441                 } else if (!err) {
9442                         printk(KERN_INFO
9443                                "hda_codec: Cannot set up configuration "
9444                                "from BIOS.  Using base mode...\n");
9445                    board_config = ALC861_3ST_DIG;
9446                 }
9447         }
9448
9449         if (board_config != ALC861_AUTO)
9450                 setup_preset(spec, &alc861_presets[board_config]);
9451
9452         spec->stream_name_analog = "ALC861 Analog";
9453         spec->stream_analog_playback = &alc861_pcm_analog_playback;
9454         spec->stream_analog_capture = &alc861_pcm_analog_capture;
9455
9456         spec->stream_name_digital = "ALC861 Digital";
9457         spec->stream_digital_playback = &alc861_pcm_digital_playback;
9458         spec->stream_digital_capture = &alc861_pcm_digital_capture;
9459
9460         codec->patch_ops = alc_patch_ops;
9461         if (board_config == ALC861_AUTO)
9462                 spec->init_hook = alc861_auto_init;
9463                 
9464         return 0;
9465 }
9466
9467 /*
9468  * ALC861-VD support
9469  *
9470  * Based on ALC882
9471  *
9472  * In addition, an independent DAC
9473  */
9474 #define ALC861VD_DIGOUT_NID     0x06
9475
9476 static hda_nid_t alc861vd_dac_nids[4] = {
9477         /* front, surr, clfe, side surr */
9478         0x02, 0x03, 0x04, 0x05
9479 };
9480
9481 /* dac_nids for ALC660vd are in a different order - according to
9482  * Realtek's driver.
9483  * This should probably tesult in a different mixer for 6stack models
9484  * of ALC660vd codecs, but for now there is only 3stack mixer
9485  * - and it is the same as in 861vd.
9486  * adc_nids in ALC660vd are (is) the same as in 861vd
9487  */
9488 static hda_nid_t alc660vd_dac_nids[3] = {
9489         /* front, rear, clfe, rear_surr */
9490         0x02, 0x04, 0x03
9491 };
9492
9493 static hda_nid_t alc861vd_adc_nids[1] = {
9494         /* ADC0 */
9495         0x09,
9496 };
9497
9498 /* input MUX */
9499 /* FIXME: should be a matrix-type input source selection */
9500 static struct hda_input_mux alc861vd_capture_source = {
9501         .num_items = 4,
9502         .items = {
9503                 { "Mic", 0x0 },
9504                 { "Front Mic", 0x1 },
9505                 { "Line", 0x2 },
9506                 { "CD", 0x4 },
9507         },
9508 };
9509
9510 static struct hda_input_mux alc861vd_dallas_capture_source = {
9511         .num_items = 3,
9512         .items = {
9513                 { "Front Mic", 0x0 },
9514                 { "ATAPI Mic", 0x1 },
9515                 { "Line In", 0x5 },
9516         },
9517 };
9518
9519 #define alc861vd_mux_enum_info alc_mux_enum_info
9520 #define alc861vd_mux_enum_get alc_mux_enum_get
9521
9522 static int alc861vd_mux_enum_put(struct snd_kcontrol *kcontrol,
9523                                 struct snd_ctl_elem_value *ucontrol)
9524 {
9525         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9526         struct alc_spec *spec = codec->spec;
9527         const struct hda_input_mux *imux = spec->input_mux;
9528         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
9529         static hda_nid_t capture_mixers[1] = { 0x22 };
9530         hda_nid_t nid = capture_mixers[adc_idx];
9531         unsigned int *cur_val = &spec->cur_mux[adc_idx];
9532         unsigned int i, idx;
9533
9534         idx = ucontrol->value.enumerated.item[0];
9535         if (idx >= imux->num_items)
9536                 idx = imux->num_items - 1;
9537         if (*cur_val == idx && !codec->in_resume)
9538                 return 0;
9539         for (i = 0; i < imux->num_items; i++) {
9540                 unsigned int v = (i == idx) ? 0x7000 : 0x7080;
9541                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
9542                                     v | (imux->items[i].index << 8));
9543         }
9544         *cur_val = idx;
9545         return 1;
9546 }
9547
9548 /*
9549  * 2ch mode
9550  */
9551 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
9552         { 2, NULL }
9553 };
9554
9555 /*
9556  * 6ch mode
9557  */
9558 static struct hda_verb alc861vd_6stack_ch6_init[] = {
9559         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
9560         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9561         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9562         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9563         { } /* end */
9564 };
9565
9566 /*
9567  * 8ch mode
9568  */
9569 static struct hda_verb alc861vd_6stack_ch8_init[] = {
9570         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9571         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9572         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9573         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
9574         { } /* end */
9575 };
9576
9577 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
9578         { 6, alc861vd_6stack_ch6_init },
9579         { 8, alc861vd_6stack_ch8_init },
9580 };
9581
9582 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
9583         {
9584                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9585                 .name = "Channel Mode",
9586                 .info = alc_ch_mode_info,
9587                 .get = alc_ch_mode_get,
9588                 .put = alc_ch_mode_put,
9589         },
9590         { } /* end */
9591 };
9592
9593 static struct snd_kcontrol_new alc861vd_capture_mixer[] = {
9594         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
9595         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
9596
9597         {
9598                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9599                 /* The multiple "Capture Source" controls confuse alsamixer
9600                  * So call somewhat different..
9601                  *FIXME: the controls appear in the "playback" view!
9602                  */
9603                 /* .name = "Capture Source", */
9604                 .name = "Input Source",
9605                 .count = 1,
9606                 .info = alc861vd_mux_enum_info,
9607                 .get = alc861vd_mux_enum_get,
9608                 .put = alc861vd_mux_enum_put,
9609         },
9610         { } /* end */
9611 };
9612
9613 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
9614  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
9615  */
9616 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
9617         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
9618         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9619
9620         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
9621         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
9622
9623         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
9624                                 HDA_OUTPUT),
9625         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
9626                                 HDA_OUTPUT),
9627         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
9628         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
9629
9630         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
9631         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
9632
9633         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9634
9635         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9636         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9637         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9638
9639         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9640         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9641         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9642
9643         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9644         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9645
9646         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9647         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9648
9649         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
9650         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
9651
9652         { } /* end */
9653 };
9654
9655 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
9656         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
9657         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9658
9659         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9660
9661         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9662         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9663         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9664
9665         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9666         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9667         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9668
9669         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9670         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9671
9672         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9673         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9674
9675         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
9676         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
9677
9678         { } /* end */
9679 };
9680
9681 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
9682         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
9683         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
9684         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9685
9686         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9687
9688         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9689         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9690         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9691
9692         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9693         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9694         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9695
9696         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9697         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9698
9699         { } /* end */
9700 };
9701
9702 /* Pin assignment: Front=0x14, HP = 0x15,
9703  *                 Front Mic=0x18, ATAPI Mic = 0x19, Line In = 0x1d
9704  */
9705 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
9706         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
9707         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
9708         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
9709         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
9710         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9711         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9712         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9713         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9714         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x05, HDA_INPUT),
9715         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x05, HDA_INPUT),
9716         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
9717         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
9718         {
9719                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9720                 /* .name = "Capture Source", */
9721                 .name = "Input Source",
9722                 .count = 1,
9723                 .info = alc882_mux_enum_info,
9724                 .get = alc882_mux_enum_get,
9725                 .put = alc882_mux_enum_put,
9726         },
9727         { } /* end */
9728 };
9729
9730 /*
9731  * generic initialization of ADC, input mixers and output mixers
9732  */
9733 static struct hda_verb alc861vd_volume_init_verbs[] = {
9734         /*
9735          * Unmute ADC0 and set the default input to mic-in
9736          */
9737         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9738         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9739
9740         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
9741          * the analog-loopback mixer widget
9742          */
9743         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9744         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9745         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9746         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9747         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
9748         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
9749
9750         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
9751         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9752         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9753         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
9754         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
9755
9756         /*
9757          * Set up output mixers (0x02 - 0x05)
9758          */
9759         /* set vol=0 to output mixers */
9760         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9761         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9762         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9763         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9764
9765         /* set up input amps for analog loopback */
9766         /* Amp Indices: DAC = 0, mixer = 1 */
9767         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9768         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9769         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9770         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9771         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9772         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9773         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9774         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9775
9776         { }
9777 };
9778
9779 /*
9780  * 3-stack pin configuration:
9781  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
9782  */
9783 static struct hda_verb alc861vd_3stack_init_verbs[] = {
9784         /*
9785          * Set pin mode and muting
9786          */
9787         /* set front pin widgets 0x14 for output */
9788         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9789         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9790         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9791
9792         /* Mic (rear) pin: input vref at 80% */
9793         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9794         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9795         /* Front Mic pin: input vref at 80% */
9796         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9797         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9798         /* Line In pin: input */
9799         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9800         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9801         /* Line-2 In: Headphone output (output 0 - 0x0c) */
9802         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9803         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9804         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9805         /* CD pin widget for input */
9806         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9807
9808         { }
9809 };
9810
9811 /*
9812  * 6-stack pin configuration:
9813  */
9814 static struct hda_verb alc861vd_6stack_init_verbs[] = {
9815         /*
9816          * Set pin mode and muting
9817          */
9818         /* set front pin widgets 0x14 for output */
9819         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9820         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9821         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9822
9823         /* Rear Pin: output 1 (0x0d) */
9824         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9825         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9826         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9827         /* CLFE Pin: output 2 (0x0e) */
9828         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9829         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9830         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
9831         /* Side Pin: output 3 (0x0f) */
9832         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9833         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9834         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
9835
9836         /* Mic (rear) pin: input vref at 80% */
9837         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9838         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9839         /* Front Mic pin: input vref at 80% */
9840         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9841         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9842         /* Line In pin: input */
9843         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9844         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9845         /* Line-2 In: Headphone output (output 0 - 0x0c) */
9846         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9847         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9848         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9849         /* CD pin widget for input */
9850         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9851
9852         { }
9853 };
9854
9855 static struct hda_verb alc861vd_eapd_verbs[] = {
9856         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9857         { }
9858 };
9859
9860 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
9861         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9862         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9863         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
9864         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9865         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT}, 
9866         {}
9867 };
9868
9869 /* toggle speaker-output according to the hp-jack state */
9870 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
9871 {
9872         unsigned int present;
9873         unsigned char bits;
9874
9875         present = snd_hda_codec_read(codec, 0x1b, 0,
9876                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9877         bits = present ? 0x80 : 0;
9878         snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
9879                                  0x80, bits);
9880         snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
9881                                  0x80, bits);
9882 }
9883
9884 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
9885 {
9886         unsigned int present;
9887         unsigned char bits;
9888
9889         present = snd_hda_codec_read(codec, 0x18, 0,
9890                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9891         bits = present ? 0x80 : 0;
9892         snd_hda_codec_amp_update(codec, 0x0b, 0, HDA_INPUT, 1,
9893                                  0x80, bits);
9894         snd_hda_codec_amp_update(codec, 0x0b, 1, HDA_INPUT, 1,
9895                                  0x80, bits);
9896 }
9897
9898 static void alc861vd_lenovo_automute(struct hda_codec *codec)
9899 {
9900         alc861vd_lenovo_hp_automute(codec);
9901         alc861vd_lenovo_mic_automute(codec);
9902 }
9903
9904 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
9905                                         unsigned int res)
9906 {
9907         switch (res >> 26) {
9908         case ALC880_HP_EVENT:
9909                 alc861vd_lenovo_hp_automute(codec);
9910                 break;
9911         case ALC880_MIC_EVENT:
9912                 alc861vd_lenovo_mic_automute(codec);
9913                 break;
9914         }
9915 }
9916
9917 static struct hda_verb alc861vd_dallas_verbs[] = {
9918         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9919         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9920         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9921         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9922
9923         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9924         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9925         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9926         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9927         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9928         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9929         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9930         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9931         
9932         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9933         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9934         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9935         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9936         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9937         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9938         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9939         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9940
9941         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
9942         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9943         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
9944         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9945         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9946         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9947         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9948         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9949
9950         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9951         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9952         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9953         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9954
9955         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9956         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},  
9957         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9958
9959         { } /* end */
9960 };
9961
9962 /* toggle speaker-output according to the hp-jack state */
9963 static void alc861vd_dallas_automute(struct hda_codec *codec)
9964 {
9965         unsigned int present;
9966
9967         present = snd_hda_codec_read(codec, 0x15, 0,
9968                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9969         snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
9970                                  0x80, present ? 0x80 : 0);
9971         snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
9972                                  0x80, present ? 0x80 : 0);
9973 }
9974
9975 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
9976 {
9977         if ((res >> 26) == ALC880_HP_EVENT)
9978                 alc861vd_dallas_automute(codec);
9979 }
9980
9981 /* pcm configuration: identiacal with ALC880 */
9982 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
9983 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
9984 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
9985 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
9986
9987 /*
9988  * configuration and preset
9989  */
9990 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
9991         [ALC660VD_3ST]          = "3stack-660",
9992         [ALC660VD_3ST_DIG]= "3stack-660-digout",
9993         [ALC861VD_3ST]          = "3stack",
9994         [ALC861VD_3ST_DIG]      = "3stack-digout",
9995         [ALC861VD_6ST_DIG]      = "6stack-digout",
9996         [ALC861VD_LENOVO]       = "lenovo",
9997         [ALC861VD_DALLAS]       = "dallas",
9998         [ALC861VD_AUTO]         = "auto",
9999 };
10000
10001 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
10002         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
10003         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
10004         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
10005         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
10006         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
10007
10008         SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),
10009         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
10010         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
10011         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
10012         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
10013         {}
10014 };
10015
10016 static struct alc_config_preset alc861vd_presets[] = {
10017         [ALC660VD_3ST] = {
10018                 .mixers = { alc861vd_3st_mixer },
10019                 .init_verbs = { alc861vd_volume_init_verbs,
10020                                  alc861vd_3stack_init_verbs },
10021                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
10022                 .dac_nids = alc660vd_dac_nids,
10023                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
10024                 .adc_nids = alc861vd_adc_nids,
10025                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10026                 .channel_mode = alc861vd_3stack_2ch_modes,
10027                 .input_mux = &alc861vd_capture_source,
10028         },
10029         [ALC660VD_3ST_DIG] = {
10030                 .mixers = { alc861vd_3st_mixer },
10031                 .init_verbs = { alc861vd_volume_init_verbs,
10032                                  alc861vd_3stack_init_verbs },
10033                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
10034                 .dac_nids = alc660vd_dac_nids,
10035                 .dig_out_nid = ALC861VD_DIGOUT_NID,
10036                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
10037                 .adc_nids = alc861vd_adc_nids,
10038                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10039                 .channel_mode = alc861vd_3stack_2ch_modes,
10040                 .input_mux = &alc861vd_capture_source,
10041         },
10042         [ALC861VD_3ST] = {
10043                 .mixers = { alc861vd_3st_mixer },
10044                 .init_verbs = { alc861vd_volume_init_verbs,
10045                                  alc861vd_3stack_init_verbs },
10046                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
10047                 .dac_nids = alc861vd_dac_nids,
10048                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10049                 .channel_mode = alc861vd_3stack_2ch_modes,
10050                 .input_mux = &alc861vd_capture_source,
10051         },
10052         [ALC861VD_3ST_DIG] = {
10053                 .mixers = { alc861vd_3st_mixer },
10054                 .init_verbs = { alc861vd_volume_init_verbs,
10055                                  alc861vd_3stack_init_verbs },
10056                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
10057                 .dac_nids = alc861vd_dac_nids,
10058                 .dig_out_nid = ALC861VD_DIGOUT_NID,
10059                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10060                 .channel_mode = alc861vd_3stack_2ch_modes,
10061                 .input_mux = &alc861vd_capture_source,
10062         },
10063         [ALC861VD_6ST_DIG] = {
10064                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
10065                 .init_verbs = { alc861vd_volume_init_verbs,
10066                                 alc861vd_6stack_init_verbs },
10067                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
10068                 .dac_nids = alc861vd_dac_nids,
10069                 .dig_out_nid = ALC861VD_DIGOUT_NID,
10070                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
10071                 .channel_mode = alc861vd_6stack_modes,
10072                 .input_mux = &alc861vd_capture_source,
10073         },
10074         [ALC861VD_LENOVO] = {
10075                 .mixers = { alc861vd_lenovo_mixer },
10076                 .init_verbs = { alc861vd_volume_init_verbs,
10077                                 alc861vd_3stack_init_verbs,
10078                                 alc861vd_eapd_verbs,
10079                                 alc861vd_lenovo_unsol_verbs },
10080                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
10081                 .dac_nids = alc660vd_dac_nids,
10082                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
10083                 .adc_nids = alc861vd_adc_nids,
10084                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10085                 .channel_mode = alc861vd_3stack_2ch_modes,
10086                 .input_mux = &alc861vd_capture_source,
10087                 .unsol_event = alc861vd_lenovo_unsol_event,
10088                 .init_hook = alc861vd_lenovo_automute,
10089         },
10090         [ALC861VD_DALLAS] = {
10091                 .mixers = { alc861vd_dallas_mixer },
10092                 .init_verbs = { alc861vd_dallas_verbs },
10093                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
10094                 .dac_nids = alc861vd_dac_nids,
10095                 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
10096                 .adc_nids = alc861vd_adc_nids,
10097                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
10098                 .channel_mode = alc861vd_3stack_2ch_modes,
10099                 .input_mux = &alc861vd_dallas_capture_source,
10100                 .unsol_event = alc861vd_dallas_unsol_event,
10101                 .init_hook = alc861vd_dallas_automute,
10102         },      
10103 };
10104
10105 /*
10106  * BIOS auto configuration
10107  */
10108 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
10109                                 hda_nid_t nid, int pin_type, int dac_idx)
10110 {
10111         /* set as output */
10112         snd_hda_codec_write(codec, nid, 0,
10113                                 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
10114         snd_hda_codec_write(codec, nid, 0,
10115                                 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
10116 }
10117
10118 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
10119 {
10120         struct alc_spec *spec = codec->spec;
10121         int i;
10122
10123         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
10124         for (i = 0; i <= HDA_SIDE; i++) {
10125                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
10126                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
10127                 if (nid)
10128                         alc861vd_auto_set_output_and_unmute(codec, nid,
10129                                                             pin_type, i);
10130         }
10131 }
10132
10133
10134 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
10135 {
10136         struct alc_spec *spec = codec->spec;
10137         hda_nid_t pin;
10138
10139         pin = spec->autocfg.hp_pins[0];
10140         if (pin) /* connect to front and  use dac 0 */
10141                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
10142 }
10143
10144 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
10145 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
10146
10147 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
10148 {
10149         struct alc_spec *spec = codec->spec;
10150         int i;
10151
10152         for (i = 0; i < AUTO_PIN_LAST; i++) {
10153                 hda_nid_t nid = spec->autocfg.input_pins[i];
10154                 if (alc861vd_is_input_pin(nid)) {
10155                         snd_hda_codec_write(codec, nid, 0,
10156                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
10157                                         i <= AUTO_PIN_FRONT_MIC ?
10158                                                         PIN_VREF80 : PIN_IN);
10159                         if (nid != ALC861VD_PIN_CD_NID)
10160                                 snd_hda_codec_write(codec, nid, 0,
10161                                                 AC_VERB_SET_AMP_GAIN_MUTE,
10162                                                 AMP_OUT_MUTE);
10163                 }
10164         }
10165 }
10166
10167 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
10168 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
10169
10170 /* add playback controls from the parsed DAC table */
10171 /* Based on ALC880 version. But ALC861VD has separate,
10172  * different NIDs for mute/unmute switch and volume control */
10173 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
10174                                              const struct auto_pin_cfg *cfg)
10175 {
10176         char name[32];
10177         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
10178         hda_nid_t nid_v, nid_s;
10179         int i, err;
10180
10181         for (i = 0; i < cfg->line_outs; i++) {
10182                 if (!spec->multiout.dac_nids[i])
10183                         continue;
10184                 nid_v = alc861vd_idx_to_mixer_vol(
10185                                 alc880_dac_to_idx(
10186                                         spec->multiout.dac_nids[i]));
10187                 nid_s = alc861vd_idx_to_mixer_switch(
10188                                 alc880_dac_to_idx(
10189                                         spec->multiout.dac_nids[i]));
10190
10191                 if (i == 2) {
10192                         /* Center/LFE */
10193                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10194                                           "Center Playback Volume",
10195                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
10196                                                               HDA_OUTPUT));
10197                         if (err < 0)
10198                                 return err;
10199                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10200                                           "LFE Playback Volume",
10201                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
10202                                                               HDA_OUTPUT));
10203                         if (err < 0)
10204                                 return err;
10205                         err = add_control(spec, ALC_CTL_BIND_MUTE,
10206                                           "Center Playback Switch",
10207                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
10208                                                               HDA_INPUT));
10209                         if (err < 0)
10210                                 return err;
10211                         err = add_control(spec, ALC_CTL_BIND_MUTE,
10212                                           "LFE Playback Switch",
10213                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
10214                                                               HDA_INPUT));
10215                         if (err < 0)
10216                                 return err;
10217                 } else {
10218                         sprintf(name, "%s Playback Volume", chname[i]);
10219                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
10220                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
10221                                                               HDA_OUTPUT));
10222                         if (err < 0)
10223                                 return err;
10224                         sprintf(name, "%s Playback Switch", chname[i]);
10225                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
10226                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
10227                                                               HDA_INPUT));
10228                         if (err < 0)
10229                                 return err;
10230                 }
10231         }
10232         return 0;
10233 }
10234
10235 /* add playback controls for speaker and HP outputs */
10236 /* Based on ALC880 version. But ALC861VD has separate,
10237  * different NIDs for mute/unmute switch and volume control */
10238 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
10239                                         hda_nid_t pin, const char *pfx)
10240 {
10241         hda_nid_t nid_v, nid_s;
10242         int err;
10243         char name[32];
10244
10245         if (!pin)
10246                 return 0;
10247
10248         if (alc880_is_fixed_pin(pin)) {
10249                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
10250                 /* specify the DAC as the extra output */
10251                 if (!spec->multiout.hp_nid)
10252                         spec->multiout.hp_nid = nid_v;
10253                 else
10254                         spec->multiout.extra_out_nid[0] = nid_v;
10255                 /* control HP volume/switch on the output mixer amp */
10256                 nid_v = alc861vd_idx_to_mixer_vol(
10257                                 alc880_fixed_pin_idx(pin));
10258                 nid_s = alc861vd_idx_to_mixer_switch(
10259                                 alc880_fixed_pin_idx(pin));
10260
10261                 sprintf(name, "%s Playback Volume", pfx);
10262                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
10263                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
10264                 if (err < 0)
10265                         return err;
10266                 sprintf(name, "%s Playback Switch", pfx);
10267                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
10268                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
10269                 if (err < 0)
10270                         return err;
10271         } else if (alc880_is_multi_pin(pin)) {
10272                 /* set manual connection */
10273                 /* we have only a switch on HP-out PIN */
10274                 sprintf(name, "%s Playback Switch", pfx);
10275                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
10276                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
10277                 if (err < 0)
10278                         return err;
10279         }
10280         return 0;
10281 }
10282
10283 /* parse the BIOS configuration and set up the alc_spec
10284  * return 1 if successful, 0 if the proper config is not found,
10285  * or a negative error code
10286  * Based on ALC880 version - had to change it to override
10287  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
10288 static int alc861vd_parse_auto_config(struct hda_codec *codec)
10289 {
10290         struct alc_spec *spec = codec->spec;
10291         int err;
10292         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
10293
10294         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10295                                            alc861vd_ignore);
10296         if (err < 0)
10297                 return err;
10298         if (!spec->autocfg.line_outs)
10299                 return 0; /* can't find valid BIOS pin config */
10300
10301         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
10302         if (err < 0)
10303                 return err;
10304         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
10305         if (err < 0)
10306                 return err;
10307         err = alc861vd_auto_create_extra_out(spec,
10308                                              spec->autocfg.speaker_pins[0],
10309                                              "Speaker");
10310         if (err < 0)
10311                 return err;
10312         err = alc861vd_auto_create_extra_out(spec,
10313                                              spec->autocfg.hp_pins[0],
10314                                              "Headphone");
10315         if (err < 0)
10316                 return err;
10317         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
10318         if (err < 0)
10319                 return err;
10320
10321         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10322
10323         if (spec->autocfg.dig_out_pin)
10324                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
10325
10326         if (spec->kctl_alloc)
10327                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10328
10329         spec->init_verbs[spec->num_init_verbs++]
10330                 = alc861vd_volume_init_verbs;
10331
10332         spec->num_mux_defs = 1;
10333         spec->input_mux = &spec->private_imux;
10334
10335         return 1;
10336 }
10337
10338 /* additional initialization for auto-configuration model */
10339 static void alc861vd_auto_init(struct hda_codec *codec)
10340 {
10341         alc861vd_auto_init_multi_out(codec);
10342         alc861vd_auto_init_hp_out(codec);
10343         alc861vd_auto_init_analog_input(codec);
10344 }
10345
10346 static int patch_alc861vd(struct hda_codec *codec)
10347 {
10348         struct alc_spec *spec;
10349         int err, board_config;
10350
10351         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10352         if (spec == NULL)
10353                 return -ENOMEM;
10354
10355         codec->spec = spec;
10356
10357         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
10358                                                   alc861vd_models,
10359                                                   alc861vd_cfg_tbl);
10360
10361         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
10362                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
10363                         "ALC861VD, trying auto-probe from BIOS...\n");
10364                 board_config = ALC861VD_AUTO;
10365         }
10366
10367         if (board_config == ALC861VD_AUTO) {
10368                 /* automatic parse from the BIOS config */
10369                 err = alc861vd_parse_auto_config(codec);
10370                 if (err < 0) {
10371                         alc_free(codec);
10372                         return err;
10373                 } else if (!err) {
10374                         printk(KERN_INFO
10375                                "hda_codec: Cannot set up configuration "
10376                                "from BIOS.  Using base mode...\n");
10377                         board_config = ALC861VD_3ST;
10378                 }
10379         }
10380
10381         if (board_config != ALC861VD_AUTO)
10382                 setup_preset(spec, &alc861vd_presets[board_config]);
10383
10384         spec->stream_name_analog = "ALC861VD Analog";
10385         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
10386         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
10387
10388         spec->stream_name_digital = "ALC861VD Digital";
10389         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
10390         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
10391
10392         spec->adc_nids = alc861vd_adc_nids;
10393         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
10394
10395         spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
10396         spec->num_mixers++;
10397
10398         codec->patch_ops = alc_patch_ops;
10399
10400         if (board_config == ALC861VD_AUTO)
10401                 spec->init_hook = alc861vd_auto_init;
10402
10403         return 0;
10404 }
10405
10406 /*
10407  * ALC662 support
10408  *
10409  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
10410  * configuration.  Each pin widget can choose any input DACs and a mixer.
10411  * Each ADC is connected from a mixer of all inputs.  This makes possible
10412  * 6-channel independent captures.
10413  *
10414  * In addition, an independent DAC for the multi-playback (not used in this
10415  * driver yet).
10416  */
10417 #define ALC662_DIGOUT_NID       0x06
10418 #define ALC662_DIGIN_NID        0x0a
10419
10420 static hda_nid_t alc662_dac_nids[4] = {
10421         /* front, rear, clfe, rear_surr */
10422         0x02, 0x03, 0x04
10423 };
10424
10425 static hda_nid_t alc662_adc_nids[1] = {
10426         /* ADC1-2 */
10427         0x09,
10428 };
10429 /* input MUX */
10430 /* FIXME: should be a matrix-type input source selection */
10431
10432 static struct hda_input_mux alc662_capture_source = {
10433         .num_items = 4,
10434         .items = {
10435                 { "Mic", 0x0 },
10436                 { "Front Mic", 0x1 },
10437                 { "Line", 0x2 },
10438                 { "CD", 0x4 },
10439         },
10440 };
10441
10442 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
10443         .num_items = 2,
10444         .items = {
10445                 { "Mic", 0x1 },
10446                 { "Line", 0x2 },
10447         },
10448 };
10449 #define alc662_mux_enum_info alc_mux_enum_info
10450 #define alc662_mux_enum_get alc_mux_enum_get
10451
10452 static int alc662_mux_enum_put(struct snd_kcontrol *kcontrol,
10453                                struct snd_ctl_elem_value *ucontrol)
10454 {
10455         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10456         struct alc_spec *spec = codec->spec;
10457         const struct hda_input_mux *imux = spec->input_mux;
10458         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
10459         static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
10460         hda_nid_t nid = capture_mixers[adc_idx];
10461         unsigned int *cur_val = &spec->cur_mux[adc_idx];
10462         unsigned int i, idx;
10463
10464         idx = ucontrol->value.enumerated.item[0];
10465         if (idx >= imux->num_items)
10466                 idx = imux->num_items - 1;
10467         if (*cur_val == idx && !codec->in_resume)
10468                 return 0;
10469         for (i = 0; i < imux->num_items; i++) {
10470                 unsigned int v = (i == idx) ? 0x7000 : 0x7080;
10471                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
10472                                     v | (imux->items[i].index << 8));
10473         }
10474         *cur_val = idx;
10475         return 1;
10476 }
10477 /*
10478  * 2ch mode
10479  */
10480 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
10481         { 2, NULL }
10482 };
10483
10484 /*
10485  * 2ch mode
10486  */
10487 static struct hda_verb alc662_3ST_ch2_init[] = {
10488         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
10489         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
10490         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
10491         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
10492         { } /* end */
10493 };
10494
10495 /*
10496  * 6ch mode
10497  */
10498 static struct hda_verb alc662_3ST_ch6_init[] = {
10499         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10500         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10501         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
10502         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10503         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10504         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
10505         { } /* end */
10506 };
10507
10508 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
10509         { 2, alc662_3ST_ch2_init },
10510         { 6, alc662_3ST_ch6_init },
10511 };
10512
10513 /*
10514  * 2ch mode
10515  */
10516 static struct hda_verb alc662_sixstack_ch6_init[] = {
10517         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10518         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
10519         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10520         { } /* end */
10521 };
10522
10523 /*
10524  * 6ch mode
10525  */
10526 static struct hda_verb alc662_sixstack_ch8_init[] = {
10527         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10528         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10529         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10530         { } /* end */
10531 };
10532
10533 static struct hda_channel_mode alc662_5stack_modes[2] = {
10534         { 2, alc662_sixstack_ch6_init },
10535         { 6, alc662_sixstack_ch8_init },
10536 };
10537
10538 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
10539  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
10540  */
10541
10542 static struct snd_kcontrol_new alc662_base_mixer[] = {
10543         /* output mixer control */
10544         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10545         HDA_CODEC_MUTE("Front Playback Switch", 0x02, 0x0, HDA_OUTPUT),
10546         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10547         HDA_CODEC_MUTE("Surround Playback Switch", 0x03, 0x0, HDA_OUTPUT),
10548         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
10549         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
10550         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
10551         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
10552         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10553
10554         /*Input mixer control */
10555         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
10556         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
10557         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
10558         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
10559         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
10560         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
10561         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
10562         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
10563
10564         /* Capture mixer control */
10565         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
10566         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
10567         {
10568                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10569                 .name = "Capture Source",
10570                 .count = 1,
10571                 .info = alc_mux_enum_info,
10572                 .get = alc_mux_enum_get,
10573                 .put = alc_mux_enum_put,
10574         },
10575         { } /* end */
10576 };
10577
10578 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
10579         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10580         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
10581         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10582         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10583         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10584         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10585         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10586         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10587         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10588         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10589         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10590         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
10591         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
10592         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
10593         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
10594         {
10595                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10596                 /* .name = "Capture Source", */
10597                 .name = "Input Source",
10598                 .count = 1,
10599                 .info = alc662_mux_enum_info,
10600                 .get = alc662_mux_enum_get,
10601                 .put = alc662_mux_enum_put,
10602         },
10603         { } /* end */
10604 };
10605
10606 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
10607         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10608         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
10609         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10610         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
10611         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
10612         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
10613         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
10614         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
10615         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10616         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10617         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10618         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10619         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10620         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10621         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10622         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10623         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10624         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
10625         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
10626         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
10627         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
10628         {
10629                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10630                 /* .name = "Capture Source", */
10631                 .name = "Input Source",
10632                 .count = 1,
10633                 .info = alc662_mux_enum_info,
10634                 .get = alc662_mux_enum_get,
10635                 .put = alc662_mux_enum_put,
10636         },
10637         { } /* end */
10638 };
10639
10640 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
10641         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
10642         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
10643         HDA_CODEC_VOLUME("iSpeaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
10644         HDA_BIND_MUTE("iSpeaker Playback Switch", 0x03, 2, HDA_INPUT),
10645         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10646         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10647         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10648         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10649         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10650         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
10651         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
10652         {
10653                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10654                 /* .name = "Capture Source", */
10655                 .name = "Input Source",
10656                 .count = 1,
10657                 .info = alc662_mux_enum_info,
10658                 .get = alc662_mux_enum_get,
10659                 .put = alc662_mux_enum_put,
10660         },
10661         { } /* end */
10662 };
10663
10664 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
10665         {
10666                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10667                 .name = "Channel Mode",
10668                 .info = alc_ch_mode_info,
10669                 .get = alc_ch_mode_get,
10670                 .put = alc_ch_mode_put,
10671         },
10672         { } /* end */
10673 };
10674
10675 static struct hda_verb alc662_init_verbs[] = {
10676         /* ADC: mute amp left and right */
10677         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10678         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10679         /* Front mixer: unmute input/output amp left and right (volume = 0) */
10680
10681         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10682         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10683         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10684         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
10685         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
10686
10687         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10688         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10689         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10690         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10691         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10692         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10693
10694         /* Front Pin: output 0 (0x0c) */
10695         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10696         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10697
10698         /* Rear Pin: output 1 (0x0d) */
10699         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10700         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10701
10702         /* CLFE Pin: output 2 (0x0e) */
10703         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10704         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10705
10706         /* Mic (rear) pin: input vref at 80% */
10707         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10708         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10709         /* Front Mic pin: input vref at 80% */
10710         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10711         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10712         /* Line In pin: input */
10713         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10714         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10715         /* Line-2 In: Headphone output (output 0 - 0x0c) */
10716         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10717         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10718         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10719         /* CD pin widget for input */
10720         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10721
10722         /* FIXME: use matrix-type input source selection */
10723         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10724         /* Input mixer */
10725         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10726         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10727         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10728         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
10729         { }
10730 };
10731
10732 static struct hda_verb alc662_sue_init_verbs[] = {
10733         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
10734         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
10735         {}
10736 };
10737
10738 /*
10739  * generic initialization of ADC, input mixers and output mixers
10740  */
10741 static struct hda_verb alc662_auto_init_verbs[] = {
10742         /*
10743          * Unmute ADC and set the default input to mic-in
10744          */
10745         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10746         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10747
10748         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10749          * mixer widget
10750          * Note: PASD motherboards uses the Line In 2 as the input for front
10751          * panel mic (mic 2)
10752          */
10753         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10754         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10755         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10756         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10757         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
10758         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
10759
10760         /*
10761          * Set up output mixers (0x0c - 0x0f)
10762          */
10763         /* set vol=0 to output mixers */
10764         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10765         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10766         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10767
10768         /* set up input amps for analog loopback */
10769         /* Amp Indices: DAC = 0, mixer = 1 */
10770         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10771         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10772         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10773         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10774         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10775         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10776
10777
10778         /* FIXME: use matrix-type input source selection */
10779         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10780         /* Input mixer */
10781         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10782         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10783         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
10784         /*{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},*/
10785         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
10786
10787         { }
10788 };
10789
10790 /* capture mixer elements */
10791 static struct snd_kcontrol_new alc662_capture_mixer[] = {
10792         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
10793         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
10794         {
10795                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10796                 /* The multiple "Capture Source" controls confuse alsamixer
10797                  * So call somewhat different..
10798                  * FIXME: the controls appear in the "playback" view!
10799                  */
10800                 /* .name = "Capture Source", */
10801                 .name = "Input Source",
10802                 .count = 1,
10803                 .info = alc882_mux_enum_info,
10804                 .get = alc882_mux_enum_get,
10805                 .put = alc882_mux_enum_put,
10806         },
10807         { } /* end */
10808 };
10809
10810 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
10811 {
10812         unsigned int present;
10813         unsigned char bits;
10814
10815         present = snd_hda_codec_read(codec, 0x14, 0,
10816                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10817         bits = present ? 0x80 : 0;
10818         snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
10819                                  0x80, bits);
10820         snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
10821                                  0x80, bits);
10822 }
10823
10824 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
10825 {
10826         unsigned int present;
10827         unsigned char bits;
10828
10829         present = snd_hda_codec_read(codec, 0x1b, 0,
10830                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10831         bits = present ? 0x80 : 0;
10832         snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
10833                                  0x80, bits);
10834         snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
10835                                  0x80, bits);
10836         snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
10837                                  0x80, bits);
10838         snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
10839                                  0x80, bits);
10840 }
10841
10842 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
10843                                            unsigned int res)
10844 {
10845         if ((res >> 26) == ALC880_HP_EVENT)
10846                 alc662_lenovo_101e_all_automute(codec);
10847         if ((res >> 26) == ALC880_FRONT_EVENT)
10848                 alc662_lenovo_101e_ispeaker_automute(codec);
10849 }
10850
10851
10852 /* pcm configuration: identiacal with ALC880 */
10853 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
10854 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
10855 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
10856 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
10857
10858 /*
10859  * configuration and preset
10860  */
10861 static const char *alc662_models[ALC662_MODEL_LAST] = {
10862         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
10863         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
10864         [ALC662_3ST_6ch]        = "3stack-6ch",
10865         [ALC662_5ST_DIG]        = "6stack-dig",
10866         [ALC662_LENOVO_101E]    = "lenovo-101e",
10867         [ALC662_AUTO]           = "auto",
10868 };
10869
10870 static struct snd_pci_quirk alc662_cfg_tbl[] = {
10871         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
10872         {}
10873 };
10874
10875 static struct alc_config_preset alc662_presets[] = {
10876         [ALC662_3ST_2ch_DIG] = {
10877                 .mixers = { alc662_3ST_2ch_mixer },
10878                 .init_verbs = { alc662_init_verbs },
10879                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
10880                 .dac_nids = alc662_dac_nids,
10881                 .dig_out_nid = ALC662_DIGOUT_NID,
10882                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
10883                 .adc_nids = alc662_adc_nids,
10884                 .dig_in_nid = ALC662_DIGIN_NID,
10885                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
10886                 .channel_mode = alc662_3ST_2ch_modes,
10887                 .input_mux = &alc662_capture_source,
10888         },
10889         [ALC662_3ST_6ch_DIG] = {
10890                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
10891                 .init_verbs = { alc662_init_verbs },
10892                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
10893                 .dac_nids = alc662_dac_nids,
10894                 .dig_out_nid = ALC662_DIGOUT_NID,
10895                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
10896                 .adc_nids = alc662_adc_nids,
10897                 .dig_in_nid = ALC662_DIGIN_NID,
10898                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
10899                 .channel_mode = alc662_3ST_6ch_modes,
10900                 .need_dac_fix = 1,
10901                 .input_mux = &alc662_capture_source,
10902         },
10903         [ALC662_3ST_6ch] = {
10904                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
10905                 .init_verbs = { alc662_init_verbs },
10906                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
10907                 .dac_nids = alc662_dac_nids,
10908                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
10909                 .adc_nids = alc662_adc_nids,
10910                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
10911                 .channel_mode = alc662_3ST_6ch_modes,
10912                 .need_dac_fix = 1,
10913                 .input_mux = &alc662_capture_source,
10914         },
10915         [ALC662_5ST_DIG] = {
10916                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
10917                 .init_verbs = { alc662_init_verbs },
10918                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
10919                 .dac_nids = alc662_dac_nids,
10920                 .dig_out_nid = ALC662_DIGOUT_NID,
10921                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
10922                 .adc_nids = alc662_adc_nids,
10923                 .dig_in_nid = ALC662_DIGIN_NID,
10924                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
10925                 .channel_mode = alc662_5stack_modes,
10926                 .input_mux = &alc662_capture_source,
10927         },
10928         [ALC662_LENOVO_101E] = {
10929                 .mixers = { alc662_lenovo_101e_mixer },
10930                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
10931                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
10932                 .dac_nids = alc662_dac_nids,
10933                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
10934                 .adc_nids = alc662_adc_nids,
10935                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
10936                 .channel_mode = alc662_3ST_2ch_modes,
10937                 .input_mux = &alc662_lenovo_101e_capture_source,
10938                 .unsol_event = alc662_lenovo_101e_unsol_event,
10939                 .init_hook = alc662_lenovo_101e_all_automute,
10940         },
10941
10942 };
10943
10944
10945 /*
10946  * BIOS auto configuration
10947  */
10948
10949 /* add playback controls from the parsed DAC table */
10950 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
10951                                              const struct auto_pin_cfg *cfg)
10952 {
10953         char name[32];
10954         static const char *chname[4] = {
10955                 "Front", "Surround", NULL /*CLFE*/, "Side"
10956         };
10957         hda_nid_t nid;
10958         int i, err;
10959
10960         for (i = 0; i < cfg->line_outs; i++) {
10961                 if (!spec->multiout.dac_nids[i])
10962                         continue;
10963                 nid = alc880_idx_to_dac(i);
10964                 if (i == 2) {
10965                         /* Center/LFE */
10966                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10967                                           "Center Playback Volume",
10968                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
10969                                                               HDA_OUTPUT));
10970                         if (err < 0)
10971                                 return err;
10972                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10973                                           "LFE Playback Volume",
10974                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10975                                                               HDA_OUTPUT));
10976                         if (err < 0)
10977                                 return err;
10978                         err = add_control(spec, ALC_CTL_BIND_MUTE,
10979                                           "Center Playback Switch",
10980                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
10981                                                               HDA_INPUT));
10982                         if (err < 0)
10983                                 return err;
10984                         err = add_control(spec, ALC_CTL_BIND_MUTE,
10985                                           "LFE Playback Switch",
10986                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
10987                                                               HDA_INPUT));
10988                         if (err < 0)
10989                                 return err;
10990                 } else {
10991                         sprintf(name, "%s Playback Volume", chname[i]);
10992                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
10993                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10994                                                               HDA_OUTPUT));
10995                         if (err < 0)
10996                                 return err;
10997                         sprintf(name, "%s Playback Switch", chname[i]);
10998                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
10999                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
11000                                                               HDA_INPUT));
11001                         if (err < 0)
11002                                 return err;
11003                 }
11004         }
11005         return 0;
11006 }
11007
11008 /* add playback controls for speaker and HP outputs */
11009 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
11010                                         const char *pfx)
11011 {
11012         hda_nid_t nid;
11013         int err;
11014         char name[32];
11015
11016         if (!pin)
11017                 return 0;
11018
11019         if (alc880_is_fixed_pin(pin)) {
11020                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
11021                 /* printk("DAC nid=%x\n",nid); */
11022                 /* specify the DAC as the extra output */
11023                 if (!spec->multiout.hp_nid)
11024                         spec->multiout.hp_nid = nid;
11025                 else
11026                         spec->multiout.extra_out_nid[0] = nid;
11027                 /* control HP volume/switch on the output mixer amp */
11028                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
11029                 sprintf(name, "%s Playback Volume", pfx);
11030                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11031                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
11032                 if (err < 0)
11033                         return err;
11034                 sprintf(name, "%s Playback Switch", pfx);
11035                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
11036                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
11037                 if (err < 0)
11038                         return err;
11039         } else if (alc880_is_multi_pin(pin)) {
11040                 /* set manual connection */
11041                 /* we have only a switch on HP-out PIN */
11042                 sprintf(name, "%s Playback Switch", pfx);
11043                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11044                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
11045                 if (err < 0)
11046                         return err;
11047         }
11048         return 0;
11049 }
11050
11051 /* create playback/capture controls for input pins */
11052 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
11053                                                 const struct auto_pin_cfg *cfg)
11054 {
11055         struct hda_input_mux *imux = &spec->private_imux;
11056         int i, err, idx;
11057
11058         for (i = 0; i < AUTO_PIN_LAST; i++) {
11059                 if (alc880_is_input_pin(cfg->input_pins[i])) {
11060                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
11061                         err = new_analog_input(spec, cfg->input_pins[i],
11062                                                auto_pin_cfg_labels[i],
11063                                                idx, 0x0b);
11064                         if (err < 0)
11065                                 return err;
11066                         imux->items[imux->num_items].label =
11067                                 auto_pin_cfg_labels[i];
11068                         imux->items[imux->num_items].index =
11069                                 alc880_input_pin_idx(cfg->input_pins[i]);
11070                         imux->num_items++;
11071                 }
11072         }
11073         return 0;
11074 }
11075
11076 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
11077                                               hda_nid_t nid, int pin_type,
11078                                               int dac_idx)
11079 {
11080         /* set as output */
11081         snd_hda_codec_write(codec, nid, 0,
11082                             AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
11083         snd_hda_codec_write(codec, nid, 0,
11084                             AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
11085         /* need the manual connection? */
11086         if (alc880_is_multi_pin(nid)) {
11087                 struct alc_spec *spec = codec->spec;
11088                 int idx = alc880_multi_pin_idx(nid);
11089                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
11090                                     AC_VERB_SET_CONNECT_SEL,
11091                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
11092         }
11093 }
11094
11095 static void alc662_auto_init_multi_out(struct hda_codec *codec)
11096 {
11097         struct alc_spec *spec = codec->spec;
11098         int i;
11099
11100         for (i = 0; i <= HDA_SIDE; i++) {
11101                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
11102                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
11103                 if (nid)
11104                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
11105                                                           i);
11106         }
11107 }
11108
11109 static void alc662_auto_init_hp_out(struct hda_codec *codec)
11110 {
11111         struct alc_spec *spec = codec->spec;
11112         hda_nid_t pin;
11113
11114         pin = spec->autocfg.hp_pins[0];
11115         if (pin) /* connect to front */
11116                 /* use dac 0 */
11117                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
11118 }
11119
11120 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
11121 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
11122
11123 static void alc662_auto_init_analog_input(struct hda_codec *codec)
11124 {
11125         struct alc_spec *spec = codec->spec;
11126         int i;
11127
11128         for (i = 0; i < AUTO_PIN_LAST; i++) {
11129                 hda_nid_t nid = spec->autocfg.input_pins[i];
11130                 if (alc662_is_input_pin(nid)) {
11131                         snd_hda_codec_write(codec, nid, 0,
11132                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
11133                                             (i <= AUTO_PIN_FRONT_MIC ?
11134                                              PIN_VREF80 : PIN_IN));
11135                         if (nid != ALC662_PIN_CD_NID)
11136                                 snd_hda_codec_write(codec, nid, 0,
11137                                                     AC_VERB_SET_AMP_GAIN_MUTE,
11138                                                     AMP_OUT_MUTE);
11139                 }
11140         }
11141 }
11142
11143 static int alc662_parse_auto_config(struct hda_codec *codec)
11144 {
11145         struct alc_spec *spec = codec->spec;
11146         int err;
11147         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
11148
11149         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11150                                            alc662_ignore);
11151         if (err < 0)
11152                 return err;
11153         if (!spec->autocfg.line_outs)
11154                 return 0; /* can't find valid BIOS pin config */
11155
11156         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
11157         if (err < 0)
11158                 return err;
11159         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
11160         if (err < 0)
11161                 return err;
11162         err = alc662_auto_create_extra_out(spec,
11163                                            spec->autocfg.speaker_pins[0],
11164                                            "Speaker");
11165         if (err < 0)
11166                 return err;
11167         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
11168                                            "Headphone");
11169         if (err < 0)
11170                 return err;
11171         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
11172         if (err < 0)
11173                 return err;
11174
11175         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11176
11177         if (spec->autocfg.dig_out_pin)
11178                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
11179
11180         if (spec->kctl_alloc)
11181                 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
11182
11183         spec->num_mux_defs = 1;
11184         spec->input_mux = &spec->private_imux;
11185         
11186         spec->init_verbs[spec->num_init_verbs++] = alc662_auto_init_verbs;
11187         spec->mixers[spec->num_mixers] = alc662_capture_mixer;
11188         spec->num_mixers++;
11189         return 1;
11190 }
11191
11192 /* additional initialization for auto-configuration model */
11193 static void alc662_auto_init(struct hda_codec *codec)
11194 {
11195         alc662_auto_init_multi_out(codec);
11196         alc662_auto_init_hp_out(codec);
11197         alc662_auto_init_analog_input(codec);
11198 }
11199
11200 static int patch_alc662(struct hda_codec *codec)
11201 {
11202         struct alc_spec *spec;
11203         int err, board_config;
11204
11205         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11206         if (!spec)
11207                 return -ENOMEM;
11208
11209         codec->spec = spec;
11210
11211         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
11212                                                   alc662_models,
11213                                                   alc662_cfg_tbl);
11214         if (board_config < 0) {
11215                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
11216                        "trying auto-probe from BIOS...\n");
11217                 board_config = ALC662_AUTO;
11218         }
11219
11220         if (board_config == ALC662_AUTO) {
11221                 /* automatic parse from the BIOS config */
11222                 err = alc662_parse_auto_config(codec);
11223                 if (err < 0) {
11224                         alc_free(codec);
11225                         return err;
11226                 } else if (!err) {
11227                         printk(KERN_INFO
11228                                "hda_codec: Cannot set up configuration "
11229                                "from BIOS.  Using base mode...\n");
11230                         board_config = ALC662_3ST_2ch_DIG;
11231                 }
11232         }
11233
11234         if (board_config != ALC662_AUTO)
11235                 setup_preset(spec, &alc662_presets[board_config]);
11236
11237         spec->stream_name_analog = "ALC662 Analog";
11238         spec->stream_analog_playback = &alc662_pcm_analog_playback;
11239         spec->stream_analog_capture = &alc662_pcm_analog_capture;
11240
11241         spec->stream_name_digital = "ALC662 Digital";
11242         spec->stream_digital_playback = &alc662_pcm_digital_playback;
11243         spec->stream_digital_capture = &alc662_pcm_digital_capture;
11244
11245         if (!spec->adc_nids && spec->input_mux) {
11246                 spec->adc_nids = alc662_adc_nids;
11247                 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
11248         }
11249
11250         codec->patch_ops = alc_patch_ops;
11251         if (board_config == ALC662_AUTO)
11252                 spec->init_hook = alc662_auto_init;
11253
11254         return 0;
11255 }
11256
11257 /*
11258  * patch entries
11259  */
11260 struct hda_codec_preset snd_hda_preset_realtek[] = {
11261         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
11262         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
11263         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
11264         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
11265           .patch = patch_alc861 },
11266         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
11267         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
11268         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
11269         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
11270           .patch = patch_alc883 },
11271         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
11272           .patch = patch_alc662 },
11273         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
11274         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
11275         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
11276         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
11277         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
11278         {} /* terminator */
11279 };