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